Skip to content

Commit 39a2ea3

Browse files
committed
CLI: Removed now unnecessary comment lines in generated static code
1 parent 003e0fa commit 39a2ea3

File tree

8 files changed

+9913
-86
lines changed

8 files changed

+9913
-86
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ Consolidates imports and converts between file formats.
356356
357357
Static targets only:
358358
359+
--no-create Does not generate create functions used for runtime compatibility.
359360
--no-encode Does not generate encode functions.
360361
--no-decode Does not generate decode functions.
361362
--no-verify Does not generate verify functions.

cli/targets/static.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ function push(line) {
7272
function pushComment(lines) {
7373
push("/**");
7474
lines.forEach(function(line) {
75+
if (line === null)
76+
return;
7577
push(" * " + line);
7678
});
7779
push(" */");
@@ -88,7 +90,7 @@ function name(name) {
8890
// library itself because the reserved words check requires a rather longish regex.
8991
util.safeProp = (function(safeProp) {
9092
return function safeProp_dn(name) {
91-
return /^[$\w]+$/.test(name) && cliUtil.reserved(name)
93+
return !/^[$\w]+$/.test(name) || cliUtil.reserved(name)
9294
? safeProp(name)
9395
: "." + name;
9496
}
@@ -233,17 +235,18 @@ function buildType(ref, type) {
233235
if (field.repeated)
234236
jsType = "Array.<" + jsType + ">";
235237
push("");
238+
var prop = util.safeProp(field.name);
236239
pushComment([
237240
type.name + " " + field.name + ".",
238-
"@name " + fullName + "#" + name(field.name),
241+
prop.charAt(0) !== "." ? "@name " + fullName + "#" + name(field.name) : null,
239242
"@type {" + jsType + "}"
240243
]);
241244
if (Array.isArray(field.defaultValue)) {
242-
push("$prototype[" + JSON.stringify(field.name) + "] = $protobuf.util.emptyArray;");
245+
push("$prototype" + prop + " = $protobuf.util.emptyArray;");
243246
} else if (util.isObject(field.defaultValue))
244-
push("$prototype[" + JSON.stringify(field.name) + "] = $protobuf.util.emptyObject;");
247+
push("$prototype" + prop + " = $protobuf.util.emptyObject;");
245248
else
246-
push("$prototype[" + JSON.stringify(field.name) + "] = " + JSON.stringify(field.defaultValue) + ";");
249+
push("$prototype" + prop + " = " + JSON.stringify(field.defaultValue) + ";");
247250
});
248251

249252
// virtual oneof fields

scripts/gentests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var fs = require("fs"),
66
"tests/data/package.proto",
77
"tests/data/rpc.proto",
88
"tests/data/mapbox/vector_tile.proto",
9-
"tests/data/ambiguous-names.proto"
9+
"tests/data/ambiguous-names.proto",
10+
"tests/data/test.proto"
1011
]
1112
.forEach(function(file) {
1213
var out = file.replace(/\.proto$/, ".js");

tests/data/ambiguous-names.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ $root.A = (function() {
2929

3030
/**
3131
* A whatever.
32-
* @name A#whatever
3332
* @type {string}
3433
*/
35-
$prototype["whatever"] = "";
34+
$prototype.whatever = "";
3635

3736
/**
3837
* Creates a new A instance using the specified properties.
@@ -159,10 +158,9 @@ $root.B = (function() {
159158

160159
/**
161160
* B A.
162-
* @name B#A
163161
* @type {A}
164162
*/
165-
$prototype["A"] = null;
163+
$prototype.A = null;
166164

167165
/**
168166
* Creates a new B instance using the specified properties.

tests/data/mapbox/vector_tile.js

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ $root.vector_tile = (function() {
3838

3939
/**
4040
* Tile layers.
41-
* @name vector_tile.Tile#layers
4241
* @type {Array.<vector_tile.Tile.Layer>}
4342
*/
44-
$prototype["layers"] = $protobuf.util.emptyArray;
43+
$prototype.layers = $protobuf.util.emptyArray;
4544

4645
/**
4746
* Creates a new Tile instance using the specified properties.
@@ -185,52 +184,45 @@ $root.vector_tile = (function() {
185184

186185
/**
187186
* Value stringValue.
188-
* @name vector_tile.Tile.Value#stringValue
189187
* @type {string}
190188
*/
191-
$prototype["stringValue"] = "";
189+
$prototype.stringValue = "";
192190

193191
/**
194192
* Value floatValue.
195-
* @name vector_tile.Tile.Value#floatValue
196193
* @type {number}
197194
*/
198-
$prototype["floatValue"] = 0;
195+
$prototype.floatValue = 0;
199196

200197
/**
201198
* Value doubleValue.
202-
* @name vector_tile.Tile.Value#doubleValue
203199
* @type {number}
204200
*/
205-
$prototype["doubleValue"] = 0;
201+
$prototype.doubleValue = 0;
206202

207203
/**
208204
* Value intValue.
209-
* @name vector_tile.Tile.Value#intValue
210205
* @type {number|Long}
211206
*/
212-
$prototype["intValue"] = $protobuf.util.emptyObject;
207+
$prototype.intValue = $protobuf.util.emptyObject;
213208

214209
/**
215210
* Value uintValue.
216-
* @name vector_tile.Tile.Value#uintValue
217211
* @type {number|Long}
218212
*/
219-
$prototype["uintValue"] = $protobuf.util.emptyObject;
213+
$prototype.uintValue = $protobuf.util.emptyObject;
220214

221215
/**
222216
* Value sintValue.
223-
* @name vector_tile.Tile.Value#sintValue
224217
* @type {number|Long}
225218
*/
226-
$prototype["sintValue"] = $protobuf.util.emptyObject;
219+
$prototype.sintValue = $protobuf.util.emptyObject;
227220

228221
/**
229222
* Value boolValue.
230-
* @name vector_tile.Tile.Value#boolValue
231223
* @type {boolean}
232224
*/
233-
$prototype["boolValue"] = false;
225+
$prototype.boolValue = false;
234226

235227
/**
236228
* Creates a new Value instance using the specified properties.
@@ -411,31 +403,27 @@ $root.vector_tile = (function() {
411403

412404
/**
413405
* Feature id.
414-
* @name vector_tile.Tile.Feature#id
415406
* @type {number|Long}
416407
*/
417-
$prototype["id"] = $protobuf.util.emptyObject;
408+
$prototype.id = $protobuf.util.emptyObject;
418409

419410
/**
420411
* Feature tags.
421-
* @name vector_tile.Tile.Feature#tags
422412
* @type {Array.<number>}
423413
*/
424-
$prototype["tags"] = $protobuf.util.emptyArray;
414+
$prototype.tags = $protobuf.util.emptyArray;
425415

426416
/**
427417
* Feature type.
428-
* @name vector_tile.Tile.Feature#type
429418
* @type {number}
430419
*/
431-
$prototype["type"] = "UNKNOWN";
420+
$prototype.type = "UNKNOWN";
432421

433422
/**
434423
* Feature geometry.
435-
* @name vector_tile.Tile.Feature#geometry
436424
* @type {Array.<number>}
437425
*/
438-
$prototype["geometry"] = $protobuf.util.emptyArray;
426+
$prototype.geometry = $protobuf.util.emptyArray;
439427

440428
/**
441429
* Creates a new Feature instance using the specified properties.
@@ -624,45 +612,39 @@ $root.vector_tile = (function() {
624612

625613
/**
626614
* Layer version.
627-
* @name vector_tile.Tile.Layer#version
628615
* @type {number}
629616
*/
630-
$prototype["version"] = 1;
617+
$prototype.version = 1;
631618

632619
/**
633620
* Layer name.
634-
* @name vector_tile.Tile.Layer#name
635621
* @type {string}
636622
*/
637-
$prototype["name"] = "";
623+
$prototype.name = "";
638624

639625
/**
640626
* Layer features.
641-
* @name vector_tile.Tile.Layer#features
642627
* @type {Array.<vector_tile.Tile.Feature>}
643628
*/
644-
$prototype["features"] = $protobuf.util.emptyArray;
629+
$prototype.features = $protobuf.util.emptyArray;
645630

646631
/**
647632
* Layer keys.
648-
* @name vector_tile.Tile.Layer#keys
649633
* @type {Array.<string>}
650634
*/
651-
$prototype["keys"] = $protobuf.util.emptyArray;
635+
$prototype.keys = $protobuf.util.emptyArray;
652636

653637
/**
654638
* Layer values.
655-
* @name vector_tile.Tile.Layer#values
656639
* @type {Array.<vector_tile.Tile.Value>}
657640
*/
658-
$prototype["values"] = $protobuf.util.emptyArray;
641+
$prototype.values = $protobuf.util.emptyArray;
659642

660643
/**
661644
* Layer extent.
662-
* @name vector_tile.Tile.Layer#extent
663645
* @type {number}
664646
*/
665-
$prototype["extent"] = 4096;
647+
$prototype.extent = 4096;
666648

667649
/**
668650
* Creates a new Layer instance using the specified properties.

tests/data/package.js

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,115 +29,99 @@ $root.Package = (function() {
2929

3030
/**
3131
* Package name.
32-
* @name Package#name
3332
* @type {string}
3433
*/
35-
$prototype["name"] = "";
34+
$prototype.name = "";
3635

3736
/**
3837
* Package version.
39-
* @name Package#version
4038
* @type {string}
4139
*/
42-
$prototype["version"] = "";
40+
$prototype.version = "";
4341

4442
/**
4543
* Package description.
46-
* @name Package#description
4744
* @type {string}
4845
*/
49-
$prototype["description"] = "";
46+
$prototype.description = "";
5047

5148
/**
5249
* Package author.
53-
* @name Package#author
5450
* @type {string}
5551
*/
56-
$prototype["author"] = "";
52+
$prototype.author = "";
5753

5854
/**
5955
* Package license.
60-
* @name Package#license
6156
* @type {string}
6257
*/
63-
$prototype["license"] = "";
58+
$prototype.license = "";
6459

6560
/**
6661
* Package repository.
67-
* @name Package#repository
6862
* @type {Package.Repository}
6963
*/
70-
$prototype["repository"] = null;
64+
$prototype.repository = null;
7165

7266
/**
7367
* Package bugs.
74-
* @name Package#bugs
7568
* @type {string}
7669
*/
77-
$prototype["bugs"] = "";
70+
$prototype.bugs = "";
7871

7972
/**
8073
* Package homepage.
81-
* @name Package#homepage
8274
* @type {string}
8375
*/
84-
$prototype["homepage"] = "";
76+
$prototype.homepage = "";
8577

8678
/**
8779
* Package keywords.
88-
* @name Package#keywords
8980
* @type {Array.<string>}
9081
*/
91-
$prototype["keywords"] = $protobuf.util.emptyArray;
82+
$prototype.keywords = $protobuf.util.emptyArray;
9283

9384
/**
9485
* Package main.
95-
* @name Package#main
9686
* @type {string}
9787
*/
98-
$prototype["main"] = "";
88+
$prototype.main = "";
9989

10090
/**
10191
* Package bin.
102-
* @name Package#bin
10392
* @type {string}
10493
*/
105-
$prototype["bin"] = $protobuf.util.emptyObject;
94+
$prototype.bin = $protobuf.util.emptyObject;
10695

10796
/**
10897
* Package scripts.
109-
* @name Package#scripts
11098
* @type {string}
11199
*/
112-
$prototype["scripts"] = $protobuf.util.emptyObject;
100+
$prototype.scripts = $protobuf.util.emptyObject;
113101

114102
/**
115103
* Package dependencies.
116-
* @name Package#dependencies
117104
* @type {string}
118105
*/
119-
$prototype["dependencies"] = $protobuf.util.emptyObject;
106+
$prototype.dependencies = $protobuf.util.emptyObject;
120107

121108
/**
122109
* Package optionalDependencies.
123-
* @name Package#optionalDependencies
124110
* @type {string}
125111
*/
126-
$prototype["optionalDependencies"] = $protobuf.util.emptyObject;
112+
$prototype.optionalDependencies = $protobuf.util.emptyObject;
127113

128114
/**
129115
* Package devDependencies.
130-
* @name Package#devDependencies
131116
* @type {string}
132117
*/
133-
$prototype["devDependencies"] = $protobuf.util.emptyObject;
118+
$prototype.devDependencies = $protobuf.util.emptyObject;
134119

135120
/**
136121
* Package types.
137-
* @name Package#types
138122
* @type {string}
139123
*/
140-
$prototype["types"] = "";
124+
$prototype.types = "";
141125

142126
/**
143127
* Creates a new Package instance using the specified properties.
@@ -488,17 +472,15 @@ $root.Package = (function() {
488472

489473
/**
490474
* Repository type.
491-
* @name Package.Repository#type
492475
* @type {string}
493476
*/
494-
$prototype["type"] = "";
477+
$prototype.type = "";
495478

496479
/**
497480
* Repository url.
498-
* @name Package.Repository#url
499481
* @type {string}
500482
*/
501-
$prototype["url"] = "";
483+
$prototype.url = "";
502484

503485
/**
504486
* Creates a new Repository instance using the specified properties.

0 commit comments

Comments
 (0)