From e30802f3e177cace8aa9dc7b6b854a332808b8df Mon Sep 17 00:00:00 2001 From: piotr Date: Mon, 2 Dec 2019 08:02:15 +0100 Subject: [PATCH 01/48] Treat \8 and \9 as invalid escapes in template strings Closes #880 --- acorn/src/tokenize.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index f9f6b2f6f..4b9cbfd74 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -628,6 +628,18 @@ pp.readEscapedChar = function(inTemplate) { case 10: // ' \n' if (this.options.locations) { this.lineStart = this.pos; ++this.curLine } return "" + case 56: + case 57: + if (inTemplate) { + const codePos = this.pos - 1 + + this.invalidStringToken( + codePos, + "Invalid escape sequence in template string" + ) + + return null + } default: if (ch >= 48 && ch <= 55) { let octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0] From cf0653ea9a15bf68d6ca714f95aa7cd055703aae Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 8 Dec 2019 21:04:58 +0900 Subject: [PATCH 02/48] update test262 --- bin/run_test262.js | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/run_test262.js b/bin/run_test262.js index c540507d7..6a2f9b05c 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -10,9 +10,12 @@ const unsupportedFeatures = [ "class-static-fields-private", "class-static-fields-public", "class-static-methods-private", + "coalesce-expression", "export-star-as-namespace-from-module", "import.meta", - "numeric-separator-literal" + "numeric-separator-literal", + "optional-chaining", + "top-level-await" ]; run( diff --git a/package.json b/package.json index eb0dd1c73..6d06debf8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-standard": "^3.0.1", "rollup": "^1.7.0", "rollup-plugin-buble": "^0.19.0", - "test262": "git+https://github.com/tc39/test262.git#de567d3aa5de4eaa11e00131d26b9fe77997dfb0", + "test262": "git+https://github.com/tc39/test262.git#09380a4ae412e986ea39eb7163f5a6b3e5b04bbc", "test262-parser-runner": "^0.5.0", "test262-stream": "^1.2.1", "unicode-12.0.0": "^0.7.9" From 75f0b4d6d35f63e472fb7cbd694be055116127ca Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 8 Dec 2019 21:24:00 +0900 Subject: [PATCH 03/48] allow escape sequence in IdentifierName Details: https://github.com/tc39/test262/pull/2295 Fixes #861 Fixes #881 --- acorn/src/expression.js | 3 ++- acorn/src/tokenize.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index de4ebd0c9..f425ab947 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -546,6 +546,7 @@ pp.parseParenArrowList = function(startPos, startLoc, exprList) { const empty = [] pp.parseNew = function() { + if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword new") let node = this.startNode() let meta = this.parseIdent(true) if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) { @@ -929,7 +930,7 @@ pp.parseIdent = function(liberal, isBinding) { } else { this.unexpected() } - this.next() + this.next(!!liberal) this.finishNode(node, "Identifier") if (!liberal) { this.checkUnreserved(node) diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index 4b9cbfd74..e45d688ee 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -28,7 +28,9 @@ const pp = Parser.prototype // Move to the next token -pp.next = function() { +pp.next = function(ignoreEscapeSequenceInKeyword) { + if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc) + this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword) if (this.options.onToken) this.options.onToken(new Token(this)) @@ -719,7 +721,6 @@ pp.readWord = function() { let word = this.readWord1() let type = tt.name if (this.keywords.test(word)) { - if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword " + word) type = keywordTypes[word] } return this.finishToken(type, word) From 9675cfae693a0bc34ae7dc0c2ba20989603eb4a3 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 8 Dec 2019 21:45:06 +0900 Subject: [PATCH 04/48] disallow non octal like in BigInt literals Details: https://github.com/tc39/test262/pull/2253 --- acorn/src/tokenize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index e45d688ee..835fdcd96 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -447,7 +447,6 @@ pp.readNumber = function(startsWithDot) { if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number") let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48 if (octal && this.strict) this.raise(start, "Invalid number") - if (octal && /[89]/.test(this.input.slice(start, this.pos))) octal = false let next = this.input.charCodeAt(this.pos) if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) { let str = this.input.slice(start, this.pos) @@ -456,6 +455,7 @@ pp.readNumber = function(startsWithDot) { if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number") return this.finishToken(tt.num, val) } + if (octal && /[89]/.test(this.input.slice(start, this.pos))) octal = false if (next === 46 && !octal) { // '.' ++this.pos this.readInt(10) From ca43135eb4520fa038ac60c54c3dd712fdd7cdf2 Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Wed, 25 Dec 2019 13:15:27 +0300 Subject: [PATCH 05/48] types property added to package.json --- acorn/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/acorn/package.json b/acorn/package.json index b9ff2b366..501b3f625 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -3,6 +3,7 @@ "description": "ECMAScript parser", "homepage": "https://github.com/acornjs/acorn", "main": "dist/acorn.js", + "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", "version": "7.1.0", "engines": {"node": ">=0.4.0"}, From 22473471a8f8c11966cc7afeaa6602086a75baeb Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 31 Dec 2019 15:31:49 +0100 Subject: [PATCH 06/48] Allow exponential op in await expression Closes #898 --- acorn/src/expression.js | 2 +- test/tests-asyncawait.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index f425ab947..9eedc13b6 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -962,6 +962,6 @@ pp.parseAwait = function() { let node = this.startNode() this.next() - node.argument = this.parseMaybeUnary(null, true) + node.argument = this.parseMaybeUnary(null, false) return this.finishNode(node, "AwaitExpression") } diff --git a/test/tests-asyncawait.js b/test/tests-asyncawait.js index 77de3c8b8..aebc6dc73 100644 --- a/test/tests-asyncawait.js +++ b/test/tests-asyncawait.js @@ -3523,3 +3523,5 @@ test( test("({ async delete() {} })", {}, {ecmaVersion: 8}) testFail("abc: async function a() {}", "Unexpected token (1:5)", {ecmaVersion: 8}) + +test("(async() => { await 4 ** 2 })()", {}, {ecmaVersion: 8}) From 4a44b8b8e493e0a990aaf4d4a3410b896e5296e1 Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Thu, 2 Jan 2020 23:28:42 +0300 Subject: [PATCH 07/48] types added --- acorn-walk/dist/walk.d.ts | 117 ++++++++++++++++++++++++++++++++++++++ acorn-walk/package.json | 1 + 2 files changed, 118 insertions(+) create mode 100644 acorn-walk/dist/walk.d.ts diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts new file mode 100644 index 000000000..f0e719e95 --- /dev/null +++ b/acorn-walk/dist/walk.d.ts @@ -0,0 +1,117 @@ +declare module "acorn-walk" { + type NodeType = import("estree").Node["type"]; + type DiscriminateUnion = T extends Record ? T : never; + type NarrowNode = DiscriminateUnion; + + type FullWalkerCallback = ( + node: import("estree").Node, + state: TState, + type: NodeType + ) => void; + + type FullAncestorWalkerCallback = ( + node: import("estree").Node, + state: TState | import("estree").Node[], + ancestors: import("estree").Node[], + type: NodeType + ) => void; + type WalkerCallback = (node: import("estree").Node, state: TState) => void; + + type SimpleWalkerFn = ( + node: NarrowNode, + state: TState + ) => void; + + type AncestorWalkerFn = ( + node: NarrowNode, + state: TState| import("estree").Node[], + ancestors: import("estree").Node[] + ) => void; + + type RecursiveWalkerFn = ( + node: NarrowNode, + state: TState, + callback: WalkerCallback + ) => void; + + type SimpleVisitors = { + [Type in Types]: SimpleWalkerFn + }; + + type AncestorVisitors = { + [Type in Types]: AncestorWalkerFn + }; + + type RecursiveVisitors = { + [Type in Types]: RecursiveWalkerFn + }; + + type FindPredicate = (type: NodeType, node: import("estree").Node) => boolean; + + interface Found { + node: NarrowNode, + state: TState + } + + export function simple( + node: import("estree").Node, + visitors: SimpleVisitors, + base?: RecursiveVisitors, + state?: TState + ): void; + + export function ancestor( + node: import("estree").Node, + visitors: AncestorVisitors, + base?: RecursiveVisitors, + state?: TState + ): void; + + export function recursive( + node: import("estree").Node, + state: TState, + functions: RecursiveVisitors, + base?: RecursiveVisitors + ): void; + + export function full( + node: import("estree").Node, + callback: FullWalkerCallback, + base?: RecursiveVisitors, + state?: TState + ): void; + + export function fullAncestor( + node: import("estree").Node, + callback: FullAncestorWalkerCallback, + base?: RecursiveVisitors, + state?: TState + ): void; + + export function make( + functions: RecursiveVisitors, + base?: RecursiveVisitors + ): RecursiveVisitors; + + export function findNodeAt( + node: import("estree").Node, + start: number | undefined, + end: number | undefined, + type: K, + base?: RecursiveVisitors, + state?: TState + ): Found | undefined; + + export function findNodeAt( + node: import("estree").Node, + start: number | undefined, + end: number | undefined, + type?: FindPredicate, + base?: RecursiveVisitors, + state?: TState + ): Found | undefined; + + export const findNodeAround: typeof findNodeAt; + + export const findNodeAfter: typeof findNodeAt; +} diff --git a/acorn-walk/package.json b/acorn-walk/package.json index 375c21fc8..630297c5d 100644 --- a/acorn-walk/package.json +++ b/acorn-walk/package.json @@ -3,6 +3,7 @@ "description": "ECMAScript (ESTree) AST walker", "homepage": "https://github.com/acornjs/acorn", "main": "dist/walk.js", + "types": "dist/walk.d.ts", "module": "dist/walk.mjs", "version": "7.0.0", "engines": {"node": ">=0.4.0"}, From 15a87cdd7d125e8351ac4d8577e0a6c6d416c97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 14 Jan 2020 23:19:34 -0500 Subject: [PATCH 08/48] fix: triple __proto__ in patterns should not throw --- acorn/src/expression.js | 8 +++++--- test/tests-harmony.js | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 9eedc13b6..c5bf0d4e5 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -44,9 +44,11 @@ pp.checkPropClash = function(prop, propHash, refDestructuringErrors) { if (this.options.ecmaVersion >= 6) { if (name === "__proto__" && kind === "init") { if (propHash.proto) { - if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start - // Backwards-compat kludge. Can be removed in version 6.0 - else this.raiseRecoverable(key.start, "Redefinition of __proto__ property") + if (refDestructuringErrors) { + if (refDestructuringErrors.doubleProto < 0) + refDestructuringErrors.doubleProto = key.start + // Backwards-compat kludge. Can be removed in version 6.0 + } else this.raiseRecoverable(key.start, "Redefinition of __proto__ property") } propHash.proto = true } diff --git a/test/tests-harmony.js b/test/tests-harmony.js index ade46a220..e7f417732 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -16512,3 +16512,5 @@ test("let x = 1; x = 2", {}, {ecmaVersion: 6}) test("function *f2() { () => yield / 1 }", {}, {ecmaVersion: 6}) test("({ a = 42, b: c.d } = e)", {}, {ecmaVersion: 6}) + +test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6}) From 1a3a564a6bf4eaa674a54f8114a705594eebca65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 19 Jan 2020 21:40:19 -0500 Subject: [PATCH 09/48] Do not reset shorthandAssign when parsing maybeAssign --- acorn/src/expression.js | 17 +++++++++-------- test/tests-harmony.js | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index c5bf0d4e5..71b02016f 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -113,12 +113,11 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) { else this.exprAllowed = false } - let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1 + let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1 if (refDestructuringErrors) { oldParenAssign = refDestructuringErrors.parenthesizedAssign oldTrailingComma = refDestructuringErrors.trailingComma - oldShorthandAssign = refDestructuringErrors.shorthandAssign - refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1 + refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1 } else { refDestructuringErrors = new DestructuringErrors ownDestructuringErrors = true @@ -133,8 +132,11 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) { let node = this.startNodeAt(startPos, startLoc) node.operator = this.value node.left = this.type === tt.eq ? this.toAssignable(left, false, refDestructuringErrors) : left - if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors) - refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly + if (!ownDestructuringErrors) { + refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1 + } + if (refDestructuringErrors.shorthandAssign >= node.left.start) + refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly this.checkLVal(left) this.next() node.right = this.parseMaybeAssign(noIn) @@ -144,7 +146,6 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) { } if (oldParenAssign > -1) refDestructuringErrors.parenthesizedAssign = oldParenAssign if (oldTrailingComma > -1) refDestructuringErrors.trailingComma = oldTrailingComma - if (oldShorthandAssign > -1) refDestructuringErrors.shorthandAssign = oldShorthandAssign return left } @@ -249,8 +250,8 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary) { pp.parseExprSubscripts = function(refDestructuringErrors) { let startPos = this.start, startLoc = this.startLoc let expr = this.parseExprAtom(refDestructuringErrors) - let skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")" - if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr + if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")") + return expr let result = this.parseSubscripts(expr, startPos, startLoc) if (refDestructuringErrors && result.type === "MemberExpression") { if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1 diff --git a/test/tests-harmony.js b/test/tests-harmony.js index e7f417732..c6b58dd5c 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -16513,4 +16513,6 @@ test("function *f2() { () => yield / 1 }", {}, {ecmaVersion: 6}) test("({ a = 42, b: c.d } = e)", {}, {ecmaVersion: 6}) +testFail("({ a = 42, b: c = d })", "Shorthand property assignments are valid only in destructuring patterns (1:5)", {ecmaVersion: 6}) + test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6}) From 978df09ac6191019d510a31dd3dabc022c5ec084 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 11 Feb 2020 09:16:45 +0100 Subject: [PATCH 10/48] Mark acorn-walk 7.1.0 --- acorn-walk/CHANGELOG.md | 6 ++++++ acorn-walk/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/acorn-walk/CHANGELOG.md b/acorn-walk/CHANGELOG.md index 82d439902..f85e2833f 100644 --- a/acorn-walk/CHANGELOG.md +++ b/acorn-walk/CHANGELOG.md @@ -1,3 +1,9 @@ +## 7.1.0 (2020-02-11) + +### New features + +Add a TypeScript definition file for the library. + ## 7.0.0 (2017-08-12) ### New features diff --git a/acorn-walk/package.json b/acorn-walk/package.json index 630297c5d..fdcedf311 100644 --- a/acorn-walk/package.json +++ b/acorn-walk/package.json @@ -5,7 +5,7 @@ "main": "dist/walk.js", "types": "dist/walk.d.ts", "module": "dist/walk.mjs", - "version": "7.0.0", + "version": "7.1.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { From 1d85e7ce982a979bb5411cd00fd9156eecf952a5 Mon Sep 17 00:00:00 2001 From: susiwen Date: Wed, 12 Feb 2020 23:07:09 +0800 Subject: [PATCH 11/48] Fix: acorn-walk type work with acorn's --- acorn-walk/dist/walk.d.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts index f0e719e95..a02c0a186 100644 --- a/acorn-walk/dist/walk.d.ts +++ b/acorn-walk/dist/walk.d.ts @@ -1,21 +1,23 @@ +import acorn from 'acorn'; + declare module "acorn-walk" { - type NodeType = import("estree").Node["type"]; + type NodeType = acorn.Node["type"]; type DiscriminateUnion = T extends Record ? T : never; - type NarrowNode = DiscriminateUnion; + type NarrowNode = DiscriminateUnion; type FullWalkerCallback = ( - node: import("estree").Node, + node: acorn.Node, state: TState, type: NodeType ) => void; type FullAncestorWalkerCallback = ( - node: import("estree").Node, - state: TState | import("estree").Node[], - ancestors: import("estree").Node[], + node: acorn.Node, + state: TState | acorn.Node[], + ancestors: acorn.Node[], type: NodeType ) => void; - type WalkerCallback = (node: import("estree").Node, state: TState) => void; + type WalkerCallback = (node: acorn.Node, state: TState) => void; type SimpleWalkerFn = ( node: NarrowNode, @@ -24,8 +26,8 @@ declare module "acorn-walk" { type AncestorWalkerFn = ( node: NarrowNode, - state: TState| import("estree").Node[], - ancestors: import("estree").Node[] + state: TState| acorn.Node[], + ancestors: acorn.Node[] ) => void; type RecursiveWalkerFn = ( @@ -46,7 +48,7 @@ declare module "acorn-walk" { [Type in Types]: RecursiveWalkerFn }; - type FindPredicate = (type: NodeType, node: import("estree").Node) => boolean; + type FindPredicate = (type: NodeType, node: acorn.Node) => boolean; interface Found { node: NarrowNode, @@ -54,35 +56,35 @@ declare module "acorn-walk" { } export function simple( - node: import("estree").Node, + node: acorn.Node, visitors: SimpleVisitors, base?: RecursiveVisitors, state?: TState ): void; export function ancestor( - node: import("estree").Node, + node: acorn.Node, visitors: AncestorVisitors, base?: RecursiveVisitors, state?: TState ): void; export function recursive( - node: import("estree").Node, + node: acorn.Node, state: TState, functions: RecursiveVisitors, base?: RecursiveVisitors ): void; export function full( - node: import("estree").Node, + node: acorn.Node, callback: FullWalkerCallback, base?: RecursiveVisitors, state?: TState ): void; export function fullAncestor( - node: import("estree").Node, + node: acorn.Node, callback: FullAncestorWalkerCallback, base?: RecursiveVisitors, state?: TState @@ -94,7 +96,7 @@ declare module "acorn-walk" { ): RecursiveVisitors; export function findNodeAt( - node: import("estree").Node, + node: acorn.Node, start: number | undefined, end: number | undefined, type: K, @@ -103,7 +105,7 @@ declare module "acorn-walk" { ): Found | undefined; export function findNodeAt( - node: import("estree").Node, + node: acorn.Node, start: number | undefined, end: number | undefined, type?: FindPredicate, From de6edeb654cf665e732d822d95c97e2d2fc879bc Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Fri, 14 Feb 2020 00:25:05 +0800 Subject: [PATCH 12/48] Remove NarrowNode from walk.d.ts --- acorn-walk/dist/walk.d.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts index a02c0a186..f452bf75b 100644 --- a/acorn-walk/dist/walk.d.ts +++ b/acorn-walk/dist/walk.d.ts @@ -1,9 +1,7 @@ import acorn from 'acorn'; declare module "acorn-walk" { - type NodeType = acorn.Node["type"]; - type DiscriminateUnion = T extends Record ? T : never; - type NarrowNode = DiscriminateUnion; + type NodeType = acorn.Node["type"]; type FullWalkerCallback = ( node: acorn.Node, @@ -20,18 +18,18 @@ declare module "acorn-walk" { type WalkerCallback = (node: acorn.Node, state: TState) => void; type SimpleWalkerFn = ( - node: NarrowNode, + node: acorn.Node, state: TState ) => void; type AncestorWalkerFn = ( - node: NarrowNode, + node: acorn.Node, state: TState| acorn.Node[], ancestors: acorn.Node[] ) => void; type RecursiveWalkerFn = ( - node: NarrowNode, + node: acorn.Node, state: TState, callback: WalkerCallback ) => void; @@ -51,7 +49,7 @@ declare module "acorn-walk" { type FindPredicate = (type: NodeType, node: acorn.Node) => boolean; interface Found { - node: NarrowNode, + node: acorn.Node, state: TState } From e9372c151f63fe254c7f5e7ffd7a820e34422208 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 13 Feb 2020 17:50:46 +0100 Subject: [PATCH 13/48] Further clean up walker types --- acorn-walk/dist/walk.d.ts | 146 +++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts index f452bf75b..f2e68483c 100644 --- a/acorn-walk/dist/walk.d.ts +++ b/acorn-walk/dist/walk.d.ts @@ -1,115 +1,113 @@ -import acorn from 'acorn'; +import {Node} from 'acorn'; declare module "acorn-walk" { - type NodeType = acorn.Node["type"]; - type FullWalkerCallback = ( - node: acorn.Node, - state: TState, - type: NodeType + node: Node, + state: TState, + type: string ) => void; type FullAncestorWalkerCallback = ( - node: acorn.Node, - state: TState | acorn.Node[], - ancestors: acorn.Node[], - type: NodeType + node: Node, + state: TState | Node[], + ancestors: Node[], + type: string ) => void; - type WalkerCallback = (node: acorn.Node, state: TState) => void; + type WalkerCallback = (node: Node, state: TState) => void; - type SimpleWalkerFn = ( - node: acorn.Node, - state: TState + type SimpleWalkerFn = ( + node: Node, + state: TState ) => void; - type AncestorWalkerFn = ( - node: acorn.Node, - state: TState| acorn.Node[], - ancestors: acorn.Node[] + type AncestorWalkerFn = ( + node: Node, + state: TState| Node[], + ancestors: Node[] ) => void; - type RecursiveWalkerFn = ( - node: acorn.Node, - state: TState, - callback: WalkerCallback + type RecursiveWalkerFn = ( + node: Node, + state: TState, + callback: WalkerCallback ) => void; - type SimpleVisitors = { - [Type in Types]: SimpleWalkerFn + type SimpleVisitors = { + [type: string]: SimpleWalkerFn }; - type AncestorVisitors = { - [Type in Types]: AncestorWalkerFn + type AncestorVisitors = { + [type: string]: AncestorWalkerFn }; - type RecursiveVisitors = { - [Type in Types]: RecursiveWalkerFn + type RecursiveVisitors = { + [type: string]: RecursiveWalkerFn }; - type FindPredicate = (type: NodeType, node: acorn.Node) => boolean; + type FindPredicate = (type: string, node: Node) => boolean; - interface Found { - node: acorn.Node, - state: TState + interface Found { + node: Node, + state: TState } - export function simple( - node: acorn.Node, - visitors: SimpleVisitors, - base?: RecursiveVisitors, - state?: TState + export function simple( + node: Node, + visitors: SimpleVisitors, + base?: RecursiveVisitors, + state?: TState ): void; - export function ancestor( - node: acorn.Node, - visitors: AncestorVisitors, - base?: RecursiveVisitors, - state?: TState + export function ancestor( + node: Node, + visitors: AncestorVisitors, + base?: RecursiveVisitors, + state?: TState ): void; - export function recursive( - node: acorn.Node, - state: TState, - functions: RecursiveVisitors, - base?: RecursiveVisitors + export function recursive( + node: Node, + state: TState, + functions: RecursiveVisitors, + base?: RecursiveVisitors ): void; export function full( - node: acorn.Node, - callback: FullWalkerCallback, - base?: RecursiveVisitors, - state?: TState + node: Node, + callback: FullWalkerCallback, + base?: RecursiveVisitors, + state?: TState ): void; export function fullAncestor( - node: acorn.Node, - callback: FullAncestorWalkerCallback, - base?: RecursiveVisitors, - state?: TState + node: Node, + callback: FullAncestorWalkerCallback, + base?: RecursiveVisitors, + state?: TState ): void; - export function make( - functions: RecursiveVisitors, - base?: RecursiveVisitors - ): RecursiveVisitors; + export function make( + functions: RecursiveVisitors, + base?: RecursiveVisitors + ): RecursiveVisitors; - export function findNodeAt( - node: acorn.Node, - start: number | undefined, - end: number | undefined, - type: K, - base?: RecursiveVisitors, - state?: TState - ): Found | undefined; + export function findNodeAt( + node: Node, + start: number | undefined, + end: number | undefined, + type: string, + base?: RecursiveVisitors, + state?: TState + ): Found | undefined; export function findNodeAt( - node: acorn.Node, - start: number | undefined, - end: number | undefined, - type?: FindPredicate, - base?: RecursiveVisitors, - state?: TState - ): Found | undefined; + node: Node, + start: number | undefined, + end: number | undefined, + type?: FindPredicate, + base?: RecursiveVisitors, + state?: TState + ): Found | undefined; export const findNodeAround: typeof findNodeAt; From 97801f0b5835bc93739666b3494c9b49aeb5fc1d Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 13 Feb 2020 17:51:41 +0100 Subject: [PATCH 14/48] Mark acorn-walk 7.1.1 --- acorn-walk/CHANGELOG.md | 6 ++++++ acorn-walk/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/acorn-walk/CHANGELOG.md b/acorn-walk/CHANGELOG.md index f85e2833f..89114970b 100644 --- a/acorn-walk/CHANGELOG.md +++ b/acorn-walk/CHANGELOG.md @@ -1,3 +1,9 @@ +## 7.1.1 (2020-02-13) + +### Bug fixes + +Clean up the type definitions to actually work well with the main parser. + ## 7.1.0 (2020-02-11) ### New features diff --git a/acorn-walk/package.json b/acorn-walk/package.json index fdcedf311..a66ca892c 100644 --- a/acorn-walk/package.json +++ b/acorn-walk/package.json @@ -5,7 +5,7 @@ "main": "dist/walk.js", "types": "dist/walk.d.ts", "module": "dist/walk.mjs", - "version": "7.1.0", + "version": "7.1.1", "engines": {"node": ">=0.4.0"}, "maintainers": [ { From 1d5028637852c2834091739646e25dd6558ee7a8 Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Sat, 15 Feb 2020 00:09:32 +0800 Subject: [PATCH 15/48] Fix some errors in walk types * Remove duplicate function * end is optional in findNodeAt --- acorn-walk/dist/walk.d.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts index f2e68483c..b4473367c 100644 --- a/acorn-walk/dist/walk.d.ts +++ b/acorn-walk/dist/walk.d.ts @@ -94,16 +94,7 @@ declare module "acorn-walk" { export function findNodeAt( node: Node, start: number | undefined, - end: number | undefined, - type: string, - base?: RecursiveVisitors, - state?: TState - ): Found | undefined; - - export function findNodeAt( - node: Node, - start: number | undefined, - end: number | undefined, + end?: number | undefined, type?: FindPredicate, base?: RecursiveVisitors, state?: TState From fa3ad8cef0f39f5ae0cbd8be0bf65eb0a782133e Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Tue, 18 Feb 2020 23:19:34 +0800 Subject: [PATCH 16/48] Further refine acorn-walk types --- acorn-walk/dist/walk.d.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/acorn-walk/dist/walk.d.ts b/acorn-walk/dist/walk.d.ts index b4473367c..00cc005f1 100644 --- a/acorn-walk/dist/walk.d.ts +++ b/acorn-walk/dist/walk.d.ts @@ -95,12 +95,18 @@ declare module "acorn-walk" { node: Node, start: number | undefined, end?: number | undefined, - type?: FindPredicate, + type?: FindPredicate | string, base?: RecursiveVisitors, state?: TState ): Found | undefined; - export const findNodeAround: typeof findNodeAt; + export function findNodeAround( + node: Node, + start: number | undefined, + type?: FindPredicate | string, + base?: RecursiveVisitors, + state?: TState + ): Found | undefined; - export const findNodeAfter: typeof findNodeAt; + export const findNodeAfter: typeof findNodeAround; } From 12ae8fed7ebc5b7c894c5976575f33cf36a223cc Mon Sep 17 00:00:00 2001 From: tuesmiddt Date: Tue, 25 Feb 2020 00:13:40 +0800 Subject: [PATCH 17/48] Parameterize dummy value and export `isDummy` --- acorn-loose/README.md | 4 ++++ acorn-loose/src/index.js | 1 + acorn-loose/src/parseutil.js | 4 +++- acorn-loose/src/state.js | 5 +++-- acorn-loose/src/tokenize.js | 3 ++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/acorn-loose/README.md b/acorn-loose/README.md index 3d8f5bac5..4641bd4fd 100644 --- a/acorn-loose/README.md +++ b/acorn-loose/README.md @@ -60,3 +60,7 @@ take the **`LooseParser`** class exported by the module, and call its static `extend` method with one or more plugins to get a customized parser class. The class has a static `parse` method that acts like the top-level `parse` method. + +**isDummy**`(node)` takes a `Node` and returns `true` if it is a dummy node +inserted by the parser. The function performs a simple equality check on the +node's name. diff --git a/acorn-loose/src/index.js b/acorn-loose/src/index.js index 903781c5f..cfa0b497b 100644 --- a/acorn-loose/src/index.js +++ b/acorn-loose/src/index.js @@ -36,6 +36,7 @@ import "./statement" import "./expression" export {LooseParser} from "./state" +export {isDummy} from "./parseutil" defaultOptions.tabSize = 4 diff --git a/acorn-loose/src/parseutil.js b/acorn-loose/src/parseutil.js index 4501e2d46..534efd4b0 100644 --- a/acorn-loose/src/parseutil.js +++ b/acorn-loose/src/parseutil.js @@ -1 +1,3 @@ -export function isDummy(node) { return node.name === "✖" } +export const dummyValue = "✖" + +export function isDummy(node) { return node.name === dummyValue } diff --git a/acorn-loose/src/state.js b/acorn-loose/src/state.js index 52887231d..322306fe4 100644 --- a/acorn-loose/src/state.js +++ b/acorn-loose/src/state.js @@ -1,4 +1,5 @@ import {Parser, SourceLocation, tokTypes as tt, Node, lineBreak, isNewLine} from "acorn" +import {dummyValue} from "./parseutil" function noop() {} @@ -63,13 +64,13 @@ export class LooseParser { dummyIdent() { let dummy = this.dummyNode("Identifier") - dummy.name = "✖" + dummy.name = dummyValue return dummy } dummyString() { let dummy = this.dummyNode("Literal") - dummy.value = dummy.raw = "✖" + dummy.value = dummy.raw = dummyValue return dummy } diff --git a/acorn-loose/src/tokenize.js b/acorn-loose/src/tokenize.js index e838b48d8..da20b7daf 100644 --- a/acorn-loose/src/tokenize.js +++ b/acorn-loose/src/tokenize.js @@ -1,5 +1,6 @@ import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from "acorn" import {LooseParser} from "./state" +import {dummyValue} from "./parseutil" const lp = LooseParser.prototype @@ -73,7 +74,7 @@ lp.readToken = function() { throw e } this.resetTo(pos) - if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"} + if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: dummyValue} if (replace) { if (this.options.locations) replace.loc = new SourceLocation( From b5c17877ac0511e31579ea31e7650ba1a5871e51 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 1 Mar 2020 13:31:53 +0100 Subject: [PATCH 18/48] Fix incorrect comment in regexp parser --- acorn/src/regexp.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/acorn/src/regexp.js b/acorn/src/regexp.js index ee19bcf55..62bebbb29 100644 --- a/acorn/src/regexp.js +++ b/acorn/src/regexp.js @@ -152,7 +152,7 @@ pp.regexp_pattern = function(state) { if (state.eat(0x29 /* ) */)) { state.raise("Unmatched ')'") } - if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) { + if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) { state.raise("Lone quantifier brackets") } } @@ -837,7 +837,7 @@ pp.regexp_eatCharacterClass = function(state) { if (state.eat(0x5B /* [ */)) { state.eat(0x5E /* ^ */) this.regexp_classRanges(state) - if (state.eat(0x5D /* [ */)) { + if (state.eat(0x5D /* ] */)) { return true } // Unreachable since it threw "unterminated regular expression" error before. @@ -885,7 +885,7 @@ pp.regexp_eatClassAtom = function(state) { } const ch = state.current() - if (ch !== 0x5D /* [ */) { + if (ch !== 0x5D /* ] */) { state.lastIntValue = ch state.advance() return true From 793c0e569ed1158672e3a40aeed1d8518832b802 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 1 Mar 2020 13:32:19 +0100 Subject: [PATCH 19/48] More rigorously check surrogate pairs in regexp validator --- acorn/src/regexp.js | 8 +++++--- test/tests-regexp.js | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/acorn/src/regexp.js b/acorn/src/regexp.js index 62bebbb29..605bce520 100644 --- a/acorn/src/regexp.js +++ b/acorn/src/regexp.js @@ -50,7 +50,8 @@ export class RegExpValidationState { if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { return c } - return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00 + const next = s.charCodeAt(i + 1) + return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c } nextIndex(i) { @@ -59,8 +60,9 @@ export class RegExpValidationState { if (i >= l) { return l } - const c = s.charCodeAt(i) - if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { + let c = s.charCodeAt(i), next + if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l || + (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) { return i + 1 } return i + 2 diff --git a/test/tests-regexp.js b/test/tests-regexp.js index 6c4719486..804e00a59 100644 --- a/test/tests-regexp.js +++ b/test/tests-regexp.js @@ -1049,6 +1049,7 @@ test("/[\\d][\\12-\\14]{1,}[^\\d]/", {}, { ecmaVersion: 2015 }) testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression flag (1:1)", { ecmaVersion: 5 }) testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression: /[\\d][\\12-\\14]{1,}[^\\d]/: Invalid class escape (1:1)", { ecmaVersion: 2015 }) test("/([a ]\\b)*\\b/", {}, { ecmaVersion: 5 }) +test("/[x-*]/u".replace("*", String.fromCharCode(0xd800)), {}, {ecmaVersion: 6}) /* // This is test case generator. From 6d194895783b03b2a37441f01857c34302eab4c8 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 1 Mar 2020 13:38:30 +0100 Subject: [PATCH 20/48] Mark release 7.1.1 --- AUTHORS | 6 ++++++ acorn/CHANGELOG.md | 12 ++++++++++++ acorn/package.json | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index c7a0fb8a0..6195b1ae8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -30,6 +30,7 @@ Fabien LOISON Felix Maier Forbes Lindesay Gilad Peleg +Huáng Jùnliàng impinball Ingvar Stepanyan Jackson Ray Hamilton @@ -68,6 +69,7 @@ Olivier Thomann Oskar Schöldström Paul Harper Peter Rust +piotr PlNG Praveen N Prayag Verma @@ -80,10 +82,14 @@ Sebastian McKenzie Shahar Soel Sheel Bedi Simen Bekkhus +susiwen +susiwen8 Teddy Katz Timothy Gu Toru Nagashima +tuesmiddt Victor Homyakov +Vladislav Tupikin Wexpo Lyu zsjforcn 龙腾道 diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index e893c221a..32f5ce8f3 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,15 @@ +## 7.1.1 (2020-03-01) + +### Bug fixes + +Treat `\8` and `\9` as invalid escapes in template strings. + +Allow unicode escapes in property names that are keywords. + +Don't error on an exponential operator expression as argument to `await`. + +More carefully check for valid UTF16 surrogate pairs in regexp validator. + ## 7.1.0 (2019-09-24) ### Bug fixes diff --git a/acorn/package.json b/acorn/package.json index 501b3f625..6a8f03607 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -5,7 +5,7 @@ "main": "dist/acorn.js", "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", - "version": "7.1.0", + "version": "7.1.1", "engines": {"node": ">=0.4.0"}, "maintainers": [ { From e75185fc6f4d446727d316658d73965aae56f2a8 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 2 Mar 2020 09:18:43 +0100 Subject: [PATCH 21/48] Check for statement end after 'use strict' marker Closes #921 --- acorn/src/parseutil.js | 9 ++++++++- test/tests.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/acorn/src/parseutil.js b/acorn/src/parseutil.js index bce71b54e..3da5fcd73 100644 --- a/acorn/src/parseutil.js +++ b/acorn/src/parseutil.js @@ -14,7 +14,14 @@ pp.strictDirective = function(start) { start += skipWhiteSpace.exec(this.input)[0].length let match = literal.exec(this.input.slice(start)) if (!match) return false - if ((match[1] || match[2]) === "use strict") return true + if ((match[1] || match[2]) === "use strict") { + skipWhiteSpace.lastIndex = start + match[0].length + let spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length + let next = this.input.charAt(end) + return next == ";" || next == "}" || + (lineBreak.test(spaceAfter[0]) && + !(/[(`\.\[+\-\/*%<>=,?^&]/.test(next) || next == "!" && this.input.charAt(end + 1) == "=")) + } start += match[0].length // Skip semicolon, if any. diff --git a/test/tests.js b/test/tests.js index 35fe29ca5..aec1739ac 100644 --- a/test/tests.js +++ b/test/tests.js @@ -29464,3 +29464,16 @@ test("/**/ --> comment\n", {}) test("x.class++", {}) testFail("½", "Unexpected character '½' (1:0)") + +// Ignore use-strict strings that aren't a stand-along expression +test("'use strict'.foo; 05", {}, {ecmaVersion: 6}) +test("'use strict'\n.foo; 05", {}, {ecmaVersion: 6}) +test("\"use strict\"(foo); 05", {}, {ecmaVersion: 6}) +test("'use strict'`foo`; 05", {}, {ecmaVersion: 6}) +test("'use strict'\n+ 10; 05", {}, {ecmaVersion: 6}) +test("'use strict'\n!=10; 05", {}, {ecmaVersion: 6}) + +// Don't ignore those that are, even with semicolon insertion +testFail("\"use strict\"\nfoo\n05", "Invalid number (3:0)", {ecmaVersion: 6}) +testFail("\"use strict\"\n;(foo)\n05", "Invalid number (3:0)", {ecmaVersion: 6}) +testFail("'use strict'\n!blah; 05", "Invalid number (2:7)", {ecmaVersion: 6}) From c6f08e80fd67db999a7ff28db4b397c780254b55 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 2 Mar 2020 09:35:26 +0100 Subject: [PATCH 22/48] Fix lint complaints --- acorn/src/parseutil.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acorn/src/parseutil.js b/acorn/src/parseutil.js index 3da5fcd73..98e35237f 100644 --- a/acorn/src/parseutil.js +++ b/acorn/src/parseutil.js @@ -18,9 +18,9 @@ pp.strictDirective = function(start) { skipWhiteSpace.lastIndex = start + match[0].length let spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length let next = this.input.charAt(end) - return next == ";" || next == "}" || + return next === ";" || next === "}" || (lineBreak.test(spaceAfter[0]) && - !(/[(`\.\[+\-\/*%<>=,?^&]/.test(next) || next == "!" && this.input.charAt(end + 1) == "=")) + !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "=")) } start += match[0].length From 44e52b237b72cca6654d513344e6c33c2194e2ff Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 2 Mar 2020 09:55:04 +0100 Subject: [PATCH 23/48] Don't tokenize the token after a class or strict function as strict Closes #912 --- acorn/src/expression.js | 8 +++----- acorn/src/statement.js | 11 +++++++---- test/tests-harmony.js | 4 ++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 71b02016f..3342335c6 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -838,16 +838,14 @@ pp.parseFunctionBody = function(node, isArrowFunction, isMethod) { // Add the params to varDeclaredNames to ensure that an error is thrown // if a let/const declaration in the function clashes with one of the params. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params)) - node.body = this.parseBlock(false) + // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' + if (this.strict && node.id) this.checkLVal(node.id, BIND_OUTSIDE) + node.body = this.parseBlock(false, undefined, useStrict && !oldStrict) node.expression = false this.adaptDirectivePrologue(node.body.body) this.labels = oldLabels } this.exitScope() - - // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' - if (this.strict && node.id) this.checkLVal(node.id, BIND_OUTSIDE) - this.strict = oldStrict } pp.isSimpleParamList = function(params) { diff --git a/acorn/src/statement.js b/acorn/src/statement.js index 8cadb5118..d15bb8e73 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -418,14 +418,16 @@ pp.parseExpressionStatement = function(node, expr) { // strict"` declarations when `allowStrict` is true (used for // function bodies). -pp.parseBlock = function(createNewLexicalScope = true, node = this.startNode()) { +pp.parseBlock = function(createNewLexicalScope = true, node = this.startNode(), exitStrict) { node.body = [] this.expect(tt.braceL) if (createNewLexicalScope) this.enterScope(0) - while (!this.eat(tt.braceR)) { + while (this.type !== tt.braceR) { let stmt = this.parseStatement(null) node.body.push(stmt) } + if (exitStrict) this.strict = false + this.next() if (createNewLexicalScope) this.exitScope() return this.finishNode(node, "BlockStatement") } @@ -578,7 +580,7 @@ pp.parseClass = function(node, isStatement) { let hadConstructor = false classBody.body = [] this.expect(tt.braceL) - while (!this.eat(tt.braceR)) { + while (this.type !== tt.braceR) { const element = this.parseClassElement(node.superClass !== null) if (element) { classBody.body.push(element) @@ -588,8 +590,9 @@ pp.parseClass = function(node, isStatement) { } } } - node.body = this.finishNode(classBody, "ClassBody") this.strict = oldStrict + this.next() + node.body = this.finishNode(classBody, "ClassBody") return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression") } diff --git a/test/tests-harmony.js b/test/tests-harmony.js index c6b58dd5c..e270abefa 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -16516,3 +16516,7 @@ test("({ a = 42, b: c.d } = e)", {}, {ecmaVersion: 6}) testFail("({ a = 42, b: c = d })", "Shorthand property assignments are valid only in destructuring patterns (1:5)", {ecmaVersion: 6}) test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6}) + +// Don't parse first token after a class or strict function as strict +test("class x {}\n05", {}, {ecmaVersion: 6}) +test("function x() { 'use strict' }\n05", {}, {ecmaVersion: 6}) From cda280a5cc5f21ded5c630751574255ec136996b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 9 Mar 2020 11:39:58 +0100 Subject: [PATCH 24/48] Add 6.4.1 to changelog --- acorn/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index 32f5ce8f3..93837a91a 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.4.1 (2020-03-09) + +### Bug fixes + +More carefully check for valid UTF16 surrogate pairs in regexp validator. + ## 7.1.1 (2020-03-01) ### Bug fixes From 7987e410aa93a446e5aeb3e3934fd1696eb3c9f3 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Mon, 16 Mar 2020 02:19:13 +0900 Subject: [PATCH 25/48] Support `export * as ns from "source"` --- acorn-loose/src/statement.js | 7 ++ acorn-walk/src/index.js | 2 + acorn/src/statement.js | 8 ++ bin/run_test262.js | 1 - test/run.js | 1 + test/tests-export-all-as-ns-from-source.js | 93 ++++++++++++++++++++++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 test/tests-export-all-as-ns-from-source.js diff --git a/acorn-loose/src/statement.js b/acorn-loose/src/statement.js index a5b574044..40230d2ee 100644 --- a/acorn-loose/src/statement.js +++ b/acorn-loose/src/statement.js @@ -358,6 +358,13 @@ lp.parseExport = function() { let node = this.startNode() this.next() if (this.eat(tt.star)) { + if (this.options.ecmaVersion >= 11) { + if (this.eatContextual("as")) { + node.exported = this.parseExprAtom() + } else { + node.exported = null + } + } node.source = this.eatContextual("from") ? this.parseExprAtom() : this.dummyString() return this.finishNode(node, "ExportAllDeclaration") } diff --git a/acorn-walk/src/index.js b/acorn-walk/src/index.js index d95af12be..498b1fc48 100644 --- a/acorn-walk/src/index.js +++ b/acorn-walk/src/index.js @@ -353,6 +353,8 @@ base.ExportNamedDeclaration = base.ExportDefaultDeclaration = (node, st, c) => { if (node.source) c(node.source, st, "Expression") } base.ExportAllDeclaration = (node, st, c) => { + if (node.exported) + c(node.exported, st) c(node.source, st, "Expression") } base.ImportDeclaration = (node, st, c) => { diff --git a/acorn/src/statement.js b/acorn/src/statement.js index d15bb8e73..8c7e171a9 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -676,6 +676,14 @@ pp.parseExport = function(node, exports) { this.next() // export * from '...' if (this.eat(tt.star)) { + if (this.options.ecmaVersion >= 11) { + if (this.eatContextual("as")) { + node.exported = this.parseIdent(true) + this.checkExport(exports, node.exported.name, this.lastTokStart) + } else { + node.exported = null + } + } this.expectContextual("from") if (this.type !== tt.string) this.unexpected() node.source = this.parseExprAtom() diff --git a/bin/run_test262.js b/bin/run_test262.js index 6a2f9b05c..4e0bc6b31 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,7 +11,6 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "coalesce-expression", - "export-star-as-namespace-from-module", "import.meta", "numeric-separator-literal", "optional-chaining", diff --git a/test/run.js b/test/run.js index 4ea981b90..b34720f7e 100644 --- a/test/run.js +++ b/test/run.js @@ -16,6 +16,7 @@ require("./tests-optional-catch-binding.js"); require("./tests-bigint.js"); require("./tests-dynamic-import.js"); + require("./tests-export-all-as-ns-from-source.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-export-all-as-ns-from-source.js b/test/tests-export-all-as-ns-from-source.js new file mode 100644 index 000000000..8a7145e71 --- /dev/null +++ b/test/tests-export-all-as-ns-from-source.js @@ -0,0 +1,93 @@ + +if (typeof exports != "undefined") { + var driver = require("./driver.js"); + var test = driver.test, testFail = driver.testFail; + var acorn = require("../acorn"); +} + +//------------------------------------------------------------------------------ +// export * as ns from "source" +//------------------------------------------------------------------------------ + +test("export * as ns from \"source\"", { + "type": "Program", + "start": 0, + "end": 28, + "body": [ + { + "type": "ExportAllDeclaration", + "start": 0, + "end": 28, + "exported": { + "type": "Identifier", + "start": 12, + "end": 14, + "name": "ns" + }, + "source": { + "type": "Literal", + "start": 20, + "end": 28, + "value": "source", + "raw": "\"source\"" + } + } + ], + "sourceType": "module" +}, { sourceType: "module", ecmaVersion: 11 }) + +test("export * as foo from \"bar\"", { + "type": "Program", + "start": 0, + "end": 26, + "body": [ + { + "type": "ExportAllDeclaration", + "start": 0, + "end": 26, + "exported": { + "type": "Identifier", + "start": 12, + "end": 15, + "name": "foo" + }, + "source": { + "type": "Literal", + "start": 21, + "end": 26, + "value": "bar", + "raw": "\"bar\"" + } + } + ], + "sourceType": "module" +}, { sourceType: "module", ecmaVersion: 11 }) + +test("export * from \"source\"", { + "type": "Program", + "start": 0, + "end": 22, + "body": [ + { + "type": "ExportAllDeclaration", + "start": 0, + "end": 22, + "exported": null, + "source": { + "type": "Literal", + "start": 14, + "end": 22, + "value": "source", + "raw": "\"source\"" + } + } + ], + "sourceType": "module" +}, { sourceType: "module", ecmaVersion: 11 }) + +testFail("export * as ns from \"source\"", "'import' and 'export' may appear only with 'sourceType: module' (1:0)", { sourceType: "script", ecmaVersion: 11 }) +testFail("export * as ns from \"source\"", "Unexpected token (1:9)", { sourceType: "module", ecmaVersion: 10 }) +testFail("export * as ns", "Unexpected token (1:14)", { sourceType: "module", ecmaVersion: 11 }) +testFail("export * as from \"source\"", "Unexpected token (1:17)", { sourceType: "module", ecmaVersion: 11 }) +testFail("export * as ns \"source\"", "Unexpected token (1:15)", { sourceType: "module", ecmaVersion: 11 }) +testFail("export {} as ns from \"source\"", "Unexpected token (1:10)", { sourceType: "module", ecmaVersion: 11 }) From 020d8ead34c0d6be433ba0f4c473bcc633493844 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 19 Mar 2020 11:04:50 +0100 Subject: [PATCH 26/48] Upgrade to Unicode 13 Closes #938 --- acorn/src/identifier.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/acorn/src/identifier.js b/acorn/src/identifier.js index 339066260..0d7c3d136 100644 --- a/acorn/src/identifier.js +++ b/acorn/src/identifier.js @@ -27,8 +27,8 @@ export const keywordRelationalOperator = /^in(stanceof)?$/ // are only applied when a character is found to actually have a // code point above 128. // Generated by `bin/generate-identifier-regex.js`. -let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc" -let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f" +let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc" +let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f" const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]") const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]") @@ -42,10 +42,10 @@ nonASCIIidentifierStartChars = nonASCIIidentifierChars = null // generated by bin/generate-identifier-regex.js // eslint-disable-next-line comma-spacing -const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,155,22,13,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,0,33,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,0,161,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,754,9486,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541] +const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938] // eslint-disable-next-line comma-spacing -const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,232,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,792487,239] +const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,239] // This has a complexity linear to the value of the code. The // assumption is that looking up astral identifier characters is diff --git a/package.json b/package.json index 6d06debf8..c419996c1 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,6 @@ "test262": "git+https://github.com/tc39/test262.git#09380a4ae412e986ea39eb7163f5a6b3e5b04bbc", "test262-parser-runner": "^0.5.0", "test262-stream": "^1.2.1", - "unicode-12.0.0": "^0.7.9" + "unicode-13.0.0": "^0.8.0" } } From 078e2cc761c0e4ff9d86963aea43efa34b7bbc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 20 Mar 2020 15:42:18 -0400 Subject: [PATCH 27/48] fix: check potentialArrowAt in maybeAsyncArrow Co-Authored-By: Vedant Roy --- acorn/src/expression.js | 3 ++- test/tests-asyncawait.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 3342335c6..a50ea7531 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -262,7 +262,8 @@ pp.parseExprSubscripts = function(refDestructuringErrors) { pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && - this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async" + this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && + this.potentialArrowAt === base.start while (true) { let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) if (element === base || element.type === "ArrowFunctionExpression") return element diff --git a/test/tests-asyncawait.js b/test/tests-asyncawait.js index aebc6dc73..f5d84794b 100644 --- a/test/tests-asyncawait.js +++ b/test/tests-asyncawait.js @@ -3525,3 +3525,5 @@ test("({ async delete() {} })", {}, {ecmaVersion: 8}) testFail("abc: async function a() {}", "Unexpected token (1:5)", {ecmaVersion: 8}) test("(async() => { await 4 ** 2 })()", {}, {ecmaVersion: 8}) + +testFail("4 + async() => 2", "Unexpected token (1:12)", {ecmaVersion: 8, loose: false}) From f1c3592ec66a05835cce2cd8a8fa68ab000e7fa4 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 2 Apr 2020 19:57:21 +0900 Subject: [PATCH 28/48] Follow regexp validation as per tc39/ecma262#1869 --- acorn/src/regexp.js | 73 ++++++++++++++++++++------------------- bin/test262.whitelist | 10 ++++++ test/run.js | 1 + test/tests-regexp-2020.js | 21 +++++++++++ 4 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 test/tests-regexp-2020.js diff --git a/acorn/src/regexp.js b/acorn/src/regexp.js index 605bce520..d0e66df83 100644 --- a/acorn/src/regexp.js +++ b/acorn/src/regexp.js @@ -40,49 +40,49 @@ export class RegExpValidationState { // If u flag is given, this returns the code point at the index (it combines a surrogate pair). // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair). - at(i) { + at(i, forceU = false) { const s = this.source const l = s.length if (i >= l) { return -1 } const c = s.charCodeAt(i) - if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { + if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { return c } const next = s.charCodeAt(i + 1) return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c } - nextIndex(i) { + nextIndex(i, forceU = false) { const s = this.source const l = s.length if (i >= l) { return l } let c = s.charCodeAt(i), next - if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l || + if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l || (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) { return i + 1 } return i + 2 } - current() { - return this.at(this.pos) + current(forceU = false) { + return this.at(this.pos, forceU) } - lookahead() { - return this.at(this.nextIndex(this.pos)) + lookahead(forceU = false) { + return this.at(this.nextIndex(this.pos, forceU), forceU) } - advance() { - this.pos = this.nextIndex(this.pos) + advance(forceU = false) { + this.pos = this.nextIndex(this.pos, forceU) } - eat(ch) { - if (this.current() === ch) { - this.advance() + eat(ch, forceU = false) { + if (this.current(forceU) === ch) { + this.advance(forceU) return true } return false @@ -418,9 +418,9 @@ pp.regexp_eatExtendedPatternCharacter = function(state) { return false } -// GroupSpecifier[U] :: +// GroupSpecifier :: // [empty] -// `?` GroupName[?U] +// `?` GroupName pp.regexp_groupSpecifier = function(state) { if (state.eat(0x3F /* ? */)) { if (this.regexp_eatGroupName(state)) { @@ -434,8 +434,8 @@ pp.regexp_groupSpecifier = function(state) { } } -// GroupName[U] :: -// `<` RegExpIdentifierName[?U] `>` +// GroupName :: +// `<` RegExpIdentifierName `>` // Note: this updates `state.lastStringValue` property with the eaten name. pp.regexp_eatGroupName = function(state) { state.lastStringValue = "" @@ -448,9 +448,9 @@ pp.regexp_eatGroupName = function(state) { return false } -// RegExpIdentifierName[U] :: -// RegExpIdentifierStart[?U] -// RegExpIdentifierName[?U] RegExpIdentifierPart[?U] +// RegExpIdentifierName :: +// RegExpIdentifierStart +// RegExpIdentifierName RegExpIdentifierPart // Note: this updates `state.lastStringValue` property with the eaten name. pp.regexp_eatRegExpIdentifierName = function(state) { state.lastStringValue = "" @@ -464,17 +464,18 @@ pp.regexp_eatRegExpIdentifierName = function(state) { return false } -// RegExpIdentifierStart[U] :: +// RegExpIdentifierStart :: // UnicodeIDStart // `$` // `_` -// `\` RegExpUnicodeEscapeSequence[?U] +// `\` RegExpUnicodeEscapeSequence[+U] pp.regexp_eatRegExpIdentifierStart = function(state) { const start = state.pos - let ch = state.current() - state.advance() + const forceU = this.options.ecmaVersion >= 11 + let ch = state.current(forceU) + state.advance(forceU) - if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) { + if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { ch = state.lastIntValue } if (isRegExpIdentifierStart(ch)) { @@ -489,19 +490,20 @@ function isRegExpIdentifierStart(ch) { return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ } -// RegExpIdentifierPart[U] :: +// RegExpIdentifierPart :: // UnicodeIDContinue // `$` // `_` -// `\` RegExpUnicodeEscapeSequence[?U] +// `\` RegExpUnicodeEscapeSequence[+U] // // pp.regexp_eatRegExpIdentifierPart = function(state) { const start = state.pos - let ch = state.current() - state.advance() + const forceU = this.options.ecmaVersion >= 11 + let ch = state.current(forceU) + state.advance(forceU) - if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) { + if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { ch = state.lastIntValue } if (isRegExpIdentifierPart(ch)) { @@ -571,7 +573,7 @@ pp.regexp_eatCharacterEscape = function(state) { this.regexp_eatCControlLetter(state) || this.regexp_eatZero(state) || this.regexp_eatHexEscapeSequence(state) || - this.regexp_eatRegExpUnicodeEscapeSequence(state) || + this.regexp_eatRegExpUnicodeEscapeSequence(state, false) || (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) || this.regexp_eatIdentityEscape(state) ) @@ -644,13 +646,14 @@ function isControlLetter(ch) { } // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence -pp.regexp_eatRegExpUnicodeEscapeSequence = function(state) { +pp.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU = false) { const start = state.pos + const switchU = forceU || state.switchU if (state.eat(0x75 /* u */)) { if (this.regexp_eatFixedHexDigits(state, 4)) { const lead = state.lastIntValue - if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) { + if (switchU && lead >= 0xD800 && lead <= 0xDBFF) { const leadSurrogateEnd = state.pos if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) { const trail = state.lastIntValue @@ -665,7 +668,7 @@ pp.regexp_eatRegExpUnicodeEscapeSequence = function(state) { return true } if ( - state.switchU && + switchU && state.eat(0x7B /* { */) && this.regexp_eatHexDigits(state) && state.eat(0x7D /* } */) && @@ -673,7 +676,7 @@ pp.regexp_eatRegExpUnicodeEscapeSequence = function(state) { ) { return true } - if (state.switchU) { + if (switchU) { state.raise("Invalid unicode escape") } state.pos = start diff --git a/bin/test262.whitelist b/bin/test262.whitelist index e69de29bb..68ddd0f1d 100644 --- a/bin/test262.whitelist +++ b/bin/test262.whitelist @@ -0,0 +1,10 @@ +language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (default) +language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (strict mode) +language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-3.js (default) +language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-3.js (strict mode) +language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-6.js (default) +language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-6.js (strict mode) +language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (default) +language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (strict mode) +language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (default) +language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (strict mode) diff --git a/test/run.js b/test/run.js index b34720f7e..929360099 100644 --- a/test/run.js +++ b/test/run.js @@ -12,6 +12,7 @@ require("./tests-async-iteration.js"); require("./tests-regexp.js"); require("./tests-regexp-2018.js"); + require("./tests-regexp-2020.js"); require("./tests-json-superset.js"); require("./tests-optional-catch-binding.js"); require("./tests-bigint.js"); diff --git a/test/tests-regexp-2020.js b/test/tests-regexp-2020.js new file mode 100644 index 000000000..7caff8f2a --- /dev/null +++ b/test/tests-regexp-2020.js @@ -0,0 +1,21 @@ +if (typeof exports != "undefined") { + var test = require("./driver.js").test + var testFail = require("./driver.js").testFail +} + +// https://github.com/tc39/ecma262/pull/1869 +testFail("/(?<\\ud835\\udc9c>.)/", "Invalid regular expression: /(?<\\ud835\\udc9c>.)/: Invalid capture group name (1:1)", { ecmaVersion: 2019 }) +test("/(?<\\ud835\\udc9c>.)/", {}, { ecmaVersion: 2020 }) +test("/(?<\\ud835\\udc9c>.)/u", {}, { ecmaVersion: 2019 }) +test("/(?<\\ud835\\udc9c>.)/u", {}, { ecmaVersion: 2020 }) + +testFail("/(?<\\u{1d49c}>.)/", "Invalid regular expression: /(?<\\u{1d49c}>.)/: Invalid capture group name (1:1)", { ecmaVersion: 2019 }) +test("/(?<\\u{1d49c}>.)/", {}, { ecmaVersion: 2020 }) +test("/(?<\\u{1d49c}>.)/u", {}, { ecmaVersion: 2019 }) +test("/(?<\\u{1d49c}>.)/u", {}, { ecmaVersion: 2020 }) + +testFail("/(?<𝒜>.)/", "Invalid regular expression: /(?<𝒜>.)/: Invalid capture group name (1:1)", { ecmaVersion: 2019 }) +test("/(?<𝒜>.)/", {}, { ecmaVersion: 2020 }) +test("/(?<𝒜>.)/u", {}, { ecmaVersion: 2019 }) +test("/(?<𝒜>.)/u", {}, { ecmaVersion: 2020 }) + From b4a6e5207aa86986a126a8ee4f8273c73d49eb74 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 2 Apr 2020 21:51:07 +0900 Subject: [PATCH 29/48] Add support for `import.meta` --- acorn-loose/src/expression.js | 11 +++- acorn-loose/src/statement.js | 11 ++-- acorn/src/expression.js | 34 ++++++++++-- acorn/src/statement.js | 2 +- bin/run_test262.js | 1 - test/run.js | 1 + test/tests-dynamic-import.js | 2 +- test/tests-harmony.js | 6 +-- test/tests-import-meta.js | 97 +++++++++++++++++++++++++++++++++++ test/tests.js | 2 +- 10 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 test/tests-import-meta.js diff --git a/acorn-loose/src/expression.js b/acorn-loose/src/expression.js index dbc41bd60..d2507f435 100644 --- a/acorn-loose/src/expression.js +++ b/acorn-loose/src/expression.js @@ -310,10 +310,13 @@ lp.parseExprAtom = function() { lp.parseExprImport = function() { const node = this.startNode() - this.next() // skip `import` + const meta = this.parseIdent(true) switch (this.tok.type) { case tt.parenL: return this.parseDynamicImport(node) + case tt.dot: + node.meta = meta + return this.parseImportMeta(node) default: node.name = "import" return this.finishNode(node, "Identifier") @@ -325,6 +328,12 @@ lp.parseDynamicImport = function(node) { return this.finishNode(node, "ImportExpression") } +lp.parseImportMeta = function(node) { + this.next() // skip '.' + node.property = this.parseIdent(true) + return this.finishNode(node, "MetaProperty") +} + lp.parseNew = function() { let node = this.startNode(), startIndent = this.curIndent, line = this.curLineStart let meta = this.parseIdent(true) diff --git a/acorn-loose/src/statement.js b/acorn-loose/src/statement.js index 40230d2ee..355d278f2 100644 --- a/acorn-loose/src/statement.js +++ b/acorn-loose/src/statement.js @@ -176,10 +176,13 @@ lp.parseStatement = function() { return this.parseClass(true) case tt._import: - if (this.options.ecmaVersion > 10 && this.lookAhead(1).type === tt.parenL) { - node.expression = this.parseExpression() - this.semicolon() - return this.finishNode(node, "ExpressionStatement") + if (this.options.ecmaVersion > 10) { + const nextType = this.lookAhead(1).type + if (nextType === tt.parenL || nextType === tt.dot) { + node.expression = this.parseExpression() + this.semicolon() + return this.finishNode(node, "ExpressionStatement") + } } return this.parseImport() diff --git a/acorn/src/expression.js b/acorn/src/expression.js index a50ea7531..006aa3bed 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -427,10 +427,18 @@ pp.parseExprAtom = function(refDestructuringErrors) { pp.parseExprImport = function() { const node = this.startNode() - this.next() // skip `import` + + // Consume `import` as an identifier for `import.meta`. + // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`. + if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword import") + const meta = this.parseIdent(true) + switch (this.type) { case tt.parenL: return this.parseDynamicImport(node) + case tt.dot: + node.meta = meta + return this.parseImportMeta(node) default: this.unexpected() } @@ -455,6 +463,22 @@ pp.parseDynamicImport = function(node) { return this.finishNode(node, "ImportExpression") } +pp.parseImportMeta = function(node) { + this.next() // skip `.` + + const containsEsc = this.containsEsc + node.property = this.parseIdent(true) + + if (node.property.name !== "meta") + this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'") + if (containsEsc) + this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters") + if (this.options.sourceType !== "module") + this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module") + + return this.finishNode(node, "MetaProperty") +} + pp.parseLiteral = function(value) { let node = this.startNode() node.value = value @@ -557,10 +581,12 @@ pp.parseNew = function() { node.meta = meta let containsEsc = this.containsEsc node.property = this.parseIdent(true) - if (node.property.name !== "target" || containsEsc) - this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target") + if (node.property.name !== "target") + this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'") + if (containsEsc) + this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters") if (!this.inNonArrowFunction()) - this.raiseRecoverable(node.start, "new.target can only be used in functions") + this.raiseRecoverable(node.start, "'new.target' can only be used in functions") return this.finishNode(node, "MetaProperty") } let startPos = this.start, startLoc = this.startLoc, isImport = this.type === tt._import diff --git a/acorn/src/statement.js b/acorn/src/statement.js index 8c7e171a9..4afea7503 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -122,7 +122,7 @@ pp.parseStatement = function(context, topLevel, exports) { skipWhiteSpace.lastIndex = this.pos let skip = skipWhiteSpace.exec(this.input) let next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next) - if (nextCh === 40) // '(' + if (nextCh === 40 || nextCh === 46) // '(' or '.' return this.parseExpressionStatement(node, this.parseExpression()) } diff --git a/bin/run_test262.js b/bin/run_test262.js index 4e0bc6b31..1521bbe15 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,7 +11,6 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "coalesce-expression", - "import.meta", "numeric-separator-literal", "optional-chaining", "top-level-await" diff --git a/test/run.js b/test/run.js index 929360099..f0e89ac97 100644 --- a/test/run.js +++ b/test/run.js @@ -18,6 +18,7 @@ require("./tests-bigint.js"); require("./tests-dynamic-import.js"); require("./tests-export-all-as-ns-from-source.js"); + require("./tests-import-meta.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-dynamic-import.js b/test/tests-dynamic-import.js index 675a45365..92e52586f 100644 --- a/test/tests-dynamic-import.js +++ b/test/tests-dynamic-import.js @@ -204,7 +204,7 @@ test( { ecmaVersion: 11 } ); -testFail('function failsParse() { return import.then(); }', 'Unexpected token (1:37)', { +testFail('function failsParse() { return import.then(); }', 'The only valid meta property for import is \'import.meta\' (1:38)', { ecmaVersion: 11, loose: false }); diff --git a/test/tests-harmony.js b/test/tests-harmony.js index e270abefa..e20bce8a6 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -14781,10 +14781,10 @@ test("function foo() { new.target; }", { sourceType: "script" }, {ecmaVersion: 6}); -testFail("new.prop", "The only valid meta property for new is new.target (1:4)", {ecmaVersion: 6}); -testFail("new.target", "new.target can only be used in functions (1:0)", {ecmaVersion: 6}); +testFail("new.prop", "The only valid meta property for new is 'new.target' (1:4)", {ecmaVersion: 6}); +testFail("new.target", "'new.target' can only be used in functions (1:0)", {ecmaVersion: 6}); test("function x() { return () => new.target }", {}, {ecmaVersion: 6}); -testFail("let y = () => new.target", "new.target can only be used in functions (1:14)", {ecmaVersion: 6}); +testFail("let y = () => new.target", "'new.target' can only be used in functions (1:14)", {ecmaVersion: 6}); test("export default function foo() {} false", { body: [ diff --git a/test/tests-import-meta.js b/test/tests-import-meta.js new file mode 100644 index 000000000..7f93d7a3a --- /dev/null +++ b/test/tests-import-meta.js @@ -0,0 +1,97 @@ +// Tests for ECMAScript 2020 `import.meta` + +if (typeof exports != 'undefined') { + var test = require('./driver.js').test; + var testFail = require('./driver.js').testFail; +} + +test( + "import.meta", + { + "type": "Program", + "start": 0, + "end": 11, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "expression": { + "type": "MetaProperty", + "start": 0, + "end": 11, + "meta": { + "type": "Identifier", + "start": 0, + "end": 6, + "name": "import" + }, + "property": { + "type": "Identifier", + "start": 7, + "end": 11, + "name": "meta" + } + } + } + ], + "sourceType": "module" + }, + { ecmaVersion: 11, sourceType: "module" } +); + +test( + "import.meta.url", + { + "type": "Program", + "start": 0, + "end": 15, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 15, + "object": { + "type": "MetaProperty", + "start": 0, + "end": 11, + "meta": { + "type": "Identifier", + "start": 0, + "end": 6, + "name": "import" + }, + "property": { + "type": "Identifier", + "start": 7, + "end": 11, + "name": "meta" + } + }, + "property": { + "type": "Identifier", + "start": 12, + "end": 15, + "name": "url" + }, + "computed": false + } + } + ], + "sourceType": "module" + }, + { ecmaVersion: 11, sourceType: "module" } +); + +testFail("import.meta", "Unexpected token (1:6)", { ecmaVersion: 10, sourceType: "module" }); +testFail("import.meta", "Cannot use 'import.meta' outside a module (1:0)", { ecmaVersion: 11, sourceType: "script" }); +testFail("import['meta']", "Unexpected token (1:6)", { ecmaVersion: 11, sourceType: "module" }); +testFail("a = import['meta']", "Unexpected token (1:10)", { ecmaVersion: 11, sourceType: "module" }); +testFail("import.target", "The only valid meta property for import is 'import.meta' (1:7)", { ecmaVersion: 11, sourceType: "module" }); +testFail("new.meta", "The only valid meta property for new is 'new.target' (1:4)", { ecmaVersion: 11, sourceType: "module" }); +testFail("im\\u0070ort.meta", "Escape sequence in keyword import (1:0)", { ecmaVersion: 11, sourceType: "module" }); +testFail("import.\\u006d\\u0065\\u0074\\u0061", "'import.meta' must not contain escaped characters (1:0)", { ecmaVersion: 11, sourceType: "module" }); diff --git a/test/tests.js b/test/tests.js index aec1739ac..0a0031484 100644 --- a/test/tests.js +++ b/test/tests.js @@ -29428,7 +29428,7 @@ test("(\\u0061sync ())", { }, {ecmaVersion: 8}) testFail("({ \\u0061sync x() { await x } })", "Unexpected token (1:14)", {ecmaVersion: 8}) testFail("for (x \\u006ff y) {}", "Unexpected token (1:7)", {ecmaVersion: 6}) -testFail("function x () { new.ta\\u0072get }", "The only valid meta property for new is new.target (1:20)", {ecmaVersion: 6}) +testFail("function x () { new.ta\\u0072get }", "'new.target' must not contain escaped characters (1:16)", {ecmaVersion: 6}) testFail("class X { st\\u0061tic y() {} }", "Unexpected token (1:22)", {ecmaVersion: 6}) testFail("(x=1)=2", "Parenthesized pattern (1:0)") From ec7cbd145d7e89ce1f6f31dc875b5dfb8092418a Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Tue, 14 Apr 2020 00:27:53 +0900 Subject: [PATCH 30/48] Add nullish coalescing --- acorn-loose/src/expression.js | 2 +- acorn/src/expression.js | 11 +- acorn/src/tokenize.js | 12 +- acorn/src/tokentype.js | 1 + bin/run_test262.js | 1 - test/run.js | 1 + test/tests-nullish-coalescing.js | 546 +++++++++++++++++++++++++++++++ 7 files changed, 570 insertions(+), 4 deletions(-) create mode 100644 test/tests-nullish-coalescing.js diff --git a/acorn-loose/src/expression.js b/acorn-loose/src/expression.js index d2507f435..be46375bf 100644 --- a/acorn-loose/src/expression.js +++ b/acorn-loose/src/expression.js @@ -102,7 +102,7 @@ lp.parseExprOp = function(left, start, minPrec, noIn, indent, line) { let rightStart = this.storeCurrentPos() node.right = this.parseExprOp(this.parseMaybeUnary(false), rightStart, prec, noIn, indent, line) } - this.finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression") + this.finishNode(node, /&&|\|\||\?\?/.test(node.operator) ? "LogicalExpression" : "BinaryExpression") return this.parseExprOp(node, start, minPrec, noIn, indent, line) } } diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 006aa3bed..ed7a1f895 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -186,11 +186,20 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { if (prec != null && (!noIn || this.type !== tt._in)) { if (prec > minPrec) { let logical = this.type === tt.logicalOR || this.type === tt.logicalAND + let coalesce = this.type === tt.coalesce + if (coalesce) { + // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions. + // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error. + prec = tt.logicalAND.binop + } let op = this.value this.next() let startPos = this.start, startLoc = this.startLoc let right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn) - let node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical) + let node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce) + if ((logical && this.type === tt.coalesce) || (coalesce && (this.type === tt.logicalOR || this.type === tt.logicalAND))) { + this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses") + } return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn) } } diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index 835fdcd96..a71a09342 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -289,6 +289,14 @@ pp.readToken_eq_excl = function(code) { // '=!' return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1) } +pp.readToken_question = function() { // '?' + if (this.options.ecmaVersion >= 11) { + let next = this.input.charCodeAt(this.pos + 1) + if (next === 63) return this.finishOp(tt.coalesce, 2) + } + return this.finishOp(tt.question, 1) +} + pp.getTokenFromCode = function(code) { switch (code) { // The interpretation of a dot depends on whether it is followed @@ -306,7 +314,6 @@ pp.getTokenFromCode = function(code) { case 123: ++this.pos; return this.finishToken(tt.braceL) case 125: ++this.pos; return this.finishToken(tt.braceR) case 58: ++this.pos; return this.finishToken(tt.colon) - case 63: ++this.pos; return this.finishToken(tt.question) case 96: // '`' if (this.options.ecmaVersion < 6) break @@ -356,6 +363,9 @@ pp.getTokenFromCode = function(code) { case 61: case 33: // '=!' return this.readToken_eq_excl(code) + case 63: // '?' + return this.readToken_question() + case 126: // '~' return this.finishOp(tt.prefix, 1) } diff --git a/acorn/src/tokentype.js b/acorn/src/tokentype.js index 7a8c48a6d..77b6ccb2c 100644 --- a/acorn/src/tokentype.js +++ b/acorn/src/tokentype.js @@ -108,6 +108,7 @@ export const types = { star: binop("*", 10), slash: binop("/", 10), starstar: new TokenType("**", {beforeExpr: true}), + coalesce: binop("??", 1), // Keyword token types. _break: kw("break"), diff --git a/bin/run_test262.js b/bin/run_test262.js index 1521bbe15..0c5a788eb 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -10,7 +10,6 @@ const unsupportedFeatures = [ "class-static-fields-private", "class-static-fields-public", "class-static-methods-private", - "coalesce-expression", "numeric-separator-literal", "optional-chaining", "top-level-await" diff --git a/test/run.js b/test/run.js index f0e89ac97..147e27a51 100644 --- a/test/run.js +++ b/test/run.js @@ -19,6 +19,7 @@ require("./tests-dynamic-import.js"); require("./tests-export-all-as-ns-from-source.js"); require("./tests-import-meta.js"); + require("./tests-nullish-coalescing.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-nullish-coalescing.js b/test/tests-nullish-coalescing.js new file mode 100644 index 000000000..6cd14a5d9 --- /dev/null +++ b/test/tests-nullish-coalescing.js @@ -0,0 +1,546 @@ + +if (typeof exports != "undefined") { + var driver = require("./driver.js"); + var test = driver.test, testFail = driver.testFail, testAssert = driver.testAssert, misMatch = driver.misMatch; + var acorn = require("../acorn"); +} + +test("a ?? b", { + "type": "Program", + "start": 0, + "end": 6, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 6, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "b" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a ?? b ?? c", { + "type": "Program", + "start": 0, + "end": 11, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 11, + "left": { + "type": "LogicalExpression", + "start": 0, + "end": 6, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "b" + } + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 10, + "end": 11, + "name": "c" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("a | b ?? c | d", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 14, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 5, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "|", + "right": { + "type": "Identifier", + "start": 4, + "end": 5, + "name": "b" + } + }, + "operator": "??", + "right": { + "type": "BinaryExpression", + "start": 9, + "end": 14, + "left": { + "type": "Identifier", + "start": 9, + "end": 10, + "name": "c" + }, + "operator": "|", + "right": { + "type": "Identifier", + "start": 13, + "end": 14, + "name": "d" + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a ?? b ? c : d", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "ConditionalExpression", + "start": 0, + "end": 14, + "test": { + "type": "LogicalExpression", + "start": 0, + "end": 6, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "b" + } + }, + "consequent": { + "type": "Identifier", + "start": 9, + "end": 10, + "name": "c" + }, + "alternate": { + "type": "Identifier", + "start": 13, + "end": 14, + "name": "d" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("(a || b) ?? c", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "LogicalExpression", + "start": 1, + "end": 7, + "left": { + "type": "Identifier", + "start": 1, + "end": 2, + "name": "a" + }, + "operator": "||", + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 12, + "end": 13, + "name": "c" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a || (b ?? c)", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "||", + "right": { + "type": "LogicalExpression", + "start": 6, + "end": 12, + "left": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "name": "c" + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("(a && b) ?? c", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "LogicalExpression", + "start": 1, + "end": 7, + "left": { + "type": "Identifier", + "start": 1, + "end": 2, + "name": "a" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 12, + "end": 13, + "name": "c" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a && (b ?? c)", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "&&", + "right": { + "type": "LogicalExpression", + "start": 6, + "end": 12, + "left": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "name": "c" + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("(a ?? b) || c", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "LogicalExpression", + "start": 1, + "end": 7, + "left": { + "type": "Identifier", + "start": 1, + "end": 2, + "name": "a" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + }, + "operator": "||", + "right": { + "type": "Identifier", + "start": 12, + "end": 13, + "name": "c" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a ?? (b || c)", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "??", + "right": { + "type": "LogicalExpression", + "start": 6, + "end": 12, + "left": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + }, + "operator": "||", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "name": "c" + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("(a ?? b) && c", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "LogicalExpression", + "start": 1, + "end": 7, + "left": { + "type": "Identifier", + "start": 1, + "end": 2, + "name": "a" + }, + "operator": "??", + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 12, + "end": 13, + "name": "c" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("a ?? (b && c)", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "LogicalExpression", + "start": 0, + "end": 13, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "operator": "??", + "right": { + "type": "LogicalExpression", + "start": 6, + "end": 12, + "left": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "name": "c" + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +testFail("a ?? b", "Unexpected token (1:3)", { ecmaVersion: 10 }) +testFail("?? b", "Unexpected token (1:0)", { ecmaVersion: 11 }) +testFail("a ??", "Unexpected token (1:4)", { ecmaVersion: 11 }) +testFail("a || b ?? c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:7)", { ecmaVersion: 11 }) +testFail("a && b ?? c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:7)", { ecmaVersion: 11 }) +testFail("a ?? b || c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:7)", { ecmaVersion: 11 }) +testFail("a ?? b && c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:7)", { ecmaVersion: 11 }) + +testFail("a+1 || b+1 ?? c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:11)", { ecmaVersion: 11 }) +testFail("a+1 && b+1 ?? c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:11)", { ecmaVersion: 11 }) +testFail("a+1 ?? b+1 || c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:11)", { ecmaVersion: 11 }) +testFail("a+1 ?? b+1 && c", "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses (1:11)", { ecmaVersion: 11 }) From 82ed10dfb6a3bdce15c77856fc4ed40abc628a39 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Mon, 13 Apr 2020 10:58:32 +0900 Subject: [PATCH 31/48] make test262 success on Windows --- bin/run_test262.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/run_test262.js b/bin/run_test262.js index 0c5a788eb..456c0fae6 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -20,6 +20,9 @@ run( { testsDirectory: path.dirname(require.resolve("test262/package.json")), skip: test => (test.attrs.features && unsupportedFeatures.some(f => test.attrs.features.includes(f))), - whitelist: fs.readFileSync("./bin/test262.whitelist", "utf8").split("\n").filter(v => v) + whitelist: fs.readFileSync("./bin/test262.whitelist", "utf8") + .split("\n") + .filter(Boolean) + .map(filename => path.sep !== "/" ? filename.split("/").join(path.sep) : filename) } ) From 6d555e826d962db66b3a2f4fb8361e57e5a1b171 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sat, 9 May 2020 09:04:01 +0200 Subject: [PATCH 32/48] Mark verison 7.2.0 --- acorn/CHANGELOG.md | 16 ++++++++++++++++ acorn/package.json | 2 +- package.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index 93837a91a..b7b232595 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,19 @@ +## 7.2.0 (2020-05-09) + +### Bug fixes + +Fix precedence issue in parsing of async arrow functions. + +### New features + +Add support for nullish coalescing. + +Add support for `import.meta`. + +Support `export * as ...` syntax. + +Upgrade to Unicode 13. + ## 6.4.1 (2020-03-09) ### Bug fixes diff --git a/acorn/package.json b/acorn/package.json index 6a8f03607..39179b6c3 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -5,7 +5,7 @@ "main": "dist/acorn.js", "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", - "version": "7.1.1", + "version": "7.2.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { diff --git a/package.json b/package.json index c419996c1..760497c9b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-standard": "^3.0.1", "rollup": "^1.7.0", "rollup-plugin-buble": "^0.19.0", - "test262": "git+https://github.com/tc39/test262.git#09380a4ae412e986ea39eb7163f5a6b3e5b04bbc", + "test262": "git+https://github.com/tc39/test262.git#2c432e35b261a2474f122631b02eff3e031de383", "test262-parser-runner": "^0.5.0", "test262-stream": "^1.2.1", "unicode-13.0.0": "^0.8.0" From 304ae5e62aafd5362c52e74778026a08ff35f562 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Mon, 11 May 2020 21:23:53 +0200 Subject: [PATCH 33/48] Enable allowAwaitOutsideFunction in test262, update whitelist --- bin/run_test262.js | 3 +-- bin/test262.whitelist | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/bin/run_test262.js b/bin/run_test262.js index 456c0fae6..f2ab82b3a 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -12,11 +12,10 @@ const unsupportedFeatures = [ "class-static-methods-private", "numeric-separator-literal", "optional-chaining", - "top-level-await" ]; run( - (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: 11, allowHashBang: true}), + (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: 11, allowHashBang: true, allowAwaitOutsideFunction: true}), { testsDirectory: path.dirname(require.resolve("test262/package.json")), skip: test => (test.attrs.features && unsupportedFeatures.some(f => test.attrs.features.includes(f))), diff --git a/bin/test262.whitelist b/bin/test262.whitelist index 68ddd0f1d..9e96f6f62 100644 --- a/bin/test262.whitelist +++ b/bin/test262.whitelist @@ -1,3 +1,30 @@ +built-ins/RegExp/property-escapes/generated/Emoji_Component.js (default) +built-ins/RegExp/property-escapes/generated/Emoji_Component.js (strict mode) +built-ins/RegExp/property-escapes/generated/Emoji_Modifier.js (default) +built-ins/RegExp/property-escapes/generated/Emoji_Modifier.js (strict mode) +built-ins/RegExp/property-escapes/generated/Emoji_Modifier_Base.js (default) +built-ins/RegExp/property-escapes/generated/Emoji_Modifier_Base.js (strict mode) +built-ins/RegExp/property-escapes/generated/Emoji_Presentation.js (default) +built-ins/RegExp/property-escapes/generated/Emoji_Presentation.js (strict mode) +built-ins/RegExp/property-escapes/generated/Extended_Pictographic.js (default) +built-ins/RegExp/property-escapes/generated/Extended_Pictographic.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_-_Chorasmian.js (default) +built-ins/RegExp/property-escapes/generated/Script_-_Chorasmian.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_-_Dives_Akuru.js (default) +built-ins/RegExp/property-escapes/generated/Script_-_Dives_Akuru.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_-_Khitan_Small_Script.js (default) +built-ins/RegExp/property-escapes/generated/Script_-_Khitan_Small_Script.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_-_Yezidi.js (default) +built-ins/RegExp/property-escapes/generated/Script_-_Yezidi.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Chorasmian.js (default) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Chorasmian.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Dives_Akuru.js (default) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Dives_Akuru.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Khitan_Small_Script.js (default) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Khitan_Small_Script.js (strict mode) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Yezidi.js (default) +built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Yezidi.js (strict mode) + language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (default) language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (strict mode) language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-3.js (default) @@ -8,3 +35,14 @@ language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (def language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (strict mode) language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (default) language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (strict mode) + +language/expressions/await/await-BindingIdentifier-in-global.js (default) +language/expressions/await/await-BindingIdentifier-in-global.js (strict mode) +language/expressions/await/await-in-global.js (default) +language/expressions/await/await-in-global.js (strict mode) +language/expressions/await/await-in-nested-function.js (default) +language/expressions/await/await-in-nested-function.js (strict mode) +language/expressions/await/await-in-nested-generator.js (default) +language/expressions/await/await-in-nested-generator.js (strict mode) +language/statements/labeled/value-await-non-module.js (default) +language/statements/labeled/value-await-non-module.js (strict mode) From f66c4e727368da794f4ded115990ce7accbcc08a Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Fri, 29 May 2020 16:22:07 +0100 Subject: [PATCH 34/48] Add type definitions for acorn.mjs (#954) For TypeScript projects that use the acorn.mjs distribution bundle, a separate `.mjs.d.ts` needs to be added to the folder. This was suggested in https://github.com/microsoft/TypeScript/issues/27957#issuecomment-623631119. --- .gitignore | 4 +++- acorn/dist/acorn.mjs.d.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 acorn/dist/acorn.mjs.d.ts diff --git a/.gitignore b/.gitignore index 1052d7d8a..983986903 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,9 @@ /.tern-port /local /bin/_acorn.js -/acorn/dist +/acorn/dist/* /acorn-loose/dist /acorn-walk/dist /yarn.lock +!/acorn/dist/acorn.d.ts +!/acorn/dist/acorn.mjs.d.ts \ No newline at end of file diff --git a/acorn/dist/acorn.mjs.d.ts b/acorn/dist/acorn.mjs.d.ts new file mode 100644 index 000000000..5f633595e --- /dev/null +++ b/acorn/dist/acorn.mjs.d.ts @@ -0,0 +1,2 @@ +import * as acorn from "./acorn"; +export = acorn; \ No newline at end of file From eec9b3762bb12314c1a82b71077d76eff4699547 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 1 Jun 2020 22:39:08 +0200 Subject: [PATCH 35/48] Fix parsing of ambiguous object pattern with a 'set' property with a default value Closes #957 --- acorn/src/expression.js | 2 +- test/tests-harmony.js | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index ed7a1f895..da94085f5 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -739,7 +739,7 @@ pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos } else if (!isPattern && !containsEsc && this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && - (this.type !== tt.comma && this.type !== tt.braceR)) { + (this.type !== tt.comma && this.type !== tt.braceR && this.type !== tt.eq)) { if (isGenerator || isAsync) this.unexpected() prop.kind = prop.key.name this.parsePropertyName(prop) diff --git a/test/tests-harmony.js b/test/tests-harmony.js index e20bce8a6..7b681e80c 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -16520,3 +16520,55 @@ test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6 // Don't parse first token after a class or strict function as strict test("class x {}\n05", {}, {ecmaVersion: 6}) test("function x() { 'use strict' }\n05", {}, {ecmaVersion: 6}) + +test("const myFn = ({ set = '' }) => {};", { + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myFn" + }, + "init": { + "type": "ArrowFunctionExpression", + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "set" + }, + "kind": "init", + "value": { + "type": "AssignmentPattern", + "left": { + "type": "Identifier", + "name": "set" + }, + "right": { + "type": "Literal", + "value": "" + } + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "body": [] + } + } + } + ], + "kind": "const" + } + ] +}, {ecmaVersion: 6}) From 4adea30d3aa0e536eb76f516344cab3cf93ee87e Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 6 Jun 2020 16:37:03 +0900 Subject: [PATCH 36/48] add optional chaining --- acorn-loose/src/expression.js | 28 +- acorn-walk/src/index.js | 2 +- acorn/src/expression.js | 35 +- acorn/src/lval.js | 8 + acorn/src/tokenize.js | 4 + acorn/src/tokentype.js | 1 + bin/run_test262.js | 1 - test/run.js | 1 + test/tests-optional-chaining.js | 1429 +++++++++++++++++++++++++++++++ 9 files changed, 1499 insertions(+), 10 deletions(-) create mode 100644 test/tests-optional-chaining.js diff --git a/acorn-loose/src/expression.js b/acorn-loose/src/expression.js index be46375bf..ca77f315d 100644 --- a/acorn-loose/src/expression.js +++ b/acorn-loose/src/expression.js @@ -159,17 +159,23 @@ lp.parseExprSubscripts = function() { } lp.parseSubscripts = function(base, start, noCalls, startIndent, line) { + const optionalSupported = this.options.ecmaVersion >= 11 + let optionalChained = false for (;;) { if (this.curLineStart !== line && this.curIndent <= startIndent && this.tokenStartsLine()) { if (this.tok.type === tt.dot && this.curIndent === startIndent) --startIndent else - return base + break } let maybeAsyncArrow = base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon() + let optional = optionalSupported && this.eat(tt.questionDot) + if (optional) { + optionalChained = true + } - if (this.eat(tt.dot)) { + if ((optional && this.tok.type !== tt.parenL && this.tok.type !== tt.bracketL && this.tok.type !== tt.backQuote) || this.eat(tt.dot)) { let node = this.startNodeAt(start) node.object = base if (this.curLineStart !== line && this.curIndent <= startIndent && this.tokenStartsLine()) @@ -177,6 +183,9 @@ lp.parseSubscripts = function(base, start, noCalls, startIndent, line) { else node.property = this.parsePropertyAccessor() || this.dummyIdent() node.computed = false + if (optionalSupported) { + node.optional = optional + } base = this.finishNode(node, "MemberExpression") } else if (this.tok.type === tt.bracketL) { this.pushCx() @@ -185,6 +194,9 @@ lp.parseSubscripts = function(base, start, noCalls, startIndent, line) { node.object = base node.property = this.parseExpression() node.computed = true + if (optionalSupported) { + node.optional = optional + } this.popCx() this.expect(tt.bracketR) base = this.finishNode(node, "MemberExpression") @@ -195,6 +207,9 @@ lp.parseSubscripts = function(base, start, noCalls, startIndent, line) { let node = this.startNodeAt(start) node.callee = base node.arguments = exprList + if (optionalSupported) { + node.optional = optional + } base = this.finishNode(node, "CallExpression") } else if (this.tok.type === tt.backQuote) { let node = this.startNodeAt(start) @@ -202,9 +217,16 @@ lp.parseSubscripts = function(base, start, noCalls, startIndent, line) { node.quasi = this.parseTemplate() base = this.finishNode(node, "TaggedTemplateExpression") } else { - return base + break } } + + if (optionalChained) { + const chainNode = this.startNodeAt(start) + chainNode.expression = base + base = this.finishNode(chainNode, "ChainExpression") + } + return base } lp.parseExprAtom = function() { diff --git a/acorn-walk/src/index.js b/acorn-walk/src/index.js index 498b1fc48..2a044b7df 100644 --- a/acorn-walk/src/index.js +++ b/acorn-walk/src/index.js @@ -192,7 +192,7 @@ base.Program = base.BlockStatement = (node, st, c) => { } base.Statement = skipThrough base.EmptyStatement = ignore -base.ExpressionStatement = base.ParenthesizedExpression = +base.ExpressionStatement = base.ParenthesizedExpression = base.ChainExpression = (node, st, c) => c(node.expression, st, "Expression") base.IfStatement = (node, st, c) => { c(node.test, st, "Expression") diff --git a/acorn/src/expression.js b/acorn/src/expression.js index da94085f5..5b8c2093d 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -273,21 +273,40 @@ pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.potentialArrowAt === base.start + let optionalChained = false + while (true) { - let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) - if (element === base || element.type === "ArrowFunctionExpression") return element + let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) + + if (element.optional) optionalChained = true + if (element === base || element.type === "ArrowFunctionExpression") { + if (optionalChained) { + const chainNode = this.startNodeAt(startPos, startLoc) + chainNode.expression = element + element = this.finishNode(chainNode, "ChainExpression") + } + return element + } + base = element } } -pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) { +pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) { + let optionalSupported = this.options.ecmaVersion >= 11 + let optional = optionalSupported && this.eat(tt.questionDot) + if (noCalls && optional) this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions") + let computed = this.eat(tt.bracketL) - if (computed || this.eat(tt.dot)) { + if (computed || (optional && this.type !== tt.parenL && this.type !== tt.backQuote) || this.eat(tt.dot)) { let node = this.startNodeAt(startPos, startLoc) node.object = base node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never") node.computed = !!computed if (computed) this.expect(tt.bracketR) + if (optionalSupported) { + node.optional = optional + } base = this.finishNode(node, "MemberExpression") } else if (!noCalls && this.eat(tt.parenL)) { let refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos @@ -295,7 +314,7 @@ pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) this.awaitPos = 0 this.awaitIdentPos = 0 let exprList = this.parseExprList(tt.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors) - if (maybeAsyncArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { + if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(tt.arrow)) { this.checkPatternErrors(refDestructuringErrors, false) this.checkYieldAwaitInDefaultParams() if (this.awaitIdentPos > 0) @@ -312,8 +331,14 @@ pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) let node = this.startNodeAt(startPos, startLoc) node.callee = base node.arguments = exprList + if (optionalSupported) { + node.optional = optional + } base = this.finishNode(node, "CallExpression") } else if (this.type === tt.backQuote) { + if (optional || optionalChained) { + this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions") + } let node = this.startNodeAt(startPos, startLoc) node.tag = base node.quasi = this.parseTemplate({isTagged: true}) diff --git a/acorn/src/lval.js b/acorn/src/lval.js index 8ad4b2639..03b3ce8c6 100644 --- a/acorn/src/lval.js +++ b/acorn/src/lval.js @@ -73,6 +73,10 @@ pp.toAssignable = function(node, isBinding, refDestructuringErrors) { this.toAssignable(node.expression, isBinding, refDestructuringErrors) break + case "ChainExpression": + this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side") + break + case "MemberExpression": if (!isBinding) break @@ -201,6 +205,10 @@ pp.checkLVal = function(expr, bindingType = BIND_NONE, checkClashes) { if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) this.declareName(expr.name, bindingType, expr.start) break + case "ChainExpression": + this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side") + break + case "MemberExpression": if (bindingType) this.raiseRecoverable(expr.start, "Binding member expression") break diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index a71a09342..c5840431e 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -292,6 +292,10 @@ pp.readToken_eq_excl = function(code) { // '=!' pp.readToken_question = function() { // '?' if (this.options.ecmaVersion >= 11) { let next = this.input.charCodeAt(this.pos + 1) + if (next === 46) { + let next2 = this.input.charCodeAt(this.pos + 2) + if (next2 < 48 || next2 > 57) return this.finishOp(tt.questionDot, 2) + } if (next === 63) return this.finishOp(tt.coalesce, 2) } return this.finishOp(tt.question, 1) diff --git a/acorn/src/tokentype.js b/acorn/src/tokentype.js index 77b6ccb2c..1e821ff40 100644 --- a/acorn/src/tokentype.js +++ b/acorn/src/tokentype.js @@ -70,6 +70,7 @@ export const types = { colon: new TokenType(":", beforeExpr), dot: new TokenType("."), question: new TokenType("?", beforeExpr), + questionDot: new TokenType("?."), arrow: new TokenType("=>", beforeExpr), template: new TokenType("template"), invalidTemplate: new TokenType("invalidTemplate"), diff --git a/bin/run_test262.js b/bin/run_test262.js index f2ab82b3a..6e20acfa0 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,7 +11,6 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "numeric-separator-literal", - "optional-chaining", ]; run( diff --git a/test/run.js b/test/run.js index 147e27a51..5485e6916 100644 --- a/test/run.js +++ b/test/run.js @@ -20,6 +20,7 @@ require("./tests-export-all-as-ns-from-source.js"); require("./tests-import-meta.js"); require("./tests-nullish-coalescing.js"); + require("./tests-optional-chaining.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-optional-chaining.js b/test/tests-optional-chaining.js new file mode 100644 index 000000000..18cb1f204 --- /dev/null +++ b/test/tests-optional-chaining.js @@ -0,0 +1,1429 @@ + +if (typeof exports != "undefined") { + var driver = require("./driver.js"); + var test = driver.test, testFail = driver.testFail, testAssert = driver.testAssert, misMatch = driver.misMatch; + var acorn = require("../acorn"); +} + +// Simple +test("obj?.foo", { + "type": "Program", + "start": 0, + "end": 8, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 8, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 8, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "foo" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj?.[foo]", { + "type": "Program", + "start": 0, + "end": 10, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 10, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 10, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "foo" + }, + "computed": true, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj?.()", { + "type": "Program", + "start": 0, + "end": 7, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 7, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 7, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "arguments": [], + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// Simple with spacing +test("obj ?. foo", { + "type": "Program", + "start": 0, + "end": 10, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 10, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 10, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 7, + "end": 10, + "name": "foo" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj ?. [foo]", { + "type": "Program", + "start": 0, + "end": 12, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 12, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 12, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 8, + "end": 11, + "name": "foo" + }, + "computed": true, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj ?. ()", { + "type": "Program", + "start": 0, + "end": 9, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 9, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 9, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 9, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "arguments": [], + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// Existing valid syntax +test("obj?.0:.1", { + "type": "Program", + "start": 0, + "end": 9, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 9, + "expression": { + "type": "ConditionalExpression", + "start": 0, + "end": 9, + "test": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "consequent": { + "type": "Literal", + "start": 4, + "end": 6, + "value": 0, + "raw": ".0" + }, + "alternate": { + "type": "Literal", + "start": 7, + "end": 9, + "value": 0.1, + "raw": ".1" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// Chaining +test("obj?.aaa?.bbb", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 13, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 13, + "object": { + "type": "MemberExpression", + "start": 0, + "end": 8, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "aaa" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "Identifier", + "start": 10, + "end": 13, + "name": "bbb" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj?.aaa.bbb", { + "type": "Program", + "start": 0, + "end": 12, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 12, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 12, + "object": { + "type": "MemberExpression", + "start": 0, + "end": 8, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "aaa" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "Identifier", + "start": 9, + "end": 12, + "name": "bbb" + }, + "computed": false, + "optional": false + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.aaa)?.bbb", { + "type": "Program", + "start": 0, + "end": 15, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 15, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 15, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 12, + "end": 15, + "name": "bbb" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.aaa).bbb", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 14, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "bbb" + }, + "computed": false, + "optional": false + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.aaa.bbb).ccc", { + "type": "Program", + "start": 0, + "end": 18, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 18, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 13, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 13, + "object": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "Identifier", + "start": 10, + "end": 13, + "name": "bbb" + }, + "computed": false, + "optional": false + } + }, + "property": { + "type": "Identifier", + "start": 15, + "end": 18, + "name": "ccc" + }, + "computed": false, + "optional": false + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("func?.()?.bbb", { + "type": "Program", + "start": 0, + "end": 13, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 13, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 13, + "object": { + "type": "CallExpression", + "start": 0, + "end": 8, + "callee": { + "type": "Identifier", + "start": 0, + "end": 4, + "name": "func" + }, + "arguments": [], + "optional": true + }, + "property": { + "type": "Identifier", + "start": 10, + "end": 13, + "name": "bbb" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("func?.().bbb", { + "type": "Program", + "start": 0, + "end": 12, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 12, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 12, + "object": { + "type": "CallExpression", + "start": 0, + "end": 8, + "callee": { + "type": "Identifier", + "start": 0, + "end": 4, + "name": "func" + }, + "arguments": [], + "optional": true + }, + "property": { + "type": "Identifier", + "start": 9, + "end": 12, + "name": "bbb" + }, + "computed": false, + "optional": false + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(func?.())?.bbb", { + "type": "Program", + "start": 0, + "end": 15, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 15, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 15, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "CallExpression", + "start": 1, + "end": 9, + "callee": { + "type": "Identifier", + "start": 1, + "end": 5, + "name": "func" + }, + "arguments": [], + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 12, + "end": 15, + "name": "bbb" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(func?.()).bbb", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 14, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "CallExpression", + "start": 1, + "end": 9, + "callee": { + "type": "Identifier", + "start": 1, + "end": 5, + "name": "func" + }, + "arguments": [], + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "bbb" + }, + "computed": false, + "optional": false + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("obj?.aaa?.()", { + "type": "Program", + "start": 0, + "end": 12, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 12, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 12, + "callee": { + "type": "MemberExpression", + "start": 0, + "end": 8, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "aaa" + }, + "computed": false, + "optional": true + }, + "arguments": [], + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("obj?.aaa()", { + "type": "Program", + "start": 0, + "end": 10, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 10, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 10, + "callee": { + "type": "MemberExpression", + "start": 0, + "end": 8, + "object": { + "type": "Identifier", + "start": 0, + "end": 3, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "aaa" + }, + "computed": false, + "optional": true + }, + "arguments": [], + "optional": false + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.aaa)?.()", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 14, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 14, + "callee": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + } + }, + "arguments": [], + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.aaa)()", { + "type": "Program", + "start": 0, + "end": 12, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 12, + "callee": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + } + }, + "arguments": [], + "optional": false + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +test("delete obj?.foo", { + "type": "Program", + "start": 0, + "end": 15, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "expression": { + "type": "UnaryExpression", + "start": 0, + "end": 15, + "operator": "delete", + "prefix": true, + "argument": { + "type": "ChainExpression", + "start": 7, + "end": 15, + "expression": { + "type": "MemberExpression", + "start": 7, + "end": 15, + "object": { + "type": "Identifier", + "start": 7, + "end": 10, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 12, + "end": 15, + "name": "foo" + }, + "computed": false, + "optional": true + } + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// OK if paranthesized. +test("new (obj?.foo)()", { + "type": "Program", + "start": 0, + "end": 16, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "expression": { + "type": "NewExpression", + "start": 0, + "end": 16, + "callee": { + "type": "ChainExpression", + "start": 5, + "end": 13, + "expression": { + "type": "MemberExpression", + "start": 5, + "end": 13, + "object": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 10, + "end": 13, + "name": "foo" + }, + "computed": false, + "optional": true + } + }, + "arguments": [] + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.foo)`template`", { + "type": "Program", + "start": 0, + "end": 20, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "expression": { + "type": "TaggedTemplateExpression", + "start": 0, + "end": 20, + "tag": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "foo" + }, + "computed": false, + "optional": true + } + }, + "quasi": { + "type": "TemplateLiteral", + "start": 10, + "end": 20, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 11, + "end": 19, + "value": { + "raw": "template", + "cooked": "template" + }, + "tail": true + } + ] + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.foo).bar = 0", { + "type": "Program", + "start": 0, + "end": 18, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 18, + "operator": "=", + "left": { + "type": "MemberExpression", + "start": 0, + "end": 14, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "foo" + }, + "computed": false, + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "bar" + }, + "computed": false, + "optional": false + }, + "right": { + "type": "Literal", + "start": 17, + "end": 18, + "value": 0, + "raw": "0" + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj?.foo).bar++", { + "type": "Program", + "start": 0, + "end": 16, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "expression": { + "type": "UpdateExpression", + "start": 0, + "end": 16, + "operator": "++", + "prefix": false, + "argument": { + "type": "MemberExpression", + "start": 0, + "end": 14, + "object": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "foo" + }, + "computed": false, + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "bar" + }, + "computed": false, + "optional": false + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("for ((obj?.foo).bar of []);", { + "type": "Program", + "start": 0, + "end": 27, + "body": [ + { + "type": "ForOfStatement", + "start": 0, + "end": 27, + "await": false, + "left": { + "type": "MemberExpression", + "start": 5, + "end": 19, + "object": { + "type": "ChainExpression", + "start": 6, + "end": 14, + "expression": { + "type": "MemberExpression", + "start": 6, + "end": 14, + "object": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "foo" + }, + "computed": false, + "optional": true + } + }, + "property": { + "type": "Identifier", + "start": 16, + "end": 19, + "name": "bar" + }, + "computed": false, + "optional": false + }, + "right": { + "type": "ArrayExpression", + "start": 23, + "end": 25, + "elements": [] + }, + "body": { + "type": "EmptyStatement", + "start": 26, + "end": 27 + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// With ParenthesizedExpression +test("(obj?.aaa).bbb", { + "type": "Program", + "start": 0, + "end": 14, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 14, + "object": { + "type": "ParenthesizedExpression", + "start": 0, + "end": 10, + "expression": { + "type": "ChainExpression", + "start": 1, + "end": 9, + "expression": { + "type": "MemberExpression", + "start": 1, + "end": 9, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 6, + "end": 9, + "name": "aaa" + }, + "computed": false, + "optional": true + } + } + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 14, + "name": "bbb" + }, + "computed": false, + "optional": false + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11, preserveParens: true }) + +// No ChainExpression if `callee|object` doesn't contain `?.` even if it's parenthesized. +test("(obj.foo.bar)?.buz", { + "type": "Program", + "start": 0, + "end": 18, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 18, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 18, + "object": { + "type": "MemberExpression", + "start": 1, + "end": 12, + "object": { + "type": "MemberExpression", + "start": 1, + "end": 8, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "foo" + }, + "computed": false, + "optional": false + }, + "property": { + "type": "Identifier", + "start": 9, + "end": 12, + "name": "bar" + }, + "computed": false, + "optional": false + }, + "property": { + "type": "Identifier", + "start": 15, + "end": 18, + "name": "buz" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) +test("(obj.foo())?.buz", { + "type": "Program", + "start": 0, + "end": 16, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "expression": { + "type": "ChainExpression", + "start": 0, + "end": 16, + "expression": { + "type": "MemberExpression", + "start": 0, + "end": 16, + "object": { + "type": "CallExpression", + "start": 1, + "end": 10, + "callee": { + "type": "MemberExpression", + "start": 1, + "end": 8, + "object": { + "type": "Identifier", + "start": 1, + "end": 4, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "foo" + }, + "computed": false, + "optional": false + }, + "arguments": [], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 13, + "end": 16, + "name": "buz" + }, + "computed": false, + "optional": true + } + } + } + ], + "sourceType": "script" +}, { ecmaVersion: 11 }) + +// With an old ecmaVersion. +testFail("obj?.foo", "Unexpected token (1:4)", { ecmaVersion: 10 }) +testFail("obj?.[foo]", "Unexpected token (1:4)", { ecmaVersion: 10 }) +testFail("obj?.()", "Unexpected token (1:4)", { ecmaVersion: 10 }) + +// Syntax errors. +testFail("obj?.0", "Unexpected token (1:6)", { ecmaVersion: 11 }) +testFail("async?.() => {}", "Unexpected token (1:10)", { ecmaVersion: 11 }) +testFail("new obj?.()", "Optional chaining cannot appear in the callee of new expressions (1:7)", { ecmaVersion: 11 }) +testFail("new obj?.foo()", "Optional chaining cannot appear in the callee of new expressions (1:7)", { ecmaVersion: 11 }) +testFail("obj?.foo\n`template`", "Optional chaining cannot appear in the tag of tagged template expressions (2:0)", { ecmaVersion: 11 }) +testFail("obj?.foo = 0", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("obj?.foo.bar = 0", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("obj?.().foo = 0", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("obj?.foo++", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("obj?.foo--", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("++obj?.foo", "Optional chaining cannot appear in left-hand side (1:2)", { ecmaVersion: 11 }) +testFail("--obj?.foo", "Optional chaining cannot appear in left-hand side (1:2)", { ecmaVersion: 11 }) +testFail("obj?.foo.bar++", "Optional chaining cannot appear in left-hand side (1:0)", { ecmaVersion: 11 }) +testFail("for (obj?.foo in {});", "Optional chaining cannot appear in left-hand side (1:5)", { ecmaVersion: 11 }) +testFail("for (obj?.foo.bar in {});", "Optional chaining cannot appear in left-hand side (1:5)", { ecmaVersion: 11 }) +testFail("for (obj?.foo of []);", "Optional chaining cannot appear in left-hand side (1:5)", { ecmaVersion: 11 }) +testFail("for (obj?.foo.bar of []);", "Optional chaining cannot appear in left-hand side (1:5)", { ecmaVersion: 11 }) From ee03be32a82c31430f5f3f820f368b53c191cc25 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 11 Jun 2020 09:51:16 +0200 Subject: [PATCH 37/48] Mark version 7.3.0 --- AUTHORS | 1 + acorn/CHANGELOG.md | 10 ++++++++++ acorn/package.json | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 6195b1ae8..904f6182e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -86,6 +86,7 @@ susiwen susiwen8 Teddy Katz Timothy Gu +Tim van der Lippe Toru Nagashima tuesmiddt Victor Homyakov diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index b7b232595..519842c4f 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,13 @@ +## 7.3.0 (2020-06-11) + +### Bug fixes + +Fix a bug that caused parsing of object patterns with a property named `set` that had a default value to fail. + +### New features + +Add support for optional chaining (`?.`). + ## 7.2.0 (2020-05-09) ### Bug fixes diff --git a/acorn/package.json b/acorn/package.json index 39179b6c3..69f3f99ce 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -5,7 +5,7 @@ "main": "dist/acorn.js", "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", - "version": "7.2.0", + "version": "7.3.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { From 50fd1bc3d3f963109a55415903cb046a1c60421f Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 11 Jun 2020 10:02:30 +0200 Subject: [PATCH 38/48] Mark version 7.1.0 of acorn-loose --- acorn-loose/CHANGELOG.md | 14 ++++++++++++++ acorn-loose/package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/acorn-loose/CHANGELOG.md b/acorn-loose/CHANGELOG.md index 83d191ec1..3c01af63b 100644 --- a/acorn-loose/CHANGELOG.md +++ b/acorn-loose/CHANGELOG.md @@ -1,3 +1,17 @@ +## 7.1.0 (2020-06-11) + +### Bug fixes + +Fix various issues in regexp validation. + +### New features + +Add support for `import.meta`. + +Add support for optional chaining (`?.`) and nullish coalescing (`??`). + +Support `export * as ns from "source"`. + ## 7.0.0 (2019-08-12) ### Breaking changes diff --git a/acorn-loose/package.json b/acorn-loose/package.json index 4beee085e..3bb01da11 100644 --- a/acorn-loose/package.json +++ b/acorn-loose/package.json @@ -4,7 +4,7 @@ "homepage": "https://github.com/acornjs/acorn", "main": "dist/acorn-loose.js", "module": "dist/acorn-loose.mjs", - "version": "7.0.0", + "version": "7.1.0", "engines": {"node": ">=0.4.0"}, "dependencies": { "acorn": "^7.0.0" From e265eae3499b01b176e71bdab8bdb0fe042f3e3d Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 11 Jun 2020 12:23:14 +0200 Subject: [PATCH 39/48] Mark version 7.3.1 --- acorn/CHANGELOG.md | 6 ++++++ acorn/package.json | 2 +- acorn/src/index.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index 519842c4f..b728cb8f6 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,9 @@ +## 7.3.1 (2020-06-11) + +### Bug fixes + +Make the string in the `version` export match the actual library version. + ## 7.3.0 (2020-06-11) ### Bug fixes diff --git a/acorn/package.json b/acorn/package.json index 69f3f99ce..18a1a3bf0 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -5,7 +5,7 @@ "main": "dist/acorn.js", "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", - "version": "7.3.0", + "version": "7.3.1", "engines": {"node": ">=0.4.0"}, "maintainers": [ { diff --git a/acorn/src/index.js b/acorn/src/index.js index f466a3b9f..549dcd226 100644 --- a/acorn/src/index.js +++ b/acorn/src/index.js @@ -31,7 +31,7 @@ import {isIdentifierChar, isIdentifierStart} from "./identifier" import {Token} from "./tokenize" import {isNewLine, lineBreak, lineBreakG, nonASCIIwhitespace} from "./whitespace" -export const version = "7.1.0" +export const version = "7.3.1" export { Parser, defaultOptions, From 3b6128e519aeb07521e102fd9ccc54aa4ceb0ac9 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 17 Jun 2020 08:25:24 +0200 Subject: [PATCH 40/48] Mark version 7.2.0 of acorn-walk --- acorn-walk/CHANGELOG.md | 10 ++++++++++ acorn-walk/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/acorn-walk/CHANGELOG.md b/acorn-walk/CHANGELOG.md index 89114970b..c6c2e058a 100644 --- a/acorn-walk/CHANGELOG.md +++ b/acorn-walk/CHANGELOG.md @@ -1,3 +1,13 @@ +## 7.2.0 (2020-06-17) + +### New features + +Support optional chaining and nullish coalescing. + +Support `import.meta`. + +Add support for `export * as ns from "source"`. + ## 7.1.1 (2020-02-13) ### Bug fixes diff --git a/acorn-walk/package.json b/acorn-walk/package.json index a66ca892c..ae8da3cf3 100644 --- a/acorn-walk/package.json +++ b/acorn-walk/package.json @@ -5,7 +5,7 @@ "main": "dist/walk.js", "types": "dist/walk.d.ts", "module": "dist/walk.mjs", - "version": "7.1.1", + "version": "7.2.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { From 31d3b1c56872c2d88bf1952885eca02187792788 Mon Sep 17 00:00:00 2001 From: Joe Krump Date: Tue, 23 Jun 2020 15:49:33 -0700 Subject: [PATCH 41/48] Add "MIT License" at the top of acorn License file Add a first line that specifies the license type "MIT License" this makes it more clear to developers which license is being used and can help them more easily determine if `acorn` is a package that they are okay to use in their software. [This is also the default for an MIT license for a repository when adding one in GitHub](https://github.com/joekrump/acorn/community/license/new?branch=master&template=mit). --- acorn/LICENSE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/acorn/LICENSE b/acorn/LICENSE index 2c0632b6a..cc5272c96 100644 --- a/acorn/LICENSE +++ b/acorn/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (C) 2012-2018 by various contributors (see AUTHORS) Permission is hereby granted, free of charge, to any person obtaining a copy From 4e2c0e21a262990b9b54eb7fc8799870ece84a92 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 24 Jun 2020 07:37:36 +0200 Subject: [PATCH 42/48] Also add license header to other packages --- acorn-loose/LICENSE | 2 ++ acorn-walk/LICENSE | 2 ++ 2 files changed, 4 insertions(+) diff --git a/acorn-loose/LICENSE b/acorn-loose/LICENSE index 2c0632b6a..cc5272c96 100644 --- a/acorn-loose/LICENSE +++ b/acorn-loose/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (C) 2012-2018 by various contributors (see AUTHORS) Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/acorn-walk/LICENSE b/acorn-walk/LICENSE index 2c0632b6a..cc5272c96 100644 --- a/acorn-walk/LICENSE +++ b/acorn-walk/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (C) 2012-2018 by various contributors (see AUTHORS) Permission is hereby granted, free of charge, to any person obtaining a copy From 459fa1eb8e8b7771496551e2d6e71937ff3a649c Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 2 Aug 2020 15:19:20 +0900 Subject: [PATCH 43/48] update test262 --- bin/run_test262.js | 1 + bin/test262.whitelist | 12 ++---------- package.json | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/bin/run_test262.js b/bin/run_test262.js index 6e20acfa0..c5892f29b 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,6 +11,7 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "numeric-separator-literal", + "logical-assignment-operators", ]; run( diff --git a/bin/test262.whitelist b/bin/test262.whitelist index 9e96f6f62..725858f89 100644 --- a/bin/test262.whitelist +++ b/bin/test262.whitelist @@ -25,16 +25,7 @@ built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Khitan_Small_Scr built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Yezidi.js (default) built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Yezidi.js (strict mode) -language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (default) -language/literals/regexp/named-groups/invalid-non-id-continue-groupspecifier.js (strict mode) -language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-3.js (default) -language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-3.js (strict mode) -language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-6.js (default) -language/literals/regexp/named-groups/invalid-non-id-start-groupspecifier-6.js (strict mode) -language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (default) -language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier.js (strict mode) -language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (default) -language/literals/regexp/named-groups/invalid-u-escape-in-groupspecifier-2.js (strict mode) +language/literals/string/legacy-non-octal-escape-sequence-8-strict.js (strict mode) language/expressions/await/await-BindingIdentifier-in-global.js (default) language/expressions/await/await-BindingIdentifier-in-global.js (strict mode) @@ -44,5 +35,6 @@ language/expressions/await/await-in-nested-function.js (default) language/expressions/await/await-in-nested-function.js (strict mode) language/expressions/await/await-in-nested-generator.js (default) language/expressions/await/await-in-nested-generator.js (strict mode) + language/statements/labeled/value-await-non-module.js (default) language/statements/labeled/value-await-non-module.js (strict mode) diff --git a/package.json b/package.json index 760497c9b..382f59e0b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-standard": "^3.0.1", "rollup": "^1.7.0", "rollup-plugin-buble": "^0.19.0", - "test262": "git+https://github.com/tc39/test262.git#2c432e35b261a2474f122631b02eff3e031de383", + "test262": "git+https://github.com/tc39/test262.git#a6c819ad0f049f23f1a37af6b89dbb79fe3b9216", "test262-parser-runner": "^0.5.0", "test262-stream": "^1.2.1", "unicode-13.0.0": "^0.8.0" From fe7b3f1ee5fc492beba8cb3d3ba1ad8626dc7265 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 2 Aug 2020 15:47:01 +0900 Subject: [PATCH 44/48] add logical assignment operators --- acorn/src/tokenize.js | 19 ++- bin/run_test262.js | 3 +- test/run.js | 1 + test/tests-logical-assignment-operators.js | 182 +++++++++++++++++++++ 4 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 test/tests-logical-assignment-operators.js diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index c5840431e..29e56b6be 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -233,7 +233,13 @@ pp.readToken_mult_modulo_exp = function(code) { // '%*' pp.readToken_pipe_amp = function(code) { // '|&' let next = this.input.charCodeAt(this.pos + 1) - if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2) + if (next === code) { + if (this.options.ecmaVersion >= 12) { + let next2 = this.input.charCodeAt(this.pos + 2) + if (next2 === 61) return this.finishOp(tt.assign, 3) + } + return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2) + } if (next === 61) return this.finishOp(tt.assign, 2) return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1) } @@ -290,13 +296,20 @@ pp.readToken_eq_excl = function(code) { // '=!' } pp.readToken_question = function() { // '?' - if (this.options.ecmaVersion >= 11) { + const ecmaVersion = this.options.ecmaVersion + if (ecmaVersion >= 11) { let next = this.input.charCodeAt(this.pos + 1) if (next === 46) { let next2 = this.input.charCodeAt(this.pos + 2) if (next2 < 48 || next2 > 57) return this.finishOp(tt.questionDot, 2) } - if (next === 63) return this.finishOp(tt.coalesce, 2) + if (next === 63) { + if (ecmaVersion >= 12) { + let next2 = this.input.charCodeAt(this.pos + 2) + if (next2 === 61) return this.finishOp(tt.assign, 3) + } + return this.finishOp(tt.coalesce, 2) + } } return this.finishOp(tt.question, 1) } diff --git a/bin/run_test262.js b/bin/run_test262.js index c5892f29b..92a2394da 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,11 +11,10 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "numeric-separator-literal", - "logical-assignment-operators", ]; run( - (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: 11, allowHashBang: true, allowAwaitOutsideFunction: true}), + (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: 12, allowHashBang: true, allowAwaitOutsideFunction: true}), { testsDirectory: path.dirname(require.resolve("test262/package.json")), skip: test => (test.attrs.features && unsupportedFeatures.some(f => test.attrs.features.includes(f))), diff --git a/test/run.js b/test/run.js index 5485e6916..bd7cebd58 100644 --- a/test/run.js +++ b/test/run.js @@ -21,6 +21,7 @@ require("./tests-import-meta.js"); require("./tests-nullish-coalescing.js"); require("./tests-optional-chaining.js"); + require("./tests-logical-assignment-operators.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-logical-assignment-operators.js b/test/tests-logical-assignment-operators.js new file mode 100644 index 000000000..2e157f019 --- /dev/null +++ b/test/tests-logical-assignment-operators.js @@ -0,0 +1,182 @@ +// Tests for ECMAScript 2021 `&&=`, `||=`, `??=` + +if (typeof exports != 'undefined') { + var test = require('./driver.js').test; + var testFail = require('./driver.js').testFail; +} + +test( + "a &&= b", + { + "type": "Program", + "start": 0, + "end": 7, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "operator": "&&=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "a ||= b", + { + "type": "Program", + "start": 0, + "end": 7, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "operator": "||=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "a ??= b", + { + "type": "Program", + "start": 0, + "end": 7, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "operator": "??=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + } + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "a &&= b ||= c ??= d", + { + "type": "Program", + "start": 0, + "end": 19, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 19, + "operator": "&&=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "name": "a" + }, + "right": { + "type": "AssignmentExpression", + "start": 6, + "end": 19, + "operator": "||=", + "left": { + "type": "Identifier", + "start": 6, + "end": 7, + "name": "b" + }, + "right": { + "type": "AssignmentExpression", + "start": 12, + "end": 19, + "operator": "??=", + "left": { + "type": "Identifier", + "start": 12, + "end": 13, + "name": "c" + }, + "right": { + "type": "Identifier", + "start": 18, + "end": 19, + "name": "d" + } + } + } + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +testFail("a &&= b", "Unexpected token (1:4)", { ecmaVersion: 11 }); +testFail("a ||= b", "Unexpected token (1:4)", { ecmaVersion: 11 }); +testFail("a ??= b", "Unexpected token (1:4)", { ecmaVersion: 11 }); + +testFail("({a} &&= b)", "Assigning to rvalue (1:1)", { ecmaVersion: 12 }); +testFail("({a} ||= b)", "Assigning to rvalue (1:1)", { ecmaVersion: 12 }); +testFail("({a} ??= b)", "Assigning to rvalue (1:1)", { ecmaVersion: 12 }); From d20ade2929485f9f875a4bc4f2834b567e82865f Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 2 Aug 2020 15:19:20 +0900 Subject: [PATCH 45/48] update test262 --- bin/run_test262.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/run_test262.js b/bin/run_test262.js index 92a2394da..f88abb2d9 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -11,6 +11,7 @@ const unsupportedFeatures = [ "class-static-fields-public", "class-static-methods-private", "numeric-separator-literal", + "logical-assignment-operators", ]; run( From e376a6631a72dff57a20ff11ba527838a555c58a Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 2 Aug 2020 19:23:54 +0900 Subject: [PATCH 46/48] add numeric separators --- acorn-loose/src/expression.js | 2 +- acorn/src/expression.js | 2 +- acorn/src/tokenize.js | 55 +++++++-- bin/run_test262.js | 1 - test/run.js | 1 + test/tests-numeric-separators.js | 199 +++++++++++++++++++++++++++++++ 6 files changed, 247 insertions(+), 13 deletions(-) create mode 100644 test/tests-numeric-separators.js diff --git a/acorn-loose/src/expression.js b/acorn-loose/src/expression.js index ca77f315d..4cfe1100d 100644 --- a/acorn-loose/src/expression.js +++ b/acorn-loose/src/expression.js @@ -266,7 +266,7 @@ lp.parseExprAtom = function() { node = this.startNode() node.value = this.tok.value node.raw = this.input.slice(this.tok.start, this.tok.end) - if (this.tok.type === tt.num && node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1) + if (this.tok.type === tt.num && node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1).replace(/_/g, "") this.next() return this.finishNode(node, "Literal") diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 5b8c2093d..d71701374 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -517,7 +517,7 @@ pp.parseLiteral = function(value) { let node = this.startNode() node.value = value node.raw = this.input.slice(this.start, this.end) - if (node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1) + if (node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1).replace(/_/g, "") this.next() return this.finishNode(node, "Literal") } diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index 29e56b6be..6c86f5c51 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -438,30 +438,67 @@ pp.readRegexp = function() { // were read, the integer value otherwise. When `len` is given, this // will return `null` unless the integer has exactly `len` digits. -pp.readInt = function(radix, len) { - let start = this.pos, total = 0 - for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { +pp.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) { + // `len` is used for character escape sequences. In that case, disallow separators. + const allowSeparators = this.options.ecmaVersion >= 12 && len === undefined + + // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b) + // and isn't fraction part nor exponent part. In that case, if the first digit + // is zero then disallow separators. + const isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48 + + let start = this.pos, total = 0, lastCode = 0 + for (let i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) { let code = this.input.charCodeAt(this.pos), val + + if (allowSeparators && code === 95) { + if (isLegacyOctalNumericLiteral) this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals") + if (lastCode === 95) this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore") + if (i === 0) this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits") + lastCode = code + continue + } + if (code >= 97) val = code - 97 + 10 // a else if (code >= 65) val = code - 65 + 10 // A else if (code >= 48 && code <= 57) val = code - 48 // 0-9 else val = Infinity if (val >= radix) break - ++this.pos + lastCode = code total = total * radix + val } + + if (allowSeparators && lastCode === 95) this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits") if (this.pos === start || len != null && this.pos - start !== len) return null return total } +function stringToNumber(str, isLegacyOctalNumericLiteral) { + if (isLegacyOctalNumericLiteral) { + return parseInt(str, 8) + } + + // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value. + return parseFloat(str.replace(/_/g, "")) +} + +function stringToBigInt(str) { + if (typeof BigInt !== "function") { + return null + } + + // `BigInt(value)` throws syntax error if the string contains numeric separators. + return BigInt(str.replace(/_/g, "")) +} + pp.readRadixNumber = function(radix) { let start = this.pos this.pos += 2 // 0x let val = this.readInt(radix) if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix) if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) { - val = typeof BigInt !== "undefined" ? BigInt(this.input.slice(start, this.pos)) : null + val = stringToBigInt(this.input.slice(start, this.pos)) ++this.pos } else if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number") return this.finishToken(tt.num, val) @@ -471,13 +508,12 @@ pp.readRadixNumber = function(radix) { pp.readNumber = function(startsWithDot) { let start = this.pos - if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number") + if (!startsWithDot && this.readInt(10, undefined, true) === null) this.raise(start, "Invalid number") let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48 if (octal && this.strict) this.raise(start, "Invalid number") let next = this.input.charCodeAt(this.pos) if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) { - let str = this.input.slice(start, this.pos) - let val = typeof BigInt !== "undefined" ? BigInt(str) : null + let val = stringToBigInt(this.input.slice(start, this.pos)) ++this.pos if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number") return this.finishToken(tt.num, val) @@ -495,8 +531,7 @@ pp.readNumber = function(startsWithDot) { } if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number") - let str = this.input.slice(start, this.pos) - let val = octal ? parseInt(str, 8) : parseFloat(str) + let val = stringToNumber(this.input.slice(start, this.pos), octal) return this.finishToken(tt.num, val) } diff --git a/bin/run_test262.js b/bin/run_test262.js index f88abb2d9..ff55bcd19 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -10,7 +10,6 @@ const unsupportedFeatures = [ "class-static-fields-private", "class-static-fields-public", "class-static-methods-private", - "numeric-separator-literal", "logical-assignment-operators", ]; diff --git a/test/run.js b/test/run.js index bd7cebd58..80d3ad42d 100644 --- a/test/run.js +++ b/test/run.js @@ -22,6 +22,7 @@ require("./tests-nullish-coalescing.js"); require("./tests-optional-chaining.js"); require("./tests-logical-assignment-operators.js"); + require("./tests-numeric-separators.js"); var acorn = require("../acorn") var acorn_loose = require("../acorn-loose") diff --git a/test/tests-numeric-separators.js b/test/tests-numeric-separators.js new file mode 100644 index 000000000..e28ef5055 --- /dev/null +++ b/test/tests-numeric-separators.js @@ -0,0 +1,199 @@ +// Tests for ECMAScript 2021 Numeric Separators + +if (typeof exports != 'undefined') { + var test = require('./driver.js').test; + var testFail = require('./driver.js').testFail; +} + +function bigint(str) { + if (typeof BigInt !== "function") { + return null + } + return BigInt(str) +} + +test( + "123_456", + { + "type": "Program", + "start": 0, + "end": 7, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "expression": { + "type": "Literal", + "start": 0, + "end": 7, + "value": 123456, + "raw": "123_456" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "123_456.123_456e+123_456", + { + "type": "Program", + "start": 0, + "end": 24, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 24, + "expression": { + "type": "Literal", + "start": 0, + "end": 24, + "value": 123456.123456e+123456, + "raw": "123_456.123_456e+123_456" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "0b1010_0001", + { + "type": "Program", + "start": 0, + "end": 11, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "expression": { + "type": "Literal", + "start": 0, + "end": 11, + "value": 0b10100001, + "raw": "0b1010_0001" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "0xDEAD_BEAF", + { + "type": "Program", + "start": 0, + "end": 11, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "expression": { + "type": "Literal", + "start": 0, + "end": 11, + "value": 0xDEADBEAF, + "raw": "0xDEAD_BEAF" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "0o755_666", + { + "type": "Program", + "start": 0, + "end": 9, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 9, + "expression": { + "type": "Literal", + "start": 0, + "end": 9, + "value": 0o755666, + "raw": "0o755_666" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + "123_456n", + { + "type": "Program", + "start": 0, + "end": 8, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "expression": { + "type": "Literal", + "start": 0, + "end": 8, + "value": bigint("123456"), + "raw": "123_456n", + "bigint": "123456" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +test( + ".012_345", + { + "type": "Program", + "start": 0, + "end": 8, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "expression": { + "type": "Literal", + "start": 0, + "end": 8, + "value": 0.012345, + "raw": ".012_345" + } + } + ], + "sourceType": "script" + }, + { ecmaVersion: 12 } +); + +testFail("123_456", "Identifier directly after number (1:3)", { ecmaVersion: 11 }); +testFail("123__456", "Numeric separator must be exactly one underscore (1:4)", { ecmaVersion: 12 }); +testFail("0._123456", "Numeric separator is not allowed at the first of digits (1:2)", { ecmaVersion: 12 }); +testFail("123456_", "Numeric separator is not allowed at the last of digits (1:6)", { ecmaVersion: 12 }); +testFail("012_345", "Numeric separator is not allowed in legacy octal numeric literals (1:3)", { ecmaVersion: 12 }); + +testFail("'\\x2_0'", "Bad character escape sequence (1:3)", { ecmaVersion: 12 }); +testFail("'\\u00_20'", "Bad character escape sequence (1:3)", { ecmaVersion: 12 }); +testFail("'\\u{2_0}'", "Bad character escape sequence (1:4)", { ecmaVersion: 12 }); From 856b720cc7f971844c5bf3ea2ac072d574cc3bbf Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 3 Aug 2020 11:57:06 +0200 Subject: [PATCH 47/48] Remove link to plugin that's part of the repository now --- acorn/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/acorn/README.md b/acorn/README.md index 585f2736f..52d2e9b71 100644 --- a/acorn/README.md +++ b/acorn/README.md @@ -266,5 +266,4 @@ Plugins for ECMAScript proposals: - [`acorn-stage3`](https://github.com/acornjs/acorn-stage3): Parse most stage 3 proposals, bundling: - [`acorn-class-fields`](https://github.com/acornjs/acorn-class-fields): Parse [class fields proposal](https://github.com/tc39/proposal-class-fields) - [`acorn-import-meta`](https://github.com/acornjs/acorn-import-meta): Parse [import.meta proposal](https://github.com/tc39/proposal-import-meta) - - [`acorn-numeric-separator`](https://github.com/acornjs/acorn-numeric-separator): Parse [numeric separator proposal](https://github.com/tc39/proposal-numeric-separator) - [`acorn-private-methods`](https://github.com/acornjs/acorn-private-methods): parse [private methods, getters and setters proposal](https://github.com/tc39/proposal-private-methods)n From 54efb62138c54f523413fb6a6c00c57c81e81f54 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 3 Aug 2020 12:00:24 +0200 Subject: [PATCH 48/48] Mark version 7.4.0 --- AUTHORS | 1 + acorn/CHANGELOG.md | 8 ++++++++ acorn/package.json | 2 +- acorn/src/index.js | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 904f6182e..f73abdf0d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,6 +36,7 @@ Ingvar Stepanyan Jackson Ray Hamilton Jesse McCarthy Jiaxing Wang +Joe Krump Joel Kemp Johannes Herr John-David Dalton diff --git a/acorn/CHANGELOG.md b/acorn/CHANGELOG.md index b728cb8f6..164fd27c6 100644 --- a/acorn/CHANGELOG.md +++ b/acorn/CHANGELOG.md @@ -1,3 +1,11 @@ +## 7.4.0 (2020-08-03) + +### New features + +Add support for logical assignment operators. + +Add support for numeric separators. + ## 7.3.1 (2020-06-11) ### Bug fixes diff --git a/acorn/package.json b/acorn/package.json index 18a1a3bf0..25bfa862b 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -5,7 +5,7 @@ "main": "dist/acorn.js", "types": "dist/acorn.d.ts", "module": "dist/acorn.mjs", - "version": "7.3.1", + "version": "7.4.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { diff --git a/acorn/src/index.js b/acorn/src/index.js index 549dcd226..eb118534b 100644 --- a/acorn/src/index.js +++ b/acorn/src/index.js @@ -31,7 +31,7 @@ import {isIdentifierChar, isIdentifierStart} from "./identifier" import {Token} from "./tokenize" import {isNewLine, lineBreak, lineBreakG, nonASCIIwhitespace} from "./whitespace" -export const version = "7.3.1" +export const version = "7.4.0" export { Parser, defaultOptions,