aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/js/js_generator.cc
diff options
context:
space:
mode:
authorGravatar Nikolai Vavilov <vvnicholas@gmail.com>2016-07-16 21:34:25 +0300
committerGravatar Nikolai Vavilov <vvnicholas@gmail.com>2016-07-19 09:39:52 +0300
commitdb1b2a06e3999ffd6e52719ec0216849aa515ba1 (patch)
tree201bae7927fc2214e62b32f31f24f32739bd15ba /src/google/protobuf/compiler/js/js_generator.cc
parent970a4fda1785de0873378bca12e907e3a86e64d2 (diff)
nits
Diffstat (limited to 'src/google/protobuf/compiler/js/js_generator.cc')
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc53
1 files changed, 21 insertions, 32 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 7829ccbf..53067739 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -1257,11 +1257,14 @@ string GetPivot(const Descriptor* desc) {
// Returns true for fields that represent "null" as distinct from the default
// value. See http://go/proto3#heading=h.kozewqqcqhuz for more information.
bool HasFieldPresence(const FieldDescriptor* field) {
+ if (field->is_repeated()) {
+ return false;
+ }
+
return
- !field->is_repeated() &&
- ((field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ||
+ (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ||
(field->containing_oneof() != NULL) ||
- (field->file()->syntax() != FileDescriptor::SYNTAX_PROTO3));
+ (field->file()->syntax() != FileDescriptor::SYNTAX_PROTO3);
}
// For proto3 fields without presence, returns a string representing the default
@@ -2322,20 +2325,6 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"clearedvalue", (field->is_repeated() ? "[]" : "undefined"),
"returnvalue", JSReturnClause(field));
- printer->Print(
- "/**\n"
- " * Returns whether this field is set.\n"
- " * @return{!boolean}\n"
- " */\n"
- "$class$.prototype.has$name$ = function() {\n"
- " return jspb.Message.getField(this, $index$) != null;\n"
- "};\n"
- "\n"
- "\n",
- "class", GetPath(options, field->containing_type()),
- "name", JSGetterName(options, field),
- "index", JSFieldIndex(field));
-
} else {
bool untyped =
false;
@@ -2497,22 +2486,22 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"clearedvalue", (field->is_repeated() ? "[]" : "undefined"),
"returnvalue", JSReturnClause(field));
}
+ }
- if (HasFieldPresence(field)) {
- printer->Print(
- "/**\n"
- " * Returns whether this field is set.\n"
- " * @return{!boolean}\n"
- " */\n"
- "$class$.prototype.has$name$ = function() {\n"
- " return jspb.Message.getField(this, $index$) != null;\n"
- "};\n"
- "\n"
- "\n",
- "class", GetPath(options, field->containing_type()),
- "name", JSGetterName(options, field),
- "index", JSFieldIndex(field));
- }
+ if (HasFieldPresence(field)) {
+ printer->Print(
+ "/**\n"
+ " * Returns whether this field is set.\n"
+ " * @return{!boolean}\n"
+ " */\n"
+ "$class$.prototype.has$name$ = function() {\n"
+ " return jspb.Message.getField(this, $index$) != null;\n"
+ "};\n"
+ "\n"
+ "\n",
+ "class", GetPath(options, field->containing_type()),
+ "name", JSGetterName(options, field),
+ "index", JSFieldIndex(field));
}
}