-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
42 changed files
with
1,210 additions
and
5,708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## 0.4.0 (2019-04-04) | ||
|
||
* Make compatible with acorn-numeric-separator | ||
|
||
## 0.3.1 (2018-10-06) | ||
|
||
* Fix creation of BigInt values everywhere (Thanks, Gus Caplan!) | ||
|
||
## 0.3.0 (2018-09-14) | ||
|
||
* Update to new acorn 6 interface | ||
* Actually support creating BigInt values in AST in Chrome | ||
* Change license to MIT | ||
|
||
## 0.2.0 (2017-12-20) | ||
|
||
* Emit BigInt values in AST if supported by runtime engine | ||
|
||
## 0.1.0 (2017-12-19) | ||
|
||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# BigInt support for Acorn | ||
|
||
[![NPM version](https://img.shields.io/npm/v/acorn-bigint.svg)](https://www.npmjs.org/package/acorn-bigint) | ||
|
||
This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript. | ||
|
||
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). | ||
|
||
## Usage | ||
|
||
This module provides a plugin that can be used to extend the Acorn `Parser` class: | ||
|
||
```javascript | ||
const {Parser} = require('acorn'); | ||
const bigInt = require('acorn-bigint'); | ||
Parser.extend(bigInt).parse('100n'); | ||
``` | ||
|
||
## License | ||
|
||
This plugin is released under an [MIT License](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use strict" | ||
|
||
const acorn = require('internal/deps/acorn/acorn/dist/acorn') | ||
const tt = acorn.tokTypes | ||
const isIdentifierStart = acorn.isIdentifierStart | ||
|
||
module.exports = function(Parser) { | ||
return class extends Parser { | ||
parseLiteral(value) { | ||
const node = super.parseLiteral(value) | ||
if (node.raw.charCodeAt(node.raw.length - 1) == 110) node.bigint = this.getNumberInput(node.start, node.end) | ||
return node | ||
} | ||
|
||
readRadixNumber(radix) { | ||
let start = this.pos | ||
this.pos += 2 // 0x | ||
let val = this.readInt(radix) | ||
if (val === null) this.raise(this.start + 2, `Expected number in radix ${radix}`) | ||
if (this.input.charCodeAt(this.pos) == 110) { | ||
let str = this.getNumberInput(start, this.pos) | ||
val = typeof BigInt !== "undefined" ? BigInt(str) : null | ||
++this.pos | ||
} else if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number") | ||
return this.finishToken(tt.num, val) | ||
} | ||
|
||
readNumber(startsWithDot) { | ||
let start = this.pos | ||
|
||
// Not an int | ||
if (startsWithDot) return super.readNumber(startsWithDot) | ||
|
||
// Legacy octal | ||
if (this.input.charCodeAt(start) === 48 && this.input.charCodeAt(start + 1) !== 110) { | ||
return super.readNumber(startsWithDot) | ||
} | ||
|
||
if (this.readInt(10) === null) this.raise(start, "Invalid number") | ||
|
||
// Not a BigInt, reset and parse again | ||
if (this.input.charCodeAt(this.pos) != 110) { | ||
this.pos = start | ||
return super.readNumber(startsWithDot) | ||
} | ||
|
||
let str = this.getNumberInput(start, this.pos) | ||
let val = typeof BigInt !== "undefined" ? BigInt(str) : null | ||
++this.pos | ||
return this.finishToken(tt.num, val) | ||
} | ||
|
||
// This is basically a hook for acorn-numeric-separator | ||
getNumberInput(start, end) { | ||
if (super.getNumberInput) return super.getNumberInput(start, end) | ||
return this.input.slice(start, end) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"_from": "acorn-bigint", | ||
"_id": "acorn-bigint@0.4.0", | ||
"_inBundle": false, | ||
"_integrity": "sha512-W9iaqWzqFo7ZBLmI9dMjHYGrN0Nm/ZgToqhvd3RELJux7RsX6k1/80h+bD9TtTpeKky/kYNbr3+vHWqI3hdyfA==", | ||
"_location": "/acorn-bigint", | ||
"_phantomChildren": {}, | ||
"_requested": { | ||
"type": "tag", | ||
"registry": true, | ||
"raw": "acorn-bigint", | ||
"name": "acorn-bigint", | ||
"escapedName": "acorn-bigint", | ||
"rawSpec": "", | ||
"saveSpec": null, | ||
"fetchSpec": "latest" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/acorn-bigint/-/acorn-bigint-0.4.0.tgz", | ||
"_shasum": "af3245ed8a7c3747387fca4680ae1960f617c4cd", | ||
"_spec": "acorn-bigint", | ||
"_where": "/home/ruben/repos/node/node", | ||
"bugs": { | ||
"url": "https://github.com/acornjs/acorn-bigint/issues" | ||
}, | ||
"bundleDependencies": false, | ||
"contributors": [ | ||
{ | ||
"name": "Adrian Heine", | ||
"email": "mail@adrianheine.de" | ||
} | ||
], | ||
"deprecated": false, | ||
"description": "Support for BigInt in acorn", | ||
"devDependencies": { | ||
"acorn": "^6.1.1", | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-node": "^8.0.1", | ||
"mocha": "^6.0.2", | ||
"test262": "git+https://github.com/tc39/test262.git#611919174ffe060503691a0c7e3eb2a65b646124", | ||
"test262-parser-runner": "^0.5.0" | ||
}, | ||
"engines": { | ||
"node": ">=4.8.2" | ||
}, | ||
"homepage": "https://github.com/acornjs/acorn-bigint", | ||
"license": "MIT", | ||
"name": "acorn-bigint", | ||
"peerDependencies": { | ||
"acorn": "^6.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/acornjs/acorn-bigint.git" | ||
}, | ||
"scripts": { | ||
"lint": "eslint -c .eslintrc.json .", | ||
"test": "mocha", | ||
"test:test262": "node run_test262.js" | ||
}, | ||
"version": "0.4.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## 0.3.1 (2019-02-09) | ||
|
||
* Restore compatibility with acorn-private-methods | ||
|
||
## 0.3.0 (2019-02-09) | ||
|
||
* Require acorn >= 6.1.0 | ||
|
||
## 0.2.1 (2018-11-06) | ||
|
||
* Adapt to changes in acorn 6.0.3 | ||
|
||
## 0.2.0 (2018-09-14) | ||
|
||
* Update to new acorn 6 interface | ||
* Change license to MIT | ||
|
||
## 0.1.2 (2018-01-26) | ||
|
||
* Don't accept whitespace between hash and private name | ||
|
||
## 0.1.1 (2018-01-17) | ||
|
||
* Correctly parse all fields named `async` | ||
|
||
## 0.1.0 (2018-01-13) | ||
|
||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Class fields support for Acorn | ||
|
||
[![NPM version](https://img.shields.io/npm/v/acorn-class-fields.svg)](https://www.npmjs.org/package/acorn-class-fields) | ||
|
||
This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript. | ||
|
||
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). | ||
|
||
## Usage | ||
|
||
This module provides a plugin that can be used to extend the Acorn `Parser` class: | ||
|
||
```javascript | ||
const {Parser} = require('acorn'); | ||
const classFields = require('acorn-class-fields'); | ||
Parser.extend(classFields).parse('class X { x = 0 }'); | ||
``` | ||
|
||
## License | ||
|
||
This plugin is released under an [MIT License](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use strict" | ||
|
||
const acorn = require('internal/deps/acorn/acorn/dist/acorn') | ||
const tt = acorn.tokTypes | ||
const privateClassElements = require('internal/deps/acorn-plugins/acorn-private-class-elements/index') | ||
|
||
function maybeParseFieldValue(field) { | ||
if (this.eat(tt.eq)) { | ||
const oldInFieldValue = this._inFieldValue | ||
this._inFieldValue = true | ||
field.value = this.parseExpression() | ||
this._inFieldValue = oldInFieldValue | ||
} else field.value = null | ||
} | ||
|
||
module.exports = function(Parser) { | ||
Parser = privateClassElements(Parser) | ||
return class extends Parser { | ||
// Parse fields | ||
parseClassElement(_constructorAllowsSuper) { | ||
if (this.options.ecmaVersion >= 8 && (this.type == tt.name || this.type == this.privateNameToken || this.type == tt.bracketL || this.type == tt.string)) { | ||
const branch = this._branch() | ||
if (branch.type == tt.bracketL) { | ||
let count = 0 | ||
do { | ||
if (branch.eat(tt.bracketL)) ++count | ||
else if (branch.eat(tt.bracketR)) --count | ||
else branch.next() | ||
} while (count > 0) | ||
} else branch.next() | ||
if (branch.type == tt.eq || branch.canInsertSemicolon() || branch.type == tt.semi) { | ||
const node = this.startNode() | ||
if (this.type == this.privateNameToken) { | ||
this.parsePrivateClassElementName(node) | ||
} else { | ||
this.parsePropertyName(node) | ||
} | ||
if ((node.key.type === "Identifier" && node.key.name === "constructor") || | ||
(node.key.type === "Literal" && node.key.value === "constructor")) { | ||
this.raise(node.key.start, "Classes may not have a field called constructor") | ||
} | ||
maybeParseFieldValue.call(this, node) | ||
this.finishNode(node, "FieldDefinition") | ||
this.semicolon() | ||
return node | ||
} | ||
} | ||
|
||
return super.parseClassElement.apply(this, arguments) | ||
} | ||
|
||
// Prohibit arguments in class field initializers | ||
parseIdent(liberal, isBinding) { | ||
const ident = super.parseIdent(liberal, isBinding) | ||
if (this._inFieldValue && ident.name == "arguments") this.raise(ident.start, "A class field initializer may not contain arguments") | ||
return ident | ||
} | ||
} | ||
} |
Oops, something went wrong.