From 13f94b4092cff9bc36a62adb4bf2e362b4f85979 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Mon, 26 Mar 2018 16:07:45 -0700 Subject: Fix strict JS generator with import in a protofile --- src/google/protobuf/compiler/js/js_generator.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index dd76a509..dfa22ac6 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -3458,7 +3458,8 @@ void Generator::GenerateFile(const GeneratorOptions& options, for (int i = 0; i < file->dependency_count(); i++) { const string& name = file->dependency(i)->name(); printer->Print( - "var $alias$ = require('$file$');\n", + "var $alias$ = require('$file$');\n" + "goog.object.extend(proto, $alias$);\n", "alias", ModuleAlias(name), "file", GetRootPath(file->name(), name) + GetJSFilename(options, name)); @@ -3497,10 +3498,12 @@ void Generator::GenerateFile(const GeneratorOptions& options, GenerateExtension(options, printer, *it); } - if ((options.import_style == GeneratorOptions::kImportCommonJs || - options.import_style == GeneratorOptions::kImportCommonJsStrict)) { + if (options.import_style == GeneratorOptions::kImportCommonJs) { printer->Print("goog.object.extend(exports, $package$);\n", "package", GetFilePath(options, file)); + } else if(options.import_style == GeneratorOptions::kImportCommonJsStrict) { + printer->Print("goog.object.extend(exports, proto);\n", + "package", GetFilePath(options, file)); } // Emit well-known type methods. -- cgit v1.2.3