protobufjs-cli
Advanced tools
| /* | ||
| Copyright 2012 the Catharsis Authors. | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| const { parse } = require('./lib/parser'); | ||
| const stringify = require('./lib/stringify'); | ||
| const Types = require('./lib/types'); | ||
| module.exports = { | ||
| parse: (typeExpr, options = {}) => { | ||
| typeExpr = typeExpr | ||
| .replace(/[\r\n]/g, '') | ||
| .replace(/\s+/g, ' ') | ||
| .trim(); | ||
| return parse(typeExpr, options); | ||
| }, | ||
| stringify: (parsedType, options = {}) => { | ||
| const stringified = stringify(parsedType, options); | ||
| if (options.validate) { | ||
| module.exports.parse(stringified, options); | ||
| } | ||
| return stringified; | ||
| }, | ||
| Types, | ||
| }; |
Sorry, the diff of this file is too big to display
| /* | ||
| Copyright 2012 the Catharsis Authors. | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| const Types = require('./types'); | ||
| function combineNameAndType(nameString, typeString) { | ||
| const separator = nameString && typeString ? ':' : ''; | ||
| return nameString + separator + typeString; | ||
| } | ||
| class Stringifier { | ||
| constructor(options) { | ||
| this._options = options || {}; | ||
| } | ||
| applications(applications) { | ||
| let result = ''; | ||
| const strings = []; | ||
| if (!applications) { | ||
| return result; | ||
| } | ||
| for (let i = 0, l = applications.length; i < l; i++) { | ||
| strings.push(this.type(applications[i])); | ||
| } | ||
| result = strings.join(', '); | ||
| if (this._options.htmlSafe) { | ||
| return `<${result}>`; | ||
| } | ||
| return `<${result}>`; | ||
| } | ||
| elements(elements) { | ||
| let result = ''; | ||
| const strings = []; | ||
| if (!elements) { | ||
| return result; | ||
| } | ||
| for (let i = 0, l = elements.length; i < l; i++) { | ||
| strings.push(this.type(elements[i])); | ||
| } | ||
| result = `(${strings.join('|')})`; | ||
| return result; | ||
| } | ||
| key(type) { | ||
| return this.type(type); | ||
| } | ||
| name(name) { | ||
| return name || ''; | ||
| } | ||
| new(funcNew) { | ||
| return funcNew ? `new:${this.type(funcNew)}` : ''; | ||
| } | ||
| nullable(nullable) { | ||
| switch (nullable) { | ||
| case true: | ||
| return '?'; | ||
| case false: | ||
| return '!'; | ||
| default: | ||
| return ''; | ||
| } | ||
| } | ||
| optional(optional) { | ||
| if (optional === true) { | ||
| return '='; | ||
| } else { | ||
| return ''; | ||
| } | ||
| } | ||
| params(params) { | ||
| let result = ''; | ||
| const strings = []; | ||
| if (!params || params.length === 0) { | ||
| return result; | ||
| } | ||
| for (let i = 0, l = params.length; i < l; i++) { | ||
| strings.push(this.type(params[i])); | ||
| } | ||
| result = strings.join(', '); | ||
| return result; | ||
| } | ||
| result(result) { | ||
| return result ? `: ${this.type(result)}` : ''; | ||
| } | ||
| stringify(type) { | ||
| return this.type(type); | ||
| } | ||
| this(funcThis) { | ||
| return funcThis ? `this:${this.type(funcThis)}` : ''; | ||
| } | ||
| type(type) { | ||
| let typeString = ''; | ||
| if (!type) { | ||
| return typeString; | ||
| } | ||
| switch (type.type) { | ||
| case Types.AllLiteral: | ||
| typeString = this._formatNameAndType(type, '*'); | ||
| break; | ||
| case Types.FunctionType: | ||
| typeString = this._signature(type); | ||
| break; | ||
| case Types.NullLiteral: | ||
| typeString = this._formatNameAndType(type, 'null'); | ||
| break; | ||
| case Types.RecordType: | ||
| typeString = this._record(type); | ||
| break; | ||
| case Types.TypeApplication: | ||
| typeString = this.type(type.expression) + this.applications(type.applications); | ||
| break; | ||
| case Types.UndefinedLiteral: | ||
| typeString = this._formatNameAndType(type, 'undefined'); | ||
| break; | ||
| case Types.TypeUnion: | ||
| typeString = this.elements(type.elements); | ||
| break; | ||
| case Types.UnknownLiteral: | ||
| typeString = this._formatNameAndType(type, '?'); | ||
| break; | ||
| default: | ||
| typeString = this._formatNameAndType(type); | ||
| } | ||
| // add optional/nullable/repeatable modifiers | ||
| if (!this._options._ignoreModifiers) { | ||
| typeString = this._addModifiers(type, typeString); | ||
| } | ||
| return typeString; | ||
| } | ||
| _record(type) { | ||
| const fields = this._recordFields(type.fields); | ||
| return `{${fields.join(', ')}}`; | ||
| } | ||
| _recordFields(fields) { | ||
| let field; | ||
| let keyAndValue; | ||
| const result = []; | ||
| if (!fields) { | ||
| return result; | ||
| } | ||
| for (let i = 0, l = fields.length; i < l; i++) { | ||
| field = fields[i]; | ||
| keyAndValue = this.key(field.key); | ||
| keyAndValue += field.value ? `: ${this.type(field.value)}` : ''; | ||
| result.push(keyAndValue); | ||
| } | ||
| return result; | ||
| } | ||
| // Adds optional, nullable, and repeatable modifiers if necessary. | ||
| _addModifiers(type, typeString) { | ||
| let combined; | ||
| let optional = ''; | ||
| let repeatable = ''; | ||
| if (type.repeatable) { | ||
| repeatable = '...'; | ||
| } | ||
| combined = this.nullable(type.nullable) + combineNameAndType('', typeString); | ||
| optional = this.optional(type.optional); | ||
| return repeatable + combined + optional; | ||
| } | ||
| _addLinks(nameString) { | ||
| const href = this._getHrefForString(nameString); | ||
| let link = nameString; | ||
| let linkClass = this._options.linkClass || ''; | ||
| if (href) { | ||
| if (linkClass) { | ||
| linkClass = ` class="${linkClass}"`; | ||
| } | ||
| link = `<a href="${href}"${linkClass}>${nameString}</a>`; | ||
| } | ||
| return link; | ||
| } | ||
| _formatNameAndType(type, literal) { | ||
| let nameString = type.name || literal || ''; | ||
| const typeString = type.type ? this.type(type.type) : ''; | ||
| nameString = this._addLinks(nameString); | ||
| return combineNameAndType(nameString, typeString); | ||
| } | ||
| _getHrefForString(nameString) { | ||
| let href = ''; | ||
| const links = this._options.links; | ||
| if (!links) { | ||
| return href; | ||
| } | ||
| // Accept a map-like object or a dictionary-style object. | ||
| if (links && typeof links.get === 'function') { | ||
| href = links.get(nameString); | ||
| } else if ({}.hasOwnProperty.call(links, nameString)) { | ||
| href = links[nameString]; | ||
| } | ||
| return href; | ||
| } | ||
| _signature(type) { | ||
| let param; | ||
| let prop; | ||
| let signature; | ||
| const params = []; | ||
| // these go within the signature's parens, in this order | ||
| const props = ['new', 'this', 'params']; | ||
| for (let i = 0, l = props.length; i < l; i++) { | ||
| prop = props[i]; | ||
| param = this[prop](type[prop]); | ||
| if (param.length > 0) { | ||
| params.push(param); | ||
| } | ||
| } | ||
| signature = `function(${params.join(', ')})`; | ||
| signature += this.result(type.result); | ||
| return signature; | ||
| } | ||
| } | ||
| module.exports = (type, options) => new Stringifier(options).stringify(type); |
| /* | ||
| Copyright 2013 the Catharsis Authors. | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
| module.exports = Object.freeze({ | ||
| // `*` | ||
| AllLiteral: 'AllLiteral', | ||
| // like `blah` in `{blah: string}` | ||
| FieldType: 'FieldType', | ||
| // like `function(string): string` | ||
| FunctionType: 'FunctionType', | ||
| // any string literal, such as `string` or `My.Namespace` | ||
| NameExpression: 'NameExpression', | ||
| // null | ||
| NullLiteral: 'NullLiteral', | ||
| // like `{foo: string}` | ||
| RecordType: 'RecordType', | ||
| // like `Array.<string>` | ||
| TypeApplication: 'TypeApplication', | ||
| // like `(number|string)` | ||
| TypeUnion: 'TypeUnion', | ||
| // undefined | ||
| UndefinedLiteral: 'UndefinedLiteral', | ||
| // `?` | ||
| UnknownLiteral: 'UnknownLiteral', | ||
| }); |
| Copyright 2012 the Catharsis Authors. | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
| associated documentation files (the "Software"), to deal in the Software without restriction, | ||
| including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
| sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all copies or substantial | ||
| portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
| NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES | ||
| OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| This directory vendors the subset of [Catharsis](https://github.com/hegemonic/catharsis) used by `pbts` through JSDoc type parsing. | ||
| Changes from upstream: | ||
| * Includes the literal-prefix type name fix from [hegemonic/catharsis#80](https://github.com/hegemonic/catharsis/pull/80). | ||
| * Keeps only the parser/stringifier files needed by JSDoc. | ||
| The vendored parser/stringifier are injected through [`tsd-jsdoc/patch.js`](../tsd-jsdoc/patch.js). |
+17
-0
| # Changelog | ||
| ## [2.5.1](https://github.com/protobufjs/protobuf.js/compare/protobufjs-cli-v2.5.0...protobufjs-cli-v2.5.1) (2026-06-04) | ||
| ### Bug Fixes | ||
| * Avoid name collisions in generated code ([#2302](https://github.com/protobufjs/protobuf.js/issues/2302)) ([ce013ab](https://github.com/protobufjs/protobuf.js/commit/ce013abb069c0df02e261a1ea3019d6c3fbe069e)) | ||
| * **cli:** Vendor patched Catharsis for pbts ([#2304](https://github.com/protobufjs/protobuf.js/issues/2304)) ([29f7c96](https://github.com/protobufjs/protobuf.js/commit/29f7c96ede419baa2e5836f7a7b61d510e36693e)) | ||
| ### Dependencies | ||
| * The following workspace dependencies were updated | ||
| * devDependencies | ||
| * protobufjs bumped from file:.. to 8.6.0 | ||
| * peerDependencies | ||
| * protobufjs bumped from ^8.5.0 to ^8.6.0 | ||
| ## [2.5.0](https://github.com/protobufjs/protobuf.js/compare/protobufjs-cli-v2.4.2...protobufjs-cli-v2.5.0) (2026-05-29) | ||
@@ -4,0 +21,0 @@ |
@@ -5,2 +5,3 @@ "use strict"; | ||
| var typeLinkerPatched = false; | ||
| var catharsisPatched = false; | ||
| var typeScriptTypePattern = /[&;]|\?:|=>|\bkeyof\b|\btypeof\b/; | ||
@@ -12,3 +13,23 @@ | ||
| function patchCatharsis() { | ||
| if (catharsisPatched) | ||
| return; | ||
| catharsisPatched = true; | ||
| var path = require("path"); | ||
| var typePath = require.resolve("jsdoc/tag/type"); | ||
| var catharsisPath = require.resolve("catharsis", { | ||
| paths: [ path.dirname(typePath) ] | ||
| }); | ||
| var catharsis = require(catharsisPath); | ||
| var vendored = require("../catharsis/catharsis"); | ||
| catharsis.Types = vendored.Types; | ||
| catharsis.parse = vendored.parse; | ||
| catharsis.stringify = vendored.stringify; | ||
| } | ||
| function patchTypeExpressionParser(dictionary) { | ||
| patchCatharsis(); | ||
| var type = require("jsdoc/tag/type"); | ||
@@ -15,0 +36,0 @@ var parse = type.parse, |
+6
-8
| { | ||
| "name": "protobufjs-cli", | ||
| "description": "Translates between file formats and generates static code as well as TypeScript definitions.", | ||
| "version": "2.5.0", | ||
| "version": "2.5.1", | ||
| "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
| "peerDependencies": { | ||
| "protobufjs": "^8.5.0" | ||
| "protobufjs": "^8.6.0" | ||
| }, | ||
@@ -29,10 +29,8 @@ "dependencies": { | ||
| "escodegen": "^1.13.0", | ||
| "espree": "^9.0.0", | ||
| "espree": "^9.6.1", | ||
| "estraverse": "^5.1.0", | ||
| "glob": "^8.0.0", | ||
| "jsdoc": "^4.0.0", | ||
| "glob": "^8.1.0", | ||
| "jsdoc": "^4.0.5", | ||
| "minimist": "^1.2.8", | ||
| "semver": "^7.1.2", | ||
| "tmp": "^0.2.1", | ||
| "uglify-js": "^3.7.7" | ||
| "tmp": "^0.2.7" | ||
| }, | ||
@@ -39,0 +37,0 @@ "devDependencies": { |
@@ -20,10 +20,2 @@ "use strict"; | ||
| function jsonSafeProp(json) { | ||
| return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) { | ||
| return protobuf.util.safeProp($2).charAt(0) === "." | ||
| ? $1 + $2 + ":" | ||
| : $0; | ||
| }); | ||
| } | ||
| function escapeName(name) { | ||
@@ -47,6 +39,6 @@ if (!name) | ||
| if (root.options) { | ||
| var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2)); | ||
| var optionsJson = JSON.stringify(root.options, null, 2); | ||
| output.push(".setOptions(" + optionsJson + ")\n"); | ||
| } | ||
| var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim()); | ||
| var json = JSON.stringify(root.nested, null, 2).trim(); | ||
| output.push(".addJSON(" + json + ");"); | ||
@@ -53,0 +45,0 @@ |
+172
-42
| "use strict"; | ||
| module.exports = static_target; | ||
| var UglifyJS = require("uglify-js"), | ||
| espree = require("espree"), | ||
| var espree = require("espree"), | ||
| escodegen = require("escodegen"), | ||
@@ -19,2 +18,4 @@ estraverse = require("estraverse"), | ||
| var config = {}; | ||
| var globalRefs = new Set(); | ||
| var globalAliasIndex = -1; | ||
@@ -36,2 +37,3 @@ static_target.description = "Static code without reflection (non-functional on its own)"; | ||
| push((config.es6 ? "const " : "var ") + aliases.map(function(name) { return "$" + name + " = $protobuf." + name; }).join(", ") + ";"); | ||
| globalAliasIndex = out.length; | ||
| push(""); | ||
@@ -49,2 +51,9 @@ } | ||
| buildNamespace(null, root); | ||
| var globalAliases = Array.from(globalRefs); | ||
| if (globalAliases.length) { | ||
| var aliasDecl = (config.es6 ? "const " : "var ") + globalAliases.map(function(name) { | ||
| return "$" + name + " = $util.global." + name; | ||
| }).join(", ") + ";"; | ||
| out.splice(globalAliasIndex, 0, aliasDecl); | ||
| } | ||
| return callback(null, out.join("\n")); | ||
@@ -57,2 +66,4 @@ } catch (err) { | ||
| config = {}; | ||
| globalRefs = new Set(); | ||
| globalAliasIndex = -1; | ||
| } | ||
@@ -206,11 +217,3 @@ } | ||
| function beautifyCode(code) { | ||
| // Add semicolons | ||
| code = UglifyJS.minify(code, { | ||
| compress: false, | ||
| mangle: false, | ||
| output: { beautify: true } | ||
| }).code; | ||
| // Properly beautify | ||
| var ast = espree.parse(code); | ||
| function beautifyAst(ast) { | ||
| estraverse.replace(ast, { | ||
@@ -235,8 +238,5 @@ enter: function(node, parent) { | ||
| }); | ||
| code = escodegen.generate(ast, { | ||
| format: { | ||
| newline: "\n", | ||
| quotes: "double" | ||
| } | ||
| }); | ||
| } | ||
| function addWireComments(code) { | ||
| // Add id, wireType comments | ||
@@ -258,5 +258,129 @@ if (config.comments) | ||
| var globalVars = new Set([ | ||
| "AbortController", | ||
| "AbortSignal", | ||
| "AggregateError", | ||
| "Array", | ||
| "ArrayBuffer", | ||
| "Atomics", | ||
| "BigInt", | ||
| "BigInt64Array", | ||
| "BigUint64Array", | ||
| "Blob", | ||
| "Boolean", | ||
| "Buffer", | ||
| "DataView", | ||
| "Date", | ||
| "DOMException", | ||
| "Error", | ||
| "Event", | ||
| "EventTarget", | ||
| "EvalError", | ||
| "File", | ||
| "FinalizationRegistry", | ||
| "Float32Array", | ||
| "Float64Array", | ||
| "FormData", | ||
| "Function", | ||
| "Headers", | ||
| "Infinity", | ||
| "Int8Array", | ||
| "Int16Array", | ||
| "Int32Array", | ||
| "Intl", | ||
| "JSON", | ||
| "Map", | ||
| "Math", | ||
| "MessageChannel", | ||
| "MessagePort", | ||
| "NaN", | ||
| "Number", | ||
| "Object", | ||
| "Promise", | ||
| "Proxy", | ||
| "RangeError", | ||
| "ReadableStream", | ||
| "ReferenceError", | ||
| "Reflect", | ||
| "RegExp", | ||
| "Request", | ||
| "Response", | ||
| "Set", | ||
| "SharedArrayBuffer", | ||
| "String", | ||
| "Symbol", | ||
| "SyntaxError", | ||
| "TextDecoder", | ||
| "TextEncoder", | ||
| "TransformStream", | ||
| "TypeError", | ||
| "URIError", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| "Uint16Array", | ||
| "Uint32Array", | ||
| "URL", | ||
| "URLSearchParams", | ||
| "WebAssembly", | ||
| "WeakMap", | ||
| "WeakRef", | ||
| "WeakSet", | ||
| "WritableStream", | ||
| "clearInterval", | ||
| "clearTimeout", | ||
| "decodeURI", | ||
| "decodeURIComponent", | ||
| "encodeURI", | ||
| "encodeURIComponent", | ||
| "escape", | ||
| "fetch", | ||
| "globalThis", | ||
| "isFinite", | ||
| "isNaN", | ||
| "parseFloat", | ||
| "parseInt", | ||
| "queueMicrotask", | ||
| "setInterval", | ||
| "setTimeout", | ||
| "structuredClone", | ||
| "undefined", | ||
| "unescape" | ||
| ]); | ||
| function globalRef(name) { | ||
| globalRefs.add(name); | ||
| return "$" + name; | ||
| } | ||
| function isIdentifierReference(node, parent) { | ||
| if (!parent) | ||
| return true; | ||
| switch (parent.type) { | ||
| case "MemberExpression": | ||
| return parent.object === node || parent.computed; | ||
| case "Property": | ||
| return parent.value === node || parent.computed; | ||
| case "VariableDeclarator": | ||
| return parent.id !== node; | ||
| case "FunctionDeclaration": | ||
| case "FunctionExpression": | ||
| return parent.id !== node && parent.params.indexOf(node) < 0; | ||
| case "CatchClause": | ||
| return parent.param !== node; | ||
| case "AssignmentExpression": | ||
| case "AssignmentPattern": | ||
| return parent.left !== node; | ||
| case "UpdateExpression": | ||
| case "BreakStatement": | ||
| case "ContinueStatement": | ||
| case "LabeledStatement": | ||
| return false; | ||
| default: | ||
| return true; | ||
| } | ||
| } | ||
| function buildFunction(type, functionName, gen, scope) { | ||
| var code = gen.toString(functionName); | ||
| var ast = espree.parse(code); | ||
| var code = gen.toString(); | ||
| var ast = espree.parse("(" + code + ");"); | ||
@@ -297,2 +421,7 @@ function rootMemberRef(object) { | ||
| }; | ||
| if (node.type === "Identifier" && globalVars.has(node.name) && isIdentifierReference(node, parent)) | ||
| return { | ||
| "type": "Identifier", | ||
| "name": globalRef(node.name) | ||
| }; | ||
| // replace generated constructor alias with the actual ctor | ||
@@ -337,2 +466,6 @@ if ( | ||
| /* eslint-enable no-extra-parens */ | ||
| if (config.beautify) | ||
| beautifyAst(ast); | ||
| ast = ast.body[0].expression; | ||
| code = escodegen.generate(ast, { | ||
@@ -344,6 +477,3 @@ format: { | ||
| }); | ||
| if (config.beautify) | ||
| code = beautifyCode(code); | ||
| code = addWireComments(code); | ||
| code = code.replace(/ {4}/g, "\t"); | ||
@@ -362,3 +492,3 @@ | ||
| if (isCtor) // constructor | ||
| push(lines[0]); | ||
| push((config.es6 ? "const " : "var ") + escapeName(type.name) + " = " + lines[0]); | ||
| else if (hasScope) // enclose in an iife | ||
@@ -377,3 +507,3 @@ push(escapeName(type.name) + "." + escapeName(functionName) + " = (function(" + Object.keys(scope).map(escapeName).join(", ") + ") { return " + lines[0]); | ||
| if (isCtor) | ||
| push("}"); | ||
| push("};"); | ||
| else if (hasScope) | ||
@@ -700,3 +830,3 @@ push("};})(" + Object.keys(scope).map(function(key) { return scope[key]; }).join(", ") + ");"); | ||
| } | ||
| push("Object.defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {"); | ||
| push(globalRef("Object") + ".defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {"); | ||
| ++indent; | ||
@@ -724,3 +854,3 @@ push("get: $util.oneOfGetter($oneOfFields = [" + oneof.oneof.map(JSON.stringify).join(", ") + "]),"); | ||
| ])); | ||
| push(escapeName(type.name) + ".create = function create(properties) {"); | ||
| push(escapeName(type.name) + ".create = function(properties) {"); | ||
| ++indent; | ||
@@ -756,3 +886,3 @@ push("return new " + escapeName(type.name) + "(properties);"); | ||
| ]); | ||
| push(escapeName(type.name) + ".encodeDelimited = function encodeDelimited(message, writer) {"); | ||
| push(escapeName(type.name) + ".encodeDelimited = function(message, writer) {"); | ||
| ++indent; | ||
@@ -792,3 +922,3 @@ push("return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();"); | ||
| ])); | ||
| push(escapeName(type.name) + ".decodeDelimited = function decodeDelimited(reader) {"); | ||
| push(escapeName(type.name) + ".decodeDelimited = function(reader) {"); | ||
| ++indent; | ||
@@ -850,5 +980,5 @@ push("if (!(reader instanceof $Reader))"); | ||
| ]); | ||
| push(escapeName(type.name) + ".prototype.toJSON = function toJSON() {"); | ||
| push(escapeName(type.name) + ".prototype.toJSON = function() {"); | ||
| ++indent; | ||
| push("return this.constructor.toObject(this, $protobuf.util.toJSONOptions);"); | ||
| push("return " + escapeName(type.name) + ".toObject(this, $protobuf.util.toJSONOptions);"); | ||
| --indent; | ||
@@ -869,5 +999,5 @@ push("};"); | ||
| ]); | ||
| push(escapeName(type.name) + ".getTypeUrl = function getTypeUrl(prefix) {"); | ||
| push(escapeName(type.name) + ".getTypeUrl = function(prefix) {"); | ||
| ++indent; | ||
| push("if (prefix === undefined)"); | ||
| push("if (prefix === " + globalRef("undefined") + ")"); | ||
| ++indent; | ||
@@ -895,9 +1025,9 @@ push("prefix = \"type.googleapis.com\";"); | ||
| ]); | ||
| push("function " + escapeName(service.name) + "(rpcImpl, requestDelimited, responseDelimited) {"); | ||
| push((config.es6 ? "const " : "var ") + escapeName(service.name) + " = function(rpcImpl, requestDelimited, responseDelimited) {"); | ||
| ++indent; | ||
| push("$protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited);"); | ||
| --indent; | ||
| push("}"); | ||
| push("};"); | ||
| push(""); | ||
| push("(" + escapeName(service.name) + ".prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = " + escapeName(service.name) + ";"); | ||
| push("(" + escapeName(service.name) + ".prototype = " + globalRef("Object") + ".create($protobuf.rpc.Service.prototype)).constructor = " + escapeName(service.name) + ";"); | ||
@@ -916,3 +1046,3 @@ if (config.create) { | ||
| ]); | ||
| push(escapeName(service.name) + ".create = function create(rpcImpl, requestDelimited, responseDelimited) {"); | ||
| push(escapeName(service.name) + ".create = function(rpcImpl, requestDelimited, responseDelimited) {"); | ||
| ++indent; | ||
@@ -961,5 +1091,5 @@ push("return new this(rpcImpl, requestDelimited, responseDelimited);"); | ||
| ]); | ||
| push("Object.defineProperties(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {"); | ||
| push(globalRef("Object") + ".defineProperties(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function(request, callback) {"); | ||
| ++indent; | ||
| push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);"); | ||
| push("return $protobuf.rpc.Service.prototype.rpcCall.call(this, " + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);"); | ||
| --indent; | ||
@@ -972,4 +1102,4 @@ push("}, {"); | ||
| push("responseType: { value: " + JSON.stringify(method.responseType) + " },"); | ||
| push("requestStream: { value: " + (method.requestStream ? "true" : "undefined") + " },"); | ||
| push("responseStream: { value: " + (method.responseStream ? "true" : "undefined") + " }"); | ||
| push("requestStream: { value: " + (method.requestStream ? "true" : globalRef("undefined")) + " },"); | ||
| push("responseStream: { value: " + (method.responseStream ? "true" : globalRef("undefined")) + " }"); | ||
| --indent; | ||
@@ -998,3 +1128,3 @@ push("});"); | ||
| ++indent; | ||
| push((config.es6 ? "const" : "var") + " valuesById = {}, values = Object.create(valuesById);"); | ||
| push((config.es6 ? "const" : "var") + " valuesById = {}, values = " + globalRef("Object") + ".create(valuesById);"); | ||
| var aliased = []; | ||
@@ -1001,0 +1131,0 @@ Object.keys(enm.values).forEach(function(key) { |
418868
162.71%9
-18.18%41
17.14%9118
161.86%10
11.11%- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated