8000 deps: add acorn stage-3 plugins · nodejs/node@5f72246 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 5f72246

Browse files
BridgeARtargos
authored andcommitted
deps: add acorn stage-3 plugins
This adds bigint, class-fields, numeric-separators, static-class features, private class methods and fields as dependency. That way it's possible to use these in combination with acorn to parse these language features. This also removes a couple of files that were not necessary for Node.js to reduce the code base. PR-URL: #27400 Refs: #27391 Refs: #25835 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent f882c9b commit 5f72246

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1210
-5708
lines changed

LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ The externally maintained libraries used by Node.js are:
7474
THE SOFTWARE.
7575
"""
7676

77+
- Acorn plugins, located at deps/acorn-plugins, is licensed as follows:
78+
"""
79+
Copyright (C) 2017-2018 by Adrian Heine
80+
81+
Permission is hereby granted, free of charge, to any person obtaining a copy
82+
of this software and associated documentation files (the "Software"), to deal
83+
in the Software without restriction, including without limitation the rights
84+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85+
copies of the Software, and to permit persons to whom the Software is
86+
furnished to do so, subject to the following conditions:
87+
88+
The above copyright notice and this permission notice shall be included in
89+
all copies or substantial portions of the Software.
90+
91+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
97+
THE SOFTWARE.
98+
"""
99+
77100
- c-ares, located at deps/cares, is licensed as follows:
78101
"""
79102
Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## 0.4.0 (2019-04-04)
2+
3+
* Make compatible with acorn-numeric-separator
4+
5+
## 0.3.1 (2018-10-06)
6+
7+
* Fix creation of BigInt values everywhere (Thanks, Gus Caplan!)
8+
9+
## 0.3.0 (2018-09-14)
10+
11+
* Update to new acorn 6 interface
12+
* Actually support creating BigInt values in AST in Chrome
13+
* Change license to MIT
14+
15+
## 0.2.0 (2017-12-20)
16+
17+
* Emit BigInt values in AST if supported by runtime engine
18+
19+
## 0.1.0 (2017-12-19)
20+
21+
Initial release
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2017-2018 by Adrian Heine
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# BigInt support for Acorn
2+
3+
[![NPM version](https://img.shields.io/npm/v/acorn-bigint.svg)](https://www.npmjs.org/package/acorn-bigint)
4+
5+
This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
6+
7+
It implements support for arbitrary precision integers as defined in the stage 3 proposal [BigInt: Arbitrary precision integers in JavaScript](https://github.com/tc39/proposal-bigint). The emitted AST follows [an ESTree proposal](https://github.com/estree/estree/blob/132be9b9ec376adbc082dd5f6ba78aefd7a1a864/experimental/bigint.md).
8+
9+
## Usage
10+
11+
This module provides a plugin that can be used to extend the Acorn `Parser` class:
12+
13+
```javascript
14+
const {Parser} = require('acorn');
15+
const bigInt = require('acorn-bigint');
16+
Parser.extend(bigInt).parse('100n');
17+
```
18+
19+
## License
20+
21+
This plugin is released under an [MIT License](./LICENSE).
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict"
2+
3+
const acorn = require('internal/deps/acorn/acorn/dist/acorn')
4+
const tt = acorn.tokTypes
5+
const isIdentifierStart = acorn.isIdentifierStart
6+
7+
module.exports = function(Parser) {
8+
return class extends Parser {
9+
parseLiteral(value) {
10+
const node = super.parseLiteral(value)
11+
if (node.raw.charCodeAt(node.raw.length - 1) == 110) node.bigint = this.getNumberInput(node.start, node.end)
12+
return node
13+
}
14+
15+
readRadixNumber(radix) {
16+
let start = this.pos
17+
this.pos += 2 // 0x
18+
let val = this.readInt(radix)
19+
if (val === null) this.raise(this.start + 2, `Expected number in radix ${radix}`)
20+
if (this.input.charCodeAt(this.pos) == 110) {
21+
let str = this.getNumberInput(start, this.pos)
22+
val = typeof BigInt !== "undefined" ? BigInt(str) : null
23+
++this.pos
24+
} else if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number")
25+
return this.finishToken(tt.num, val)
26+
}
27+
28+
readNumber(startsWithDot) {
29+
let start = this.pos
30+
31+
// Not an int
32+
if (startsWithDot) return super.readNumber(startsWithDot)
33+
34+
// Legacy octal
35+
if (this.input.charCodeAt(start) === 48 && this.input.charCodeAt(start + 1) !== 110) {
36+
return super.readNumber(startsWithDot)
37+
}
38+
39+
if (this.readInt(10) === null) this.raise(start, "Invalid number")
40+
41+
// Not a BigInt, reset and parse again
42+
if (this.input.charCodeAt(this.pos) != 110) {
43+
this.pos = start
44+
return super.readNumber(startsWithDot)
45+
}
46+
47+
let str = this.getNumberInput(start, this.pos)
48+
let val = typeof BigInt !== "undefined" ? BigInt(str) : null
49+
++this.pos
50+
return this.finishToken(tt.num, val)
51+
}
52+
53+
// This is basically a hook for acorn-numeric-separator
54+
getNumberInput(start, end) {
55+
if (super.getNumberInput) return super.getNumberInput(start, end)
56+
return this.input.slice(start, end)
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"_from": "acorn-bigint",
3+
"_id": "acorn-bigint@0.4.0",
4+
"_inBundle": false,
5+
"_integrity": "sha512-W9iaqWzqFo7ZBLmI9dMjHYGrN0Nm/ZgToqhvd3RELJux7RsX6k1/80h+bD9TtTpeKky/kYNbr3+vHWqI3hdyfA==",
6+
"_location": "/acorn-bigint",
7+
"_phantomChildren": {},
8+
"_requested": {
9+
"type": "tag",
10+
"registry": true,
11+
"raw": "acorn-bigint",
12+
"name": "acorn-bigint",
13+
"escapedName": "acorn-bigint",
14+
"rawSpec": "",
15+
"saveSpec": null,
16+
"fetchSpec": "latest"
17+
},
18+
"_requiredBy": [
19+
"#USER",
20+
"/"
21+
],
22+
"_resolved": "https://registry.npmjs.org/acorn-bigint/-/acorn-bigint-0.4.0.tgz",
23+
"_shasum": "af3245ed8a7c3747387fca4680ae1960f617c4cd",
24+
"_spec": "acorn-bigint",
25+
"_where": "/home/ruben/repos/node/node",
26+
"bugs": {
27+
"url": "https://github.com/acornjs/acorn-bigint/issues"
28+
},
29+
"bundleDependencies": false,
30+
"contributors": [
31+
{
32+
"name": "Adrian Heine",
33+
"email": "mail@adrianheine.de"
34+
}
35+
],
36+
"deprecated": false,
37+
"description": "Support for BigInt in acorn",
38+
"devDependencies": {
39+
"acorn": "^6.1.1",
40+
"eslint": "^5.16.0",
41+
"eslint-plugin-node": "^8.0.1",
42+
"mocha": "^6.0.2",
43+
"test262": "git+https://github.com/tc39/test262.git#611919174ffe060503691a0c7e3eb2a65b646124",
44+
"test262-parser-runner": "^0.5.0"
45+
},
46+
"engines": {
47+
"node": ">=4.8.2"
48+
},
49+
"homepage": "https://github.com/acornjs/acorn-bigint",
50+
"license": "MIT",
51+
"name": "acorn-bigint",
52+
"peerDependencies": {
53+
"acorn": "^6.0.0"
54+
},
55+
"repository": {
56+
"type": "git",
57+
"url": "git+https://github.com/acornjs/acorn-bigint.git"
58+
},
59+
"scripts": {
60+
"lint": "eslint -c .eslintrc.json .",
61+
"test": "mocha",
62+
"test:test262": "node run_test262.js"
63+
},
64+
"version": "0.4.0"
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## 0.3.1 (2019-02-09)
2+
3+
* Restore compatibility with acorn-private-methods
4+
5+
## 0.3.0 (2019-02-09)
6+
7+
* Require acorn >= 6.1.0
8+
9+
## 0.2.1 (2018-11-06)
10+
11+
* Adapt to changes in acorn 6.0.3
12+
13+
## 0.2.0 (2018-09-14)
14+
15+
* Update to new acorn 6 interface
16+
* Change license to MIT
17+
18+
## 0.1.2 (2018-01-26)
19+
20+
* Don't accept whitespace between hash and private name
21+
22+
## 0.1.1 (2018-01-17)
23+
24+
* Correctly parse all fields named `async`
25+
26+
## 0.1.0 (2018-01-13)
27+
28+
Initial release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2017-2018 by Adrian Heine
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Class fields support for Acorn
2+
3+
[![NPM version](https://img.shields.io/npm/v/acorn-class-fields.svg)](https://www.npmjs.org/package/acorn-class-fields)
4+
5+
This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
6+
7+
It implements support for class fields as defined in the stage 3 proposal [Class field declarations for JavaScript](https://github.com/tc39/proposal-class-fields). The emitted AST follows [an ESTree proposal](https://github.com/estree/estree/pull/180).
8+
9+
## Usage
10+
11+
This module provides a plugin that can be used to extend the Acorn `Parser` class:
12+
13+
```javascript
14+
const {Parser} = require('acorn');
15+
const classFields = require('acorn-class-fields');
16+
Parser.extend(classFields).parse('class X { x = 0 }');
17+
```
18+
19+
## License
20+
21+
This plugin is released under an [MIT License](./LICENSE).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict"
2+
3+
const acorn = require('internal/deps/acorn/acorn/dist/acorn')
4+
const tt = acorn.tokTypes
5+
const privateClassElements = require('internal/deps/acorn-plugins/acorn-private-class-elements/index')
6+
7+
function maybeParseFieldValue(field) {
8+
if (this.eat(tt.eq)) {
9+
const oldInFieldValue = this._inFieldValue
10+
this._inFieldValue = true
11+
field.value = this.parseExpression()
12+
this._inFieldValue = oldInFieldValue
13+
} else field.value = null
14+
}
15+
16+
module.exports = function(Parser) {
17+
Parser = privateClassElements(Parser)
18+
return class extends Parser {
19+
// Parse fields
20+
parseClassElement(_constructorAllowsSuper) {
21+
if (this.options.ecmaVersion >= 8 && (this.type == tt.name || this.type == this.privateNameToken || this.type == tt.bracketL || this.type == tt.string)) {
22+
const branch = this._branch()
23+
if (branch.type == tt.bracketL) {
24+
let count = 0
25+
do {
26+
if (branch.eat(tt.bracketL)) ++count
27+
else if (branch.eat(tt.bracketR)) --count
28+
else branch.next()
29+
} while (count > 0)
30+
} else branch.next()
31+
if (branch.type == tt.eq || branch.canInsertSemicolon() || branch.type == tt.semi) {
32+
const node = this.startNode()
33+
if (this.type == this.privateNameToken) {
34+
this.parsePrivateClassElementName(node)
35+
} else {
36+
this.parsePropertyName(node)
37+
}
38+
if ((node.key.type === "Identifier" && node.key.name === "constructor") ||
39+
(node.key.type === "Literal" && node.key.value === "constructor")) {
40+
this.raise(node.key.start, "Classes may not have a field called constructor")
41+
}
42+
maybeParseFieldValue.call(this, node)
43+
this.finishNode(node, "FieldDefinition")
44+
this.semicolon()
45+
return node
46+
}
47+
}
48+
49+
return super.parseClassElement.apply(this, arguments)
50+
}
51+
52+
// Prohibit arguments in class field initializers
53+
parseIdent(liberal, isBinding) {
54+
const ident = super.parseIdent(liberal, isBinding)
55+
if (this._inFieldValue && ident.name == "arguments") this.raise(ident.start, "A class field initializer may not contain arguments")
56+
return ident
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)
0