Bigint Support without transform (#8006)

This commit is contained in:
Henry Zhu 2018-05-22 15:31:34 -04:00 committed by GitHub
parent 981bff08e4
commit b4d18f4764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 100 additions and 0 deletions

View File

@ -143,3 +143,12 @@ export function StringLiteral(node: Object) {
return this.token(val);
}
export function BigIntLiteral(node: Object) {
const raw = this.getPossibleRaw(node);
if (!this.format.minified && raw != null) {
this.token(raw);
return;
}
this.token(node.value);
}

View File

@ -0,0 +1,5 @@
100n;
9223372036854775807n;
0o16432n;
0xFFF123n;
0b101011101n;

View File

@ -0,0 +1 @@
{ "plugins": ["bigInt"] }

View File

@ -0,0 +1,5 @@
100n;
9223372036854775807n;
0o16432n;
0xFFF123n;
0b101011101n;

View File

@ -0,0 +1,3 @@
node_modules
*.log
src

View File

@ -0,0 +1,36 @@
# @babel/plugin-syntax-bigint
> Allow parsing of BigInt literals.
## Installation
```sh
npm install --save-dev @babel/plugin-syntax-bigint
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["@babel/plugin-syntax-bigint"]
}
```
### Via CLI
```sh
babel --plugins @babel/plugin-syntax-bigint script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["@babel/plugin-syntax-bigint"]
});
```

View File

@ -0,0 +1,20 @@
{
"name": "@babel/plugin-syntax-bigint",
"version": "7.0.0-beta.47",
"description": "Allow parsing of BigInt literals",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-bigint",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.47"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.47"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.47"
}
}

View File

@ -0,0 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";
export default declare(api => {
api.assertVersion(7);
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("bigInt");
},
};
});

View File

@ -190,3 +190,13 @@ defineType("PrivateName", {
},
},
});
defineType("BigIntLiteral", {
builder: ["value"],
fields: {
value: {
validate: assertValueType("string"),
},
},
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
});