Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix js generator for commonjs_strict #8696

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions js/commonjs/strict_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand All @@ -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());
});

Expand Down
15 changes: 6 additions & 9 deletions src/google/protobuf/compiler/js/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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.
Expand Down