Permalink
Browse files

CLI: Made sure that static target's replacement regexes don't match f…

…ields
  • Loading branch information...
dcodeIO committed Jan 14, 2017
1 parent cda5c54 commit 1cc8a2460c7e161c9bc58fa441ec88e752df409c
@@ -41,7 +41,7 @@ function static_target(root, options, callback) {
buildNamespace(null, root);
push("");
if (config.comments)
push("// Resolve lazy type names to actual types");
push("// Resolve lazy type references to actual types");
push("$util.lazyResolve($root, $lazyTypes);");
return callback(null, out.join("\n"));
} catch (err) {
@@ -172,10 +172,10 @@ function buildFunction(type, functionName, gen, scope) {
var code = gen.str(functionName)
.replace(/\(this.ctor\)/g, " $root" + type.fullName) // types: construct directly instead of using reflected ctor
.replace(/(types\[\d+])(\.values)/g, "$1") // enums: use types[N] instead of reflected types[N].values
.replace(/\bWriter\b/g, "$Writer") // use common aliases instead of binding through an iife
.replace(/\bReader\b/g, "$Reader")
.replace(/\butil\b/g, "$util")
.replace(/\btypes\b/g, "$types");
.replace(/\b(?!\.)Writer\b/g, "$Writer") // use common aliases instead of binding through an iife
.replace(/\b(?!\.)Reader\b/g, "$Reader")
.replace(/\b(?!\.)util\.\b/g, "$util.")
.replace(/\b(?!\.)types\[\b/g, "$types[");
if (config.beautify)
code = beautify(code);
@@ -331,15 +331,21 @@ function buildType(ref, type) {
type.fieldsArray.forEach(function(field, index) {
if (field.resolve().resolvedType) { // including enums!
hasTypes = true;
types.push(index + ":"+JSON.stringify(field.resolvedType.fullName.substring(1)));
types.push(index + ": "+JSON.stringify(field.resolvedType.fullName.substring(1)));
}
});
if (hasTypes && (config.encode || config.decode || config.verify || config.convert)) {
push("");
if (config.comments)
push("// Lazily resolved referenced types");
push("var $types = {" + types.join(",") + "}; $lazyTypes.push($types);");
push("// Lazily resolved type references");
push("var $types = {");
++indent;
types.forEach(function(line, i) {
push(line + (i === types.length - 1 ? "" : ","));
});
--indent;
push("}; $lazyTypes.push($types);");
}
if (config.create) {
@@ -3,7 +3,5 @@ define(["protobuf"], function($protobuf) {
%OUTPUT%
$protobuf.roots[%ROOT%] = $root;
return $root;
return $protobuf.roots[%ROOT%] = $root;
});
@@ -4,6 +4,4 @@ var $protobuf = require(%DEPENDENCY%);
%OUTPUT%
$protobuf.roots[%ROOT%] = $root;
module.exports = $root;
module.exports = $protobuf.roots[%ROOT%] = $root;
@@ -11,7 +11,5 @@
%OUTPUT%
$protobuf.roots[%ROOT%] = $root;
return $root;
return $protobuf.roots[%ROOT%] = $root;
});
@@ -210,8 +210,10 @@ $root.B = (function() {
*/
B.prototype.A = null;
// Lazily resolved referenced types
var $types = {0:"A"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
0: "A"
}; $lazyTypes.push($types);
/**
* Creates a new B instance using the specified properties.
@@ -366,9 +368,7 @@ $root.B = (function() {
return B;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_ambiguous-names"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_ambiguous-names"] = $root;
@@ -401,9 +401,7 @@ $root.Test3 = (function() {
return values;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_comments"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_comments"] = $root;
@@ -84,8 +84,11 @@ $root.Message = (function() {
*/
Message.prototype.int64Map = $util.emptyObject;
// Lazily resolved referenced types
var $types = {6:"Message.SomeEnum",7:"Message.SomeEnum"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
6: "Message.SomeEnum",
7: "Message.SomeEnum"
}; $lazyTypes.push($types);
/**
* Creates a new Message instance using the specified properties.
@@ -637,9 +640,7 @@ $root.Message = (function() {
return Message;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_convert"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_convert"] = $root;
@@ -45,8 +45,10 @@ $root.vector_tile = (function() {
*/
Tile.prototype.layers = $util.emptyArray;
// Lazily resolved referenced types
var $types = {0:"vector_tile.Tile.Layer"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
0: "vector_tile.Tile.Layer"
}; $lazyTypes.push($types);
/**
* Creates a new Tile instance using the specified properties.
@@ -685,8 +687,10 @@ $root.vector_tile = (function() {
*/
Feature.prototype.geometry = $util.emptyArray;
// Lazily resolved referenced types
var $types = {2:"vector_tile.Tile.GeomType"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
2: "vector_tile.Tile.GeomType"
}; $lazyTypes.push($types);
/**
* Creates a new Feature instance using the specified properties.
@@ -1058,8 +1062,11 @@ $root.vector_tile = (function() {
*/
Layer.prototype.extent = 4096;
// Lazily resolved referenced types
var $types = {2:"vector_tile.Tile.Feature",4:"vector_tile.Tile.Value"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
2: "vector_tile.Tile.Feature",
4: "vector_tile.Tile.Value"
}; $lazyTypes.push($types);
/**
* Creates a new Layer instance using the specified properties.
@@ -1373,9 +1380,7 @@ $root.vector_tile = (function() {
return vector_tile;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_vector_tile"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_vector_tile"] = $root;
@@ -132,8 +132,10 @@ $root.Package = (function() {
*/
Package.prototype.cliDependencies = $util.emptyArray;
// Lazily resolved referenced types
var $types = {5:"Package.Repository"}; $lazyTypes.push($types);
// Lazily resolved type references
var $types = {
5: "Package.Repository"
}; $lazyTypes.push($types);
/**
* Creates a new Package instance using the specified properties.
@@ -211,8 +213,8 @@ $root.Package = (function() {
writer.uint32(122).fork().uint32(10).string(keys[i]).uint32(18).string(message.devDependencies[keys[i]]).ldelim();
}
}
if (message.$types !== undefined && message.$types !== "") {
writer.uint32(138).string(message.$types);
if (message.types !== undefined && message.types !== "") {
writer.uint32(138).string(message.types);
}
if (message.cliDependencies) {
for (var i = 0; i < message.cliDependencies.length; ++i) {
@@ -340,7 +342,7 @@ $root.Package = (function() {
break;
case 17:
message.$types = reader.string();
message.types = reader.string();
break;
case 18:
@@ -485,9 +487,9 @@ $root.Package = (function() {
}
}
}
if (message.$types !== undefined) {
if (!$util.isString(message.$types)) {
return "$types: string expected";
if (message.types !== undefined) {
if (!$util.isString(message.types)) {
return "types: string expected";
}
}
if (message.cliDependencies !== undefined) {
@@ -573,8 +575,8 @@ $root.Package = (function() {
message.devDependencies[keys[i]] = String(object.devDependencies[keys[i]]);
}
}
if (object.$types !== undefined && object.$types !== null) {
message.$types = String(object.$types);
if (object.types !== undefined && object.types !== null) {
message.types = String(object.types);
}
if (object.cliDependencies) {
message.cliDependencies = [];
@@ -625,7 +627,7 @@ $root.Package = (function() {
object.bugs = "";
object.homepage = "";
object.main = "";
object.$types = "";
object.types = "";
}
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
switch (keys[i]) {
@@ -737,9 +739,9 @@ $root.Package = (function() {
}
break;
case "$types":
if (message.$types !== undefined && message.$types !== null) {
object.$types = message.$types;
case "types":
if (message.types !== undefined && message.types !== null) {
object.types = message.types;
}
break;
@@ -978,9 +980,7 @@ $root.Package = (function() {
return Package;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_package"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_package"] = $root;
@@ -454,9 +454,7 @@ $root.MyResponse = (function() {
return MyResponse;
})();
// Resolve lazy type names to actual types
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);
$protobuf.roots["test_rpc"] = $root;
module.exports = $root;
module.exports = $protobuf.roots["test_rpc"] = $root;
Oops, something went wrong.

0 comments on commit 1cc8a24

Please sign in to comment.