Skip to content

Commit

Permalink
CLI: Removed now unnecessary comment lines in generated static code
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 27, 2016
1 parent 003e0fa commit 39a2ea3
Show file tree
Hide file tree
Showing 8 changed files with 9,913 additions and 86 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ Consolidates imports and converts between file formats.
Static targets only:
--no-create Does not generate create functions used for runtime compatibility.
--no-encode Does not generate encode functions.
--no-decode Does not generate decode functions.
--no-verify Does not generate verify functions.
Expand Down
13 changes: 8 additions & 5 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ function push(line) {
function pushComment(lines) {
push("/**");
lines.forEach(function(line) {
if (line === null)
return;
push(" * " + line);
});
push(" */");
Expand All @@ -88,7 +90,7 @@ function name(name) {
// library itself because the reserved words check requires a rather longish regex.
util.safeProp = (function(safeProp) {
return function safeProp_dn(name) {
return /^[$\w]+$/.test(name) && cliUtil.reserved(name)
return !/^[$\w]+$/.test(name) || cliUtil.reserved(name)
? safeProp(name)
: "." + name;
}
Expand Down Expand Up @@ -233,17 +235,18 @@ function buildType(ref, type) {
if (field.repeated)
jsType = "Array.<" + jsType + ">";
push("");
var prop = util.safeProp(field.name);
pushComment([
type.name + " " + field.name + ".",
"@name " + fullName + "#" + name(field.name),
prop.charAt(0) !== "." ? "@name " + fullName + "#" + name(field.name) : null,
"@type {" + jsType + "}"
]);
if (Array.isArray(field.defaultValue)) {
push("$prototype[" + JSON.stringify(field.name) + "] = $protobuf.util.emptyArray;");
push("$prototype" + prop + " = $protobuf.util.emptyArray;");
} else if (util.isObject(field.defaultValue))
push("$prototype[" + JSON.stringify(field.name) + "] = $protobuf.util.emptyObject;");
push("$prototype" + prop + " = $protobuf.util.emptyObject;");
else
push("$prototype[" + JSON.stringify(field.name) + "] = " + JSON.stringify(field.defaultValue) + ";");
push("$prototype" + prop + " = " + JSON.stringify(field.defaultValue) + ";");
});

// virtual oneof fields
Expand Down
3 changes: 2 additions & 1 deletion scripts/gentests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var fs = require("fs"),
"tests/data/package.proto",
"tests/data/rpc.proto",
"tests/data/mapbox/vector_tile.proto",
"tests/data/ambiguous-names.proto"
"tests/data/ambiguous-names.proto",
"tests/data/test.proto"
]
.forEach(function(file) {
var out = file.replace(/\.proto$/, ".js");
Expand Down
6 changes: 2 additions & 4 deletions tests/data/ambiguous-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ $root.A = (function() {

/**
* A whatever.
* @name A#whatever
* @type {string}
*/
$prototype["whatever"] = "";
$prototype.whatever = "";

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

/**
* B A.
* @name B#A
* @type {A}
*/
$prototype["A"] = null;
$prototype.A = null;

/**
* Creates a new B instance using the specified properties.
Expand Down
54 changes: 18 additions & 36 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ $root.vector_tile = (function() {

/**
* Tile layers.
* @name vector_tile.Tile#layers
* @type {Array.<vector_tile.Tile.Layer>}
*/
$prototype["layers"] = $protobuf.util.emptyArray;
$prototype.layers = $protobuf.util.emptyArray;

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

/**
* Value stringValue.
* @name vector_tile.Tile.Value#stringValue
* @type {string}
*/
$prototype["stringValue"] = "";
$prototype.stringValue = "";

/**
* Value floatValue.
* @name vector_tile.Tile.Value#floatValue
* @type {number}
*/
$prototype["floatValue"] = 0;
$prototype.floatValue = 0;

/**
* Value doubleValue.
* @name vector_tile.Tile.Value#doubleValue
* @type {number}
*/
$prototype["doubleValue"] = 0;
$prototype.doubleValue = 0;

/**
* Value intValue.
* @name vector_tile.Tile.Value#intValue
* @type {number|Long}
*/
$prototype["intValue"] = $protobuf.util.emptyObject;
$prototype.intValue = $protobuf.util.emptyObject;

/**
* Value uintValue.
* @name vector_tile.Tile.Value#uintValue
* @type {number|Long}
*/
$prototype["uintValue"] = $protobuf.util.emptyObject;
$prototype.uintValue = $protobuf.util.emptyObject;

/**
* Value sintValue.
* @name vector_tile.Tile.Value#sintValue
* @type {number|Long}
*/
$prototype["sintValue"] = $protobuf.util.emptyObject;
$prototype.sintValue = $protobuf.util.emptyObject;

/**
* Value boolValue.
* @name vector_tile.Tile.Value#boolValue
* @type {boolean}
*/
$prototype["boolValue"] = false;
$prototype.boolValue = false;

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

/**
* Feature id.
* @name vector_tile.Tile.Feature#id
* @type {number|Long}
*/
$prototype["id"] = $protobuf.util.emptyObject;
$prototype.id = $protobuf.util.emptyObject;

/**
* Feature tags.
* @name vector_tile.Tile.Feature#tags
* @type {Array.<number>}
*/
$prototype["tags"] = $protobuf.util.emptyArray;
$prototype.tags = $protobuf.util.emptyArray;

/**
* Feature type.
* @name vector_tile.Tile.Feature#type
* @type {number}
*/
$prototype["type"] = "UNKNOWN";
$prototype.type = "UNKNOWN";

/**
* Feature geometry.
* @name vector_tile.Tile.Feature#geometry
* @type {Array.<number>}
*/
$prototype["geometry"] = $protobuf.util.emptyArray;
$prototype.geometry = $protobuf.util.emptyArray;

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

/**
* Layer version.
* @name vector_tile.Tile.Layer#version
* @type {number}
*/
$prototype["version"] = 1;
$prototype.version = 1;

/**
* Layer name.
* @name vector_tile.Tile.Layer#name
* @type {string}
*/
$prototype["name"] = "";
$prototype.name = "";

/**
* Layer features.
* @name vector_tile.Tile.Layer#features
* @type {Array.<vector_tile.Tile.Feature>}
*/
$prototype["features"] = $protobuf.util.emptyArray;
$prototype.features = $protobuf.util.emptyArray;

/**
* Layer keys.
* @name vector_tile.Tile.Layer#keys
* @type {Array.<string>}
*/
$prototype["keys"] = $protobuf.util.emptyArray;
$prototype.keys = $protobuf.util.emptyArray;

/**
* Layer values.
* @name vector_tile.Tile.Layer#values
* @type {Array.<vector_tile.Tile.Value>}
*/
$prototype["values"] = $protobuf.util.emptyArray;
$prototype.values = $protobuf.util.emptyArray;

/**
* Layer extent.
* @name vector_tile.Tile.Layer#extent
* @type {number}
*/
$prototype["extent"] = 4096;
$prototype.extent = 4096;

/**
* Creates a new Layer instance using the specified properties.
Expand Down
54 changes: 18 additions & 36 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,115 +29,99 @@ $root.Package = (function() {

/**
* Package name.
* @name Package#name
* @type {string}
*/
$prototype["name"] = "";
$prototype.name = "";

/**
* Package version.
* @name Package#version
* @type {string}
*/
$prototype["version"] = "";
$prototype.version = "";

/**
* Package description.
* @name Package#description
* @type {string}
*/
$prototype["description"] = "";
$prototype.description = "";

/**
* Package author.
* @name Package#author
* @type {string}
*/
$prototype["author"] = "";
$prototype.author = "";

/**
* Package license.
* @name Package#license
* @type {string}
*/
$prototype["license"] = "";
$prototype.license = "";

/**
* Package repository.
* @name Package#repository
* @type {Package.Repository}
*/
$prototype["repository"] = null;
$prototype.repository = null;

/**
* Package bugs.
* @name Package#bugs
* @type {string}
*/
$prototype["bugs"] = "";
$prototype.bugs = "";

/**
* Package homepage.
* @name Package#homepage
* @type {string}
*/
$prototype["homepage"] = "";
$prototype.homepage = "";

/**
* Package keywords.
* @name Package#keywords
* @type {Array.<string>}
*/
$prototype["keywords"] = $protobuf.util.emptyArray;
$prototype.keywords = $protobuf.util.emptyArray;

/**
* Package main.
* @name Package#main
* @type {string}
*/
$prototype["main"] = "";
$prototype.main = "";

/**
* Package bin.
* @name Package#bin
* @type {string}
*/
$prototype["bin"] = $protobuf.util.emptyObject;
$prototype.bin = $protobuf.util.emptyObject;

/**
* Package scripts.
* @name Package#scripts
* @type {string}
*/
$prototype["scripts"] = $protobuf.util.emptyObject;
$prototype.scripts = $protobuf.util.emptyObject;

/**
* Package dependencies.
* @name Package#dependencies
* @type {string}
*/
$prototype["dependencies"] = $protobuf.util.emptyObject;
$prototype.dependencies = $protobuf.util.emptyObject;

/**
* Package optionalDependencies.
* @name Package#optionalDependencies
* @type {string}
*/
$prototype["optionalDependencies"] = $protobuf.util.emptyObject;
$prototype.optionalDependencies = $protobuf.util.emptyObject;

/**
* Package devDependencies.
* @name Package#devDependencies
* @type {string}
*/
$prototype["devDependencies"] = $protobuf.util.emptyObject;
$prototype.devDependencies = $protobuf.util.emptyObject;

/**
* Package types.
* @name Package#types
* @type {string}
*/
$prototype["types"] = "";
$prototype.types = "";

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

/**
* Repository type.
* @name Package.Repository#type
* @type {string}
*/
$prototype["type"] = "";
$prototype.type = "";

/**
* Repository url.
* @name Package.Repository#url
* @type {string}
*/
$prototype["url"] = "";
$prototype.url = "";

/**
* Creates a new Repository instance using the specified properties.
Expand Down
Loading

0 comments on commit 39a2ea3

Please sign in to comment.