From 91b1fff21928815fb0b5ec3143ededde5711611c Mon Sep 17 00:00:00 2001 From: Paul Johnston Date: Mon, 6 Oct 2025 14:16:43 -0600 Subject: [PATCH 1/3] Fix closure-js output --- BUILD.bazel | 95 +++++++++++++------------------------- binary/bytesource_alias.js | 9 ++++ binary/encoder.js | 9 ++++ binary/utils.js | 1 + generator/js_generator.cc | 3 +- internal_public.js | 2 +- message.js | 4 +- 7 files changed, 56 insertions(+), 67 deletions(-) create mode 100644 binary/bytesource_alias.js diff --git a/BUILD.bazel b/BUILD.bazel index 62355ce..f989623 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,10 +2,6 @@ # # See also code generation logic under generator/ -load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix") -load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip") -load("//:protobuf_javascript_release.bzl", "package_naming") - config_setting( name = "x64_x86_windows", values = {"cpu": "x64_x86_windows"}, @@ -31,65 +27,38 @@ config_setting( values = {"cpu": "darwin_x86_64"}, ) -package_naming( - name = "protobuf_javascript_pkg_naming", - platform = select({ - ":k8": "linux-x86_64", # currently the only supported build type in Github Actions - ":x64_x86_windows": "win32", - ":x64_windows": "win64", - ":darwin_arm64": "osx-aarch_64", - ":darwin_x86_64": "osx-x86_64", - "//conditions:default": "" # continues with current behavior when no --cpu is specified allowing existing internal builds to function - }) -) - -pkg_files( - name = "plugin_files", - srcs = ["//generator:protoc-gen-js"], - attributes = pkg_attributes(mode = "0555"), - prefix = "bin/", -) - -pkg_files( - name = "dist_files", - srcs = glob([ - "google/protobuf/*.js", - "google/protobuf/compiler/*.js" - ]) + [ - "google-protobuf.js", - "package.json", - "README.md", - "LICENSE.md", - "LICENSE-asserts.md", - ], - strip_prefix = strip_prefix.from_root(""), -) - -pkg_tar( - name = "dist_tar", - srcs = [ - ":dist_files", - ":plugin_files", - ], - extension = "tar.gz", - package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz", - package_variables = ":protobuf_javascript_pkg_naming", -) - -pkg_zip( - name = "dist_zip", - srcs = [ - ":dist_files", - ":plugin_files", - ], - package_file_name = "protobuf-javascript-{version}-{platform}.zip", - package_variables = ":protobuf_javascript_pkg_naming", -) - filegroup( - name = "dist_all", + name = "javascript", srcs = [ - ":dist_tar", - ":dist_zip", - ] + "asserts.js", + "binary/any_field_type.js", + "binary/arith.js", + "binary/binary_constants.js", + "binary/bytesource.js", + "binary/bytesource_alias.js", + "binary/decoder.js", + "binary/decoder_alias.js", + "binary/encoder.js", + "binary/encoder_alias.js", + "binary/errors.js", + "binary/internal_buffer.js", + "binary/reader.js", + "binary/reader_alias.js", + "binary/repeated_field_type.js", + "binary/scalar_field_type.js", + "binary/test_utils.js", + "binary/utf8.js", + "binary/utils.js", + "binary/writer.js", + "binary/writer_alias.js", + "bytestring.js", + "debug.js", + "internal_bytes.js", + "internal_options.js", + "internal_public.js", + "map.js", + "message.js", + "unsafe_bytestring.js", + ], + visibility = ["//visibility:public"], ) diff --git a/binary/bytesource_alias.js b/binary/bytesource_alias.js new file mode 100644 index 0000000..2815ee5 --- /dev/null +++ b/binary/bytesource_alias.js @@ -0,0 +1,9 @@ +/** + * @fileoverview Legacy alias for the old namespace used by encoder.js + */ +goog.module('jspb.ByteSource'); +goog.module.declareLegacyNamespace(); + +const { ByteSource } = goog.require('jspb.binary.bytesource'); + +exports = ByteSource; diff --git a/binary/encoder.js b/binary/encoder.js index 216bd14..e1d787a 100755 --- a/binary/encoder.js +++ b/binary/encoder.js @@ -191,6 +191,15 @@ class BinaryEncoder { this.writeSplitVarint64(utils.getSplit64Low(), utils.getSplit64High()); } + /** + * Encodes a BigInt into its wire-format, zigzag-encoded varint + * representation and stores it in the buffer. + * @param {bigint} value The BigInt to convert. + */ + writeZigzagVarint64BigInt(value) { + this.writeZigzagVarint64String(value.toString()); + } + /** * Encodes a JavaScript decimal string into its wire-format, zigzag-encoded * varint representation and stores it in the buffer. Integers not diff --git a/binary/utils.js b/binary/utils.js index 6664fe2..088015a 100755 --- a/binary/utils.js +++ b/binary/utils.js @@ -12,6 +12,7 @@ goog.module.declareLegacyNamespace(); const BinaryConstants = goog.require('jspb.BinaryConstants'); const { assert } = goog.require('goog.asserts'); const { isBigIntAvailable } = goog.require('jspb.internal_options'); +const { ByteSource } = goog.require('jspb.binary.bytesource'); const { ByteString } = goog.require('jspb.bytestring'); const { decodeStringToUint8Array } = goog.require('goog.crypt.base64'); const { unsafeUint8ArrayFromByteString } = goog.require('jspb.unsafe_bytestring'); diff --git a/generator/js_generator.cc b/generator/js_generator.cc index a1619fa..7ba8bf0 100644 --- a/generator/js_generator.cc +++ b/generator/js_generator.cc @@ -1855,6 +1855,7 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options, required->insert("jspb.internal.public_for_gencode"); required->insert("jspb.BinaryReader"); required->insert("jspb.BinaryWriter"); + required->insert("jspb.binary.bytesource"); } if (require_extension) { required->insert("jspb.ExtensionFieldBinaryInfo"); @@ -3016,7 +3017,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, printer->Print( "/**\n" " * Deserializes binary data (in protobuf wire format).\n" - " * @param {jspb.ByteSource} bytes The bytes to deserialize.\n" + " * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize.\n" " * @return {!$class$}\n" " */\n" "$class$.deserializeBinary = function(bytes) {\n" diff --git a/internal_public.js b/internal_public.js index cf4a61d..03d52f0 100644 --- a/internal_public.js +++ b/internal_public.js @@ -12,7 +12,7 @@ goog.module.declareLegacyNamespace(); const asserts = goog.require('goog.asserts'); const { BinaryReader } = goog.require('jspb.binary.reader'); const { BinaryWriter } = goog.requireType('jspb.binary.writer'); -const {Map: JspbMap} = goog.requireType('jspb.Map'); +const JspbMap = goog.requireType('jspb.Map'); /** * Write this Map field in wire format to a BinaryWriter, using the given diff --git a/message.js b/message.js index f4db81a..430cb52 100644 --- a/message.js +++ b/message.js @@ -1876,7 +1876,7 @@ jspb.Message.clone_ = function(obj) { // NOTE:redundant null check existing for NTI compatibility. // see b/70515949 clonedArray[i] = (typeof o == 'object') ? - jspb.Message.clone_(jspb.asserts.assert(o)) : + jspb.Message.clone_(/** @type {!Object} */(jspb.asserts.assert(o))) : o; } } @@ -1892,7 +1892,7 @@ jspb.Message.clone_ = function(obj) { // NOTE:redundant null check existing for NTI compatibility. // see b/70515949 clone[key] = (typeof o == 'object') ? - jspb.Message.clone_(jspb.asserts.assert(o)) : + jspb.Message.clone_(/** @type {!Object} */(jspb.asserts.assert(o))) : o; } } From fd0e3c90aa686e85db064ed6def6dd59d8c9172f Mon Sep 17 00:00:00 2001 From: Paul Johnston Date: Wed, 8 Oct 2025 15:31:14 -0600 Subject: [PATCH 2/3] Revert BUILD file change, remove bigint handling in writer.js --- BUILD.bazel | 95 ++++++++++++++++++++++++++++++++---------------- binary/writer.js | 8 ---- 2 files changed, 63 insertions(+), 40 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index f989623..62355ce 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,6 +2,10 @@ # # See also code generation logic under generator/ +load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix") +load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip") +load("//:protobuf_javascript_release.bzl", "package_naming") + config_setting( name = "x64_x86_windows", values = {"cpu": "x64_x86_windows"}, @@ -27,38 +31,65 @@ config_setting( values = {"cpu": "darwin_x86_64"}, ) -filegroup( - name = "javascript", +package_naming( + name = "protobuf_javascript_pkg_naming", + platform = select({ + ":k8": "linux-x86_64", # currently the only supported build type in Github Actions + ":x64_x86_windows": "win32", + ":x64_windows": "win64", + ":darwin_arm64": "osx-aarch_64", + ":darwin_x86_64": "osx-x86_64", + "//conditions:default": "" # continues with current behavior when no --cpu is specified allowing existing internal builds to function + }) +) + +pkg_files( + name = "plugin_files", + srcs = ["//generator:protoc-gen-js"], + attributes = pkg_attributes(mode = "0555"), + prefix = "bin/", +) + +pkg_files( + name = "dist_files", + srcs = glob([ + "google/protobuf/*.js", + "google/protobuf/compiler/*.js" + ]) + [ + "google-protobuf.js", + "package.json", + "README.md", + "LICENSE.md", + "LICENSE-asserts.md", + ], + strip_prefix = strip_prefix.from_root(""), +) + +pkg_tar( + name = "dist_tar", srcs = [ - "asserts.js", - "binary/any_field_type.js", - "binary/arith.js", - "binary/binary_constants.js", - "binary/bytesource.js", - "binary/bytesource_alias.js", - "binary/decoder.js", - "binary/decoder_alias.js", - "binary/encoder.js", - "binary/encoder_alias.js", - "binary/errors.js", - "binary/internal_buffer.js", - "binary/reader.js", - "binary/reader_alias.js", - "binary/repeated_field_type.js", - "binary/scalar_field_type.js", - "binary/test_utils.js", - "binary/utf8.js", - "binary/utils.js", - "binary/writer.js", - "binary/writer_alias.js", - "bytestring.js", - "debug.js", - "internal_bytes.js", - "internal_options.js", - "internal_public.js", - "map.js", - "message.js", - "unsafe_bytestring.js", + ":dist_files", + ":plugin_files", ], - visibility = ["//visibility:public"], + extension = "tar.gz", + package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz", + package_variables = ":protobuf_javascript_pkg_naming", +) + +pkg_zip( + name = "dist_zip", + srcs = [ + ":dist_files", + ":plugin_files", + ], + package_file_name = "protobuf-javascript-{version}-{platform}.zip", + package_variables = ":protobuf_javascript_pkg_naming", +) + +filegroup( + name = "dist_all", + srcs = [ + ":dist_tar", + ":dist_zip", + ] ) diff --git a/binary/writer.js b/binary/writer.js index e3874de..0a0302c 100755 --- a/binary/writer.js +++ b/binary/writer.js @@ -430,10 +430,6 @@ class BinaryWriter { this.encoder_.writeZigzagVarint64(/** @type {number} */(value)); break; - case 'bigint': - this.encoder_.writeZigzagVarint64BigInt(/** @type {bigint} */(value)); - break; - default: this.encoder_.writeZigzagVarint64String(/** @type {string} */(value)); break; @@ -1425,10 +1421,6 @@ class BinaryWriter { this.encoder_.writeZigzagVarint64(v); break; - case 'bigint': - this.encoder_.writeZigzagVarint64BigInt(/** @type {bigint} */(v)); - break; - default: this.encoder_.writeZigzagVarint64String(/** @type {string} */(v)); break; From 263ee701cba6b75e1f8eddad5adcdf74718318b1 Mon Sep 17 00:00:00 2001 From: Paul Johnston Date: Wed, 8 Oct 2025 15:32:22 -0600 Subject: [PATCH 3/3] remove writeZigzagVarint64BigInt --- binary/encoder.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/binary/encoder.js b/binary/encoder.js index e1d787a..4bc849f 100755 --- a/binary/encoder.js +++ b/binary/encoder.js @@ -190,15 +190,6 @@ class BinaryEncoder { utils.splitZigzag64(value); this.writeSplitVarint64(utils.getSplit64Low(), utils.getSplit64High()); } - - /** - * Encodes a BigInt into its wire-format, zigzag-encoded varint - * representation and stores it in the buffer. - * @param {bigint} value The BigInt to convert. - */ - writeZigzagVarint64BigInt(value) { - this.writeZigzagVarint64String(value.toString()); - } /** * Encodes a JavaScript decimal string into its wire-format, zigzag-encoded