Skip to content

Commit

Permalink
Fixed: Respect long defaults in converters
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 4, 2017
1 parent e3170a1 commit 62eef58
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function genConvert(field, fieldIndex, prop) {
case "fixed64":
case "sfixed64":
// longs
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, 0, 0, field.type.charAt(0) === "u");
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, field.typeDefault.low, field.typeDefault.high, field.type.charAt(0) === "u");
case "bytes":
// bytes
return sprintf("f.bytes(s%s,%j,o)", prop, Array.prototype.slice.call(field.typeDefault));
Expand Down
6 changes: 3 additions & 3 deletions tests/data/ambiguous-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ $root.A = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.whatever === undefined && options.defaults) {
dst.whatever = "";
Expand Down Expand Up @@ -294,9 +294,9 @@ $root.B = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (!(src.A === undefined || src.A === null) || options.defaults) {
if (src.A !== undefined && src.A !== null || options.defaults) {
dst.A = types[0].convert(src.A, impl, options);
}
}
Expand Down
18 changes: 9 additions & 9 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (src.layers && src.layers.length) {
dst.layers = [];
Expand Down Expand Up @@ -445,7 +445,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.stringValue === undefined && options.defaults) {
dst.stringValue = "";
Expand All @@ -456,13 +456,13 @@ $root.vector_tile = (function() {
if (dst.doubleValue === undefined && options.defaults) {
dst.doubleValue = 0;
}
if (!(src.intValue === undefined || src.intValue === null) || options.defaults) {
if (src.intValue !== undefined && src.intValue !== null || options.defaults) {
dst.intValue = impl.longs(src.intValue, 0, 0, false, options);
}
if (!(src.uintValue === undefined || src.uintValue === null) || options.defaults) {
if (src.uintValue !== undefined && src.uintValue !== null || options.defaults) {
dst.uintValue = impl.longs(src.uintValue, 0, 0, true, options);
}
if (!(src.sintValue === undefined || src.sintValue === null) || options.defaults) {
if (src.sintValue !== undefined && src.sintValue !== null || options.defaults) {
dst.sintValue = impl.longs(src.sintValue, 0, 0, false, options);
}
if (dst.boolValue === undefined && options.defaults) {
Expand Down Expand Up @@ -721,9 +721,9 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (!(src.id === undefined || src.id === null) || options.defaults) {
if (src.id !== undefined && src.id !== null || options.defaults) {
dst.id = impl.longs(src.id, 0, 0, true, options);
}
if (src.tags && src.tags.length) {
Expand All @@ -736,7 +736,7 @@ $root.vector_tile = (function() {
dst.tags = [];
}
}
if (!(src.type === undefined || src.type === null) || options.defaults) {
if (src.type !== undefined || options.defaults) {
dst.type = impl.enums(src.type, undefined, types[2], options);
}
if (src.geometry && src.geometry.length) {
Expand Down Expand Up @@ -1017,7 +1017,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.version === undefined && options.defaults) {
dst.version = 1;
Expand Down
6 changes: 3 additions & 3 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ $root.Package = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
Expand All @@ -520,7 +520,7 @@ $root.Package = (function() {
if (dst.license === undefined && options.defaults) {
dst.license = "";
}
if (!(src.repository === undefined || src.repository === null) || options.defaults) {
if (src.repository !== undefined && src.repository !== null || options.defaults) {
dst.repository = types[5].convert(src.repository, impl, options);
}
if (dst.bugs === undefined && options.defaults) {
Expand Down Expand Up @@ -726,7 +726,7 @@ $root.Package = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.type === undefined && options.defaults) {
dst.type = "";
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ $root.MyRequest = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.path === undefined && options.defaults) {
dst.path = "";
Expand Down Expand Up @@ -382,7 +382,7 @@ $root.MyResponse = (function() {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options) || null;
var dst = impl.create(src, this, options);
if (dst) {
if (dst.status === undefined && options.defaults) {
dst.status = 0;
Expand Down
Loading

0 comments on commit 62eef58

Please sign in to comment.