Add decimal parsing support (#11640)
* docs: add DecimalLiteral to AST spec * add decimal support * fix: throw invalid decimal on start * add DecimalLiteral type definitions * update parser typings * add generator support * add syntax-decimal plugin * Add syntax-decimal to babel-standalone * add syntax-decimal to missing plugin helpers * fix incorrect test macro
This commit is contained in:
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/decimal/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/decimal/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.1m;
|
||||
3
packages/babel-parser/test/fixtures/experimental/_no-plugin/decimal/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/experimental/_no-plugin/decimal/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "This experimental syntax requires enabling the parser plugin: 'decimal' (1:2)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/decimal-as-property-name/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/decimal-as-property-name/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
({ 0m: 0, .1m() {}, get 0.2m(){}, set 3m(_){}, async 4m() {}, *.5m() {} });
|
||||
188
packages/babel-parser/test/fixtures/experimental/decimal/decimal-as-property-name/output.json
vendored
Normal file
188
packages/babel-parser/test/fixtures/experimental/decimal/decimal-as-property-name/output.json
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
|
||||
"expression": {
|
||||
"type": "ObjectExpression",
|
||||
"start":1,"end":73,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":73}},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":3,"end":8,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":8}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":3,"end":5,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":5}},
|
||||
"extra": {
|
||||
"rawValue": "0",
|
||||
"raw": "0m"
|
||||
},
|
||||
"value": "0"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": false,
|
||||
"value": {
|
||||
"type": "NumericLiteral",
|
||||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":10,"end":18,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":18}},
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13}},
|
||||
"extra": {
|
||||
"rawValue": ".1",
|
||||
"raw": ".1m"
|
||||
},
|
||||
"value": ".1"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":20,"end":32,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":32}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}},
|
||||
"extra": {
|
||||
"rawValue": "0.2",
|
||||
"raw": "0.2m"
|
||||
},
|
||||
"value": "0.2"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "get",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":30,"end":32,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":32}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":34,"end":45,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":45}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":38,"end":40,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":40}},
|
||||
"extra": {
|
||||
"rawValue": "3",
|
||||
"raw": "3m"
|
||||
},
|
||||
"value": "3"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "set",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":41,"end":42,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":42},"identifierName":"_"},
|
||||
"name": "_"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":43,"end":45,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":45}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":47,"end":60,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":60}},
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":53,"end":55,"loc":{"start":{"line":1,"column":53},"end":{"line":1,"column":55}},
|
||||
"extra": {
|
||||
"rawValue": "4",
|
||||
"raw": "4m"
|
||||
},
|
||||
"value": "4"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":58,"end":60,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":60}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":62,"end":71,"loc":{"start":{"line":1,"column":62},"end":{"line":1,"column":71}},
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":63,"end":66,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":66}},
|
||||
"extra": {
|
||||
"rawValue": ".5",
|
||||
"raw": ".5m"
|
||||
},
|
||||
"value": ".5"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":69,"end":71,"loc":{"start":{"line":1,"column":69},"end":{"line":1,"column":71}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-binary/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-binary/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
0b101011101m
|
||||
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-binary/options.json
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-binary/options.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"decimal"
|
||||
],
|
||||
"throws": "Invalid decimal (1:0)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-e/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-e/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
2e9m
|
||||
29
packages/babel-parser/test/fixtures/experimental/decimal/invalid-e/output.json
vendored
Normal file
29
packages/babel-parser/test/fixtures/experimental/decimal/invalid-e/output.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid decimal (1:0)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"extra": {
|
||||
"rawValue": "2e9",
|
||||
"raw": "2e9m"
|
||||
},
|
||||
"value": "2e9"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-hexadecimal/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-hexadecimal/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
0x16432m
|
||||
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-hexadecimal/options.json
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-hexadecimal/options.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"decimal"
|
||||
],
|
||||
"throws": "Invalid decimal (1:0)"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
089m
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid decimal (1:0)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"extra": {
|
||||
"rawValue": "089",
|
||||
"raw": "089m"
|
||||
},
|
||||
"value": "089"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-legacy/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-legacy/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
016432m
|
||||
29
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-legacy/output.json
vendored
Normal file
29
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-legacy/output.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid decimal (1:0)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
|
||||
"extra": {
|
||||
"rawValue": "016432",
|
||||
"raw": "016432m"
|
||||
},
|
||||
"value": "016432"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-new/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-new/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
0o16432m
|
||||
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-new/options.json
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/decimal/invalid-octal-new/options.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"decimal"
|
||||
],
|
||||
"throws": "Invalid decimal (1:0)"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/experimental/decimal/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/experimental/decimal/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["decimal"]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-decimal/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-decimal/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.m
|
||||
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-decimal/output.json
vendored
Normal file
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-decimal/output.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||
"extra": {
|
||||
"rawValue": "1.",
|
||||
"raw": "1.m"
|
||||
},
|
||||
"value": "1."
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-float-decimal/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-float-decimal/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
100.0m
|
||||
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-float-decimal/output.json
vendored
Normal file
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-float-decimal/output.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
|
||||
"extra": {
|
||||
"rawValue": "100.0",
|
||||
"raw": "100.0m"
|
||||
},
|
||||
"value": "100.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-float/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-float/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
100m
|
||||
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-float/output.json
vendored
Normal file
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-float/output.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"extra": {
|
||||
"rawValue": "100",
|
||||
"raw": "100m"
|
||||
},
|
||||
"value": "100"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-large/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-large/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
9223372036854775807m
|
||||
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-large/output.json
vendored
Normal file
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-large/output.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
||||
"extra": {
|
||||
"rawValue": "9223372036854775807",
|
||||
"raw": "9223372036854775807m"
|
||||
},
|
||||
"value": "9223372036854775807"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-small/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/decimal/valid-small/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
100.m
|
||||
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-small/output.json
vendored
Normal file
26
packages/babel-parser/test/fixtures/experimental/decimal/valid-small/output.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"expression": {
|
||||
"type": "DecimalLiteral",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"extra": {
|
||||
"rawValue": "100.",
|
||||
"raw": "100.m"
|
||||
},
|
||||
"value": "100."
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user