From 624e2af672c498a784309a0e4c0503140571e51b Mon Sep 17 00:00:00 2001 From: Edgar Kazimetov Date: Fri, 4 Jun 2021 16:55:59 +0300 Subject: [PATCH] Fix js generator for commonjs_strict --- js/commonjs/strict_test.js | 8 ++++---- src/google/protobuf/compiler/js/js_generator.cc | 15 ++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/js/commonjs/strict_test.js b/js/commonjs/strict_test.js index 46458c10b32a5..b02ac3bf5ef67 100644 --- a/js/commonjs/strict_test.js +++ b/js/commonjs/strict_test.js @@ -44,8 +44,8 @@ var test10_pb = require('./test10_pb'); describe('Strict test suite', function() { it('testImportedMessage', function() { - var simple1 = new test9_pb.jspb.exttest.strict.nine.Simple9() - var simple2 = new test9_pb.jspb.exttest.strict.nine.Simple9() + var simple1 = new test9_pb.Simple9(); + var simple2 = new test9_pb.Simple9(); assertObjectEquals(simple1.toObject(), simple2.toObject()); }); @@ -55,8 +55,8 @@ describe('Strict test suite', function() { describe('with imports', function() { it('testImportedMessage', function() { - var simple1 = new test10_pb.jspb.exttest.strict.ten.Simple10() - var simple2 = new test10_pb.jspb.exttest.strict.ten.Simple10() + var simple1 = new test10_pb.Simple10(); + var simple2 = new test10_pb.Simple10(); assertObjectEquals(simple1.toObject(), simple2.toObject()); }); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 819622e9ab42a..bba111e5bf09c 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2967,13 +2967,13 @@ void Generator::GenerateRepeatedMessageHelperMethods( printer->Annotate("addername", field); printer->Print( - "this, $index$$oneofgroup$, opt_value, $ctor$, opt_index);\n" + "this, $index$$oneofgroup$, opt_value, $wrapperclass$, opt_index);\n" "};\n" "\n" "\n", "index", JSFieldIndex(field), "oneofgroup", - (InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""), "ctor", - GetMessagePath(options, field->message_type())); + (InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""), "wrapperclass", + SubmessageTypeRef(options, field)); } void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, @@ -3647,8 +3647,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, for (int i = 0; i < file->dependency_count(); i++) { const std::string& name = file->dependency(i)->name(); printer->Print( - "var $alias$ = require('$file$');\n" - "goog.object.extend(proto, $alias$);\n", + "var $alias$ = require('$file$');\n", "alias", ModuleAlias(name), "file", GetRootPath(file->name(), name) + GetJSFilename(options, name)); } @@ -3687,13 +3686,11 @@ void Generator::GenerateFile(const GeneratorOptions& options, } // if provided is empty, do not export anything - if (options.import_style == GeneratorOptions::kImportCommonJs && + if ((options.import_style == GeneratorOptions::kImportCommonJs || + options.import_style == GeneratorOptions::kImportCommonJsStrict) && !provided.empty()) { printer->Print("goog.object.extend(exports, $package$);\n", "package", GetNamespace(options, file)); - } else if (options.import_style == GeneratorOptions::kImportCommonJsStrict) { - printer->Print("goog.object.extend(exports, proto);\n", "package", - GetNamespace(options, file)); } // Emit well-known type methods.