aboutsummaryrefslogtreecommitdiffhomepage
path: root/js
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2016-09-27 15:36:41 -0700
committerGravatar Bo Yang <teboring@google.com>2016-10-10 11:44:21 -0700
commit4a4a1627c158d976ee80f278024a49ced8b12712 (patch)
tree7f619a542f6e83f251284b7561a789672df94b11 /js
parent0bf5482712e849f67d7fe98217608f95ba60c776 (diff)
Fixed references to foreign nested messages with CommonJS-style imports
A bug was causing generated JSPB code with CommonJS-style imports to refer incorrectly to nested messages from other .proto files. The generated code would have things like "test_pb.InnerMessage" instead of "test_pb.OuterMessage.InnerMessage". This commit fixes the problem by correctly taking into account any message nesting.
Diffstat (limited to 'js')
-rw-r--r--js/message_test.js14
-rw-r--r--js/test.proto8
-rw-r--r--js/test2.proto6
3 files changed, 28 insertions, 0 deletions
diff --git a/js/message_test.js b/js/message_test.js
index 97c594c8..b0a0a72e 100644
--- a/js/message_test.js
+++ b/js/message_test.js
@@ -1040,4 +1040,18 @@ describe('Message test suite', function() {
assertNan(message.getDefaultDoubleField());
});
+ // Verify that we can successfully use a field referring to a nested message
+ // from a different .proto file.
+ it('testForeignNestedMessage', function() {
+ var msg = new proto.jspb.test.ForeignNestedFieldMessage();
+ var nested = new proto.jspb.test.Deeply.Nested.Message();
+ nested.setCount(5);
+ msg.setDeeplyNestedMessage(nested);
+
+ // After a serialization-deserialization round trip we should get back the
+ // same data we started with.
+ var serialized = msg.serializeBinary();
+ var deserialized = proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized);
+ assertEquals(5, deserialized.getDeeplyNestedMessage().getCount());
+ });
});
diff --git a/js/test.proto b/js/test.proto
index 48cb37e1..db238e1a 100644
--- a/js/test.proto
+++ b/js/test.proto
@@ -260,3 +260,11 @@ enum MapValueEnumNoBinary {
message MapValueMessageNoBinary {
optional int32 foo = 1;
}
+
+message Deeply {
+ message Nested {
+ message Message {
+ optional int32 count = 1;
+ }
+ }
+}
diff --git a/js/test2.proto b/js/test2.proto
index 44e55eff..b67f93fa 100644
--- a/js/test2.proto
+++ b/js/test2.proto
@@ -35,6 +35,8 @@ option java_multiple_files = true;
package jspb.test;
+import "test.proto";
+
message TestExtensionsMessage {
optional int32 intfield = 1;
extensions 100 to max;
@@ -52,3 +54,7 @@ extend TestExtensionsMessage {
optional ExtensionMessage floating_msg_field = 101;
optional string floating_str_field = 102;
}
+
+message ForeignNestedFieldMessage {
+ optional Deeply.Nested.Message deeply_nested_message = 1;
+}