From 6eb88ab11c94a52f98d09ff0484ef31afbfa575b Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 11 Jun 2021 13:49:30 -0700 Subject: [PATCH 01/10] Update: Support top-level await and regexp match indices --- package.json | 2 +- .../regexp-match-indices.result.js | 194 ++++++++++++++++++ .../regexp-match-indices.src.js | 1 + .../13/top-level-await/top-await.result.js | 183 +++++++++++++++++ .../13/top-level-await/top-await.src.js | 1 + 5 files changed, 380 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js create mode 100644 tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js create mode 100644 tests/fixtures/ecma-version/13/top-level-await/top-await.result.js create mode 100644 tests/fixtures/ecma-version/13/top-level-await/top-await.src.js diff --git a/package.json b/package.json index 128db95a..6d18adc2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.2.2", + "acorn": "^8.4.0", "acorn-jsx": "^5.3.1", "eslint-visitor-keys": "^2.1.0" }, diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js new file mode 100644 index 00000000..6245528a --- /dev/null +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -0,0 +1,194 @@ +export default { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 0, + 26 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 0, + 26 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 6, + 25 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ], + "name": "re1" + }, + "init": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 12, + 25 + ], + "value": null, + "raw": "/a+(?z)?/d", + "regex": { + "pattern": "a+(?z)?", + "flags": "d" + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "const", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Identifier", + "value": "re1", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "type": "RegularExpression", + "value": "/a+(?z)?/d", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 12, + 25 + ], + "regex": { + "flags": "d", + "pattern": "a+(?z)?" + } + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 25, + 26 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js new file mode 100644 index 00000000..675916df --- /dev/null +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js @@ -0,0 +1 @@ +const re1 = /a+(?z)?/d; diff --git a/tests/fixtures/ecma-version/13/top-level-await/top-await.result.js b/tests/fixtures/ecma-version/13/top-level-await/top-await.result.js new file mode 100644 index 00000000..d7b70cf0 --- /dev/null +++ b/tests/fixtures/ecma-version/13/top-level-await/top-await.result.js @@ -0,0 +1,183 @@ +export default { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 0, + 12 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 0, + 12 + ], + "expression": { + "type": "AwaitExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "argument": { + "type": "CallExpression", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 6, + 11 + ], + "callee": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ], + "name": "foo" + }, + "arguments": [], + "optional": false + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "await", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Identifier", + "value": "foo", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ] + }, + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-version/13/top-level-await/top-await.src.js b/tests/fixtures/ecma-version/13/top-level-await/top-await.src.js new file mode 100644 index 00000000..41756a59 --- /dev/null +++ b/tests/fixtures/ecma-version/13/top-level-await/top-await.src.js @@ -0,0 +1 @@ +await foo(); From f04ec91d72746d99b8e71094c053f5ac4b582d95 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 11 Jun 2021 13:59:25 -0700 Subject: [PATCH 02/10] Fix failing test --- .../13/regexp-match-indices/regexp-match-indices.result.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js index 6245528a..565eddcd 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -82,7 +82,8 @@ export default { 12, 25 ], - "value": null, + // Only supported in Node.js 16+ + "value": /^(12|14)\./.test(process.versions.node) ? null : eval("a+(?z)?/d"), "raw": "/a+(?z)?/d", "regex": { "pattern": "a+(?z)?", @@ -191,4 +192,4 @@ export default { ] } ] -}; \ No newline at end of file +}; From d58eaea0f65b33adaf54fba7528bb1d70c4567ea Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 11 Jun 2021 14:12:04 -0700 Subject: [PATCH 03/10] Fix test --- .../regexp-match-indices.result.js | 41 ++++++++++--------- .../regexp-match-indices.src.js | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js index 565eddcd..3effcc07 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -7,12 +7,12 @@ export default { }, "end": { "line": 1, - "column": 26 + "column": 25 } }, "range": [ 0, - 26 + 25 ], "body": [ { @@ -24,12 +24,12 @@ export default { }, "end": { "line": 1, - "column": 26 + "column": 25 } }, "range": [ 0, - 26 + 25 ], "declarations": [ { @@ -41,12 +41,12 @@ export default { }, "end": { "line": 1, - "column": 25 + "column": 24 } }, "range": [ 6, - 25 + 24 ], "id": { "type": "Identifier", @@ -75,18 +75,19 @@ export default { }, "end": { "line": 1, - "column": 25 + "column": 24 } }, "range": [ 12, - 25 + 24 ], - // Only supported in Node.js 16+ - "value": /^(12|14)\./.test(process.versions.node) ? null : eval("a+(?z)?/d"), - "raw": "/a+(?z)?/d", + + // /d flag no supported in Node.js 12 or 14 yet + "value": /^(12|14)\./.test(process.versions.node) ? null : eval("/a+(z)?/d"), + "raw": "/a+(z)?/d", "regex": { - "pattern": "a+(?z)?", + "pattern": "a+(z)?", "flags": "d" } } @@ -153,7 +154,7 @@ export default { }, { "type": "RegularExpression", - "value": "/a+(?z)?/d", + "value": "/a+(z)?/d", "loc": { "start": { "line": 1, @@ -161,16 +162,16 @@ export default { }, "end": { "line": 1, - "column": 25 + "column": 24 } }, "range": [ 12, - 25 + 24 ], "regex": { "flags": "d", - "pattern": "a+(?z)?" + "pattern": "a+(z)?" } }, { @@ -179,16 +180,16 @@ export default { "loc": { "start": { "line": 1, - "column": 25 + "column": 24 }, "end": { "line": 1, - "column": 26 + "column": 25 } }, "range": [ - 25, - 26 + 24, + 25 ] } ] diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js index 675916df..0c0d5c29 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.src.js @@ -1 +1 @@ -const re1 = /a+(?z)?/d; +const re1 = /a+(z)?/d; From c4d770931aeaf06b34d2e39231f1ef630e88c87a Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 14 Jun 2021 10:37:18 -0700 Subject: [PATCH 04/10] Clean up regex test --- .../regexp-match-indices.result.js | 9 ++-- tests/lib/conditional-regex-value.js | 44 ++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js index 3effcc07..bb45ebf7 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -1,3 +1,6 @@ +import conditionalRegexValue from "../../../../lib/conditional-regex-value.js"; +import conditionalRegex from "../../../../lib/conditional-regex-value.js"; + export default { "type": "Program", "loc": { @@ -66,7 +69,7 @@ export default { ], "name": "re1" }, - "init": { + "init": conditionalRegexValue({ "type": "Literal", "loc": { "start": { @@ -84,13 +87,13 @@ export default { ], // /d flag no supported in Node.js 12 or 14 yet - "value": /^(12|14)\./.test(process.versions.node) ? null : eval("/a+(z)?/d"), + "value": null, "raw": "/a+(z)?/d", "regex": { "pattern": "a+(z)?", "flags": "d" } - } + }) } ], "kind": "const" diff --git a/tests/lib/conditional-regex-value.js b/tests/lib/conditional-regex-value.js index e2d568b2..192df527 100644 --- a/tests/lib/conditional-regex-value.js +++ b/tests/lib/conditional-regex-value.js @@ -1,4 +1,17 @@ -// eslint-disable-next-line jsdoc/require-jsdoc +/** + * @fileoverview A function for working regex flags in tests. + * @author Mike Reinstein + */ + +/** + * Given an AST node representing a regular expression, this function + * determines whether or not to create a RegExp object to use in the + * value property of the node. This is because not all Node.js versions + * support all RegExp flags, in which case the value property should be + * null. + * @param {ASTNode} literalNode The node to work on. + * @returns {ASTNode} The node that was passed in. + */ export default function(literalNode) { if (literalNode.regex) { try { @@ -10,3 +23,32 @@ export default function(literalNode) { } return literalNode; } + +/* +Example usage: + +conditionalRegex({ + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 10, + 16 + ], + "value": null, + "raw": "/foo/y", + "regex": { + "pattern": "foo", + "flags": "y" + } +}) + +*/ From 8499129c8183af38bfa3f88e7b0568e0293866ef Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 17 Jun 2021 13:14:35 -0700 Subject: [PATCH 05/10] Update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6ccbc728..5c99ac4b 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,8 @@ Because ECMAScript 2022 is still under development, we are implementing features * [Class instance fields](https://github.com/tc39/proposal-class-fields) * [Class private instance methods and accessors](https://github.com/tc39/proposal-private-methods) * [Class static fields, static private methods and accessors](https://github.com/tc39/proposal-static-class-features) +* [RegExp match indices](https://github.com/tc39/proposal-regexp-match-indices) +* [Top-level await](https://github.com/tc39/proposal-top-level-await) See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized. From 960c9f1f4d39649690691f4ec6751a3750036ce7 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 21 Jun 2021 17:18:28 -0700 Subject: [PATCH 06/10] Update tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js Co-authored-by: Milos Djermanovic --- .../13/regexp-match-indices/regexp-match-indices.result.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js index bb45ebf7..78e0362e 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -1,4 +1,3 @@ -import conditionalRegexValue from "../../../../lib/conditional-regex-value.js"; import conditionalRegex from "../../../../lib/conditional-regex-value.js"; export default { From 2d03c414393f46bfefbb22d98c654e592c5ff0e7 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 21 Jun 2021 17:18:38 -0700 Subject: [PATCH 07/10] Update tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js Co-authored-by: Milos Djermanovic --- .../13/regexp-match-indices/regexp-match-indices.result.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js index 78e0362e..d30ace1d 100644 --- a/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js +++ b/tests/fixtures/ecma-version/13/regexp-match-indices/regexp-match-indices.result.js @@ -68,7 +68,7 @@ export default { ], "name": "re1" }, - "init": conditionalRegexValue({ + "init": conditionalRegex({ "type": "Literal", "loc": { "start": { From 9ec557cde43151974be331691a4707a3944e5c9e Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 23 Jun 2021 13:45:13 -0700 Subject: [PATCH 08/10] Ensure top-level await test only runs in modules --- .../13/top-level-await/{ => modules}/top-await.result.js | 0 .../13/top-level-await/{ => modules}/top-await.src.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/fixtures/ecma-version/13/top-level-await/{ => modules}/top-await.result.js (100%) rename tests/fixtures/ecma-version/13/top-level-await/{ => modules}/top-await.src.js (100%) diff --git a/tests/fixtures/ecma-version/13/top-level-await/top-await.result.js b/tests/fixtures/ecma-version/13/top-level-await/modules/top-await.result.js similarity index 100% rename from tests/fixtures/ecma-version/13/top-level-await/top-await.result.js rename to tests/fixtures/ecma-version/13/top-level-await/modules/top-await.result.js diff --git a/tests/fixtures/ecma-version/13/top-level-await/top-await.src.js b/tests/fixtures/ecma-version/13/top-level-await/modules/top-await.src.js similarity index 100% rename from tests/fixtures/ecma-version/13/top-level-await/top-await.src.js rename to tests/fixtures/ecma-version/13/top-level-await/modules/top-await.src.js From b2c7e350425968db3ee7c62352184595531a2912 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 23 Jun 2021 13:50:30 -0700 Subject: [PATCH 09/10] Cleanup file structure --- .../modules => modules/top-level-await}/top-await.result.js | 0 .../modules => modules/top-level-await}/top-await.src.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/fixtures/ecma-version/13/{top-level-await/modules => modules/top-level-await}/top-await.result.js (100%) rename tests/fixtures/ecma-version/13/{top-level-await/modules => modules/top-level-await}/top-await.src.js (100%) diff --git a/tests/fixtures/ecma-version/13/top-level-await/modules/top-await.result.js b/tests/fixtures/ecma-version/13/modules/top-level-await/top-await.result.js similarity index 100% rename from tests/fixtures/ecma-version/13/top-level-await/modules/top-await.result.js rename to tests/fixtures/ecma-version/13/modules/top-level-await/top-await.result.js diff --git a/tests/fixtures/ecma-version/13/top-level-await/modules/top-await.src.js b/tests/fixtures/ecma-version/13/modules/top-level-await/top-await.src.js similarity index 100% rename from tests/fixtures/ecma-version/13/top-level-await/modules/top-await.src.js rename to tests/fixtures/ecma-version/13/modules/top-level-await/top-await.src.js From b7f13446e0ec11992ab8e0f787ba71f5c0793287 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 24 Jun 2021 11:11:18 -0700 Subject: [PATCH 10/10] Update Acorn --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d18adc2..10031411 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.4.0", + "acorn": "^8.4.1", "acorn-jsx": "^5.3.1", "eslint-visitor-keys": "^2.1.0" },