File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -394,8 +394,7 @@ function buildType(ref, type) {
394
394
if ( config . comments ) {
395
395
push ( "" ) ;
396
396
var jsType = toJsType ( field ) ;
397
- if ( field . optional && ! field . map && ! field . repeated && field . resolvedType instanceof Type ||
398
- field . options && field . options . proto3_optional )
397
+ if ( field . optional && ! field . map && ! field . repeated && field . resolvedType instanceof Type || field . partOf )
399
398
jsType = jsType + "|null|undefined" ;
400
399
pushComment ( [
401
400
field . comment || type . name + " " + field . name + "." ,
@@ -411,9 +410,8 @@ function buildType(ref, type) {
411
410
push ( escapeName ( type . name ) + ".prototype" + prop + " = $util.emptyArray;" ) ; // overwritten in constructor
412
411
else if ( field . map )
413
412
push ( escapeName ( type . name ) + ".prototype" + prop + " = $util.emptyObject;" ) ; // overwritten in constructor
414
- else if ( field . options && field . options . proto3_optional ) {
415
- push ( escapeName ( type . name ) + ".prototype" + prop + " = null;" ) ; // do not set default value for proto3 optional fields
416
- }
413
+ else if ( field . partOf )
414
+ push ( escapeName ( type . name ) + ".prototype" + prop + " = null;" ) ; // do not set default value for oneof members
417
415
else if ( field . long )
418
416
push ( escapeName ( type . name ) + ".prototype" + prop + " = $util.Long ? $util.Long.fromBits("
419
417
+ JSON . stringify ( field . typeDefault . low ) + ","
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ var Module = require("module");
6
6
var protobuf = require ( ".." ) ;
7
7
8
8
tape . test ( "pbjs generates static code" , function ( test ) {
9
+ // pbjs does not seem to work with Node v4, so skip this test if we're running on it
10
+ if ( process . versions . node . match ( / ^ 4 \. / ) ) {
11
+ test . end ( ) ;
12
+ return ;
13
+ }
14
+
9
15
// Alter the require cache to make the cli/targets/static work since it requires "protobufjs"
10
16
// and we don't want to mess with "npm link"
11
17
var savedResolveFilename = Module . _resolveFilename ;
@@ -59,7 +65,6 @@ tape.test("pbjs generates static code", function(test) {
59
65
instance . messageInOneof . value = 42 ;
60
66
instance . regularField = "abc" ;
61
67
var instance1 = OneofContainerDynamic . toObject ( OneofContainerDynamic . fromObject ( instance ) ) ;
62
- console . log ( instance1 ) ;
63
68
// The following test fails: will be fixed by the next commit
64
69
test . deepEqual ( instance , instance1 , "fromObject and toObject work for instance of the static type" ) ;
65
70
You can’t perform that action at this time.
0 commit comments