aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/js/js_generator.cc
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2017-12-01 10:05:10 -0800
committerGravatar Adam Cozzette <acozzette@google.com>2017-12-01 10:05:10 -0800
commit92a7e778e7394386f413cec28d67a07630f784b1 (patch)
treecb5673c7c09b0d3905b48a24765d07e423bc5b30 /src/google/protobuf/compiler/js/js_generator.cc
parentce0a53273a400369932ba788d17500336a6ecaad (diff)
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/compiler/js/js_generator.cc')
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 16fe19ad..fd2d3dfd 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -195,9 +195,9 @@ string ModuleAlias(const string& filename) {
// We'll worry about this problem if/when we actually see it. This name isn't
// exposed to users so we can change it later if we need to.
string basename = StripProto(filename);
- StripString(&basename, "-", '$');
- StripString(&basename, "/", '_');
- StripString(&basename, ".", '_');
+ ReplaceCharacters(&basename, "-", '$');
+ ReplaceCharacters(&basename, "/", '_');
+ ReplaceCharacters(&basename, ".", '_');
return basename + "_pb";
}
@@ -1028,7 +1028,7 @@ string JSFieldTypeAnnotation(const GeneratorOptions& options,
if (!IsPrimitive(jstype)) {
jstype = "!" + jstype;
}
- jstype = "Array.<" + jstype + ">";
+ jstype = "Array<" + jstype + ">";
}
}
@@ -1558,6 +1558,22 @@ bool GenerateJspbAllowedSet(const GeneratorOptions& options,
return true;
}
+// Embeds base64 encoded GeneratedCodeInfo proto in a comment at the end of
+// file.
+void EmbedCodeAnnotations(const GeneratedCodeInfo& annotations,
+ io::Printer* printer) {
+ // Serialize annotations proto into base64 string.
+ string meta_content;
+ annotations.SerializeToString(&meta_content);
+ string meta_64;
+ Base64Escape(meta_content, &meta_64);
+
+ // Print base64 encoded annotations at the end of output file in
+ // a comment.
+ printer->Print("\n// Below is base64 encoded GeneratedCodeInfo proto");
+ printer->Print("\n// $encoded_proto$\n", "encoded_proto", meta_64);
+}
+
} // anonymous namespace
void Generator::GenerateHeader(const GeneratorOptions& options,
@@ -2822,7 +2838,7 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
"so that it\n"
" * works in OPTIMIZED mode.\n"
" *\n"
- " * @type {!Object.<number, jspb.ExtensionFieldInfo>}\n"
+ " * @type {!Object<number, jspb.ExtensionFieldInfo>}\n"
" */\n"
"$class$.extensions = {};\n"
"\n",
@@ -2843,7 +2859,7 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
"so that it\n"
" * works in OPTIMIZED mode.\n"
" *\n"
- " * @type {!Object.<number, jspb.ExtensionFieldBinaryInfo>}\n"
+ " * @type {!Object<number, jspb.ExtensionFieldBinaryInfo>}\n"
" */\n"
"$class$.extensionsBinary = {};\n"
"\n",
@@ -3195,7 +3211,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
"/**\n"
" * A tuple of {field number, class constructor} for the extension\n"
" * field named `$name$`.\n"
- " * @type {!jspb.ExtensionFieldInfo.<$extensionType$>}\n"
+ " * @type {!jspb.ExtensionFieldInfo<$extensionType$>}\n"
" */\n"
"$class$.$name$ = new jspb.ExtensionFieldInfo(\n",
"name", JSObjectFieldName(options, field),
@@ -3634,10 +3650,7 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
}
if (options.annotate_code) {
- const string meta_file = filename + ".meta";
- google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> info_output(
- context->Open(meta_file));
- annotations.SerializeToZeroCopyStream(info_output.get());
+ EmbedCodeAnnotations(annotations, &printer);
}
}
}