Bigint Support without transform (#8006)
This commit is contained in:
parent
981bff08e4
commit
b4d18f4764
@ -143,3 +143,12 @@ export function StringLiteral(node: Object) {
|
|||||||
|
|
||||||
return this.token(val);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
5
packages/babel-generator/test/fixtures/types/BigIntLiteral/input.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/types/BigIntLiteral/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
100n;
|
||||||
|
9223372036854775807n;
|
||||||
|
0o16432n;
|
||||||
|
0xFFF123n;
|
||||||
|
0b101011101n;
|
||||||
1
packages/babel-generator/test/fixtures/types/BigIntLiteral/options.json
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/BigIntLiteral/options.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ "plugins": ["bigInt"] }
|
||||||
5
packages/babel-generator/test/fixtures/types/BigIntLiteral/output.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/types/BigIntLiteral/output.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
100n;
|
||||||
|
9223372036854775807n;
|
||||||
|
0o16432n;
|
||||||
|
0xFFF123n;
|
||||||
|
0b101011101n;
|
||||||
3
packages/babel-plugin-syntax-bigint/.npmignore
Normal file
3
packages/babel-plugin-syntax-bigint/.npmignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
*.log
|
||||||
|
src
|
||||||
36
packages/babel-plugin-syntax-bigint/README.md
Normal file
36
packages/babel-plugin-syntax-bigint/README.md
Normal 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"]
|
||||||
|
});
|
||||||
|
```
|
||||||
20
packages/babel-plugin-syntax-bigint/package.json
Normal file
20
packages/babel-plugin-syntax-bigint/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
packages/babel-plugin-syntax-bigint/src/index.js
Normal file
11
packages/babel-plugin-syntax-bigint/src/index.js
Normal 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");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
@ -190,3 +190,13 @@ defineType("PrivateName", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineType("BigIntLiteral", {
|
||||||
|
builder: ["value"],
|
||||||
|
fields: {
|
||||||
|
value: {
|
||||||
|
validate: assertValueType("string"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user