diff options
Diffstat (limited to 'deps/acorn-plugins/acorn-private-class-elements')
5 files changed, 223 insertions, 0 deletions
diff --git a/deps/acorn-plugins/acorn-private-class-elements/CHANGELOG.md b/deps/acorn-plugins/acorn-private-class-elements/CHANGELOG.md new file mode 100644 index 0000000000..5b49344b7a --- /dev/null +++ b/deps/acorn-plugins/acorn-private-class-elements/CHANGELOG.md @@ -0,0 +1,7 @@ +## 0.1.1 (2019-02-09) + +* Add \_branch() method + +## 0.1.0 (2019-02-09) + +Initial release diff --git a/deps/acorn-plugins/acorn-private-class-elements/LICENSE b/deps/acorn-plugins/acorn-private-class-elements/LICENSE new file mode 100644 index 0000000000..7c2b27a19c --- /dev/null +++ b/deps/acorn-plugins/acorn-private-class-elements/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2017-2018 by Adrian Heine + +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. diff --git a/deps/acorn-plugins/acorn-private-class-elements/README.md b/deps/acorn-plugins/acorn-private-class-elements/README.md new file mode 100644 index 0000000000..0d228820cd --- /dev/null +++ b/deps/acorn-plugins/acorn-private-class-elements/README.md @@ -0,0 +1,11 @@ +# Helpers for supporting private class methods and fields for Acorn + +[](https://www.npmjs.org/package/acorn-private-class-elements) + +This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript. + +It provides helpers for implementing support for private class elements. The emitted AST follows [an ESTree proposal](https://github.com/estree/estree/pull/180). + +## License + +This plugin is released under an [MIT License](./LICENSE). diff --git a/deps/acorn-plugins/acorn-private-class-elements/index.js b/deps/acorn-plugins/acorn-private-class-elements/index.js new file mode 100644 index 0000000000..90f2b70437 --- /dev/null +++ b/deps/acorn-plugins/acorn-private-class-elements/index.js @@ -0,0 +1,123 @@ +"use strict" + +const acorn = require('internal/deps/acorn/acorn/dist/acorn') +if (acorn.version.indexOf("6.") != 0 || acorn.version.indexOf("6.0.") == 0) { + throw new Error(`acorn-private-class-elements requires acorn@^6.1.0, not ${acorn.version}`) +} +const tt = acorn.tokTypes +const TokenType = acorn.TokenType + +module.exports = function(Parser) { + // Only load this plugin once. + if (Parser.prototype.parsePrivateName) { + return Parser + } + + // Make sure `Parser` comes from the same acorn as our `tt`, + // otherwise the comparisons fail. + let cur = Parser + while (cur && cur !== acorn.Parser) { + cur = cur.__proto__ + } + if (cur !== acorn.Parser) { + throw new Error("acorn-private-class-elements does not support mixing different acorn copies") + } + + Parser = class extends Parser { + _branch() { + this.__branch = this.__branch || new Parser({ecmaVersion: this.options.ecmaVersion}, this.input) + this.__branch.end = this.end + this.__branch.pos = this.pos + this.__branch.type = this.type + this.__branch.value = this.value + this.__branch.containsEsc = this.containsEsc + return this.__branch + } + + parsePrivateClassElementName(element) { + element.computed = false + element.key = this.parsePrivateName() + if (element.key.name == "constructor") this.raise(element.key.start, "Classes may not have a private element named constructor") + const accept = {get: "set", set: "get"}[element.kind] + const privateBoundNames = this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1] + if (Object.prototype.hasOwnProperty.call(privateBoundNames, element.key.name) && privateBoundNames[element.key.name] !== accept) { + this.raise(element.start, "Duplicate private element") + } + privateBoundNames[element.key.name] = element.kind || true + delete this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][element.key.name] + return element.key + } + + parsePrivateName() { + const node = this.startNode() + node.name = this.value + this.next() + this.finishNode(node, "PrivateName") + if (this.options.allowReserved == "never") this.checkUnreserved(node) + return node + } + + // Parse # token + getTokenFromCode(code) { + if (code === 35) { + ++this.pos + const word = this.readWord1() + return this.finishToken(this.privateNameToken, word) + } + return super.getTokenFromCode(code) + } + + // Manage stacks and check for undeclared private names + parseClass(node, isStatement) { + this._privateBoundNamesStack = this._privateBoundNamesStack || [] + const privateBoundNames = Object.create(this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1] || null) + this._privateBoundNamesStack.push(privateBoundNames) + this._unresolvedPrivateNamesStack = this._unresolvedPrivateNamesStack || [] + const unresolvedPrivateNames = Object.create(null) + this._unresolvedPrivateNamesStack.push(unresolvedPrivateNames) + const _return = super.parseClass(node, isStatement) + this._privateBoundNamesStack.pop() + this._unresolvedPrivateNamesStack.pop() + if (!this._unresolvedPrivateNamesStack.length) { + const names = Object.keys(unresolvedPrivateNames) + if (names.length) { + names.sort((n1, n2) => unresolvedPrivateNames[n1] - unresolvedPrivateNames[n2]) + this.raise(unresolvedPrivateNames[names[0]], "Usage of undeclared private name") + } + } else Object.assign(this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1], unresolvedPrivateNames) + return _return + } + + // Parse private element access + parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) { + if (!this.eat(tt.dot)) { + return super.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) + } + let node = this.startNodeAt(startPos, startLoc) + node.object = base + node.computed = false + if (this.type == this.privateNameToken) { + node.property = this.parsePrivateName() + if (!this._privateBoundNamesStack.length || !this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1][node.property.name]) { + this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][node.property.name] = node.property.start + } + } else { + node.property = this.parseIdent(true) + } + return this.finishNode(node, "MemberExpression") + } + + // Prohibit delete of private class elements + parseMaybeUnary(refDestructuringErrors, sawUnary) { + const _return = super.parseMaybeUnary(refDestructuringErrors, sawUnary) + if (_return.operator == "delete") { + if (_return.argument.type == "MemberExpression" && _return.argument.property.type == "PrivateName") { + this.raise(_return.start, "Private elements may not be deleted") + } + } + return _return + } + } + Parser.prototype.privateNameToken = new TokenType("privateName") + return Parser +} diff --git a/deps/acorn-plugins/acorn-private-class-elements/package.json b/deps/acorn-plugins/acorn-private-class-elements/package.json new file mode 100644 index 0000000000..cd43012dc7 --- /dev/null +++ b/deps/acorn-plugins/acorn-private-class-elements/package.json @@ -0,0 +1,63 @@ +{ + "_from": "acorn-private-class-elements@^0.1.1", + "_id": "acorn-private-class-elements@0.1.1", + "_inBundle": false, + "_integrity": "sha512-bZpmSnaOsK3jkF7J8xaLJ05f008vapPX+XliIv8+jjkclvDR+M4OnTHLhFnCCSeJ0fMwRKjbY+BXsglSNpVZtw==", + "_location": "/acorn-private-class-elements", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "acorn-private-class-elements@^0.1.1", + "name": "acorn-private-class-elements", + "escapedName": "acorn-private-class-elements", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/acorn-class-fields" + ], + "_resolved": "https://registry.npmjs.org/acorn-private-class-elements/-/acorn-private-class-elements-0.1.1.tgz", + "_shasum": "85209cb5791ab84fde2362cb208fa51e7679bcdc", + "_spec": "acorn-private-class-elements@^0.1.1", + "_where": "/home/ruben/repos/node/node/node_modules/acorn-class-fields", + "bugs": { + "url": "https://github.com/acornjs/acorn-private-class-elements/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Adrian Heine", + "email": "mail@adrianheine.de" + } + ], + "dependencies": { + "mocha": "^5.2.0" + }, + "deprecated": false, + "description": "Helpers for supporting private class methods and fields in acorn", + "devDependencies": { + "acorn": "^6.1.0", + "eslint": "^5.13.0", + "eslint-plugin-node": "^8.0.1" + }, + "engines": { + "node": ">=4.8.2" + }, + "homepage": "https://github.com/acornjs/acorn-private-class-elements", + "license": "MIT", + "name": "acorn-private-class-elements", + "peerDependencies": { + "acorn": "^6.1.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/acornjs/acorn-private-class-elements.git" + }, + "scripts": { + "lint": "eslint -c .eslintrc.json .", + "test": "mocha" + }, + "version": "0.1.1" +} |