From 79e600881f730e8b1e915c3a0cd703ec72c7d536 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Wed, 12 Jul 2023 13:42:05 +0800 Subject: [PATCH 1/9] feat(typescript-estree): throw on invalid update expressions --- .../fixtures/_error_/call-expr/fixture.ts | 1 + .../call-expr/snapshots/1-TSESTree-Error.shot | 8 + .../call-expr/snapshots/2-Babel-Error.shot | 3 + .../snapshots/3-Alignment-Error.shot | 3 + .../fixtures/_error_/literal/fixture.ts | 1 + .../literal/snapshots/1-TSESTree-Error.shot | 8 + .../literal/snapshots/2-Babel-Error.shot | 3 + .../literal/snapshots/3-Alignment-Error.shot | 3 + .../fixtures/valid-assignment/fixture.ts | 10 + .../snapshots/1-TSESTree-AST.shot | 363 +++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 356 +++++++++++++++++ .../snapshots/3-Babel-AST.shot | 339 ++++++++++++++++ .../snapshots/4-Babel-Tokens.shot | 356 +++++++++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 367 ++++++++++++++++++ .../snapshots/6-AST-Alignment-Tokens.shot | 366 +++++++++++++++++ .../tests/fixtures-with-differences-ast.shot | 1 + .../fixtures-with-differences-tokens.shot | 1 + packages/typescript-estree/src/convert.ts | 7 + packages/typescript-estree/src/node-utils.ts | 15 + 19 files changed, 2211 insertions(+) create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/fixture.ts new file mode 100644 index 000000000000..3151b42d808e --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/fixture.ts @@ -0,0 +1 @@ +a()++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..05532bec78b0 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ call-expr TSESTree - Error 1`] = ` +"TSError +> 1 | a()++; + | ^^^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..28dbe5eb0cbe --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ call-expr Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..d78bd34c0e40 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ call-expr Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/fixture.ts new file mode 100644 index 000000000000..f85efba66e65 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/fixture.ts @@ -0,0 +1 @@ +1++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..433b834d72db --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ literal TSESTree - Error 1`] = ` +"TSError +> 1 | 1++; + | ^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..fae8771457f6 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ literal Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..27b640e2a9b3 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ literal Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts new file mode 100644 index 000000000000..926d49142370 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts @@ -0,0 +1,10 @@ +class F { + #a; + + m() { + this.#a++; + this.m().a++; + this[1] = 1; + F++; + } +} diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..370ce54396ec --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,363 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - AST 1`] = ` +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + abstract: false, + body: ClassBody { + type: "ClassBody", + body: [ + PropertyDefinition { + type: "PropertyDefinition", + computed: false, + declare: false, + decorators: [], + definite: false, + key: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + optional: false, + override: false, + readonly: false, + static: false, + value: null, + + range: [12, 15], + loc: { + start: { column: 2, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + MethodDefinition { + type: "MethodDefinition", + computed: false, + decorators: [], + key: Identifier { + type: "Identifier", + decorators: [], + name: "m", + optional: false, + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + kind: "method", + optional: false, + override: false, + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [ + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + + range: [29, 36], + loc: { + start: { column: 4, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + operator: "++", + prefix: false, + + range: [29, 38], + loc: { + start: { column: 4, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + + range: [29, 39], + loc: { + start: { column: 4, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: CallExpression { + type: "CallExpression", + arguments: [], + callee: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + decorators: [], + name: "m", + optional: false, + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + + range: [44, 50], + loc: { + start: { column: 4, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + optional: false, + + range: [44, 52], + loc: { + start: { column: 4, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + decorators: [], + name: "a", + optional: false, + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + + range: [44, 54], + loc: { + start: { column: 4, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + operator: "++", + prefix: false, + + range: [44, 56], + loc: { + start: { column: 4, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + + range: [44, 57], + loc: { + start: { column: 4, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: AssignmentExpression { + type: "AssignmentExpression", + left: MemberExpression { + type: "MemberExpression", + computed: true, + object: ThisExpression { + type: "ThisExpression", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + optional: false, + property: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + + range: [62, 69], + loc: { + start: { column: 4, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + operator: "=", + right: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 73], + loc: { + start: { column: 4, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 74], + loc: { + start: { column: 4, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: Identifier { + type: "Identifier", + decorators: [], + name: "F", + optional: false, + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + operator: "++", + prefix: false, + + range: [79, 82], + loc: { + start: { column: 4, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + + range: [79, 83], + loc: { + start: { column: 4, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + ], + + range: [23, 87], + loc: { + start: { column: 6, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + declare: false, + expression: false, + generator: false, + id: null, + params: [], + + range: [20, 87], + loc: { + start: { column: 3, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + + range: [19, 87], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + ], + + range: [8, 89], + loc: { + start: { column: 8, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, + declare: false, + decorators: [], + id: Identifier { + type: "Identifier", + decorators: [], + name: "F", + optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + implements: [], + superClass: null, + + range: [0, 89], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, + ], + sourceType: "script", + + range: [0, 90], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 11 }, + }, +} +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..f2d04022010c --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,356 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - Tokens 1`] = ` +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [14, 15], + loc: { + start: { column: 4, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [20, 21], + loc: { + start: { column: 3, line: 4 }, + end: { column: 4, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [21, 22], + loc: { + start: { column: 4, line: 4 }, + end: { column: 5, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [23, 24], + loc: { + start: { column: 6, line: 4 }, + end: { column: 7, line: 4 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [33, 34], + loc: { + start: { column: 8, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [36, 38], + loc: { + start: { column: 11, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [38, 39], + loc: { + start: { column: 13, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [48, 49], + loc: { + start: { column: 8, line: 6 }, + end: { column: 9, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [50, 51], + loc: { + start: { column: 10, line: 6 }, + end: { column: 11, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [51, 52], + loc: { + start: { column: 11, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [52, 53], + loc: { + start: { column: 12, line: 6 }, + end: { column: 13, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [54, 56], + loc: { + start: { column: 14, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [56, 57], + loc: { + start: { column: 16, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [66, 67], + loc: { + start: { column: 8, line: 7 }, + end: { column: 9, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [68, 69], + loc: { + start: { column: 10, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [70, 71], + loc: { + start: { column: 12, line: 7 }, + end: { column: 13, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [73, 74], + loc: { + start: { column: 15, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [80, 82], + loc: { + start: { column: 5, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [82, 83], + loc: { + start: { column: 7, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [86, 87], + loc: { + start: { column: 2, line: 9 }, + end: { column: 3, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [88, 89], + loc: { + start: { column: 0, line: 10 }, + end: { column: 1, line: 10 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..d685e046b897 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot @@ -0,0 +1,339 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + body: ClassBody { + type: "ClassBody", + body: [ + PropertyDefinition { + type: "PropertyDefinition", + computed: false, + key: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + static: false, + value: null, + + range: [12, 15], + loc: { + start: { column: 2, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + MethodDefinition { + type: "MethodDefinition", + computed: false, + key: Identifier { + type: "Identifier", + name: "m", + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + kind: "method", + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [ + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + + range: [29, 36], + loc: { + start: { column: 4, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + operator: "++", + prefix: false, + + range: [29, 38], + loc: { + start: { column: 4, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + + range: [29, 39], + loc: { + start: { column: 4, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: CallExpression { + type: "CallExpression", + arguments: [], + callee: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + name: "m", + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + + range: [44, 50], + loc: { + start: { column: 4, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + optional: false, + + range: [44, 52], + loc: { + start: { column: 4, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + name: "a", + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + + range: [44, 54], + loc: { + start: { column: 4, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + operator: "++", + prefix: false, + + range: [44, 56], + loc: { + start: { column: 4, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + + range: [44, 57], + loc: { + start: { column: 4, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: AssignmentExpression { + type: "AssignmentExpression", + left: MemberExpression { + type: "MemberExpression", + computed: true, + object: ThisExpression { + type: "ThisExpression", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + optional: false, + property: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + + range: [62, 69], + loc: { + start: { column: 4, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + operator: "=", + right: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 73], + loc: { + start: { column: 4, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 74], + loc: { + start: { column: 4, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: Identifier { + type: "Identifier", + name: "F", + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + operator: "++", + prefix: false, + + range: [79, 82], + loc: { + start: { column: 4, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + + range: [79, 83], + loc: { + start: { column: 4, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + ], + + range: [23, 87], + loc: { + start: { column: 6, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + expression: false, + generator: false, + id: null, + params: [], + + range: [20, 87], + loc: { + start: { column: 3, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + + range: [19, 87], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + ], + + range: [8, 89], + loc: { + start: { column: 8, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "F", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + superClass: null, + + range: [0, 89], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, + ], + sourceType: "script", + + range: [0, 90], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 11 }, + }, +} +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..41362f99e498 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,356 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Tokens 1`] = ` +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [14, 15], + loc: { + start: { column: 4, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [20, 21], + loc: { + start: { column: 3, line: 4 }, + end: { column: 4, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [21, 22], + loc: { + start: { column: 4, line: 4 }, + end: { column: 5, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [23, 24], + loc: { + start: { column: 6, line: 4 }, + end: { column: 7, line: 4 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [33, 34], + loc: { + start: { column: 8, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [36, 38], + loc: { + start: { column: 11, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [38, 39], + loc: { + start: { column: 13, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [48, 49], + loc: { + start: { column: 8, line: 6 }, + end: { column: 9, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [50, 51], + loc: { + start: { column: 10, line: 6 }, + end: { column: 11, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [51, 52], + loc: { + start: { column: 11, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [52, 53], + loc: { + start: { column: 12, line: 6 }, + end: { column: 13, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [54, 56], + loc: { + start: { column: 14, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [56, 57], + loc: { + start: { column: 16, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [66, 67], + loc: { + start: { column: 8, line: 7 }, + end: { column: 9, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [68, 69], + loc: { + start: { column: 10, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [70, 71], + loc: { + start: { column: 12, line: 7 }, + end: { column: 13, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [73, 74], + loc: { + start: { column: 15, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [80, 82], + loc: { + start: { column: 5, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [82, 83], + loc: { + start: { column: 7, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [86, 87], + loc: { + start: { column: 2, line: 9 }, + end: { column: 3, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [88, 89], + loc: { + start: { column: 0, line: 10 }, + end: { column: 1, line: 10 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot new file mode 100644 index 000000000000..1579d88fc972 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot @@ -0,0 +1,367 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment - AST 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Program { + type: 'Program', + body: Array [ + ClassDeclaration { + type: 'ClassDeclaration', +- abstract: false, + body: ClassBody { + type: 'ClassBody', + body: Array [ + PropertyDefinition { + type: 'PropertyDefinition', + computed: false, +- declare: false, +- decorators: Array [], +- definite: false, + key: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, +- optional: false, +- override: false, +- readonly: false, + static: false, + value: null, + + range: [12, 15], + loc: { + start: { column: 2, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + MethodDefinition { + type: 'MethodDefinition', + computed: false, +- decorators: Array [], + key: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'm', +- optional: false, + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + kind: 'method', +- optional: false, +- override: false, + static: false, + value: FunctionExpression { + type: 'FunctionExpression', + async: false, + body: BlockStatement { + type: 'BlockStatement', + body: Array [ + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + + range: [29, 36], + loc: { + start: { column: 4, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + operator: '++', + prefix: false, + + range: [29, 38], + loc: { + start: { column: 4, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + + range: [29, 39], + loc: { + start: { column: 4, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: MemberExpression { + type: 'MemberExpression', + computed: false, + object: CallExpression { + type: 'CallExpression', + arguments: Array [], + callee: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'm', +- optional: false, + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + + range: [44, 50], + loc: { + start: { column: 4, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + optional: false, + + range: [44, 52], + loc: { + start: { column: 4, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'a', +- optional: false, + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + + range: [44, 54], + loc: { + start: { column: 4, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + operator: '++', + prefix: false, + + range: [44, 56], + loc: { + start: { column: 4, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + + range: [44, 57], + loc: { + start: { column: 4, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: AssignmentExpression { + type: 'AssignmentExpression', + left: MemberExpression { + type: 'MemberExpression', + computed: true, + object: ThisExpression { + type: 'ThisExpression', + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + optional: false, + property: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + + range: [62, 69], + loc: { + start: { column: 4, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + operator: '=', + right: Literal { + type: 'Literal', + raw: '1', + value: 1, + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 73], + loc: { + start: { column: 4, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 74], + loc: { + start: { column: 4, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'F', +- optional: false, + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + operator: '++', + prefix: false, + + range: [79, 82], + loc: { + start: { column: 4, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + + range: [79, 83], + loc: { + start: { column: 4, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + ], + + range: [23, 87], + loc: { + start: { column: 6, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, +- declare: false, + expression: false, + generator: false, + id: null, + params: Array [], + + range: [20, 87], + loc: { + start: { column: 3, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + + range: [19, 87], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 9 }, + }, + }, + ], + + range: [8, 89], + loc: { + start: { column: 8, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, +- declare: false, +- decorators: Array [], + id: Identifier { + type: 'Identifier', +- decorators: Array [], + name: 'F', +- optional: false, + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, +- implements: Array [], + superClass: null, + + range: [0, 89], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 10 }, + }, + }, + ], + sourceType: 'script', + + range: [0, 90], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 11 }, + }, + }" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot new file mode 100644 index 000000000000..f9d0a71e1f57 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot @@ -0,0 +1,366 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment - Token 1`] = ` +"Snapshot Diff: +- TSESTree ++ Babel + + Array [ + Keyword { + type: 'Keyword', + value: 'class', + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'F', + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '{', + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [14, 15], + loc: { + start: { column: 4, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'm', + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [20, 21], + loc: { + start: { column: 3, line: 4 }, + end: { column: 4, line: 4 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [21, 22], + loc: { + start: { column: 4, line: 4 }, + end: { column: 5, line: 4 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '{', + + range: [23, 24], + loc: { + start: { column: 6, line: 4 }, + end: { column: 7, line: 4 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [33, 34], + loc: { + start: { column: 8, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [36, 38], + loc: { + start: { column: 11, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [38, 39], + loc: { + start: { column: 13, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [48, 49], + loc: { + start: { column: 8, line: 6 }, + end: { column: 9, line: 6 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'm', + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [50, 51], + loc: { + start: { column: 10, line: 6 }, + end: { column: 11, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [51, 52], + loc: { + start: { column: 11, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [52, 53], + loc: { + start: { column: 12, line: 6 }, + end: { column: 13, line: 6 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'a', + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [54, 56], + loc: { + start: { column: 14, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [56, 57], + loc: { + start: { column: 16, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '[', + + range: [66, 67], + loc: { + start: { column: 8, line: 7 }, + end: { column: 9, line: 7 }, + }, + }, + Numeric { + type: 'Numeric', + value: '1', + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ']', + + range: [68, 69], + loc: { + start: { column: 10, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '=', + + range: [70, 71], + loc: { + start: { column: 12, line: 7 }, + end: { column: 13, line: 7 }, + }, + }, + Numeric { + type: 'Numeric', + value: '1', + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [73, 74], + loc: { + start: { column: 15, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'F', + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [80, 82], + loc: { + start: { column: 5, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [82, 83], + loc: { + start: { column: 7, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '}', + + range: [86, 87], + loc: { + start: { column: 2, line: 9 }, + end: { column: 3, line: 9 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '}', + + range: [88, 89], + loc: { + start: { column: 0, line: 10 }, + end: { column: 1, line: 10 }, + }, + }, + ]" +`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index a41c223827df..409216445120 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -143,6 +143,7 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "expression/TSSatisfiesExpression/fixtures/logical-with-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-inner-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-outer-parentheses/fixture.ts", + "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/accessor-decorators/fixtures/accessor-decorator-factory-instance-member/fixture.ts", diff --git a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot index b15734b809f0..43ef25b5170b 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot @@ -26,6 +26,7 @@ exports[`AST Fixtures List fixtures with Token differences 1`] = ` "element/AccessorProperty/fixtures/modifier-private/fixture.ts", "element/AccessorProperty/fixtures/modifier-protected/fixture.ts", "element/AccessorProperty/fixtures/modifier-public/fixture.ts", + "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/basics/fixtures/abstract-class-with-abstract-readonly-property/fixture.ts", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 4be5c8783b6d..cf0e031d4f68 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -26,6 +26,7 @@ import { isESTreeClassMember, isOptional, isThisInTypeQuery, + isValidAssignmentTarget, nodeCanBeDecorated, nodeHasIllegalDecorators, nodeIsPresent, @@ -2020,6 +2021,12 @@ export class Converter { * ESTree uses UpdateExpression for ++/-- */ if (operator === '++' || operator === '--') { + if (!isValidAssignmentTarget(node.operand)) { + this.#throwUnlessAllowInvalidAST( + node, + 'Invalid left-hand side expression in unary operation', + ); + } return this.createNode(node, { type: AST_NODE_TYPES.UpdateExpression, operator, diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 0a382248c369..3009751d4715 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -929,6 +929,21 @@ export function nodeCanBeDecorated(node: TSNode): boolean { return false; } +export function isValidAssignmentTarget(node: ts.Node): boolean { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + return true; + case SyntaxKind.ParenthesizedExpression: + return isValidAssignmentTarget( + (node as ts.ParenthesizedExpression).expression, + ); + default: + return false; + } +} + export function getNamespaceModifiers( node: ts.ModuleDeclaration, ): ts.Modifier[] | undefined { From 331216ce9298514a606911c27b494fb3e69ac655 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Wed, 12 Jul 2023 14:19:38 +0800 Subject: [PATCH 2/9] Test parens --- .../fixtures/_error_/paren-expr/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 ++ .../paren-expr/snapshots/2-Babel-Error.shot | 3 + .../snapshots/3-Alignment-Error.shot | 3 + .../fixtures/valid-assignment/fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 74 +++++++++++++--- .../snapshots/2-TSESTree-Tokens.shot | 82 ++++++++++++++++-- .../snapshots/3-Babel-AST.shot | 74 +++++++++++++--- .../snapshots/4-Babel-Tokens.shot | 82 ++++++++++++++++-- .../snapshots/5-AST-Alignment-AST.shot | 74 +++++++++++++--- .../snapshots/6-AST-Alignment-Tokens.shot | 85 +++++++++++++++++-- 11 files changed, 433 insertions(+), 54 deletions(-) create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/3-Alignment-Error.shot diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/fixture.ts new file mode 100644 index 000000000000..72bf8d5de4f2 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/fixture.ts @@ -0,0 +1 @@ +(a())++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..4d702a0fa9dd --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ paren-expr TSESTree - Error 1`] = ` +"TSError +> 1 | (a())++; + | ^^^^^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..d2b3aa8b891f --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ paren-expr Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:1)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..7c9eced86151 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ paren-expr Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts index 926d49142370..adcfedc2fc9f 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts @@ -6,5 +6,6 @@ class F { this.m().a++; this[1] = 1; F++; + this.#a++; } } diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot index 370ce54396ec..453b40b66b09 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot @@ -293,12 +293,62 @@ Program { end: { column: 8, line: 8 }, }, }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + + range: [89, 96], + loc: { + start: { column: 5, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + operator: "++", + prefix: false, + + range: [88, 99], + loc: { + start: { column: 4, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + + range: [88, 100], + loc: { + start: { column: 4, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, ], - range: [23, 87], + range: [23, 104], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, declare: false, @@ -307,25 +357,25 @@ Program { id: null, params: [], - range: [20, 87], + range: [20, 104], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, - range: [19, 87], + range: [19, 104], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, ], - range: [8, 89], + range: [8, 106], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, declare: false, @@ -345,19 +395,19 @@ Program { implements: [], superClass: null, - range: [0, 89], + range: [0, 106], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, ], sourceType: "script", - range: [0, 90], + range: [0, 107], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 11 }, + end: { column: 0, line: 12 }, }, } `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot index f2d04022010c..f62b5da7a9d6 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot @@ -332,24 +332,94 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - To end: { column: 8, line: 8 }, }, }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [88, 89], + loc: { + start: { column: 4, line: 9 }, + end: { column: 5, line: 9 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [93, 94], + loc: { + start: { column: 9, line: 9 }, + end: { column: 10, line: 9 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [96, 97], + loc: { + start: { column: 12, line: 9 }, + end: { column: 13, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [97, 99], + loc: { + start: { column: 13, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [99, 100], + loc: { + start: { column: 15, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, Punctuator { type: "Punctuator", value: "}", - range: [86, 87], + range: [103, 104], loc: { - start: { column: 2, line: 9 }, - end: { column: 3, line: 9 }, + start: { column: 2, line: 10 }, + end: { column: 3, line: 10 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [88, 89], + range: [105, 106], loc: { - start: { column: 0, line: 10 }, - end: { column: 1, line: 10 }, + start: { column: 0, line: 11 }, + end: { column: 1, line: 11 }, }, }, ] diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot index d685e046b897..10c75720e072 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot @@ -275,12 +275,62 @@ Program { end: { column: 8, line: 8 }, }, }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + + range: [89, 96], + loc: { + start: { column: 5, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + operator: "++", + prefix: false, + + range: [88, 99], + loc: { + start: { column: 4, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + + range: [88, 100], + loc: { + start: { column: 4, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, ], - range: [23, 87], + range: [23, 104], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, expression: false, @@ -288,25 +338,25 @@ Program { id: null, params: [], - range: [20, 87], + range: [20, 104], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, - range: [19, 87], + range: [19, 104], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, ], - range: [8, 89], + range: [8, 106], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, id: Identifier { @@ -321,19 +371,19 @@ Program { }, superClass: null, - range: [0, 89], + range: [0, 106], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, ], sourceType: "script", - range: [0, 90], + range: [0, 107], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 11 }, + end: { column: 0, line: 12 }, }, } `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot index 41362f99e498..c4a7e2e62511 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot @@ -332,24 +332,94 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Token end: { column: 8, line: 8 }, }, }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [88, 89], + loc: { + start: { column: 4, line: 9 }, + end: { column: 5, line: 9 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [93, 94], + loc: { + start: { column: 9, line: 9 }, + end: { column: 10, line: 9 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [96, 97], + loc: { + start: { column: 12, line: 9 }, + end: { column: 13, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [97, 99], + loc: { + start: { column: 13, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [99, 100], + loc: { + start: { column: 15, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, Punctuator { type: "Punctuator", value: "}", - range: [86, 87], + range: [103, 104], loc: { - start: { column: 2, line: 9 }, - end: { column: 3, line: 9 }, + start: { column: 2, line: 10 }, + end: { column: 3, line: 10 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [88, 89], + range: [105, 106], loc: { - start: { column: 0, line: 10 }, - end: { column: 1, line: 10 }, + start: { column: 0, line: 11 }, + end: { column: 1, line: 11 }, }, }, ] diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot index 1579d88fc972..f0ab3153ee9f 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot @@ -297,12 +297,62 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment end: { column: 8, line: 8 }, }, }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + + range: [89, 96], + loc: { + start: { column: 5, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + operator: '++', + prefix: false, + + range: [88, 99], + loc: { + start: { column: 4, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + + range: [88, 100], + loc: { + start: { column: 4, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, ], - range: [23, 87], + range: [23, 104], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, - declare: false, @@ -311,25 +361,25 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment id: null, params: Array [], - range: [20, 87], + range: [20, 104], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, - range: [19, 87], + range: [19, 104], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 9 }, + end: { column: 3, line: 10 }, }, }, ], - range: [8, 89], + range: [8, 106], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, - declare: false, @@ -349,19 +399,19 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment - implements: Array [], superClass: null, - range: [0, 89], + range: [0, 106], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 10 }, + end: { column: 1, line: 11 }, }, }, ], sourceType: 'script', - range: [0, 90], + range: [0, 107], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 11 }, + end: { column: 0, line: 12 }, }, }" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot index f9d0a71e1f57..51d703a051fd 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot @@ -342,24 +342,97 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment end: { column: 8, line: 8 }, }, }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [88, 89], + loc: { + start: { column: 4, line: 9 }, + end: { column: 5, line: 9 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [89, 93], + loc: { + start: { column: 5, line: 9 }, + end: { column: 9, line: 9 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [93, 94], + loc: { + start: { column: 9, line: 9 }, + end: { column: 10, line: 9 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [94, 96], + loc: { + start: { column: 10, line: 9 }, + end: { column: 12, line: 9 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [96, 97], + loc: { + start: { column: 12, line: 9 }, + end: { column: 13, line: 9 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [97, 99], + loc: { + start: { column: 13, line: 9 }, + end: { column: 15, line: 9 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [99, 100], + loc: { + start: { column: 15, line: 9 }, + end: { column: 16, line: 9 }, + }, + }, Punctuator { type: 'Punctuator', value: '}', - range: [86, 87], + range: [103, 104], loc: { - start: { column: 2, line: 9 }, - end: { column: 3, line: 9 }, + start: { column: 2, line: 10 }, + end: { column: 3, line: 10 }, }, }, Punctuator { type: 'Punctuator', value: '}', - range: [88, 89], + range: [105, 106], loc: { - start: { column: 0, line: 10 }, - end: { column: 1, line: 10 }, + start: { column: 0, line: 11 }, + end: { column: 1, line: 11 }, }, }, ]" From 23b9921651ff9aa8b8b7bce777f93284d8fa4e4f Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Tue, 18 Jul 2023 22:07:09 +0800 Subject: [PATCH 3/9] Handle optional chain + assertion --- .../_error_/optional-chain/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 +++ .../snapshots/2-Babel-Error.shot | 3 ++ .../snapshots/3-Alignment-Error.shot | 3 ++ .../_error_/optional-chain2/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 +++ .../snapshots/2-Babel-Error.shot | 3 ++ .../snapshots/3-Alignment-Error.shot | 3 ++ .../_error_/optional-chain3/fixture.ts | 1 + .../snapshots/1-TSESTree-Error.shot | 8 +++ .../snapshots/2-Babel-Error.shot | 3 ++ .../snapshots/3-Alignment-Error.shot | 3 ++ .../snapshots/1-TSESTree-AST.shot | 38 ++++++------- .../snapshots/2-TSESTree-Tokens.shot | 54 ++++++------------- .../snapshots/3-Babel-AST.shot | 38 ++++++------- .../snapshots/4-Babel-Tokens.shot | 54 ++++++------------- .../snapshots/5-AST-Alignment-AST.shot | 38 ++++++------- .../snapshots/6-AST-Alignment-Tokens.shot | 54 ++++++------------- packages/typescript-estree/src/node-utils.ts | 7 ++- 19 files changed, 159 insertions(+), 169 deletions(-) create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/fixture.ts create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/3-Alignment-Error.shot diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/fixture.ts new file mode 100644 index 000000000000..8ca46af977de --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/fixture.ts @@ -0,0 +1 @@ +x?.y++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..8d2af8dc0fad --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain TSESTree - Error 1`] = ` +"TSError +> 1 | x?.y++; + | ^^^^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..29a072c41745 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..c885159e6f5e --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/fixture.ts new file mode 100644 index 000000000000..a0b0600d9718 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/fixture.ts @@ -0,0 +1 @@ +x?.y.z++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..6b10c2433178 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 TSESTree - Error 1`] = ` +"TSError +> 1 | x?.y.z++; + | ^^^^^^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..13d2912a340f --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..7738fc5cc034 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/fixture.ts new file mode 100644 index 000000000000..b84ecd36d994 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/fixture.ts @@ -0,0 +1 @@ +x?.y().z++; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot new file mode 100644 index 000000000000..293098986119 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 TSESTree - Error 1`] = ` +"TSError +> 1 | x?.y().z++; + | ^^^^^^^^^^ Invalid left-hand side expression in unary operation + 2 |" +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot new file mode 100644 index 000000000000..89b1d94499c9 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/3-Alignment-Error.shot new file mode 100644 index 000000000000..4583f6dbbdd2 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot index 453b40b66b09..47d0275ed45b 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot @@ -303,10 +303,10 @@ Program { object: ThisExpression { type: "ThisExpression", - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, optional: false, @@ -314,38 +314,38 @@ Program { type: "PrivateIdentifier", name: "a", - range: [94, 96], + range: [93, 95], loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, - range: [89, 96], + range: [88, 95], loc: { - start: { column: 5, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 11, line: 9 }, }, }, operator: "++", prefix: false, - range: [88, 99], + range: [88, 97], loc: { start: { column: 4, line: 9 }, - end: { column: 15, line: 9 }, + end: { column: 13, line: 9 }, }, }, - range: [88, 100], + range: [88, 98], loc: { start: { column: 4, line: 9 }, - end: { column: 16, line: 9 }, + end: { column: 14, line: 9 }, }, }, ], - range: [23, 104], + range: [23, 102], loc: { start: { column: 6, line: 4 }, end: { column: 3, line: 10 }, @@ -357,14 +357,14 @@ Program { id: null, params: [], - range: [20, 104], + range: [20, 102], loc: { start: { column: 3, line: 4 }, end: { column: 3, line: 10 }, }, }, - range: [19, 104], + range: [19, 102], loc: { start: { column: 2, line: 4 }, end: { column: 3, line: 10 }, @@ -372,7 +372,7 @@ Program { }, ], - range: [8, 106], + range: [8, 104], loc: { start: { column: 8, line: 1 }, end: { column: 1, line: 11 }, @@ -395,7 +395,7 @@ Program { implements: [], superClass: null, - range: [0, 106], + range: [0, 104], loc: { start: { column: 0, line: 1 }, end: { column: 1, line: 11 }, @@ -404,7 +404,7 @@ Program { ], sourceType: "script", - range: [0, 107], + range: [0, 105], loc: { start: { column: 0, line: 1 }, end: { column: 0, line: 12 }, diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot index f62b5da7a9d6..e43a87778a6d 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot @@ -332,81 +332,61 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - To end: { column: 8, line: 8 }, }, }, - Punctuator { - type: "Punctuator", - value: "(", - - range: [88, 89], - loc: { - start: { column: 4, line: 9 }, - end: { column: 5, line: 9 }, - }, - }, Keyword { type: "Keyword", value: "this", - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, Punctuator { type: "Punctuator", value: ".", - range: [93, 94], + range: [92, 93], loc: { - start: { column: 9, line: 9 }, - end: { column: 10, line: 9 }, + start: { column: 8, line: 9 }, + end: { column: 9, line: 9 }, }, }, Identifier { type: "Identifier", value: "#a", - range: [94, 96], - loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ")", - - range: [96, 97], + range: [93, 95], loc: { - start: { column: 12, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, Punctuator { type: "Punctuator", value: "++", - range: [97, 99], + range: [95, 97], loc: { - start: { column: 13, line: 9 }, - end: { column: 15, line: 9 }, + start: { column: 11, line: 9 }, + end: { column: 13, line: 9 }, }, }, Punctuator { type: "Punctuator", value: ";", - range: [99, 100], + range: [97, 98], loc: { - start: { column: 15, line: 9 }, - end: { column: 16, line: 9 }, + start: { column: 13, line: 9 }, + end: { column: 14, line: 9 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [103, 104], + range: [101, 102], loc: { start: { column: 2, line: 10 }, end: { column: 3, line: 10 }, @@ -416,7 +396,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - To type: "Punctuator", value: "}", - range: [105, 106], + range: [103, 104], loc: { start: { column: 0, line: 11 }, end: { column: 1, line: 11 }, diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot index 10c75720e072..7b31d7d3bf4b 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot @@ -285,10 +285,10 @@ Program { object: ThisExpression { type: "ThisExpression", - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, optional: false, @@ -296,38 +296,38 @@ Program { type: "PrivateIdentifier", name: "a", - range: [94, 96], + range: [93, 95], loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, - range: [89, 96], + range: [88, 95], loc: { - start: { column: 5, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 11, line: 9 }, }, }, operator: "++", prefix: false, - range: [88, 99], + range: [88, 97], loc: { start: { column: 4, line: 9 }, - end: { column: 15, line: 9 }, + end: { column: 13, line: 9 }, }, }, - range: [88, 100], + range: [88, 98], loc: { start: { column: 4, line: 9 }, - end: { column: 16, line: 9 }, + end: { column: 14, line: 9 }, }, }, ], - range: [23, 104], + range: [23, 102], loc: { start: { column: 6, line: 4 }, end: { column: 3, line: 10 }, @@ -338,14 +338,14 @@ Program { id: null, params: [], - range: [20, 104], + range: [20, 102], loc: { start: { column: 3, line: 4 }, end: { column: 3, line: 10 }, }, }, - range: [19, 104], + range: [19, 102], loc: { start: { column: 2, line: 4 }, end: { column: 3, line: 10 }, @@ -353,7 +353,7 @@ Program { }, ], - range: [8, 106], + range: [8, 104], loc: { start: { column: 8, line: 1 }, end: { column: 1, line: 11 }, @@ -371,7 +371,7 @@ Program { }, superClass: null, - range: [0, 106], + range: [0, 104], loc: { start: { column: 0, line: 1 }, end: { column: 1, line: 11 }, @@ -380,7 +380,7 @@ Program { ], sourceType: "script", - range: [0, 107], + range: [0, 105], loc: { start: { column: 0, line: 1 }, end: { column: 0, line: 12 }, diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot index c4a7e2e62511..2766ff67185c 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot @@ -332,81 +332,61 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Token end: { column: 8, line: 8 }, }, }, - Punctuator { - type: "Punctuator", - value: "(", - - range: [88, 89], - loc: { - start: { column: 4, line: 9 }, - end: { column: 5, line: 9 }, - }, - }, Keyword { type: "Keyword", value: "this", - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, Punctuator { type: "Punctuator", value: ".", - range: [93, 94], + range: [92, 93], loc: { - start: { column: 9, line: 9 }, - end: { column: 10, line: 9 }, + start: { column: 8, line: 9 }, + end: { column: 9, line: 9 }, }, }, PrivateIdentifier { type: "PrivateIdentifier", value: "a", - range: [94, 96], - loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ")", - - range: [96, 97], + range: [93, 95], loc: { - start: { column: 12, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, Punctuator { type: "Punctuator", value: "++", - range: [97, 99], + range: [95, 97], loc: { - start: { column: 13, line: 9 }, - end: { column: 15, line: 9 }, + start: { column: 11, line: 9 }, + end: { column: 13, line: 9 }, }, }, Punctuator { type: "Punctuator", value: ";", - range: [99, 100], + range: [97, 98], loc: { - start: { column: 15, line: 9 }, - end: { column: 16, line: 9 }, + start: { column: 13, line: 9 }, + end: { column: 14, line: 9 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [103, 104], + range: [101, 102], loc: { start: { column: 2, line: 10 }, end: { column: 3, line: 10 }, @@ -416,7 +396,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Token type: "Punctuator", value: "}", - range: [105, 106], + range: [103, 104], loc: { start: { column: 0, line: 11 }, end: { column: 1, line: 11 }, diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot index f0ab3153ee9f..b0ae16f9c6b1 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot @@ -307,10 +307,10 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment object: ThisExpression { type: 'ThisExpression', - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, optional: false, @@ -318,38 +318,38 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment type: 'PrivateIdentifier', name: 'a', - range: [94, 96], + range: [93, 95], loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, - range: [89, 96], + range: [88, 95], loc: { - start: { column: 5, line: 9 }, - end: { column: 12, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 11, line: 9 }, }, }, operator: '++', prefix: false, - range: [88, 99], + range: [88, 97], loc: { start: { column: 4, line: 9 }, - end: { column: 15, line: 9 }, + end: { column: 13, line: 9 }, }, }, - range: [88, 100], + range: [88, 98], loc: { start: { column: 4, line: 9 }, - end: { column: 16, line: 9 }, + end: { column: 14, line: 9 }, }, }, ], - range: [23, 104], + range: [23, 102], loc: { start: { column: 6, line: 4 }, end: { column: 3, line: 10 }, @@ -361,14 +361,14 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment id: null, params: Array [], - range: [20, 104], + range: [20, 102], loc: { start: { column: 3, line: 4 }, end: { column: 3, line: 10 }, }, }, - range: [19, 104], + range: [19, 102], loc: { start: { column: 2, line: 4 }, end: { column: 3, line: 10 }, @@ -376,7 +376,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment }, ], - range: [8, 106], + range: [8, 104], loc: { start: { column: 8, line: 1 }, end: { column: 1, line: 11 }, @@ -399,7 +399,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment - implements: Array [], superClass: null, - range: [0, 106], + range: [0, 104], loc: { start: { column: 0, line: 1 }, end: { column: 1, line: 11 }, @@ -408,7 +408,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment ], sourceType: 'script', - range: [0, 107], + range: [0, 105], loc: { start: { column: 0, line: 1 }, end: { column: 0, line: 12 }, diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot index 51d703a051fd..7c457a652dfd 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot @@ -342,34 +342,24 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment end: { column: 8, line: 8 }, }, }, - Punctuator { - type: 'Punctuator', - value: '(', - - range: [88, 89], - loc: { - start: { column: 4, line: 9 }, - end: { column: 5, line: 9 }, - }, - }, Keyword { type: 'Keyword', value: 'this', - range: [89, 93], + range: [88, 92], loc: { - start: { column: 5, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 4, line: 9 }, + end: { column: 8, line: 9 }, }, }, Punctuator { type: 'Punctuator', value: '.', - range: [93, 94], + range: [92, 93], loc: { - start: { column: 9, line: 9 }, - end: { column: 10, line: 9 }, + start: { column: 8, line: 9 }, + end: { column: 9, line: 9 }, }, }, - Identifier { @@ -379,47 +369,37 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment + type: 'PrivateIdentifier', + value: 'a', - range: [94, 96], - loc: { - start: { column: 10, line: 9 }, - end: { column: 12, line: 9 }, - }, - }, - Punctuator { - type: 'Punctuator', - value: ')', - - range: [96, 97], + range: [93, 95], loc: { - start: { column: 12, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 9, line: 9 }, + end: { column: 11, line: 9 }, }, }, Punctuator { type: 'Punctuator', value: '++', - range: [97, 99], + range: [95, 97], loc: { - start: { column: 13, line: 9 }, - end: { column: 15, line: 9 }, + start: { column: 11, line: 9 }, + end: { column: 13, line: 9 }, }, }, Punctuator { type: 'Punctuator', value: ';', - range: [99, 100], + range: [97, 98], loc: { - start: { column: 15, line: 9 }, - end: { column: 16, line: 9 }, + start: { column: 13, line: 9 }, + end: { column: 14, line: 9 }, }, }, Punctuator { type: 'Punctuator', value: '}', - range: [103, 104], + range: [101, 102], loc: { start: { column: 2, line: 10 }, end: { column: 3, line: 10 }, @@ -429,7 +409,7 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment type: 'Punctuator', value: '}', - range: [105, 106], + range: [103, 104], loc: { start: { column: 0, line: 11 }, end: { column: 1, line: 11 }, diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 3009751d4715..fcd8a6845029 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -932,12 +932,17 @@ export function nodeCanBeDecorated(node: TSNode): boolean { export function isValidAssignmentTarget(node: ts.Node): boolean { switch (node.kind) { case SyntaxKind.Identifier: + return true; case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: + if (node.flags & ts.NodeFlags.OptionalChain) { + return false; + } return true; case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.TypeAssertionExpression: return isValidAssignmentTarget( - (node as ts.ParenthesizedExpression).expression, + (node as ts.ParenthesizedExpression | ts.TypeAssertion).expression, ); default: return false; From 79726b80426786978e0a09096b5b2a887178bb92 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 28 Jul 2023 12:40:05 -0400 Subject: [PATCH 4/9] Update packages/typescript-estree/src/convert.ts Co-authored-by: fisker Cheung --- packages/typescript-estree/src/convert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index cf0e031d4f68..5193e0ec0536 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2023,7 +2023,7 @@ export class Converter { if (operator === '++' || operator === '--') { if (!isValidAssignmentTarget(node.operand)) { this.#throwUnlessAllowInvalidAST( - node, + node.operand, 'Invalid left-hand side expression in unary operation', ); } From a9918d364633d00338decedee30c480295733cd3 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 28 Jul 2023 12:41:47 -0400 Subject: [PATCH 5/9] Update snapshot --- .../fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot | 2 +- .../fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot | 2 +- .../_error_/optional-chain/snapshots/1-TSESTree-Error.shot | 2 +- .../_error_/optional-chain2/snapshots/1-TSESTree-Error.shot | 2 +- .../_error_/optional-chain3/snapshots/1-TSESTree-Error.shot | 2 +- .../fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot index 05532bec78b0..99d70fe0d336 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/call-expr/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ call-expr TSESTree - Error 1`] = ` "TSError > 1 | a()++; - | ^^^^^ Invalid left-hand side expression in unary operation + | ^^^ Invalid left-hand side expression in unary operation 2 |" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot index 433b834d72db..b865892e099c 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ literal TSESTree - Error 1`] = ` "TSError > 1 | 1++; - | ^^^ Invalid left-hand side expression in unary operation + | ^ Invalid left-hand side expression in unary operation 2 |" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot index 8d2af8dc0fad..11b7cfb86db7 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ optional-chain TSESTree - Error 1`] = ` "TSError > 1 | x?.y++; - | ^^^^^^ Invalid left-hand side expression in unary operation + | ^^^^ Invalid left-hand side expression in unary operation 2 |" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot index 6b10c2433178..47124ed689b4 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 TSESTree - Error 1`] = ` "TSError > 1 | x?.y.z++; - | ^^^^^^^^ Invalid left-hand side expression in unary operation + | ^^^^^^ Invalid left-hand side expression in unary operation 2 |" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot index 293098986119..3e691a5c8dd5 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 TSESTree - Error 1`] = ` "TSError > 1 | x?.y().z++; - | ^^^^^^^^^^ Invalid left-hand side expression in unary operation + | ^^^^^^^^ Invalid left-hand side expression in unary operation 2 |" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot index 4d702a0fa9dd..9e304a2beb93 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/paren-expr/snapshots/1-TSESTree-Error.shot @@ -3,6 +3,6 @@ exports[`AST Fixtures expression UpdateExpression _error_ paren-expr TSESTree - Error 1`] = ` "TSError > 1 | (a())++; - | ^^^^^^^ Invalid left-hand side expression in unary operation + | ^^^^^ Invalid left-hand side expression in unary operation 2 |" `; From 548a792bc5034478f13bf4952710dee665b4ad64 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 23 Nov 2023 14:04:25 -0500 Subject: [PATCH 6/9] Add test cases, add satisfies & as --- .../fixtures/valid-assignment/fixture.ts | 6 +- .../snapshots/1-Babel-AST.shot | 525 +++++++++++++++ .../snapshots/1-TSESTree-AST.shot | 258 +++++++- .../snapshots/2-Babel-Tokens.shot | 606 ++++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 342 +++++++++- .../snapshots/3-Babel-AST.shot | 258 +++++++- .../snapshots/4-Babel-Tokens.shot | 342 +++++++++- .../snapshots/5-AST-Alignment-AST.shot | 258 +++++++- .../snapshots/6-AST-Alignment-Tokens.shot | 351 +++++++++- .../tests/fixtures-with-differences-ast.shot | 1 - .../fixtures-with-differences-tokens.shot | 1 - packages/typescript-estree/src/node-utils.ts | 9 +- 12 files changed, 2809 insertions(+), 148 deletions(-) create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-Babel-AST.shot create mode 100644 packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-Babel-Tokens.shot diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts index adcfedc2fc9f..d9cd1cd35dd7 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts @@ -6,6 +6,10 @@ class F { this.m().a++; this[1] = 1; F++; - this.#a++; + // prettier-ignore + (this.#a)++; + (this.#a)++; + (this.#a satisfies number)++; + (this.#a as number)++; } } diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-Babel-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-Babel-AST.shot new file mode 100644 index 000000000000..5d282e70bed8 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-Babel-AST.shot @@ -0,0 +1,525 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - AST 1`] = ` +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + body: ClassBody { + type: "ClassBody", + body: [ + PropertyDefinition { + type: "PropertyDefinition", + computed: false, + key: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + static: false, + value: null, + + range: [12, 15], + loc: { + start: { column: 2, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + MethodDefinition { + type: "MethodDefinition", + computed: false, + key: Identifier { + type: "Identifier", + name: "m", + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + kind: "method", + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [ + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + + range: [29, 36], + loc: { + start: { column: 4, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + operator: "++", + prefix: false, + + range: [29, 38], + loc: { + start: { column: 4, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + + range: [29, 39], + loc: { + start: { column: 4, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: CallExpression { + type: "CallExpression", + arguments: [], + callee: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + name: "m", + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + + range: [44, 50], + loc: { + start: { column: 4, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + optional: false, + + range: [44, 52], + loc: { + start: { column: 4, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + optional: false, + property: Identifier { + type: "Identifier", + name: "a", + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + + range: [44, 54], + loc: { + start: { column: 4, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + operator: "++", + prefix: false, + + range: [44, 56], + loc: { + start: { column: 4, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + + range: [44, 57], + loc: { + start: { column: 4, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: AssignmentExpression { + type: "AssignmentExpression", + left: MemberExpression { + type: "MemberExpression", + computed: true, + object: ThisExpression { + type: "ThisExpression", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + optional: false, + property: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + + range: [62, 69], + loc: { + start: { column: 4, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + operator: "=", + right: Literal { + type: "Literal", + raw: "1", + value: 1, + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 73], + loc: { + start: { column: 4, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + + range: [62, 74], + loc: { + start: { column: 4, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: Identifier { + type: "Identifier", + name: "F", + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + operator: "++", + prefix: false, + + range: [79, 82], + loc: { + start: { column: 4, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + + range: [79, 83], + loc: { + start: { column: 4, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [112, 116], + loc: { + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [117, 119], + loc: { + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + + range: [112, 119], + loc: { + start: { column: 5, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + operator: "++", + prefix: false, + + range: [111, 122], + loc: { + start: { column: 4, line: 10 }, + end: { column: 15, line: 10 }, + }, + }, + + range: [111, 123], + loc: { + start: { column: 4, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSSatisfiesExpression { + type: "TSSatisfiesExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [129, 133], + loc: { + start: { column: 5, line: 11 }, + end: { column: 9, line: 11 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [134, 136], + loc: { + start: { column: 10, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + + range: [129, 136], + loc: { + start: { column: 5, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [147, 153], + loc: { + start: { column: 23, line: 11 }, + end: { column: 29, line: 11 }, + }, + }, + + range: [129, 153], + loc: { + start: { column: 5, line: 11 }, + end: { column: 29, line: 11 }, + }, + }, + operator: "++", + prefix: false, + + range: [128, 156], + loc: { + start: { column: 4, line: 11 }, + end: { column: 32, line: 11 }, + }, + }, + + range: [128, 157], + loc: { + start: { column: 4, line: 11 }, + end: { column: 33, line: 11 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSAsExpression { + type: "TSAsExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [163, 167], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [168, 170], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + + range: [163, 170], + loc: { + start: { column: 5, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [174, 180], + loc: { + start: { column: 16, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + + range: [163, 180], + loc: { + start: { column: 5, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + operator: "++", + prefix: false, + + range: [162, 183], + loc: { + start: { column: 4, line: 12 }, + end: { column: 25, line: 12 }, + }, + }, + + range: [162, 184], + loc: { + start: { column: 4, line: 12 }, + end: { column: 26, line: 12 }, + }, + }, + ], + + range: [23, 188], + loc: { + start: { column: 6, line: 4 }, + end: { column: 3, line: 13 }, + }, + }, + expression: false, + generator: false, + id: null, + params: [], + + range: [20, 188], + loc: { + start: { column: 3, line: 4 }, + end: { column: 3, line: 13 }, + }, + }, + + range: [19, 188], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 13 }, + }, + }, + ], + + range: [8, 190], + loc: { + start: { column: 8, line: 1 }, + end: { column: 1, line: 14 }, + }, + }, + id: Identifier { + type: "Identifier", + name: "F", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + superClass: null, + + range: [0, 190], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 14 }, + }, + }, + ], + sourceType: "script", + + range: [0, 191], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 15 }, + }, +} +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot index 47d0275ed45b..73ab33da2857 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/1-TSESTree-AST.shot @@ -303,10 +303,10 @@ Program { object: ThisExpression { type: "ThisExpression", - range: [88, 92], + range: [112, 116], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, }, }, optional: false, @@ -314,41 +314,245 @@ Program { type: "PrivateIdentifier", name: "a", - range: [93, 95], + range: [117, 119], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, }, }, - range: [88, 95], + range: [112, 119], loc: { - start: { column: 4, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 12, line: 10 }, }, }, operator: "++", prefix: false, - range: [88, 97], + range: [111, 122], loc: { - start: { column: 4, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 15, line: 10 }, }, }, - range: [88, 98], + range: [111, 123], loc: { - start: { column: 4, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSTypeAssertion { + type: "TSTypeAssertion", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [137, 141], + loc: { + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + + range: [137, 144], + loc: { + start: { column: 13, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + + range: [129, 144], + loc: { + start: { column: 5, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + operator: "++", + prefix: false, + + range: [128, 147], + loc: { + start: { column: 4, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + + range: [128, 148], + loc: { + start: { column: 4, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSSatisfiesExpression { + type: "TSSatisfiesExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + + range: [154, 161], + loc: { + start: { column: 5, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + + range: [154, 178], + loc: { + start: { column: 5, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + operator: "++", + prefix: false, + + range: [153, 181], + loc: { + start: { column: 4, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + + range: [153, 182], + loc: { + start: { column: 4, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSAsExpression { + type: "TSAsExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [188, 192], + loc: { + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + + range: [188, 195], + loc: { + start: { column: 5, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + + range: [188, 205], + loc: { + start: { column: 5, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + operator: "++", + prefix: false, + + range: [187, 208], + loc: { + start: { column: 4, line: 13 }, + end: { column: 25, line: 13 }, + }, + }, + + range: [187, 209], + loc: { + start: { column: 4, line: 13 }, + end: { column: 26, line: 13 }, }, }, ], - range: [23, 102], + range: [23, 213], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, declare: false, @@ -357,25 +561,25 @@ Program { id: null, params: [], - range: [20, 102], + range: [20, 213], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, - range: [19, 102], + range: [19, 213], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, ], - range: [8, 104], + range: [8, 215], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, declare: false, @@ -395,19 +599,19 @@ Program { implements: [], superClass: null, - range: [0, 104], + range: [0, 215], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, ], sourceType: "script", - range: [0, 105], + range: [0, 216], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 12 }, + end: { column: 0, line: 16 }, }, } `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-Babel-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-Babel-Tokens.shot new file mode 100644 index 000000000000..3431ef68783e --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-Babel-Tokens.shot @@ -0,0 +1,606 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Tokens 1`] = ` +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [6, 7], + loc: { + start: { column: 6, line: 1 }, + end: { column: 7, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [8, 9], + loc: { + start: { column: 8, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [12, 14], + loc: { + start: { column: 2, line: 2 }, + end: { column: 4, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [14, 15], + loc: { + start: { column: 4, line: 2 }, + end: { column: 5, line: 2 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [19, 20], + loc: { + start: { column: 2, line: 4 }, + end: { column: 3, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [20, 21], + loc: { + start: { column: 3, line: 4 }, + end: { column: 4, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [21, 22], + loc: { + start: { column: 4, line: 4 }, + end: { column: 5, line: 4 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [23, 24], + loc: { + start: { column: 6, line: 4 }, + end: { column: 7, line: 4 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [29, 33], + loc: { + start: { column: 4, line: 5 }, + end: { column: 8, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [33, 34], + loc: { + start: { column: 8, line: 5 }, + end: { column: 9, line: 5 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [34, 36], + loc: { + start: { column: 9, line: 5 }, + end: { column: 11, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [36, 38], + loc: { + start: { column: 11, line: 5 }, + end: { column: 13, line: 5 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [38, 39], + loc: { + start: { column: 13, line: 5 }, + end: { column: 14, line: 5 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [44, 48], + loc: { + start: { column: 4, line: 6 }, + end: { column: 8, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [48, 49], + loc: { + start: { column: 8, line: 6 }, + end: { column: 9, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "m", + + range: [49, 50], + loc: { + start: { column: 9, line: 6 }, + end: { column: 10, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [50, 51], + loc: { + start: { column: 10, line: 6 }, + end: { column: 11, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [51, 52], + loc: { + start: { column: 11, line: 6 }, + end: { column: 12, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [52, 53], + loc: { + start: { column: 12, line: 6 }, + end: { column: 13, line: 6 }, + }, + }, + Identifier { + type: "Identifier", + value: "a", + + range: [53, 54], + loc: { + start: { column: 13, line: 6 }, + end: { column: 14, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [54, 56], + loc: { + start: { column: 14, line: 6 }, + end: { column: 16, line: 6 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [56, 57], + loc: { + start: { column: 16, line: 6 }, + end: { column: 17, line: 6 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [62, 66], + loc: { + start: { column: 4, line: 7 }, + end: { column: 8, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "[", + + range: [66, 67], + loc: { + start: { column: 8, line: 7 }, + end: { column: 9, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [67, 68], + loc: { + start: { column: 9, line: 7 }, + end: { column: 10, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "]", + + range: [68, 69], + loc: { + start: { column: 10, line: 7 }, + end: { column: 11, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [70, 71], + loc: { + start: { column: 12, line: 7 }, + end: { column: 13, line: 7 }, + }, + }, + Numeric { + type: "Numeric", + value: "1", + + range: [72, 73], + loc: { + start: { column: 14, line: 7 }, + end: { column: 15, line: 7 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [73, 74], + loc: { + start: { column: 15, line: 7 }, + end: { column: 16, line: 7 }, + }, + }, + Identifier { + type: "Identifier", + value: "F", + + range: [79, 80], + loc: { + start: { column: 4, line: 8 }, + end: { column: 5, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [80, 82], + loc: { + start: { column: 5, line: 8 }, + end: { column: 7, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [82, 83], + loc: { + start: { column: 7, line: 8 }, + end: { column: 8, line: 8 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [111, 112], + loc: { + start: { column: 4, line: 10 }, + end: { column: 5, line: 10 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [112, 116], + loc: { + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [116, 117], + loc: { + start: { column: 9, line: 10 }, + end: { column: 10, line: 10 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [117, 119], + loc: { + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [119, 120], + loc: { + start: { column: 12, line: 10 }, + end: { column: 13, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [120, 122], + loc: { + start: { column: 13, line: 10 }, + end: { column: 15, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [122, 123], + loc: { + start: { column: 15, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [128, 129], + loc: { + start: { column: 4, line: 11 }, + end: { column: 5, line: 11 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [129, 133], + loc: { + start: { column: 5, line: 11 }, + end: { column: 9, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [133, 134], + loc: { + start: { column: 9, line: 11 }, + end: { column: 10, line: 11 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [134, 136], + loc: { + start: { column: 10, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + Identifier { + type: "Identifier", + value: "satisfies", + + range: [137, 146], + loc: { + start: { column: 13, line: 11 }, + end: { column: 22, line: 11 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [147, 153], + loc: { + start: { column: 23, line: 11 }, + end: { column: 29, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [153, 154], + loc: { + start: { column: 29, line: 11 }, + end: { column: 30, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [154, 156], + loc: { + start: { column: 30, line: 11 }, + end: { column: 32, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [156, 157], + loc: { + start: { column: 32, line: 11 }, + end: { column: 33, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [162, 163], + loc: { + start: { column: 4, line: 12 }, + end: { column: 5, line: 12 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [163, 167], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [167, 168], + loc: { + start: { column: 9, line: 12 }, + end: { column: 10, line: 12 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [168, 170], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "as", + + range: [171, 173], + loc: { + start: { column: 13, line: 12 }, + end: { column: 15, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [174, 180], + loc: { + start: { column: 16, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [180, 181], + loc: { + start: { column: 22, line: 12 }, + end: { column: 23, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [181, 183], + loc: { + start: { column: 23, line: 12 }, + end: { column: 25, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [183, 184], + loc: { + start: { column: 25, line: 12 }, + end: { column: 26, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [187, 188], + loc: { + start: { column: 2, line: 13 }, + end: { column: 3, line: 13 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [189, 190], + loc: { + start: { column: 0, line: 14 }, + end: { column: 1, line: 14 }, + }, + }, +] +`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot index e43a87778a6d..88344ebebfee 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/2-TSESTree-Tokens.shot @@ -332,74 +332,374 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment TSESTree - To end: { column: 8, line: 8 }, }, }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [111, 112], + loc: { + start: { column: 4, line: 10 }, + end: { column: 5, line: 10 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [112, 116], + loc: { + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [116, 117], + loc: { + start: { column: 9, line: 10 }, + end: { column: 10, line: 10 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [117, 119], + loc: { + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [119, 120], + loc: { + start: { column: 12, line: 10 }, + end: { column: 13, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [120, 122], + loc: { + start: { column: 13, line: 10 }, + end: { column: 15, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [122, 123], + loc: { + start: { column: 15, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [128, 129], + loc: { + start: { column: 4, line: 11 }, + end: { column: 5, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "<", + + range: [129, 130], + loc: { + start: { column: 5, line: 11 }, + end: { column: 6, line: 11 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ">", + + range: [136, 137], + loc: { + start: { column: 12, line: 11 }, + end: { column: 13, line: 11 }, + }, + }, Keyword { type: "Keyword", value: "this", - range: [88, 92], + range: [137, 141], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, }, }, Punctuator { type: "Punctuator", value: ".", - range: [92, 93], + range: [141, 142], loc: { - start: { column: 8, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 17, line: 11 }, + end: { column: 18, line: 11 }, }, }, Identifier { type: "Identifier", value: "#a", - range: [93, 95], + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [144, 145], + loc: { + start: { column: 20, line: 11 }, + end: { column: 21, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [145, 147], + loc: { + start: { column: 21, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [147, 148], + loc: { + start: { column: 23, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [153, 154], + loc: { + start: { column: 4, line: 12 }, + end: { column: 5, line: 12 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [158, 159], + loc: { + start: { column: 9, line: 12 }, + end: { column: 10, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "satisfies", + + range: [162, 171], + loc: { + start: { column: 13, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [178, 179], + loc: { + start: { column: 29, line: 12 }, + end: { column: 30, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [179, 181], + loc: { + start: { column: 30, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [181, 182], + loc: { + start: { column: 32, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [187, 188], + loc: { + start: { column: 4, line: 13 }, + end: { column: 5, line: 13 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [188, 192], + loc: { + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [192, 193], + loc: { + start: { column: 9, line: 13 }, + end: { column: 10, line: 13 }, + }, + }, + Identifier { + type: "Identifier", + value: "#a", + + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + Identifier { + type: "Identifier", + value: "as", + + range: [196, 198], + loc: { + start: { column: 13, line: 13 }, + end: { column: 15, line: 13 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [205, 206], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 22, line: 13 }, + end: { column: 23, line: 13 }, }, }, Punctuator { type: "Punctuator", value: "++", - range: [95, 97], + range: [206, 208], loc: { - start: { column: 11, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 23, line: 13 }, + end: { column: 25, line: 13 }, }, }, Punctuator { type: "Punctuator", value: ";", - range: [97, 98], + range: [208, 209], loc: { - start: { column: 13, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 25, line: 13 }, + end: { column: 26, line: 13 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [101, 102], + range: [212, 213], loc: { - start: { column: 2, line: 10 }, - end: { column: 3, line: 10 }, + start: { column: 2, line: 14 }, + end: { column: 3, line: 14 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [103, 104], + range: [214, 215], loc: { - start: { column: 0, line: 11 }, - end: { column: 1, line: 11 }, + start: { column: 0, line: 15 }, + end: { column: 1, line: 15 }, }, }, ] diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot index 7b31d7d3bf4b..3bb1e5bb04e8 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/3-Babel-AST.shot @@ -285,10 +285,10 @@ Program { object: ThisExpression { type: "ThisExpression", - range: [88, 92], + range: [112, 116], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, }, }, optional: false, @@ -296,41 +296,245 @@ Program { type: "PrivateIdentifier", name: "a", - range: [93, 95], + range: [117, 119], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, }, }, - range: [88, 95], + range: [112, 119], loc: { - start: { column: 4, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 12, line: 10 }, }, }, operator: "++", prefix: false, - range: [88, 97], + range: [111, 122], loc: { - start: { column: 4, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 15, line: 10 }, }, }, - range: [88, 98], + range: [111, 123], loc: { - start: { column: 4, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSTypeAssertion { + type: "TSTypeAssertion", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [137, 141], + loc: { + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + + range: [137, 144], + loc: { + start: { column: 13, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + + range: [129, 144], + loc: { + start: { column: 5, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + operator: "++", + prefix: false, + + range: [128, 147], + loc: { + start: { column: 4, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + + range: [128, 148], + loc: { + start: { column: 4, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSSatisfiesExpression { + type: "TSSatisfiesExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + + range: [154, 161], + loc: { + start: { column: 5, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + + range: [154, 178], + loc: { + start: { column: 5, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + operator: "++", + prefix: false, + + range: [153, 181], + loc: { + start: { column: 4, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + + range: [153, 182], + loc: { + start: { column: 4, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + ExpressionStatement { + type: "ExpressionStatement", + expression: UpdateExpression { + type: "UpdateExpression", + argument: TSAsExpression { + type: "TSAsExpression", + expression: MemberExpression { + type: "MemberExpression", + computed: false, + object: ThisExpression { + type: "ThisExpression", + + range: [188, 192], + loc: { + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: "PrivateIdentifier", + name: "a", + + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + + range: [188, 195], + loc: { + start: { column: 5, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: "TSNumberKeyword", + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + + range: [188, 205], + loc: { + start: { column: 5, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + operator: "++", + prefix: false, + + range: [187, 208], + loc: { + start: { column: 4, line: 13 }, + end: { column: 25, line: 13 }, + }, + }, + + range: [187, 209], + loc: { + start: { column: 4, line: 13 }, + end: { column: 26, line: 13 }, }, }, ], - range: [23, 102], + range: [23, 213], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, expression: false, @@ -338,25 +542,25 @@ Program { id: null, params: [], - range: [20, 102], + range: [20, 213], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, - range: [19, 102], + range: [19, 213], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, ], - range: [8, 104], + range: [8, 215], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, id: Identifier { @@ -371,19 +575,19 @@ Program { }, superClass: null, - range: [0, 104], + range: [0, 215], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, ], sourceType: "script", - range: [0, 105], + range: [0, 216], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 12 }, + end: { column: 0, line: 16 }, }, } `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot index 2766ff67185c..6ac417a13b3f 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/4-Babel-Tokens.shot @@ -332,74 +332,374 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment Babel - Token end: { column: 8, line: 8 }, }, }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [111, 112], + loc: { + start: { column: 4, line: 10 }, + end: { column: 5, line: 10 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [112, 116], + loc: { + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [116, 117], + loc: { + start: { column: 9, line: 10 }, + end: { column: 10, line: 10 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [117, 119], + loc: { + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [119, 120], + loc: { + start: { column: 12, line: 10 }, + end: { column: 13, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [120, 122], + loc: { + start: { column: 13, line: 10 }, + end: { column: 15, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [122, 123], + loc: { + start: { column: 15, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [128, 129], + loc: { + start: { column: 4, line: 11 }, + end: { column: 5, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "<", + + range: [129, 130], + loc: { + start: { column: 5, line: 11 }, + end: { column: 6, line: 11 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ">", + + range: [136, 137], + loc: { + start: { column: 12, line: 11 }, + end: { column: 13, line: 11 }, + }, + }, Keyword { type: "Keyword", value: "this", - range: [88, 92], + range: [137, 141], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, }, }, Punctuator { type: "Punctuator", value: ".", - range: [92, 93], + range: [141, 142], loc: { - start: { column: 8, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 17, line: 11 }, + end: { column: 18, line: 11 }, }, }, PrivateIdentifier { type: "PrivateIdentifier", value: "a", - range: [93, 95], + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [144, 145], + loc: { + start: { column: 20, line: 11 }, + end: { column: 21, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [145, 147], + loc: { + start: { column: 21, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [147, 148], + loc: { + start: { column: 23, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [153, 154], + loc: { + start: { column: 4, line: 12 }, + end: { column: 5, line: 12 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [158, 159], + loc: { + start: { column: 9, line: 12 }, + end: { column: 10, line: 12 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "satisfies", + + range: [162, 171], + loc: { + start: { column: 13, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [178, 179], + loc: { + start: { column: 29, line: 12 }, + end: { column: 30, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "++", + + range: [179, 181], + loc: { + start: { column: 30, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [181, 182], + loc: { + start: { column: 32, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [187, 188], + loc: { + start: { column: 4, line: 13 }, + end: { column: 5, line: 13 }, + }, + }, + Keyword { + type: "Keyword", + value: "this", + + range: [188, 192], + loc: { + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ".", + + range: [192, 193], + loc: { + start: { column: 9, line: 13 }, + end: { column: 10, line: 13 }, + }, + }, + PrivateIdentifier { + type: "PrivateIdentifier", + value: "a", + + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + Identifier { + type: "Identifier", + value: "as", + + range: [196, 198], + loc: { + start: { column: 13, line: 13 }, + end: { column: 15, line: 13 }, + }, + }, + Identifier { + type: "Identifier", + value: "number", + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [205, 206], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 22, line: 13 }, + end: { column: 23, line: 13 }, }, }, Punctuator { type: "Punctuator", value: "++", - range: [95, 97], + range: [206, 208], loc: { - start: { column: 11, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 23, line: 13 }, + end: { column: 25, line: 13 }, }, }, Punctuator { type: "Punctuator", value: ";", - range: [97, 98], + range: [208, 209], loc: { - start: { column: 13, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 25, line: 13 }, + end: { column: 26, line: 13 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [101, 102], + range: [212, 213], loc: { - start: { column: 2, line: 10 }, - end: { column: 3, line: 10 }, + start: { column: 2, line: 14 }, + end: { column: 3, line: 14 }, }, }, Punctuator { type: "Punctuator", value: "}", - range: [103, 104], + range: [214, 215], loc: { - start: { column: 0, line: 11 }, - end: { column: 1, line: 11 }, + start: { column: 0, line: 15 }, + end: { column: 1, line: 15 }, }, }, ] diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot index b0ae16f9c6b1..ad036e5f596c 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/5-AST-Alignment-AST.shot @@ -307,10 +307,10 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment object: ThisExpression { type: 'ThisExpression', - range: [88, 92], + range: [112, 116], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, }, }, optional: false, @@ -318,41 +318,245 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment type: 'PrivateIdentifier', name: 'a', - range: [93, 95], + range: [117, 119], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, }, }, - range: [88, 95], + range: [112, 119], loc: { - start: { column: 4, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 5, line: 10 }, + end: { column: 12, line: 10 }, }, }, operator: '++', prefix: false, - range: [88, 97], + range: [111, 122], loc: { - start: { column: 4, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 15, line: 10 }, }, }, - range: [88, 98], + range: [111, 123], loc: { - start: { column: 4, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 4, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: TSTypeAssertion { + type: 'TSTypeAssertion', + expression: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [137, 141], + loc: { + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + + range: [137, 144], + loc: { + start: { column: 13, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + + range: [129, 144], + loc: { + start: { column: 5, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + operator: '++', + prefix: false, + + range: [128, 147], + loc: { + start: { column: 4, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + + range: [128, 148], + loc: { + start: { column: 4, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: TSSatisfiesExpression { + type: 'TSSatisfiesExpression', + expression: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + + range: [154, 161], + loc: { + start: { column: 5, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + + range: [154, 178], + loc: { + start: { column: 5, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + operator: '++', + prefix: false, + + range: [153, 181], + loc: { + start: { column: 4, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + + range: [153, 182], + loc: { + start: { column: 4, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + ExpressionStatement { + type: 'ExpressionStatement', + expression: UpdateExpression { + type: 'UpdateExpression', + argument: TSAsExpression { + type: 'TSAsExpression', + expression: MemberExpression { + type: 'MemberExpression', + computed: false, + object: ThisExpression { + type: 'ThisExpression', + + range: [188, 192], + loc: { + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, + }, + }, + optional: false, + property: PrivateIdentifier { + type: 'PrivateIdentifier', + name: 'a', + + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + + range: [188, 195], + loc: { + start: { column: 5, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + typeAnnotation: TSNumberKeyword { + type: 'TSNumberKeyword', + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + + range: [188, 205], + loc: { + start: { column: 5, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + operator: '++', + prefix: false, + + range: [187, 208], + loc: { + start: { column: 4, line: 13 }, + end: { column: 25, line: 13 }, + }, + }, + + range: [187, 209], + loc: { + start: { column: 4, line: 13 }, + end: { column: 26, line: 13 }, }, }, ], - range: [23, 102], + range: [23, 213], loc: { start: { column: 6, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, - declare: false, @@ -361,25 +565,25 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment id: null, params: Array [], - range: [20, 102], + range: [20, 213], loc: { start: { column: 3, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, - range: [19, 102], + range: [19, 213], loc: { start: { column: 2, line: 4 }, - end: { column: 3, line: 10 }, + end: { column: 3, line: 14 }, }, }, ], - range: [8, 104], + range: [8, 215], loc: { start: { column: 8, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, - declare: false, @@ -399,19 +603,19 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment - implements: Array [], superClass: null, - range: [0, 104], + range: [0, 215], loc: { start: { column: 0, line: 1 }, - end: { column: 1, line: 11 }, + end: { column: 1, line: 15 }, }, }, ], sourceType: 'script', - range: [0, 105], + range: [0, 216], loc: { start: { column: 0, line: 1 }, - end: { column: 0, line: 12 }, + end: { column: 0, line: 16 }, }, }" `; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot index 7c457a652dfd..32f3ae8d058a 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/snapshots/6-AST-Alignment-Tokens.shot @@ -342,24 +342,303 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment end: { column: 8, line: 8 }, }, }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [111, 112], + loc: { + start: { column: 4, line: 10 }, + end: { column: 5, line: 10 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [112, 116], + loc: { + start: { column: 5, line: 10 }, + end: { column: 9, line: 10 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [116, 117], + loc: { + start: { column: 9, line: 10 }, + end: { column: 10, line: 10 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [117, 119], + loc: { + start: { column: 10, line: 10 }, + end: { column: 12, line: 10 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [119, 120], + loc: { + start: { column: 12, line: 10 }, + end: { column: 13, line: 10 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [120, 122], + loc: { + start: { column: 13, line: 10 }, + end: { column: 15, line: 10 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [122, 123], + loc: { + start: { column: 15, line: 10 }, + end: { column: 16, line: 10 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [128, 129], + loc: { + start: { column: 4, line: 11 }, + end: { column: 5, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '<', + + range: [129, 130], + loc: { + start: { column: 5, line: 11 }, + end: { column: 6, line: 11 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'number', + + range: [130, 136], + loc: { + start: { column: 6, line: 11 }, + end: { column: 12, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '>', + + range: [136, 137], + loc: { + start: { column: 12, line: 11 }, + end: { column: 13, line: 11 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [137, 141], + loc: { + start: { column: 13, line: 11 }, + end: { column: 17, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [141, 142], + loc: { + start: { column: 17, line: 11 }, + end: { column: 18, line: 11 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [142, 144], + loc: { + start: { column: 18, line: 11 }, + end: { column: 20, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [144, 145], + loc: { + start: { column: 20, line: 11 }, + end: { column: 21, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [145, 147], + loc: { + start: { column: 21, line: 11 }, + end: { column: 23, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [147, 148], + loc: { + start: { column: 23, line: 11 }, + end: { column: 24, line: 11 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [153, 154], + loc: { + start: { column: 4, line: 12 }, + end: { column: 5, line: 12 }, + }, + }, + Keyword { + type: 'Keyword', + value: 'this', + + range: [154, 158], + loc: { + start: { column: 5, line: 12 }, + end: { column: 9, line: 12 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '.', + + range: [158, 159], + loc: { + start: { column: 9, line: 12 }, + end: { column: 10, line: 12 }, + }, + }, +- Identifier { +- type: 'Identifier', +- value: '#a', ++ PrivateIdentifier { ++ type: 'PrivateIdentifier', ++ value: 'a', + + range: [159, 161], + loc: { + start: { column: 10, line: 12 }, + end: { column: 12, line: 12 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'satisfies', + + range: [162, 171], + loc: { + start: { column: 13, line: 12 }, + end: { column: 22, line: 12 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'number', + + range: [172, 178], + loc: { + start: { column: 23, line: 12 }, + end: { column: 29, line: 12 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [178, 179], + loc: { + start: { column: 29, line: 12 }, + end: { column: 30, line: 12 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '++', + + range: [179, 181], + loc: { + start: { column: 30, line: 12 }, + end: { column: 32, line: 12 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ';', + + range: [181, 182], + loc: { + start: { column: 32, line: 12 }, + end: { column: 33, line: 12 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: '(', + + range: [187, 188], + loc: { + start: { column: 4, line: 13 }, + end: { column: 5, line: 13 }, + }, + }, Keyword { type: 'Keyword', value: 'this', - range: [88, 92], + range: [188, 192], loc: { - start: { column: 4, line: 9 }, - end: { column: 8, line: 9 }, + start: { column: 5, line: 13 }, + end: { column: 9, line: 13 }, }, }, Punctuator { type: 'Punctuator', value: '.', - range: [92, 93], + range: [192, 193], loc: { - start: { column: 8, line: 9 }, - end: { column: 9, line: 9 }, + start: { column: 9, line: 13 }, + end: { column: 10, line: 13 }, }, }, - Identifier { @@ -369,50 +648,80 @@ exports[`AST Fixtures expression UpdateExpression valid-assignment AST Alignment + type: 'PrivateIdentifier', + value: 'a', - range: [93, 95], + range: [193, 195], + loc: { + start: { column: 10, line: 13 }, + end: { column: 12, line: 13 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'as', + + range: [196, 198], + loc: { + start: { column: 13, line: 13 }, + end: { column: 15, line: 13 }, + }, + }, + Identifier { + type: 'Identifier', + value: 'number', + + range: [199, 205], + loc: { + start: { column: 16, line: 13 }, + end: { column: 22, line: 13 }, + }, + }, + Punctuator { + type: 'Punctuator', + value: ')', + + range: [205, 206], loc: { - start: { column: 9, line: 9 }, - end: { column: 11, line: 9 }, + start: { column: 22, line: 13 }, + end: { column: 23, line: 13 }, }, }, Punctuator { type: 'Punctuator', value: '++', - range: [95, 97], + range: [206, 208], loc: { - start: { column: 11, line: 9 }, - end: { column: 13, line: 9 }, + start: { column: 23, line: 13 }, + end: { column: 25, line: 13 }, }, }, Punctuator { type: 'Punctuator', value: ';', - range: [97, 98], + range: [208, 209], loc: { - start: { column: 13, line: 9 }, - end: { column: 14, line: 9 }, + start: { column: 25, line: 13 }, + end: { column: 26, line: 13 }, }, }, Punctuator { type: 'Punctuator', value: '}', - range: [101, 102], + range: [212, 213], loc: { - start: { column: 2, line: 10 }, - end: { column: 3, line: 10 }, + start: { column: 2, line: 14 }, + end: { column: 3, line: 14 }, }, }, Punctuator { type: 'Punctuator', value: '}', - range: [103, 104], + range: [214, 215], loc: { - start: { column: 0, line: 11 }, - end: { column: 1, line: 11 }, + start: { column: 0, line: 15 }, + end: { column: 1, line: 15 }, }, }, ]" diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index 409216445120..a41c223827df 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -143,7 +143,6 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "expression/TSSatisfiesExpression/fixtures/logical-with-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-inner-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-outer-parentheses/fixture.ts", - "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/accessor-decorators/fixtures/accessor-decorator-factory-instance-member/fixture.ts", diff --git a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot index 43ef25b5170b..b15734b809f0 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot @@ -26,7 +26,6 @@ exports[`AST Fixtures List fixtures with Token differences 1`] = ` "element/AccessorProperty/fixtures/modifier-private/fixture.ts", "element/AccessorProperty/fixtures/modifier-protected/fixture.ts", "element/AccessorProperty/fixtures/modifier-public/fixture.ts", - "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/basics/fixtures/abstract-class-with-abstract-readonly-property/fixture.ts", diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index fcd8a6845029..f8c76d1c6983 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -941,8 +941,15 @@ export function isValidAssignmentTarget(node: ts.Node): boolean { return true; case SyntaxKind.ParenthesizedExpression: case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.SatisfiesExpression: return isValidAssignmentTarget( - (node as ts.ParenthesizedExpression | ts.TypeAssertion).expression, + ( + node as + | ts.ParenthesizedExpression + | ts.AssertionExpression + | ts.SatisfiesExpression + ).expression, ); default: return false; From 97b9d04fc2a685bd2af5e6cafb314301366835f0 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 7 Dec 2023 20:16:34 -0500 Subject: [PATCH 7/9] Fix fixtures? --- .../snapshots/3-Babel-AST.shot | 79 ------------------- .../snapshots/5-AST-Alignment-AST.shot | 79 ------------------- .../tests/fixtures-with-differences-ast.shot | 1 + .../fixtures-with-differences-tokens.shot | 1 + 4 files changed, 2 insertions(+), 158 deletions(-) diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot index 422530628713..fec2f6e4759d 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot @@ -87,85 +87,6 @@ Program { end: { column: 42, line: 3 }, }, }, - options: ObjectExpression { - type: "ObjectExpression", - properties: [ - Property { - type: "Property", - computed: false, - key: Identifier { - type: "Identifier", - name: "assert", - - range: [89, 95], - loc: { - start: { column: 16, line: 3 }, - end: { column: 22, line: 3 }, - }, - }, - kind: "init", - method: false, - shorthand: false, - value: ObjectExpression { - type: "ObjectExpression", - properties: [ - Property { - type: "Property", - computed: false, - key: Identifier { - type: "Identifier", - name: "type", - - range: [99, 103], - loc: { - start: { column: 26, line: 3 }, - end: { column: 30, line: 3 }, - }, - }, - kind: "init", - method: false, - shorthand: false, - value: Literal { - type: "Literal", - raw: "'json'", - value: "json", - - range: [105, 111], - loc: { - start: { column: 32, line: 3 }, - end: { column: 38, line: 3 }, - }, - }, - - range: [99, 111], - loc: { - start: { column: 26, line: 3 }, - end: { column: 38, line: 3 }, - }, - }, - ], - - range: [97, 113], - loc: { - start: { column: 24, line: 3 }, - end: { column: 40, line: 3 }, - }, - }, - - range: [89, 113], - loc: { - start: { column: 16, line: 3 }, - end: { column: 40, line: 3 }, - }, - }, - ], - - range: [87, 115], - loc: { - start: { column: 14, line: 3 }, - end: { column: 42, line: 3 }, - }, - }, source: Literal { type: "Literal", raw: "'foo'", diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot index 716706840f94..e2f15f25d11e 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot @@ -21,85 +21,6 @@ exports[`AST Fixtures legacy-fixtures basics dynamic-import-with-import-assertio key: Identifier { type: 'Identifier', - decorators: Array [], -+ name: 'assert', -+ -+ range: [89, 95], -+ loc: { -+ start: { column: 16, line: 3 }, -+ end: { column: 22, line: 3 }, -+ }, -+ }, -+ kind: 'init', -+ method: false, -+ shorthand: false, -+ value: ObjectExpression { -+ type: 'ObjectExpression', -+ properties: Array [ -+ Property { -+ type: 'Property', -+ computed: false, -+ key: Identifier { -+ type: 'Identifier', -+ name: 'type', -+ -+ range: [99, 103], -+ loc: { -+ start: { column: 26, line: 3 }, -+ end: { column: 30, line: 3 }, -+ }, -+ }, -+ kind: 'init', -+ method: false, -+ shorthand: false, -+ value: Literal { -+ type: 'Literal', -+ raw: '\\'json\\'', -+ value: 'json', -+ -+ range: [105, 111], -+ loc: { -+ start: { column: 32, line: 3 }, -+ end: { column: 38, line: 3 }, -+ }, -+ }, -+ -+ range: [99, 111], -+ loc: { -+ start: { column: 26, line: 3 }, -+ end: { column: 38, line: 3 }, -+ }, -+ }, -+ ], -+ -+ range: [97, 113], -+ loc: { -+ start: { column: 24, line: 3 }, -+ end: { column: 40, line: 3 }, -+ }, -+ }, -+ -+ range: [89, 113], -+ loc: { -+ start: { column: 16, line: 3 }, -+ end: { column: 40, line: 3 }, -+ }, -+ }, -+ ], -+ -+ range: [87, 115], -+ loc: { -+ start: { column: 14, line: 3 }, -+ end: { column: 42, line: 3 }, -+ }, -+ }, -+ options: ObjectExpression { -+ type: 'ObjectExpression', -+ properties: Array [ -+ Property { -+ type: 'Property', -+ computed: false, -+ key: Identifier { -+ type: 'Identifier', name: 'assert', - optional: false, diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index a41c223827df..409216445120 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -143,6 +143,7 @@ exports[`AST Fixtures List fixtures with AST differences 1`] = ` "expression/TSSatisfiesExpression/fixtures/logical-with-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-inner-parentheses/fixture.ts", "expression/TSSatisfiesExpression/fixtures/object-object-outer-parentheses/fixture.ts", + "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/accessor-decorators/fixtures/accessor-decorator-factory-instance-member/fixture.ts", diff --git a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot index b15734b809f0..43ef25b5170b 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-tokens.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-tokens.shot @@ -26,6 +26,7 @@ exports[`AST Fixtures List fixtures with Token differences 1`] = ` "element/AccessorProperty/fixtures/modifier-private/fixture.ts", "element/AccessorProperty/fixtures/modifier-protected/fixture.ts", "element/AccessorProperty/fixtures/modifier-public/fixture.ts", + "expression/UpdateExpression/fixtures/valid-assignment/fixture.ts", "jsx/JSXNamespacedName/fixtures/component-dashed/fixture.tsx", "jsx/JSXNamespacedName/fixtures/component/fixture.tsx", "legacy-fixtures/basics/fixtures/abstract-class-with-abstract-readonly-property/fixture.ts", From d709adf7332ccd389861c3c6eeb4652c2b40ece1 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Tue, 12 Dec 2023 18:17:36 -0500 Subject: [PATCH 8/9] Fix? --- .../snapshots/2-Babel-Error.shot | 2 +- .../snapshots/2-Babel-Error.shot | 2 +- .../snapshots/2-Babel-Error.shot | 2 +- .../snapshots/3-Babel-AST.shot | 79 +++++++++++++++++++ .../snapshots/5-AST-Alignment-AST.shot | 79 +++++++++++++++++++ 5 files changed, 161 insertions(+), 3 deletions(-) diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot index 29a072c41745..0b089f45210e 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain/snapshots/2-Babel-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures expression UpdateExpression _error_ optional-chain Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain Babel - Error 1`] = `[SyntaxError: This experimental syntax requires enabling the parser plugin: "optionalChainingAssign". (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot index 13d2912a340f..75a24ee97f7b 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain2/snapshots/2-Babel-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain2 Babel - Error 1`] = `[SyntaxError: This experimental syntax requires enabling the parser plugin: "optionalChainingAssign". (1:0)]`; diff --git a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot index 89b1d94499c9..45fb7b64fd13 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot +++ b/packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/optional-chain3/snapshots/2-Babel-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 Babel - Error 1`] = `[SyntaxError: Invalid left-hand side in postfix operation. (1:0)]`; +exports[`AST Fixtures expression UpdateExpression _error_ optional-chain3 Babel - Error 1`] = `[SyntaxError: This experimental syntax requires enabling the parser plugin: "optionalChainingAssign". (1:0)]`; diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot index fec2f6e4759d..422530628713 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/3-Babel-AST.shot @@ -87,6 +87,85 @@ Program { end: { column: 42, line: 3 }, }, }, + options: ObjectExpression { + type: "ObjectExpression", + properties: [ + Property { + type: "Property", + computed: false, + key: Identifier { + type: "Identifier", + name: "assert", + + range: [89, 95], + loc: { + start: { column: 16, line: 3 }, + end: { column: 22, line: 3 }, + }, + }, + kind: "init", + method: false, + shorthand: false, + value: ObjectExpression { + type: "ObjectExpression", + properties: [ + Property { + type: "Property", + computed: false, + key: Identifier { + type: "Identifier", + name: "type", + + range: [99, 103], + loc: { + start: { column: 26, line: 3 }, + end: { column: 30, line: 3 }, + }, + }, + kind: "init", + method: false, + shorthand: false, + value: Literal { + type: "Literal", + raw: "'json'", + value: "json", + + range: [105, 111], + loc: { + start: { column: 32, line: 3 }, + end: { column: 38, line: 3 }, + }, + }, + + range: [99, 111], + loc: { + start: { column: 26, line: 3 }, + end: { column: 38, line: 3 }, + }, + }, + ], + + range: [97, 113], + loc: { + start: { column: 24, line: 3 }, + end: { column: 40, line: 3 }, + }, + }, + + range: [89, 113], + loc: { + start: { column: 16, line: 3 }, + end: { column: 40, line: 3 }, + }, + }, + ], + + range: [87, 115], + loc: { + start: { column: 14, line: 3 }, + end: { column: 42, line: 3 }, + }, + }, source: Literal { type: "Literal", raw: "'foo'", diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot index e2f15f25d11e..716706840f94 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/dynamic-import-with-import-assertions/snapshots/5-AST-Alignment-AST.shot @@ -21,6 +21,85 @@ exports[`AST Fixtures legacy-fixtures basics dynamic-import-with-import-assertio key: Identifier { type: 'Identifier', - decorators: Array [], ++ name: 'assert', ++ ++ range: [89, 95], ++ loc: { ++ start: { column: 16, line: 3 }, ++ end: { column: 22, line: 3 }, ++ }, ++ }, ++ kind: 'init', ++ method: false, ++ shorthand: false, ++ value: ObjectExpression { ++ type: 'ObjectExpression', ++ properties: Array [ ++ Property { ++ type: 'Property', ++ computed: false, ++ key: Identifier { ++ type: 'Identifier', ++ name: 'type', ++ ++ range: [99, 103], ++ loc: { ++ start: { column: 26, line: 3 }, ++ end: { column: 30, line: 3 }, ++ }, ++ }, ++ kind: 'init', ++ method: false, ++ shorthand: false, ++ value: Literal { ++ type: 'Literal', ++ raw: '\\'json\\'', ++ value: 'json', ++ ++ range: [105, 111], ++ loc: { ++ start: { column: 32, line: 3 }, ++ end: { column: 38, line: 3 }, ++ }, ++ }, ++ ++ range: [99, 111], ++ loc: { ++ start: { column: 26, line: 3 }, ++ end: { column: 38, line: 3 }, ++ }, ++ }, ++ ], ++ ++ range: [97, 113], ++ loc: { ++ start: { column: 24, line: 3 }, ++ end: { column: 40, line: 3 }, ++ }, ++ }, ++ ++ range: [89, 113], ++ loc: { ++ start: { column: 16, line: 3 }, ++ end: { column: 40, line: 3 }, ++ }, ++ }, ++ ], ++ ++ range: [87, 115], ++ loc: { ++ start: { column: 14, line: 3 }, ++ end: { column: 42, line: 3 }, ++ }, ++ }, ++ options: ObjectExpression { ++ type: 'ObjectExpression', ++ properties: Array [ ++ Property { ++ type: 'Property', ++ computed: false, ++ key: Identifier { ++ type: 'Identifier', name: 'assert', - optional: false, From 8c60dc98ba8a8748194002a22606e229e2068236 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Tue, 12 Dec 2023 19:07:57 -0500 Subject: [PATCH 9/9] Fix tests --- .../tests/rules/no-extra-parens.test.ts | 9 --------- .../tests/rules/no-unsafe-member-access.test.ts | 10 ---------- .../tests/rules/unbound-method.test.ts | 2 -- .../tests/util/getWrappingFixer.test.ts | 16 ---------------- 4 files changed, 37 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts b/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts index 94c796a98a8e..ce3b72c06ad4 100644 --- a/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts @@ -346,10 +346,6 @@ typeof (a); code: 'const x = !(1 as 1);', options: ['all', { nestedBinaryExpressions: false }], }, - { - code: 'const x = (1 as 1)++;', - options: ['all', { nestedBinaryExpressions: false }], - }, { code: 'function *x() { yield (1 as 1); yield 1; }', options: ['all', { nestedBinaryExpressions: false }], @@ -479,11 +475,6 @@ typeof (a); parserOptions: { ecmaFeatures: { jsx: false } }, options: ['all', { nestedBinaryExpressions: false }], }, - { - code: 'const x = (<1>1)++;', - parserOptions: { ecmaFeatures: { jsx: false } }, - options: ['all', { nestedBinaryExpressions: false }], - }, { code: 'function *x() { yield (<1>1); yield 1; }', parserOptions: { ecmaFeatures: { jsx: false } }, diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-member-access.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-member-access.test.ts index 367ae0c6e3c2..292c52759c0d 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-member-access.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-member-access.test.ts @@ -55,16 +55,6 @@ function foo(x: string[]) { } `, ` -function foo(x?: string[]) { - x?.[1++]; -} - `, - ` -function foo(x?: string[]) { - x?.[(1 as any)++]; -} - `, - ` class B implements FG.A {} `, ` diff --git a/packages/eslint-plugin/tests/rules/unbound-method.test.ts b/packages/eslint-plugin/tests/rules/unbound-method.test.ts index 9eb2b73b22c2..f0442c29cb03 100644 --- a/packages/eslint-plugin/tests/rules/unbound-method.test.ts +++ b/packages/eslint-plugin/tests/rules/unbound-method.test.ts @@ -207,8 +207,6 @@ function foo(instance: ContainsMethods | null) { instance?.bound(); instance?.unbound(); - instance?.bound++; - if (instance?.bound) { } if (instance?.unbound) { diff --git a/packages/eslint-plugin/tests/util/getWrappingFixer.test.ts b/packages/eslint-plugin/tests/util/getWrappingFixer.test.ts index 78e5e21bad5a..b9a07bf8181d 100644 --- a/packages/eslint-plugin/tests/util/getWrappingFixer.test.ts +++ b/packages/eslint-plugin/tests/util/getWrappingFixer.test.ts @@ -98,11 +98,6 @@ ruleTester.run('getWrappingFixer - voidEverythingRule', voidEverythingRule, { errors: [{ messageId: 'addVoid' }], output: '!(void wrapMe)', }, - { - code: 'wrapMe++', - errors: [{ messageId: 'addVoid' }], - output: '(void wrapMe)++', - }, { code: '"wrapMe" + "dontWrap"', errors: [{ messageId: 'addVoid' }], @@ -202,17 +197,6 @@ ruleTester.run('getWrappingFixer - voidEverythingRule', voidEverythingRule, { ;(void "wrapMe") + "!" `, }, - { - code: ` - dontWrap - wrapMe++ - `, - errors: [{ messageId: 'addVoid' }], - output: ` - dontWrap - ;(void wrapMe)++ - `, - }, { code: ` dontWrap()