Skip to content

Commit 62eef58

Browse files
committed
Fixed: Respect long defaults in converters
1 parent e3170a1 commit 62eef58

File tree

6 files changed

+111
-111
lines changed

6 files changed

+111
-111
lines changed

src/converter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function genConvert(field, fieldIndex, prop) {
2121
case "fixed64":
2222
case "sfixed64":
2323
// longs
24-
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, 0, 0, field.type.charAt(0) === "u");
24+
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, field.typeDefault.low, field.typeDefault.high, field.type.charAt(0) === "u");
2525
case "bytes":
2626
// bytes
2727
return sprintf("f.bytes(s%s,%j,o)", prop, Array.prototype.slice.call(field.typeDefault));

tests/data/ambiguous-names.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ $root.A = (function() {
134134
if (!options) {
135135
options = {};
136136
}
137-
var dst = impl.create(src, this, options) || null;
137+
var dst = impl.create(src, this, options);
138138
if (dst) {
139139
if (dst.whatever === undefined && options.defaults) {
140140
dst.whatever = "";
@@ -294,9 +294,9 @@ $root.B = (function() {
294294
if (!options) {
295295
options = {};
296296
}
297-
var dst = impl.create(src, this, options) || null;
297+
var dst = impl.create(src, this, options);
298298
if (dst) {
299-
if (!(src.A === undefined || src.A === null) || options.defaults) {
299+
if (src.A !== undefined && src.A !== null || options.defaults) {
300300
dst.A = types[0].convert(src.A, impl, options);
301301
}
302302
}

tests/data/mapbox/vector_tile.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ $root.vector_tile = (function() {
157157
if (!options) {
158158
options = {};
159159
}
160-
var dst = impl.create(src, this, options) || null;
160+
var dst = impl.create(src, this, options);
161161
if (dst) {
162162
if (src.layers && src.layers.length) {
163163
dst.layers = [];
@@ -445,7 +445,7 @@ $root.vector_tile = (function() {
445445
if (!options) {
446446
options = {};
447447
}
448-
var dst = impl.create(src, this, options) || null;
448+
var dst = impl.create(src, this, options);
449449
if (dst) {
450450
if (dst.stringValue === undefined && options.defaults) {
451451
dst.stringValue = "";
@@ -456,13 +456,13 @@ $root.vector_tile = (function() {
456456
if (dst.doubleValue === undefined && options.defaults) {
457457
dst.doubleValue = 0;
458458
}
459-
if (!(src.intValue === undefined || src.intValue === null) || options.defaults) {
459+
if (src.intValue !== undefined && src.intValue !== null || options.defaults) {
460460
dst.intValue = impl.longs(src.intValue, 0, 0, false, options);
461461
}
462-
if (!(src.uintValue === undefined || src.uintValue === null) || options.defaults) {
462+
if (src.uintValue !== undefined && src.uintValue !== null || options.defaults) {
463463
dst.uintValue = impl.longs(src.uintValue, 0, 0, true, options);
464464
}
465-
if (!(src.sintValue === undefined || src.sintValue === null) || options.defaults) {
465+
if (src.sintValue !== undefined && src.sintValue !== null || options.defaults) {
466466
dst.sintValue = impl.longs(src.sintValue, 0, 0, false, options);
467467
}
468468
if (dst.boolValue === undefined && options.defaults) {
@@ -721,9 +721,9 @@ $root.vector_tile = (function() {
721721
if (!options) {
722722
options = {};
723723
}
724-
var dst = impl.create(src, this, options) || null;
724+
var dst = impl.create(src, this, options);
725725
if (dst) {
726-
if (!(src.id === undefined || src.id === null) || options.defaults) {
726+
if (src.id !== undefined && src.id !== null || options.defaults) {
727727
dst.id = impl.longs(src.id, 0, 0, true, options);
728728
}
729729
if (src.tags && src.tags.length) {
@@ -736,7 +736,7 @@ $root.vector_tile = (function() {
736736
dst.tags = [];
737737
}
738738
}
739-
if (!(src.type === undefined || src.type === null) || options.defaults) {
739+
if (src.type !== undefined || options.defaults) {
740740
dst.type = impl.enums(src.type, undefined, types[2], options);
741741
}
742742
if (src.geometry && src.geometry.length) {
@@ -1017,7 +1017,7 @@ $root.vector_tile = (function() {
10171017
if (!options) {
10181018
options = {};
10191019
}
1020-
var dst = impl.create(src, this, options) || null;
1020+
var dst = impl.create(src, this, options);
10211021
if (dst) {
10221022
if (dst.version === undefined && options.defaults) {
10231023
dst.version = 1;

tests/data/package.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ $root.Package = (function() {
503503
if (!options) {
504504
options = {};
505505
}
506-
var dst = impl.create(src, this, options) || null;
506+
var dst = impl.create(src, this, options);
507507
if (dst) {
508508
if (dst.name === undefined && options.defaults) {
509509
dst.name = "";
@@ -520,7 +520,7 @@ $root.Package = (function() {
520520
if (dst.license === undefined && options.defaults) {
521521
dst.license = "";
522522
}
523-
if (!(src.repository === undefined || src.repository === null) || options.defaults) {
523+
if (src.repository !== undefined && src.repository !== null || options.defaults) {
524524
dst.repository = types[5].convert(src.repository, impl, options);
525525
}
526526
if (dst.bugs === undefined && options.defaults) {
@@ -726,7 +726,7 @@ $root.Package = (function() {
726726
if (!options) {
727727
options = {};
728728
}
729-
var dst = impl.create(src, this, options) || null;
729+
var dst = impl.create(src, this, options);
730730
if (dst) {
731731
if (dst.type === undefined && options.defaults) {
732732
dst.type = "";

tests/data/rpc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ $root.MyRequest = (function() {
226226
if (!options) {
227227
options = {};
228228
}
229-
var dst = impl.create(src, this, options) || null;
229+
var dst = impl.create(src, this, options);
230230
if (dst) {
231231
if (dst.path === undefined && options.defaults) {
232232
dst.path = "";
@@ -382,7 +382,7 @@ $root.MyResponse = (function() {
382382
if (!options) {
383383
options = {};
384384
}
385-
var dst = impl.create(src, this, options) || null;
385+
var dst = impl.create(src, this, options);
386386
if (dst) {
387387
if (dst.status === undefined && options.defaults) {
388388
dst.status = 0;

0 commit comments

Comments
 (0)