From f22a34a071753bca416732ec4d01892263f543fb Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Thu, 5 Jan 2017 01:44:29 +0100 Subject: [PATCH] Other: Updated tests for new package.json layout; Other: Added break/continue label support to codegen --- package.json | 11 ++++++++-- src/util/codegen/index.js | 2 +- src/util/codegen/package.json | 2 +- tests/data/package.js | 40 ++++++++++++++++++++++++++++++++++- tests/data/package.proto | 1 + 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7d0e2a359..26925374f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" + ] } diff --git a/src/util/codegen/index.js b/src/util/codegen/index.js index 3bf8ecb7b..a63638d05 100644 --- a/src/util/codegen/index.js +++ b/src/util/codegen/index.js @@ -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. diff --git a/src/util/codegen/package.json b/src/util/codegen/package.json index f62bcf639..f79463120 100644 --- a/src/util/codegen/package.json +++ b/src/util/codegen/package.json @@ -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 ", "repository": { "type": "git", diff --git a/tests/data/package.js b/tests/data/package.js index 80e03d7d0..7b9aa3d97 100644 --- a/tests/data/package.js +++ b/tests/data/package.js @@ -124,8 +124,14 @@ $root.Package = (function() { */ $prototype.types = ""; + /** + * Package cliDependencies. + * @type {Array.} + */ + $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. @@ -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); @@ -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; @@ -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); @@ -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); diff --git a/tests/data/package.proto b/tests/data/package.proto index cbc7e5b61..1169f54f1 100644 --- a/tests/data/package.proto +++ b/tests/data/package.proto @@ -24,4 +24,5 @@ message Package { map devDependencies = 15; // map browser = 16; string types = 17; + repeated string cliDependencies = 18; }