aboutsummaryrefslogtreecommitdiff
path: root/deps/acorn-plugins/acorn-static-class-features
diff options
context:
space:
mode:
Diffstat (limited to 'deps/acorn-plugins/acorn-static-class-features')
-rw-r--r--deps/acorn-plugins/acorn-static-class-features/CHANGELOG.md11
-rw-r--r--deps/acorn-plugins/acorn-static-class-features/LICENSE19
-rw-r--r--deps/acorn-plugins/acorn-static-class-features/README.md21
-rw-r--r--deps/acorn-plugins/acorn-static-class-features/index.js126
-rw-r--r--deps/acorn-plugins/acorn-static-class-features/package.json68
5 files changed, 245 insertions, 0 deletions
diff --git a/deps/acorn-plugins/acorn-static-class-features/CHANGELOG.md b/deps/acorn-plugins/acorn-static-class-features/CHANGELOG.md
new file mode 100644
index 0000000000..b9896a4bc5
--- /dev/null
+++ b/deps/acorn-plugins/acorn-static-class-features/CHANGELOG.md
@@ -0,0 +1,11 @@
+## 0.2.0 (2019-02-09)
+
+* Require acorn >= 6.1.0
+
+## 0.1.1 (2018-11-06)
+
+* Adapt to changes in acorn 6.0.3
+
+## 0.1.0 (2018-09-14)
+
+Initial release
diff --git a/deps/acorn-plugins/acorn-static-class-features/LICENSE b/deps/acorn-plugins/acorn-static-class-features/LICENSE
new file mode 100644
index 0000000000..7c2b27a19c
--- /dev/null
+++ b/deps/acorn-plugins/acorn-static-class-features/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-static-class-features/README.md b/deps/acorn-plugins/acorn-static-class-features/README.md
new file mode 100644
index 0000000000..bb214fce16
--- /dev/null
+++ b/deps/acorn-plugins/acorn-static-class-features/README.md
@@ -0,0 +1,21 @@
+# Static class features support for Acorn
+
+[![NPM version](https://img.shields.io/npm/v/acorn-class-fields.svg)](https://www.npmjs.org/package/acorn-static-class-features)
+
+This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
+
+It implements support for static class features as defined in the stage 3 proposal [Static class features](https://github.com/tc39/proposal-static-class-features). The emitted AST follows [an ESTree proposal](https://github.com/estree/estree/pull/180).
+
+## Usage
+
+This module provides a plugin that can be used to extend the Acorn `Parser` class:
+
+```javascript
+const {Parser} = require('acorn');
+const staticClassFeatures = require('acorn-static-class-features');
+Parser.extend(staticClassFeatures).parse('class X { static x = 0 }');
+```
+
+## License
+
+This plugin is released under an [MIT License](./LICENSE).
diff --git a/deps/acorn-plugins/acorn-static-class-features/index.js b/deps/acorn-plugins/acorn-static-class-features/index.js
new file mode 100644
index 0000000000..d8954bf327
--- /dev/null
+++ b/deps/acorn-plugins/acorn-static-class-features/index.js
@@ -0,0 +1,126 @@
+"use strict"
+
+const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g
+
+const acorn = require('internal/deps/acorn/acorn/dist/acorn')
+const tt = acorn.tokTypes
+
+function maybeParseFieldValue(field) {
+ if (this.eat(tt.eq)) {
+ const oldInFieldValue = this._inStaticFieldValue
+ this._inStaticFieldValue = true
+ field.value = this.parseExpression()
+ this._inStaticFieldValue = oldInFieldValue
+ } else field.value = null
+}
+
+const privateClassElements = require("internal/deps/acorn-plugins/acorn-private-class-elements/index")
+
+module.exports = function(Parser) {
+ const ExtendedParser = privateClassElements(Parser)
+
+ return class extends ExtendedParser {
+ // Parse private fields
+ parseClassElement(_constructorAllowsSuper) {
+ if (this.eat(tt.semi)) return null
+
+ const node = this.startNode()
+
+ const tryContextual = (k, noLineBreak) => {
+ if (typeof noLineBreak == "undefined") noLineBreak = false
+ const start = this.start, startLoc = this.startLoc
+ if (!this.eatContextual(k)) return false
+ if (this.type !== tt.parenL && (!noLineBreak || !this.canInsertSemicolon())) return true
+ if (node.key) this.unexpected()
+ node.computed = false
+ node.key = this.startNodeAt(start, startLoc)
+ node.key.name = k
+ this.finishNode(node.key, "Identifier")
+ return false
+ }
+
+ node.static = tryContextual("static")
+ if (!node.static) return super.parseClassElement.apply(this, arguments)
+
+ let isGenerator = this.eat(tt.star)
+ let isAsync = false
+ if (!isGenerator) {
+ // Special-case for `async`, since `parseClassMember` currently looks
+ // for `(` to determine whether `async` is a method name
+ if (this.options.ecmaVersion >= 8 && this.isContextual("async")) {
+ skipWhiteSpace.lastIndex = this.pos
+ let skip = skipWhiteSpace.exec(this.input)
+ let next = this.input.charAt(this.pos + skip[0].length)
+ if (next === ";" || next === "=") {
+ node.key = this.parseIdent(true)
+ node.computed = false
+ maybeParseFieldValue.call(this, node)
+ this.finishNode(node, "FieldDefinition")
+ this.semicolon()
+ return node
+ } else if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
+ isAsync = true
+ isGenerator = this.options.ecmaVersion >= 9 && this.eat(tt.star)
+ }
+ } else if (tryContextual("get")) {
+ node.kind = "get"
+ } else if (tryContextual("set")) {
+ node.kind = "set"
+ }
+ }
+ if (this.type === this.privateNameToken) {
+ this.parsePrivateClassElementName(node)
+ if (this.type !== tt.parenL) {
+ if (node.key.name === "prototype") {
+ this.raise(node.key.start, "Classes may not have a private static property named prototype")
+ }
+ maybeParseFieldValue.call(this, node)
+ this.finishNode(node, "FieldDefinition")
+ this.semicolon()
+ return node
+ }
+ } else if (!node.key) {
+ this.parsePropertyName(node)
+ if ((node.key.name || node.key.value) === "prototype" && !node.computed) {
+ this.raise(node.key.start, "Classes may not have a static property named prototype")
+ }
+ }
+ if (!node.kind) node.kind = "method"
+ this.parseClassMethod(node, isGenerator, isAsync)
+ if (!node.kind && (node.key.name || node.key.value) === "constructor" && !node.computed) {
+ this.raise(node.key.start, "Classes may not have a static field named constructor")
+ }
+ if (node.kind === "get" && node.value.params.length !== 0) {
+ this.raiseRecoverable(node.value.start, "getter should have no params")
+ }
+ if (node.kind === "set" && node.value.params.length !== 1) {
+ this.raiseRecoverable(node.value.start, "setter should have exactly one param")
+ }
+ if (node.kind === "set" && node.value.params[0].type === "RestElement") {
+ this.raiseRecoverable(node.value.params[0].start, "Setter cannot use rest params")
+ }
+
+ return node
+
+ }
+
+ // Parse public static fields
+ parseClassMethod(method, isGenerator, isAsync, _allowsDirectSuper) {
+ if (isGenerator || isAsync || method.kind != "method" || !method.static || this.options.ecmaVersion < 8 || this.type == tt.parenL) {
+ return super.parseClassMethod.apply(this, arguments)
+ }
+ maybeParseFieldValue.call(this, method)
+ delete method.kind
+ method = this.finishNode(method, "FieldDefinition")
+ this.semicolon()
+ return method
+ }
+
+ // Prohibit arguments in class field initializers
+ parseIdent(liberal, isBinding) {
+ const ident = super.parseIdent(liberal, isBinding)
+ if (this._inStaticFieldValue && ident.name == "arguments") this.raise(ident.start, "A static class field initializer may not contain arguments")
+ return ident
+ }
+ }
+}
diff --git a/deps/acorn-plugins/acorn-static-class-features/package.json b/deps/acorn-plugins/acorn-static-class-features/package.json
new file mode 100644
index 0000000000..ff9ff30c05
--- /dev/null
+++ b/deps/acorn-plugins/acorn-static-class-features/package.json
@@ -0,0 +1,68 @@
+{
+ "_from": "acorn-static-class-features",
+ "_id": "acorn-static-class-features@0.2.0",
+ "_inBundle": false,
+ "_integrity": "sha512-46IooHSRsvgSi+t36Wx9iPfF9BKFKVDcAWELXVqvKHmZogSCk11iUCi2FiZmLeTaM0hlJ3EYDyYiVmHRUGPzWA==",
+ "_location": "/acorn-static-class-features",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "tag",
+ "registry": true,
+ "raw": "acorn-static-class-features",
+ "name": "acorn-static-class-features",
+ "escapedName": "acorn-static-class-features",
+ "rawSpec": "",
+ "saveSpec": null,
+ "fetchSpec": "latest"
+ },
+ "_requiredBy": [
+ "#USER",
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/acorn-static-class-features/-/acorn-static-class-features-0.2.0.tgz",
+ "_shasum": "8a12b0b280b2e067e268fdbb14116a5b02affd71",
+ "_spec": "acorn-static-class-features",
+ "_where": "/home/ruben/repos/node/node",
+ "bugs": {
+ "url": "https://github.com/acornjs/acorn-static-class-features/issues"
+ },
+ "bundleDependencies": false,
+ "contributors": [
+ {
+ "name": "Adrian Heine",
+ "email": "mail@adrianheine.de"
+ }
+ ],
+ "dependencies": {
+ "acorn-private-class-elements": "^0.1.0"
+ },
+ "deprecated": false,
+ "description": "Support for static class features in acorn",
+ "devDependencies": {
+ "acorn": "^6.1.0",
+ "eslint": "^5.13.0",
+ "eslint-plugin-node": "^8.0.1",
+ "mocha": "^5.2.0",
+ "test262": "git+https://github.com/tc39/test262.git#33a306d1026b72227eb50a918db19ada16f12b3d",
+ "test262-parser-runner": "^0.5.0"
+ },
+ "engines": {
+ "node": ">=4.8.2"
+ },
+ "homepage": "https://github.com/acornjs/acorn-static-class-features",
+ "license": "MIT",
+ "name": "acorn-static-class-features",
+ "peerDependencies": {
+ "acorn": "^6.1.0"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/acornjs/acorn-static-class-features.git"
+ },
+ "scripts": {
+ "lint": "eslint -c .eslintrc.json .",
+ "test": "mocha",
+ "test:test262": "node run_test262.js"
+ },
+ "version": "0.2.0"
+}