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

42 files changed

Lines changed: 1210 additions & 5708 deletions

Some content is hidden

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

‎LICENSE‎

Lines changed: 23 additions & 0 deletions
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
Lines changed: 21 additions & 0 deletions
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
Lines changed: 19 additions & 0 deletions
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.
Lines changed: 21 additions & 0 deletions
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+
constbigInt=require('acorn-bigint');
16+
Parser.extend(bigInt).parse('100n');
17+
```
18+
19+
## License
20+
21+
This plugin is released under an [MIT License](./LICENSE).
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict"
2+
3+
constacorn=require('internal/deps/acorn/acorn/dist/acorn')
4+
consttt=acorn.tokTypes
5+
constisIdentifierStart=acorn.isIdentifierStart
6+
7+
module.exports=function(Parser){
8+
returnclassextendsParser{
9+
parseLiteral(value){
10+
constnode=super.parseLiteral(value)
11+
if(node.raw.charCodeAt(node.raw.length-1)==110)node.bigint=this.getNumberInput(node.start,node.end)
12+
returnnode
13+
}
14+
15+
readRadixNumber(radix){
16+
letstart=this.pos
17+
this.pos+=2// 0x
18+
letval=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+
letstr=this.getNumberInput(start,this.pos)
22+
val=typeofBigInt!=="undefined" ? BigInt(str) : null
23+
++this.pos
24+
}elseif(isIdentifierStart(this.fullCharCodeAtPos()))this.raise(this.pos,"Identifier directly after number")
25+
returnthis.finishToken(tt.num,val)
26+
}
27+
28+
readNumber(startsWithDot){
29+
letstart=this.pos
30+
31+
// Not an int
32+
if(startsWithDot)returnsuper.readNumber(startsWithDot)
33+
34+
// Legacy octal
35+
if(this.input.charCodeAt(start)===48&&this.input.charCodeAt(start+1)!==110){
36+
returnsuper.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+
returnsuper.readNumber(startsWithDot)
45+
}
46+
47+
letstr=this.getNumberInput(start,this.pos)
48+
letval=typeofBigInt!=="undefined" ? BigInt(str) : null
49+
++this.pos
50+
returnthis.finishToken(tt.num,val)
51+
}
52+
53+
// This is basically a hook for acorn-numeric-separator
54+
getNumberInput(start,end){
55+
if(super.getNumberInput)returnsuper.getNumberInput(start,end)
56+
returnthis.input.slice(start,end)
57+
}
58+
}
59+
}
Lines changed: 65 additions & 0 deletions
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+
}
Lines changed: 28 additions & 0 deletions
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
Lines changed: 19 additions & 0 deletions
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.
Lines changed: 21 additions & 0 deletions
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+
constclassFields=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).
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict"
2+
3+
constacorn=require('internal/deps/acorn/acorn/dist/acorn')
4+
consttt=acorn.tokTypes
5+
constprivateClassElements=require('internal/deps/acorn-plugins/acorn-private-class-elements/index')
6+
7+
functionmaybeParseFieldValue(field){
8+
if(this.eat(tt.eq)){
9+
constoldInFieldValue=this._inFieldValue
10+
this._inFieldValue=true
11+
field.value=this.parseExpression()
12+
this._inFieldValue=oldInFieldValue
13+
}elsefield.value=null
14+
}
15+
16+
module.exports=function(Parser){
17+
Parser=privateClassElements(Parser)
18+
returnclassextendsParser{
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+
constbranch=this._branch()
23+
if(branch.type==tt.bracketL){
24+
letcount=0
25+
do{
26+
if(branch.eat(tt.bracketL))++count
27+
elseif(branch.eat(tt.bracketR))--count
28+
elsebranch.next()
29+
}while(count>0)
30+
}elsebranch.next()
31+
if(branch.type==tt.eq||branch.canInsertSemicolon()||branch.type==tt.semi){
32+
constnode=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+
returnnode
46+
}
47+
}
48+
49+
returnsuper.parseClassElement.apply(this,arguments)
50+
}
51+
52+
// Prohibit arguments in class field initializers
53+
parseIdent(liberal,isBinding){
54+
constident=super.parseIdent(liberal,isBinding)
55+
if(this._inFieldValue&&ident.name=="arguments")this.raise(ident.start,"A class field initializer may not contain arguments")
56+
returnident
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)