Skip to content

Commit dbd19fd

Browse files
committed
New: Removed various clutter from generated static code
1 parent c7e14b1 commit dbd19fd

28 files changed

+773
-1028
lines changed

cli/targets/static.js

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,8 @@ function static_target(root, options, callback) {
3535
buildNamespace(null, root);
3636
push("");
3737
if (config.comments)
38-
push("// Resolve lazy types");
39-
push("$lazyTypes.forEach(function(types) {");
40-
++indent;
41-
push("types.forEach(function(path, i) {");
42-
++indent;
43-
push("if (!path)");
44-
++indent;
45-
push("return;");
46-
--indent;
47-
push("path = path.split(\".\");");
48-
push("var ptr = $root;");
49-
push("while (path.length)");
50-
++indent;
51-
push("ptr = ptr[path.shift()];");
52-
--indent;
53-
push("types[i] = ptr;");
54-
--indent;
55-
push("});");
56-
--indent;
57-
push("});");
38+
push("// Resolve lazy type names to actual types");
39+
push("$protobuf.util.lazyResolve($root, $lazyTypes);");
5840
return callback(null, out.join("\n"));
5941
} catch (err) {
6042
return callback(err);
@@ -330,19 +312,19 @@ function buildType(ref, type) {
330312
});
331313

332314
var hasTypes = false;
333-
var types = type.fieldsArray.map(function(field) {
315+
var types = [];
316+
type.fieldsArray.forEach(function(field, index) {
334317
if (field.resolve().resolvedType) { // including enums!
335318
hasTypes = true;
336-
return JSON.stringify(field.resolvedType.fullName.substring(1));
319+
types.push(index + ":"+JSON.stringify(field.resolvedType.fullName.substring(1)));
337320
}
338-
return "null";
339-
}).join(", ");
321+
});
340322

341323
if (hasTypes && (config.encode || config.decode || config.verify || config.convert)) {
342324
push("");
343325
if (config.comments)
344326
push("// Referenced types");
345-
push("var $types = [" + types + "]; $lazyTypes.push($types);");
327+
push("var $types = {" + types.join(",") + "}; $lazyTypes.push($types);");
346328
}
347329

348330
if (config.create) {
@@ -492,13 +474,7 @@ function buildType(ref, type) {
492474
]);
493475
push("$prototype.toJSON = function toJSON() {");
494476
++indent;
495-
push("return this.constructor.toObject(this, {");
496-
++indent;
497-
push("longs: String,");
498-
push("enums: String,");
499-
push("bytes: String");
500-
--indent;
501-
push("});");
477+
push("return this.constructor.toObject(this, $protobuf.util.toJSONOptions);");
502478
--indent;
503479
push("};");
504480
}

dist/noparse/protobuf.js

Lines changed: 39 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/noparse/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/noparse/protobuf.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/noparse/protobuf.min.js.gz

72 Bytes
Binary file not shown.

dist/noparse/protobuf.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js

Lines changed: 39 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

71 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)