diff --git a/README.md b/README.md index 6ac8fdd5..e7b5064c 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,8 @@ const options = { // create a top-level tokens array containing all tokens tokens: false, - // Set to 3, 5 (default), 6, 7, 8, 9, or 10 to specify the version of ECMAScript syntax you want to use. - // You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), or 2020 (same as 11) to use the year-based naming. + // Set to 3, 5 (default), 6, 7, 8, 9, 10, 11, or 12 to specify the version of ECMAScript syntax you want to use. + // You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), or 2021 (same as 12) to use the year-based naming. ecmaVersion: 5, // specify which type of script you're parsing ("script" or "module") @@ -217,38 +217,16 @@ Acorn is a great JavaScript parser that produces an AST that is compatible with We are building on top of Acorn, however, so that we can contribute back and help make Acorn even better. -### What ECMAScript 6 features do you support? +### What ECMAScript features do you support? -All of them. +Espree supports all ECMAScript 2020 features and partially supports ECMAScript 2021 features. -### What ECMAScript 7/2016 features do you support? +Because ECMAScript 2021 is still under development, we are implementing features as they are finalized. Currently, Espree supports: -There is only one ECMAScript 2016 syntax change: the exponentiation operator. Espree supports this. +* [Logical Assignment Operators](https://github.com/tc39/proposal-logical-assignment) +* [Numeric Separators](https://github.com/tc39/proposal-numeric-separator) -### What ECMAScript 2017 features do you support? - -There are two ECMAScript 2017 syntax changes: `async` functions, and trailing commas in function declarations and calls. Espree supports both of them. - -### What ECMAScript 2018 features do you support? - -There are seven ECMAScript 2018 syntax changes: - -* Invalid escape sequences in tagged template literals -* Rest/spread properties -* Async iteration -* RegExp `s` flag -* RegExp named capture groups -* RegExp lookbehind assertions -* RegExp Unicode property escapes - -Espree supports all of them. - -### What ECMAScript 2019 features do you support? - -Because ECMAScript 2019 is still under development, we are implementing features as they are finalized. Currently, Espree supports: - -* Optional `catch` binding -* JSON superset (`\u2028` and `\u2029` in string literals) +See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized. ### How do you determine which experimental features to support? diff --git a/lib/options.js b/lib/options.js index ccebbea4..eddca200 100644 --- a/lib/options.js +++ b/lib/options.js @@ -18,7 +18,8 @@ const SUPPORTED_VERSIONS = [ 8, 9, 10, - 11 + 11, + 12 ]; /** diff --git a/package.json b/package.json index 6c7d948c..569226e9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^7.3.1", + "acorn": "^7.4.0", "acorn-jsx": "^5.2.0", "eslint-visitor-keys": "^1.3.0" }, diff --git a/tests/fixtures/ecma-version/11/bigint/binary.result.js b/tests/fixtures/ecma-version/11/bigint/binary.result.js index 280dd585..39634d06 100644 --- a/tests/fixtures/ecma-version/11/bigint/binary.result.js +++ b/tests/fixtures/ecma-version/11/bigint/binary.result.js @@ -47,7 +47,7 @@ module.exports = { 0, 7 ], - "value": null, + "value": 0b0101n, "raw": "0b0101n", "bigint": "0b0101" } @@ -74,4 +74,4 @@ module.exports = { ] } ] -}; \ No newline at end of file +}; diff --git a/tests/fixtures/ecma-version/11/bigint/decimal.result.js b/tests/fixtures/ecma-version/11/bigint/decimal.result.js index e5fb5ae0..d38c50ef 100644 --- a/tests/fixtures/ecma-version/11/bigint/decimal.result.js +++ b/tests/fixtures/ecma-version/11/bigint/decimal.result.js @@ -47,7 +47,7 @@ module.exports = { 0, 2 ], - "value": null, + "value": 1n, "raw": "1n", "bigint": "1" } @@ -74,4 +74,4 @@ module.exports = { ] } ] -}; \ No newline at end of file +}; diff --git a/tests/fixtures/ecma-version/11/bigint/hex.result.js b/tests/fixtures/ecma-version/11/bigint/hex.result.js index c9b46b0d..b0f4332a 100644 --- a/tests/fixtures/ecma-version/11/bigint/hex.result.js +++ b/tests/fixtures/ecma-version/11/bigint/hex.result.js @@ -47,7 +47,7 @@ module.exports = { 0, 5 ], - "value": null, + "value": 0x80n, "raw": "0x80n", "bigint": "0x80" } @@ -74,4 +74,4 @@ module.exports = { ] } ] -}; \ No newline at end of file +}; diff --git a/tests/fixtures/ecma-version/11/bigint/octal.result.js b/tests/fixtures/ecma-version/11/bigint/octal.result.js index 949109de..fda6ca8c 100644 --- a/tests/fixtures/ecma-version/11/bigint/octal.result.js +++ b/tests/fixtures/ecma-version/11/bigint/octal.result.js @@ -47,7 +47,7 @@ module.exports = { 0, 6 ], - "value": null, + "value": 0o755n, "raw": "0o755n", "bigint": "0o755" } @@ -74,4 +74,4 @@ module.exports = { ] } ] -}; \ No newline at end of file +}; diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/and.result.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/and.result.js new file mode 100644 index 00000000..068e06da --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/and.result.js @@ -0,0 +1,147 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "operator": "&&=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "&&=", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/and.src.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/and.src.js new file mode 100644 index 00000000..3f2a6109 --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/and.src.js @@ -0,0 +1 @@ +a &&= b diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.result.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.result.js new file mode 100644 index 00000000..d8b28484 --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.result.js @@ -0,0 +1,147 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "operator": "??=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "??=", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.src.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.src.js new file mode 100644 index 00000000..deb2afe4 --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/coalesce.src.js @@ -0,0 +1 @@ +a ??= b diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.result.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.result.js new file mode 100644 index 00000000..7ce2b104 --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.result.js @@ -0,0 +1,291 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 0, + 19 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 0, + 19 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 0, + 19 + ], + "operator": "&&=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ], + "name": "a" + }, + "right": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 6, + 19 + ], + "operator": "||=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + }, + "right": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 12, + 19 + ], + "operator": "??=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "c" + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ], + "name": "d" + } + } + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "&&=", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Punctuator", + "value": "||=", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 8, + 11 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Punctuator", + "value": "??=", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 14, + 17 + ] + }, + { + "type": "Identifier", + "value": "d", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.src.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.src.js new file mode 100644 index 00000000..c243a9df --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/mix.src.js @@ -0,0 +1 @@ +a &&= b ||= c ??= d diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/or.result.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/or.result.js new file mode 100644 index 00000000..969f9ccb --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/or.result.js @@ -0,0 +1,147 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "operator": "||=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "||=", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/logical-assignment-operators/or.src.js b/tests/fixtures/ecma-version/12/logical-assignment-operators/or.src.js new file mode 100644 index 00000000..8911d581 --- /dev/null +++ b/tests/fixtures/ecma-version/12/logical-assignment-operators/or.src.js @@ -0,0 +1 @@ +a ||= b diff --git a/tests/fixtures/ecma-version/12/numeric-separators/bigint.result.js b/tests/fixtures/ecma-version/12/numeric-separators/bigint.result.js new file mode 100644 index 00000000..07674564 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/bigint.result.js @@ -0,0 +1,77 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "value": 123456n, + "raw": "123_456n", + "bigint": "123456" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "123_456n", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/12/numeric-separators/bigint.src.js b/tests/fixtures/ecma-version/12/numeric-separators/bigint.src.js new file mode 100644 index 00000000..61dbef70 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/bigint.src.js @@ -0,0 +1 @@ +123_456n diff --git a/tests/fixtures/ecma-version/12/numeric-separators/binary.result.js b/tests/fixtures/ecma-version/12/numeric-separators/binary.result.js new file mode 100644 index 00000000..6fd8c9d9 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/binary.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "value": 0b01011010, + "raw": "0b0101_1010" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "0b0101_1010", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/12/numeric-separators/binary.src.js b/tests/fixtures/ecma-version/12/numeric-separators/binary.src.js new file mode 100644 index 00000000..3eed469b --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/binary.src.js @@ -0,0 +1 @@ +0b0101_1010 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/decimal.result.js b/tests/fixtures/ecma-version/12/numeric-separators/decimal.result.js new file mode 100644 index 00000000..5375b7b0 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/decimal.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ], + "value": 123456, + "raw": "123_456" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "123_456", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 0, + 7 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/decimal.src.js b/tests/fixtures/ecma-version/12/numeric-separators/decimal.src.js new file mode 100644 index 00000000..d302f6fb --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/decimal.src.js @@ -0,0 +1 @@ +123_456 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/exponent.result.js b/tests/fixtures/ecma-version/12/numeric-separators/exponent.result.js new file mode 100644 index 00000000..083f011f --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/exponent.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "value": 1e0123345, + "raw": "1e0123_345" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "1e0123_345", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/12/numeric-separators/exponent.src.js b/tests/fixtures/ecma-version/12/numeric-separators/exponent.src.js new file mode 100644 index 00000000..ff236be7 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/exponent.src.js @@ -0,0 +1 @@ +1e0123_345 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/fraction.result.js b/tests/fixtures/ecma-version/12/numeric-separators/fraction.result.js new file mode 100644 index 00000000..b0a05c49 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/fraction.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "value": 1.012345, + "raw": "1.012_345" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "1.012_345", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/fraction.src.js b/tests/fixtures/ecma-version/12/numeric-separators/fraction.src.js new file mode 100644 index 00000000..4a9a20d3 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/fraction.src.js @@ -0,0 +1 @@ +1.012_345 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/hex.result.js b/tests/fixtures/ecma-version/12/numeric-separators/hex.result.js new file mode 100644 index 00000000..8187a006 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/hex.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "value": 0xdeadbeaf, + "raw": "0xdead_beaf" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "0xdead_beaf", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/12/numeric-separators/hex.src.js b/tests/fixtures/ecma-version/12/numeric-separators/hex.src.js new file mode 100644 index 00000000..8d74e146 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/hex.src.js @@ -0,0 +1 @@ +0xdead_beaf diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.result.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.result.js new file mode 100644 index 00000000..31058f35 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 2, + "lineNumber": 1, + "column": 3, + "message": "Numeric separator is not allowed at the first of digits" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.src.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.src.js new file mode 100644 index 00000000..86cf9401 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-first.src.js @@ -0,0 +1 @@ +0._123 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.result.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.result.js new file mode 100644 index 00000000..830ca129 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 3, + "lineNumber": 1, + "column": 4, + "message": "Numeric separator is not allowed at the last of digits" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.src.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.src.js new file mode 100644 index 00000000..d4af1111 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-at-last.src.js @@ -0,0 +1 @@ +123_ diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.result.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.result.js new file mode 100644 index 00000000..502ebf2e --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 4, + "lineNumber": 1, + "column": 5, + "message": "Numeric separator must be exactly one underscore" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.src.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.src.js new file mode 100644 index 00000000..b305bfd0 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-double-sep.src.js @@ -0,0 +1 @@ +123__456 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.result.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.result.js new file mode 100644 index 00000000..0cde6f38 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 3, + "lineNumber": 1, + "column": 4, + "message": "Numeric separator is not allowed in legacy octal numeric literals" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.src.js b/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.src.js new file mode 100644 index 00000000..d3546fcc --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/invalid-legacy-octal.src.js @@ -0,0 +1 @@ +012_345 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/octal.result.js b/tests/fixtures/ecma-version/12/numeric-separators/octal.result.js new file mode 100644 index 00000000..47bf5e3e --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/octal.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "value": 0o755666, + "raw": "0o755_666" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": "0o755_666", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-version/12/numeric-separators/octal.src.js b/tests/fixtures/ecma-version/12/numeric-separators/octal.src.js new file mode 100644 index 00000000..8131bf32 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/octal.src.js @@ -0,0 +1 @@ +0o755_666 diff --git a/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.result.js b/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.result.js new file mode 100644 index 00000000..88399505 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.result.js @@ -0,0 +1,76 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "expression": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ], + "value": 0.012345, + "raw": ".012_345" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Numeric", + "value": ".012_345", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.src.js b/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.src.js new file mode 100644 index 00000000..f0177467 --- /dev/null +++ b/tests/fixtures/ecma-version/12/numeric-separators/starts-with-dot.src.js @@ -0,0 +1 @@ +.012_345 diff --git a/tests/lib/supported-ecmaversions.js b/tests/lib/supported-ecmaversions.js index 2285bc6d..dff72a76 100644 --- a/tests/lib/supported-ecmaversions.js +++ b/tests/lib/supported-ecmaversions.js @@ -18,7 +18,7 @@ const assert = require("assert"), describe("latestEcmaVersion", () => { it("should return the latest supported ecmaVersion", () => { - assert.strictEqual(espree.latestEcmaVersion, 11); + assert.strictEqual(espree.latestEcmaVersion, 12); }); }); @@ -26,7 +26,7 @@ describe("supportedEcmaVersions", () => { it("should return an array of all supported versions", () => { assert.deepStrictEqual( espree.supportedEcmaVersions, - [3, 5, 6, 7, 8, 9, 10, 11] + [3, 5, 6, 7, 8, 9, 10, 11, 12] ); }); }); diff --git a/tests/lib/tester.js b/tests/lib/tester.js index 0d7cd8eb..d0e502f4 100644 --- a/tests/lib/tester.js +++ b/tests/lib/tester.js @@ -24,18 +24,26 @@ const assert = require("assert"), * @private */ function getRaw(ast) { - return JSON.parse(JSON.stringify(ast, (key, value) => { - if ((key === "start" || key === "end") && typeof value === "number") { - return undefined; // eslint-disable-line no-undefined - } + return JSON.parse( + JSON.stringify(ast, (key, value) => { + if ((key === "start" || key === "end") && typeof value === "number") { + return undefined; // eslint-disable-line no-undefined + } - // JSON cannot handle BigInt. - if (typeof value === "bigint") { - return null; - } + // JSON cannot handle BigInt. + if (typeof value === "bigint") { + return `$$BIGINT$$${value}`; + } - return value; - })); + return value; + }), + (_key, value) => { + if (typeof value === "string" && value.startsWith("$$BIGINT$$")) { + return BigInt(value.slice("$$BIGINT$$".length)); + } + return value; + } + ); } //------------------------------------------------------------------------------