From 35298f97793d2b875a349db852b17ba979cf5e13 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 4 Feb 2016 17:01:33 -0800 Subject: [PATCH] Fixed definition of extensions, and added CommonJS tests to Travis. --- js/gulpfile.js | 4 ++++ js/package.json | 2 +- src/google/protobuf/compiler/js/js_generator.cc | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/js/gulpfile.js b/js/gulpfile.js index bdc4212b..d8f8ef4a 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -88,3 +88,7 @@ gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) { cb(err); }); }); + +gulp.task('test', ['test_closure', 'test_commonjs'], function(cb) { + cb(); +}); diff --git a/js/package.json b/js/package.json index d37da1dd..6418e507 100644 --- a/js/package.json +++ b/js/package.json @@ -13,7 +13,7 @@ "glob": "~6.0.4" }, "scripts": { - "test": "./node_modules/gulp/bin/gulp.js test_closure" + "test": "./node_modules/gulp/bin/gulp.js test" }, "repository": { "type": "git", diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 7ebb9b12..351c3966 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2530,8 +2530,15 @@ void Generator::GenerateFile(const GeneratorOptions& options, // // Later generated code expects foo.bar = {} to exist: // foo.bar.Baz = function() { /* ... */ } std::set provided; + + // Cover the case where this file declares extensions but no messages. + // This will ensure that the file-level object will be declared to hold + // the extensions. + for (int i = 0; i < file->extension_count(); i++) { + provided.insert(file->extension(i)->full_name()); + } + FindProvidesForFile(options, printer, file, &provided); - //FindProvidesForFields(options, printer, extensions, &provided); for (std::set::iterator it = provided.begin(); it != provided.end(); ++it) { printer->Print("goog.exportSymbol('$name$', null, global);\n",