Skip to content

Commit

Permalink
Other: Updated tests for new package.json layout; Other: Added break/…
Browse files Browse the repository at this point in the history
…continue label support to codegen
  • Loading branch information
dcodeIO committed Jan 5, 2017
1 parent e88d13c commit f22a34a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@protobufjs/aspromise": "^1.0.5",
"@protobufjs/base64": "^1.0.5",
"@protobufjs/codegen": "^1.0.4",
"@protobufjs/codegen": "^1.0.5",
"@protobufjs/eventemitter": "^1.0.5",
"@protobufjs/extend": "^1.0.2",
"@protobufjs/fetch": "^1.0.4",
Expand Down Expand Up @@ -89,5 +89,12 @@
"zuul": "^3.11.1",
"zuul-ngrok": "^4.0.0"
},
"cliDependencies": [ "chalk", "glob", "jsdoc", "minimist", "tmp", "uglify-js" ]
"cliDependencies": [
"chalk",
"glob",
"jsdoc",
"minimist",
"tmp",
"uglify-js"
]
}
2 changes: 1 addition & 1 deletion src/util/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var blockOpenRe = /[{[]$/,
blockCloseRe = /^[}\]]/,
casingRe = /:$/,
branchRe = /^\s*(?:if|}?else if|while|for)\b|\b(?:else)\s*$/,
breakRe = /\b(?:break|continue);?$|^\s*return\b/;
breakRe = /\b(?:break|continue)(?: \w+)?;?$|^\s*return\b/;

/**
* A closure for generating functions programmatically.
Expand Down
2 changes: 1 addition & 1 deletion src/util/codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/codegen",
"description": "A closure for generating functions programmatically.",
"version": "1.0.4",
"version": "1.0.5",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"repository": {
"type": "git",
Expand Down
40 changes: 39 additions & 1 deletion tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ $root.Package = (function() {
*/
$prototype.types = "";

/**
* Package cliDependencies.
* @type {Array.<string>}
*/
$prototype.cliDependencies = $protobuf.util.emptyArray;

// Referenced types
var $types = [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null]; $lazyTypes.push($types);
var $types = [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null, null]; $lazyTypes.push($types);

/**
* Creates a new Package instance using the specified properties.
Expand Down Expand Up @@ -207,6 +213,11 @@ $root.Package = (function() {
if (message.types !== undefined && message.types !== "") {
writer.uint32(138).string(message.types);
}
if (message.cliDependencies) {
for (var i = 0; i < message.cliDependencies.length; ++i) {
writer.uint32(146).string(message.cliDependencies[i]);
}
}
return writer;
};})($protobuf.Writer, $protobuf.util, $types);

Expand Down Expand Up @@ -347,6 +358,13 @@ $root.Package = (function() {
message.types = reader.string();
break;

case 18:
if (!(message.cliDependencies && message.cliDependencies.length)) {
message.cliDependencies = [];
}
message.cliDependencies.push(reader.string());
break;

default:
reader.skipType(tag & 7);
break;
Expand Down Expand Up @@ -488,6 +506,16 @@ $root.Package = (function() {
return "Package.types: string expected";
}
}
if (message.cliDependencies !== undefined) {
if (!Array.isArray(message.cliDependencies)) {
return "Package.cliDependencies: array expected";
}
for (var i = 0; i < message.cliDependencies.length; ++i) {
if (!util.isString(message.cliDependencies[i])) {
return "Package.cliDependencies: string[] expected";
}
}
}
return null;
};})($protobuf.util, $types);

Expand Down Expand Up @@ -560,6 +588,16 @@ $root.Package = (function() {
if (dst.types === undefined && options.defaults) {
dst.types = "";
}
if (src.cliDependencies && src.cliDependencies.length) {
dst.cliDependencies = [];
for (var i = 0; i < src.cliDependencies.length; ++i) {
dst.cliDependencies.push(src.cliDependencies[i]);
}
} else {
if (options.defaults || options.arrays) {
dst.cliDependencies = [];
}
}
}
return dst;
};})($types);
Expand Down
1 change: 1 addition & 0 deletions tests/data/package.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ message Package {
map<string, string> devDependencies = 15;
// map<string, bool> browser = 16;
string types = 17;
repeated string cliDependencies = 18;
}

0 comments on commit f22a34a

Please sign in to comment.