Pārlūkot izejas kodu

Fixed definition of extensions, and added CommonJS tests to Travis.

Josh Haberman 9 gadi atpakaļ
vecāks
revīzija
35298f9779
3 mainītis faili ar 13 papildinājumiem un 2 dzēšanām
  1. 4 0
      js/gulpfile.js
  2. 1 1
      js/package.json
  3. 8 1
      src/google/protobuf/compiler/js/js_generator.cc

+ 4 - 0
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();
+});

+ 1 - 1
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",

+ 8 - 1
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<std::string> 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<string>::iterator it = provided.begin();
        it != provided.end(); ++it) {
     printer->Print("goog.exportSymbol('$name$', null, global);\n",