From 8cb0297d11423f532ef001c3904b1911debdf4f6 Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 11 Jan 2020 18:28:32 +0100 Subject: [PATCH 1/5] test(typescript-estree): enable alignment tests for optional methods --- ...class-with-optional-computed-method.src.ts | 7 + .../tests/ast-alignment/fixtures-to-test.ts | 14 +- .../tests/ast-alignment/utils.ts | 8 + .../semantic-diagnostics-enabled.ts.snap | 2 + .../lib/__snapshots__/typescript.ts.snap | 1283 +++++++++++++++++ 5 files changed, 1305 insertions(+), 9 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts new file mode 100644 index 000000000000..1141e5aa4b8b --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts @@ -0,0 +1,7 @@ +class X { + [foo.bar]?(); + [foo]?(); + ['foo']?(); + [`${foo}`]?(); + private [foo]?(); +} diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index ab677004678a..a83e53c49213 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -360,14 +360,6 @@ tester.addFixturePatternConfig('typescript/babylon-convergence', { tester.addFixturePatternConfig('typescript/basics', { fileType: 'ts', ignore: [ - /** - * Babel and ts-estree reports optional field on different nodes - * TODO: investigate - */ - 'class-with-optional-methods', - 'abstract-class-with-abstract-method', - 'abstract-class-with-optional-method', - 'declare-class-with-optional-method', /** * Babel parses it as TSQualifiedName * ts parses it as MemberExpression @@ -397,7 +389,11 @@ tester.addFixturePatternConfig('typescript/basics', { * SyntaxError: 'abstract' modifier can only appear on a class, method, or property declaration. */ 'abstract-class-with-abstract-constructor', - // babel hard fails on computed string enum members, but TS doesn't + /** + * [BABEL ERRORED, BUT TS-ESTREE DID NOT] + * babel hard fails on computed string enum members, but TS doesn't + * TODO: report this to babel + */ 'export-named-enum-computed-string', /** * Babel: TSTypePredicate includes `:` statement in range diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 002a4c66dcbd..1f0f082ffcf5 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -198,6 +198,14 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { node.range[0] = node.typeParameters.range[0]; node.loc.start = Object.assign({}, node.typeParameters.loc.start); } + + /** + * babel: sets body property as Object/undefined + * ts-estree: sets body property as Object/null + */ + if (!node.body) { + node.body = null; + } }, /** * Template strings seem to also be affected by the difference in opinion between different parsers in diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 1b81d29c0842..635b2662717a 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1763,6 +1763,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-mixin-reference.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-optional-computed-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-optional-computed-property.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-optional-methods.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index cbd1e12b3783..95b4eb7f07f4 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -23783,6 +23783,1289 @@ Object { } `; +exports[`typescript fixtures/basics/class-with-optional-computed-method.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": true, + "key": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "name": "foo", + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 17, + 20, + ], + "type": "Identifier", + }, + "range": Array [ + 13, + 20, + ], + "type": "MemberExpression", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 12, + 25, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 22, + 25, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "name": "foo", + "optional": true, + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 28, + 37, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "params": Array [], + "range": Array [ + 34, + 37, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "range": Array [ + 41, + 46, + ], + "raw": "'foo'", + "type": "Literal", + "value": "foo", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 40, + 51, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "params": Array [], + "range": Array [ + 48, + 51, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "expressions": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "foo", + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + }, + ], + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "quasis": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "range": Array [ + 55, + 58, + ], + "tail": false, + "type": "TemplateElement", + "value": Object { + "cooked": "", + "raw": "", + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 9, + "line": 5, + }, + }, + "range": Array [ + 61, + 63, + ], + "tail": true, + "type": "TemplateElement", + "value": Object { + "cooked": "", + "raw": "", + }, + }, + ], + "range": Array [ + 55, + 63, + ], + "type": "TemplateLiteral", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 54, + 68, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "params": Array [], + "range": Array [ + 65, + 68, + ], + "type": "FunctionExpression", + }, + }, + Object { + "accessibility": "private", + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 6, + }, + "start": Object { + "column": 11, + "line": 6, + }, + }, + "name": "foo", + "optional": true, + "range": Array [ + 80, + 83, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 71, + 88, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 6, + }, + }, + "params": Array [], + "range": Array [ + 85, + 88, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 90, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "X", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 90, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 91, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + "value": "X", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 13, + 16, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 17, + 20, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 40, + 41, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "range": Array [ + 41, + 46, + ], + "type": "String", + "value": "'foo'", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 48, + 49, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 11, + "line": 4, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 12, + "line": 4, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 54, + 55, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "range": Array [ + 55, + 58, + ], + "type": "Template", + "value": "\`\${", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 9, + "line": 5, + }, + }, + "range": Array [ + 61, + 63, + ], + "type": "Template", + "value": "}\`", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 5, + }, + "start": Object { + "column": 11, + "line": 5, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 12, + "line": 5, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 65, + 66, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 15, + "line": 5, + }, + }, + "range": Array [ + 67, + 68, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 71, + 78, + ], + "type": "Keyword", + "value": "private", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 10, + "line": 6, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 6, + }, + "start": Object { + "column": 11, + "line": 6, + }, + }, + "range": Array [ + 80, + 83, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 14, + "line": 6, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 6, + }, + "start": Object { + "column": 15, + "line": 6, + }, + }, + "range": Array [ + 84, + 85, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 6, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 6, + }, + "start": Object { + "column": 17, + "line": 6, + }, + }, + "range": Array [ + 86, + 87, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 87, + 88, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 89, + 90, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/class-with-optional-computed-property.src 1`] = ` Object { "body": Array [ From ec3c5c6b7fdab46ecb831eb78ca3def458fc4ee8 Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 11 Jan 2020 18:37:35 +0100 Subject: [PATCH 2/5] test(typescript-estree): update tests --- ...class-with-optional-computed-method.src.ts | 19 +- .../lib/__snapshots__/typescript.ts.snap | 2743 +++++++++++++---- 2 files changed, 2135 insertions(+), 627 deletions(-) diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts index 1141e5aa4b8b..d8f20647788b 100644 --- a/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts @@ -1,7 +1,16 @@ +const computed1 = "buzz"; +const computed2 = "bazz"; +const obj = { + member: "member", + member2: "member2", +}; class X { - [foo.bar]?(); - [foo]?(); - ['foo']?(); - [`${foo}`]?(); - private [foo]?(); + [computed1]?(); + [computed2]?() {}; + [1]?(); + [2]?() {}; + ["literal1"]?(); + ["literal2"]?() {}; + [obj.member]?() {}; + [obj.member2]?(); } diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 95b4eb7f07f4..3654f109feaa 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -23787,329 +23787,381 @@ exports[`typescript fixtures/basics/class-with-optional-computed-method.src 1`] Object { "body": Array [ Object { - "body": Object { - "body": Array [ - Object { - "computed": true, - "key": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 3, - "line": 2, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 2, - }, - "start": Object { - "column": 3, - "line": 2, - }, - }, - "name": "foo", - "range": Array [ - 13, - 16, - ], - "type": "Identifier", - }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 7, - "line": 2, - }, - }, - "name": "bar", - "range": Array [ - 17, - 20, - ], - "type": "Identifier", - }, - "range": Array [ - 13, - 20, - ], - "type": "MemberExpression", - }, - "kind": "method", + "declarations": Array [ + Object { + "id": Object { "loc": Object { "end": Object { "column": 15, - "line": 2, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 6, + "line": 1, }, }, + "name": "computed1", "range": Array [ - 12, - 25, + 6, + 15, ], - "static": false, - "type": "MethodDefinition", - "value": Object { - "async": false, - "body": null, - "expression": false, - "generator": false, - "id": null, - "loc": Object { - "end": Object { - "column": 15, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, - }, - "params": Array [], - "range": Array [ - 22, - 25, - ], - "type": "FunctionExpression", - }, + "type": "Identifier", }, - Object { - "computed": true, - "key": Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "name": "foo", - "optional": true, - "range": Array [ - 29, - 32, - ], - "type": "Identifier", - }, - "kind": "method", + "init": Object { "loc": Object { "end": Object { - "column": 11, - "line": 3, + "column": 24, + "line": 1, }, "start": Object { - "column": 2, - "line": 3, + "column": 18, + "line": 1, }, }, "range": Array [ - 28, - 37, + 18, + 24, ], - "static": false, - "type": "MethodDefinition", - "value": Object { - "async": false, - "body": null, - "expression": false, - "generator": false, - "id": null, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "params": Array [], - "range": Array [ - 34, - 37, - ], - "type": "FunctionExpression", + "raw": "\\"buzz\\"", + "type": "Literal", + "value": "buzz", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, }, }, - Object { - "computed": true, - "key": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, + "range": Array [ + 6, + 24, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 25, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, }, - "range": Array [ - 41, - 46, - ], - "raw": "'foo'", - "type": "Literal", - "value": "foo", }, - "kind": "method", + "name": "computed2", + "range": Array [ + 32, + 41, + ], + "type": "Identifier", + }, + "init": Object { "loc": Object { "end": Object { - "column": 13, - "line": 4, + "column": 24, + "line": 2, }, "start": Object { - "column": 2, - "line": 4, + "column": 18, + "line": 2, }, }, "range": Array [ - 40, - 51, + 44, + 50, ], - "static": false, - "type": "MethodDefinition", - "value": Object { - "async": false, - "body": null, - "expression": false, - "generator": false, - "id": null, - "loc": Object { - "end": Object { - "column": 13, - "line": 4, - }, - "start": Object { - "column": 10, - "line": 4, - }, + "raw": "\\"bazz\\"", + "type": "Literal", + "value": "bazz", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 32, + 50, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 26, + 51, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, }, - "params": Array [], - "range": Array [ - 48, - 51, - ], - "type": "FunctionExpression", }, + "name": "obj", + "range": Array [ + 58, + 61, + ], + "type": "Identifier", }, - Object { - "computed": true, - "key": Object { - "expressions": Array [ - Object { + "init": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 6, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "properties": Array [ + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 8, + "line": 4, }, "start": Object { - "column": 6, - "line": 5, + "column": 2, + "line": 4, }, }, - "name": "foo", + "name": "member", "range": Array [ - 58, - 61, + 68, + 74, ], "type": "Identifier", }, - ], - "loc": Object { - "end": Object { - "column": 11, - "line": 5, + "kind": "init", + "loc": Object { + "end": Object { + "column": 18, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, }, - "start": Object { - "column": 3, - "line": 5, + "method": false, + "range": Array [ + 68, + 84, + ], + "shorthand": false, + "type": "Property", + "value": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 76, + 84, + ], + "raw": "\\"member\\"", + "type": "Literal", + "value": "member", }, }, - "quasis": Array [ - Object { + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 6, + "column": 9, "line": 5, }, "start": Object { - "column": 3, + "column": 2, "line": 5, }, }, + "name": "member2", "range": Array [ - 55, - 58, + 88, + 95, ], - "tail": false, - "type": "TemplateElement", - "value": Object { - "cooked": "", - "raw": "", + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, }, }, - Object { + "method": false, + "range": Array [ + 88, + 106, + ], + "shorthand": false, + "type": "Property", + "value": Object { "loc": Object { "end": Object { - "column": 11, + "column": 20, "line": 5, }, "start": Object { - "column": 9, + "column": 11, "line": 5, }, }, "range": Array [ - 61, - 63, + 97, + 106, ], - "tail": true, - "type": "TemplateElement", - "value": Object { - "cooked": "", - "raw": "", - }, + "raw": "\\"member2\\"", + "type": "Literal", + "value": "member2", }, - ], + }, + ], + "range": Array [ + 64, + 109, + ], + "type": "ObjectExpression", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 6, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 58, + 109, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 2, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 52, + 110, + ], + "type": "VariableDeclaration", + }, + Object { + "body": Object { + "body": Array [ + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 8, + }, + "start": Object { + "column": 3, + "line": 8, + }, + }, + "name": "computed1", + "optional": true, "range": Array [ - 55, - 63, + 124, + 133, ], - "type": "TemplateLiteral", + "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 16, - "line": 5, + "column": 17, + "line": 8, }, "start": Object { "column": 2, - "line": 5, + "line": 8, }, }, "range": Array [ - 54, - 68, + 123, + 138, ], "static": false, "type": "MethodDefinition", @@ -24121,41 +24173,40 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 16, - "line": 5, + "column": 17, + "line": 8, }, "start": Object { - "column": 13, - "line": 5, + "column": 14, + "line": 8, }, }, "params": Array [], "range": Array [ - 65, - 68, + 135, + 138, ], "type": "FunctionExpression", }, }, Object { - "accessibility": "private", "computed": true, "key": Object { "loc": Object { "end": Object { - "column": 14, - "line": 6, + "column": 12, + "line": 9, }, "start": Object { - "column": 11, - "line": 6, + "column": 3, + "line": 9, }, }, - "name": "foo", + "name": "computed2", "optional": true, "range": Array [ - 80, - 83, + 142, + 151, ], "type": "Identifier", }, @@ -24163,252 +24214,1736 @@ Object { "loc": Object { "end": Object { "column": 19, - "line": 6, + "line": 9, }, "start": Object { "column": 2, - "line": 6, + "line": 9, }, }, "range": Array [ - 71, - 88, + 141, + 158, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, - "body": null, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 17, + "line": 9, + }, + }, + "range": Array [ + 156, + 158, + ], + "type": "BlockStatement", + }, "expression": false, "generator": false, "id": null, "loc": Object { "end": Object { "column": 19, - "line": 6, + "line": 9, }, "start": Object { - "column": 16, - "line": 6, + "column": 14, + "line": 9, }, }, "params": Array [], "range": Array [ - 85, - 88, + 153, + 158, ], "type": "FunctionExpression", }, }, - ], - "loc": Object { - "end": Object { - "column": 1, - "line": 7, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "range": Array [ - 8, - 90, - ], - "type": "ClassBody", - }, - "id": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 1, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 10, + }, + "start": Object { + "column": 3, + "line": 10, + }, + }, + "range": Array [ + 163, + 164, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 9, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "range": Array [ + 162, + 169, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 9, + "line": 10, + }, + "start": Object { + "column": 6, + "line": 10, + }, + }, + "params": Array [], + "range": Array [ + 166, + 169, + ], + "type": "FunctionExpression", + }, }, - "start": Object { - "column": 6, - "line": 1, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 11, + }, + "start": Object { + "column": 3, + "line": 11, + }, + }, + "range": Array [ + 173, + 174, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 11, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 11, + }, + }, + "range": Array [ + 172, + 181, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 11, + "line": 11, + }, + "start": Object { + "column": 9, + "line": 11, + }, + }, + "range": Array [ + 179, + 181, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 11, + "line": 11, + }, + "start": Object { + "column": 6, + "line": 11, + }, + }, + "params": Array [], + "range": Array [ + 176, + 181, + ], + "type": "FunctionExpression", + }, }, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 12, + }, + "start": Object { + "column": 3, + "line": 12, + }, + }, + "range": Array [ + 186, + 196, + ], + "raw": "\\"literal1\\"", + "type": "Literal", + "value": "literal1", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 18, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "range": Array [ + 185, + 201, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 18, + "line": 12, + }, + "start": Object { + "column": 15, + "line": 12, + }, + }, + "params": Array [], + "range": Array [ + 198, + 201, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 13, + }, + "start": Object { + "column": 3, + "line": 13, + }, + }, + "range": Array [ + 205, + 215, + ], + "raw": "\\"literal2\\"", + "type": "Literal", + "value": "literal2", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 20, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + "range": Array [ + 204, + 222, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 20, + "line": 13, + }, + "start": Object { + "column": 18, + "line": 13, + }, + }, + "range": Array [ + 220, + 222, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 20, + "line": 13, + }, + "start": Object { + "column": 15, + "line": 13, + }, + }, + "params": Array [], + "range": Array [ + 217, + 222, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 13, + "line": 14, + }, + "start": Object { + "column": 3, + "line": 14, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 14, + }, + "start": Object { + "column": 3, + "line": 14, + }, + }, + "name": "obj", + "range": Array [ + 227, + 230, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 14, + }, + "start": Object { + "column": 7, + "line": 14, + }, + }, + "name": "member", + "range": Array [ + 231, + 237, + ], + "type": "Identifier", + }, + "range": Array [ + 227, + 237, + ], + "type": "MemberExpression", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 20, + "line": 14, + }, + "start": Object { + "column": 2, + "line": 14, + }, + }, + "range": Array [ + 226, + 244, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 20, + "line": 14, + }, + "start": Object { + "column": 18, + "line": 14, + }, + }, + "range": Array [ + 242, + 244, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 20, + "line": 14, + }, + "start": Object { + "column": 15, + "line": 14, + }, + }, + "params": Array [], + "range": Array [ + 239, + 244, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": true, + "key": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 14, + "line": 15, + }, + "start": Object { + "column": 3, + "line": 15, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 15, + }, + "start": Object { + "column": 3, + "line": 15, + }, + }, + "name": "obj", + "range": Array [ + 249, + 252, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 15, + }, + "start": Object { + "column": 7, + "line": 15, + }, + }, + "name": "member2", + "range": Array [ + 253, + 260, + ], + "type": "Identifier", + }, + "range": Array [ + 249, + 260, + ], + "type": "MemberExpression", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 19, + "line": 15, + }, + "start": Object { + "column": 2, + "line": 15, + }, + }, + "range": Array [ + 248, + 265, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": null, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 19, + "line": 15, + }, + "start": Object { + "column": 16, + "line": 15, + }, + }, + "params": Array [], + "range": Array [ + 262, + 265, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 16, + }, + "start": Object { + "column": 8, + "line": 7, + }, + }, + "range": Array [ + 119, + 267, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "name": "X", + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 16, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 111, + 267, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 17, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 268, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + "value": "computed1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 24, + ], + "type": "String", + "value": "\\"buzz\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 26, + 31, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 32, + 41, + ], + "type": "Identifier", + "value": "computed2", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 44, + 50, + ], + "type": "String", + "value": "\\"bazz\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 52, + 57, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + "value": "obj", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 62, + 63, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 68, + 74, + ], + "type": "Identifier", + "value": "member", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 76, + 84, + ], + "type": "String", + "value": "\\"member\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 4, + }, + "start": Object { + "column": 18, + "line": 4, + }, + }, + "range": Array [ + 84, + 85, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 88, + 95, + ], + "type": "Identifier", + "value": "member2", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 5, + }, + "start": Object { + "column": 9, + "line": 5, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 11, + "line": 5, + }, + }, + "range": Array [ + 97, + 106, + ], + "type": "String", + "value": "\\"member2\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 5, + }, + "start": Object { + "column": 20, + "line": 5, + }, + }, + "range": Array [ + 106, + 107, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 6, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 6, + }, + "start": Object { + "column": 1, + "line": 6, + }, + }, + "range": Array [ + 109, + 110, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 111, + 116, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + "value": "X", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 7, + }, + "start": Object { + "column": 8, + "line": 7, + }, + }, + "range": Array [ + 119, + 120, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "range": Array [ + 123, + 124, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 8, + }, + "start": Object { + "column": 3, + "line": 8, + }, + }, + "range": Array [ + 124, + 133, + ], + "type": "Identifier", + "value": "computed1", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 8, + }, + "start": Object { + "column": 12, + "line": 8, + }, + }, + "range": Array [ + 133, + 134, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 8, + }, + "start": Object { + "column": 13, + "line": 8, + }, + }, + "range": Array [ + 134, + 135, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 8, + }, + "start": Object { + "column": 14, + "line": 8, + }, + }, + "range": Array [ + 135, + 136, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 8, + }, + "start": Object { + "column": 15, + "line": 8, + }, + }, + "range": Array [ + 136, + 137, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 8, + }, + "start": Object { + "column": 16, + "line": 8, + }, + }, + "range": Array [ + 137, + 138, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "range": Array [ + 141, + 142, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 9, + }, + "start": Object { + "column": 3, + "line": 9, + }, + }, + "range": Array [ + 142, + 151, + ], + "type": "Identifier", + "value": "computed2", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 9, + }, + "start": Object { + "column": 12, + "line": 9, + }, + }, + "range": Array [ + 151, + 152, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 9, + }, + "start": Object { + "column": 13, + "line": 9, + }, + }, + "range": Array [ + 152, + 153, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 9, + }, + "start": Object { + "column": 14, + "line": 9, + }, + }, + "range": Array [ + 153, + 154, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 9, + }, + "start": Object { + "column": 15, + "line": 9, + }, + }, + "range": Array [ + 154, + 155, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 9, + }, + "start": Object { + "column": 17, + "line": 9, + }, + }, + "range": Array [ + 156, + 157, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 18, + "line": 9, + }, + }, + "range": Array [ + 157, + 158, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 9, + }, + "start": Object { + "column": 19, + "line": 9, + }, + }, + "range": Array [ + 158, + 159, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, }, - "name": "X", - "range": Array [ - 6, - 7, - ], - "type": "Identifier", }, + "range": Array [ + 162, + 163, + ], + "type": "Punctuator", + "value": "[", + }, + Object { "loc": Object { "end": Object { - "column": 1, - "line": 7, + "column": 4, + "line": 10, }, "start": Object { - "column": 0, - "line": 1, + "column": 3, + "line": 10, }, }, "range": Array [ - 0, - 90, + 163, + 164, ], - "superClass": null, - "type": "ClassDeclaration", - }, - ], - "loc": Object { - "end": Object { - "column": 0, - "line": 8, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "Numeric", + "value": "1", }, - }, - "range": Array [ - 0, - 91, - ], - "sourceType": "script", - "tokens": Array [ Object { "loc": Object { "end": Object { "column": 5, - "line": 1, + "line": 10, }, "start": Object { - "column": 0, - "line": 1, + "column": 4, + "line": 10, }, }, "range": Array [ - 0, - 5, + 164, + 165, ], - "type": "Keyword", - "value": "class", + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 10, + }, + "start": Object { + "column": 5, + "line": 10, + }, + }, + "range": Array [ + 165, + 166, + ], + "type": "Punctuator", + "value": "?", }, Object { "loc": Object { "end": Object { "column": 7, - "line": 1, + "line": 10, }, "start": Object { "column": 6, - "line": 1, + "line": 10, }, }, "range": Array [ - 6, - 7, + 166, + 167, ], - "type": "Identifier", - "value": "X", + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 10, + }, + "start": Object { + "column": 7, + "line": 10, + }, + }, + "range": Array [ + 167, + 168, + ], + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { "column": 9, - "line": 1, + "line": 10, }, "start": Object { "column": 8, - "line": 1, + "line": 10, }, }, "range": Array [ - 8, - 9, + 168, + 169, ], "type": "Punctuator", - "value": "{", + "value": ";", }, Object { "loc": Object { "end": Object { "column": 3, - "line": 2, + "line": 11, }, "start": Object { "column": 2, - "line": 2, + "line": 11, }, }, "range": Array [ - 12, - 13, + 172, + 173, ], "type": "Punctuator", "value": "[", }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 11, + }, + "start": Object { + "column": 3, + "line": 11, + }, + }, + "range": Array [ + 173, + 174, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 11, + }, + "start": Object { + "column": 4, + "line": 11, + }, + }, + "range": Array [ + 174, + 175, + ], + "type": "Punctuator", + "value": "]", + }, Object { "loc": Object { "end": Object { "column": 6, - "line": 2, + "line": 11, + }, + "start": Object { + "column": 5, + "line": 11, + }, + }, + "range": Array [ + 175, + 176, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 11, + }, + "start": Object { + "column": 6, + "line": 11, + }, + }, + "range": Array [ + 176, + 177, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 11, + }, + "start": Object { + "column": 7, + "line": 11, + }, + }, + "range": Array [ + 177, + 178, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 11, + }, + "start": Object { + "column": 9, + "line": 11, + }, + }, + "range": Array [ + 179, + 180, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 11, + }, + "start": Object { + "column": 10, + "line": 11, + }, + }, + "range": Array [ + 180, + 181, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 11, }, "start": Object { - "column": 3, - "line": 2, + "column": 11, + "line": 11, }, }, "range": Array [ - 13, - 16, + 181, + 182, ], - "type": "Identifier", - "value": "foo", + "type": "Punctuator", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 7, - "line": 2, + "column": 3, + "line": 12, }, "start": Object { - "column": 6, - "line": 2, + "column": 2, + "line": 12, }, }, "range": Array [ - 16, - 17, + 185, + 186, ], "type": "Punctuator", - "value": ".", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 2, + "column": 13, + "line": 12, }, "start": Object { - "column": 7, - "line": 2, + "column": 3, + "line": 12, }, }, "range": Array [ - 17, - 20, + 186, + 196, ], - "type": "Identifier", - "value": "bar", + "type": "String", + "value": "\\"literal1\\"", }, Object { "loc": Object { "end": Object { - "column": 11, - "line": 2, + "column": 14, + "line": 12, }, "start": Object { - "column": 10, - "line": 2, + "column": 13, + "line": 12, }, }, "range": Array [ - 20, - 21, + 196, + 197, ], "type": "Punctuator", "value": "]", @@ -24416,17 +25951,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, - "line": 2, + "column": 15, + "line": 12, }, "start": Object { - "column": 11, - "line": 2, + "column": 14, + "line": 12, }, }, "range": Array [ - 21, - 22, + 197, + 198, ], "type": "Punctuator", "value": "?", @@ -24434,17 +25969,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, - "line": 2, + "column": 16, + "line": 12, }, "start": Object { - "column": 12, - "line": 2, + "column": 15, + "line": 12, }, }, "range": Array [ - 22, - 23, + 198, + 199, ], "type": "Punctuator", "value": "(", @@ -24452,17 +25987,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, - "line": 2, + "column": 17, + "line": 12, }, "start": Object { - "column": 13, - "line": 2, + "column": 16, + "line": 12, }, }, "range": Array [ - 23, - 24, + 199, + 200, ], "type": "Punctuator", "value": ")", @@ -24470,17 +26005,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, - "line": 2, + "column": 18, + "line": 12, }, "start": Object { - "column": 14, - "line": 2, + "column": 17, + "line": 12, }, }, "range": Array [ - 24, - 25, + 200, + 201, ], "type": "Punctuator", "value": ";", @@ -24489,16 +26024,16 @@ Object { "loc": Object { "end": Object { "column": 3, - "line": 3, + "line": 13, }, "start": Object { "column": 2, - "line": 3, + "line": 13, }, }, "range": Array [ - 28, - 29, + 204, + 205, ], "type": "Punctuator", "value": "[", @@ -24506,35 +26041,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 6, - "line": 3, + "column": 13, + "line": 13, }, "start": Object { "column": 3, - "line": 3, + "line": 13, }, }, "range": Array [ - 29, - 32, + 205, + 215, ], - "type": "Identifier", - "value": "foo", + "type": "String", + "value": "\\"literal2\\"", }, Object { "loc": Object { "end": Object { - "column": 7, - "line": 3, + "column": 14, + "line": 13, }, "start": Object { - "column": 6, - "line": 3, + "column": 13, + "line": 13, }, }, "range": Array [ - 32, - 33, + 215, + 216, ], "type": "Punctuator", "value": "]", @@ -24542,17 +26077,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 8, - "line": 3, + "column": 15, + "line": 13, }, "start": Object { - "column": 7, - "line": 3, + "column": 14, + "line": 13, }, }, "range": Array [ - 33, - 34, + 216, + 217, ], "type": "Punctuator", "value": "?", @@ -24560,17 +26095,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, - "line": 3, + "column": 16, + "line": 13, }, "start": Object { - "column": 8, - "line": 3, + "column": 15, + "line": 13, }, }, "range": Array [ - 34, - 35, + 217, + 218, ], "type": "Punctuator", "value": "(", @@ -24578,17 +26113,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, - "line": 3, + "column": 17, + "line": 13, }, "start": Object { - "column": 9, - "line": 3, + "column": 16, + "line": 13, }, }, "range": Array [ - 35, - 36, + 218, + 219, ], "type": "Punctuator", "value": ")", @@ -24596,377 +26131,341 @@ Object { Object { "loc": Object { "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 10, - "line": 3, - }, - }, - "range": Array [ - 36, - 37, - ], - "type": "Punctuator", - "value": ";", - }, - Object { - "loc": Object { - "end": Object { - "column": 3, - "line": 4, + "column": 19, + "line": 13, }, "start": Object { - "column": 2, - "line": 4, + "column": 18, + "line": 13, }, }, "range": Array [ - 40, - 41, + 220, + 221, ], "type": "Punctuator", - "value": "[", - }, - Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "range": Array [ - 41, - 46, - ], - "type": "String", - "value": "'foo'", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 9, - "line": 4, + "column": 20, + "line": 13, }, "start": Object { - "column": 8, - "line": 4, + "column": 19, + "line": 13, }, }, "range": Array [ - 46, - 47, + 221, + 222, ], "type": "Punctuator", - "value": "]", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 4, + "column": 21, + "line": 13, }, "start": Object { - "column": 9, - "line": 4, + "column": 20, + "line": 13, }, }, "range": Array [ - 47, - 48, + 222, + 223, ], "type": "Punctuator", - "value": "?", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 11, - "line": 4, + "column": 3, + "line": 14, }, "start": Object { - "column": 10, - "line": 4, + "column": 2, + "line": 14, }, }, "range": Array [ - 48, - 49, + 226, + 227, ], "type": "Punctuator", - "value": "(", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 12, - "line": 4, + "column": 6, + "line": 14, }, "start": Object { - "column": 11, - "line": 4, + "column": 3, + "line": 14, }, }, "range": Array [ - 49, - 50, + 227, + 230, ], - "type": "Punctuator", - "value": ")", + "type": "Identifier", + "value": "obj", }, Object { "loc": Object { "end": Object { - "column": 13, - "line": 4, + "column": 7, + "line": 14, }, "start": Object { - "column": 12, - "line": 4, + "column": 6, + "line": 14, }, }, "range": Array [ - 50, - 51, + 230, + 231, ], "type": "Punctuator", - "value": ";", + "value": ".", }, Object { "loc": Object { "end": Object { - "column": 3, - "line": 5, + "column": 13, + "line": 14, }, "start": Object { - "column": 2, - "line": 5, + "column": 7, + "line": 14, }, }, "range": Array [ - 54, - 55, + 231, + 237, ], - "type": "Punctuator", - "value": "[", + "type": "Identifier", + "value": "member", }, Object { "loc": Object { "end": Object { - "column": 6, - "line": 5, + "column": 14, + "line": 14, }, "start": Object { - "column": 3, - "line": 5, + "column": 13, + "line": 14, }, }, "range": Array [ - 55, - 58, + 237, + 238, ], - "type": "Template", - "value": "\`\${", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 15, + "line": 14, }, "start": Object { - "column": 6, - "line": 5, + "column": 14, + "line": 14, }, }, "range": Array [ - 58, - 61, + 238, + 239, ], - "type": "Identifier", - "value": "foo", + "type": "Punctuator", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 11, - "line": 5, + "column": 16, + "line": 14, }, "start": Object { - "column": 9, - "line": 5, + "column": 15, + "line": 14, }, }, "range": Array [ - 61, - 63, + 239, + 240, ], - "type": "Template", - "value": "}\`", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 12, - "line": 5, + "column": 17, + "line": 14, }, "start": Object { - "column": 11, - "line": 5, + "column": 16, + "line": 14, }, }, "range": Array [ - 63, - 64, + 240, + 241, ], "type": "Punctuator", - "value": "]", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 13, - "line": 5, + "column": 19, + "line": 14, }, "start": Object { - "column": 12, - "line": 5, + "column": 18, + "line": 14, }, }, "range": Array [ - 64, - 65, + 242, + 243, ], "type": "Punctuator", - "value": "?", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 14, - "line": 5, + "column": 20, + "line": 14, }, "start": Object { - "column": 13, - "line": 5, + "column": 19, + "line": 14, }, }, "range": Array [ - 65, - 66, + 243, + 244, ], "type": "Punctuator", - "value": "(", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 15, - "line": 5, + "column": 21, + "line": 14, }, "start": Object { - "column": 14, - "line": 5, + "column": 20, + "line": 14, }, }, "range": Array [ - 66, - 67, + 244, + 245, ], "type": "Punctuator", - "value": ")", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 5, + "column": 3, + "line": 15, }, "start": Object { - "column": 15, - "line": 5, + "column": 2, + "line": 15, }, }, "range": Array [ - 67, - 68, + 248, + 249, ], "type": "Punctuator", - "value": ";", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 9, - "line": 6, + "column": 6, + "line": 15, }, "start": Object { - "column": 2, - "line": 6, + "column": 3, + "line": 15, }, }, "range": Array [ - 71, - 78, + 249, + 252, ], - "type": "Keyword", - "value": "private", + "type": "Identifier", + "value": "obj", }, Object { "loc": Object { "end": Object { - "column": 11, - "line": 6, + "column": 7, + "line": 15, }, "start": Object { - "column": 10, - "line": 6, + "column": 6, + "line": 15, }, }, "range": Array [ - 79, - 80, + 252, + 253, ], "type": "Punctuator", - "value": "[", + "value": ".", }, Object { "loc": Object { "end": Object { "column": 14, - "line": 6, + "line": 15, }, "start": Object { - "column": 11, - "line": 6, + "column": 7, + "line": 15, }, }, "range": Array [ - 80, - 83, + 253, + 260, ], "type": "Identifier", - "value": "foo", + "value": "member2", }, Object { "loc": Object { "end": Object { "column": 15, - "line": 6, + "line": 15, }, "start": Object { "column": 14, - "line": 6, + "line": 15, }, }, "range": Array [ - 83, - 84, + 260, + 261, ], "type": "Punctuator", "value": "]", @@ -24975,16 +26474,16 @@ Object { "loc": Object { "end": Object { "column": 16, - "line": 6, + "line": 15, }, "start": Object { "column": 15, - "line": 6, + "line": 15, }, }, "range": Array [ - 84, - 85, + 261, + 262, ], "type": "Punctuator", "value": "?", @@ -24993,16 +26492,16 @@ Object { "loc": Object { "end": Object { "column": 17, - "line": 6, + "line": 15, }, "start": Object { "column": 16, - "line": 6, + "line": 15, }, }, "range": Array [ - 85, - 86, + 262, + 263, ], "type": "Punctuator", "value": "(", @@ -25011,16 +26510,16 @@ Object { "loc": Object { "end": Object { "column": 18, - "line": 6, + "line": 15, }, "start": Object { "column": 17, - "line": 6, + "line": 15, }, }, "range": Array [ - 86, - 87, + 263, + 264, ], "type": "Punctuator", "value": ")", @@ -25029,16 +26528,16 @@ Object { "loc": Object { "end": Object { "column": 19, - "line": 6, + "line": 15, }, "start": Object { "column": 18, - "line": 6, + "line": 15, }, }, "range": Array [ - 87, - 88, + 264, + 265, ], "type": "Punctuator", "value": ";", @@ -25047,16 +26546,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 7, + "line": 16, }, "start": Object { "column": 0, - "line": 7, + "line": 16, }, }, "range": Array [ - 89, - 90, + 266, + 267, ], "type": "Punctuator", "value": "}", From 6aa721224cc0d9f4dbd7ab76868ef3845ebead61 Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 11 Jan 2020 19:08:16 +0100 Subject: [PATCH 3/5] feat(typescript-estree): optional field on methods and properties --- .../lib/__snapshots__/typescript.ts.snap | 731 ++++++++++++++++++ ...class-with-optional-computed-method.src.ts | 1 + packages/typescript-estree/src/convert.ts | 7 +- .../src/ts-estree/ts-estree.ts | 12 +- .../tests/ast-alignment/utils.ts | 10 + .../lib/__snapshots__/typescript.ts.snap | 318 +++++++- 6 files changed, 1052 insertions(+), 27 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index e23e1fc48747..1e605e756b67 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -8149,6 +8149,737 @@ Object { } `; +exports[`typescript fixtures/basics/class-with-optional-computed-method.src 1`] = ` +Object { + "$id": 25, + "block": Object { + "range": Array [ + 0, + 282, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 24, + "block": Object { + "range": Array [ + 0, + 282, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 23, + "block": Object { + "range": Array [ + 111, + 281, + ], + "type": "ClassDeclaration", + }, + "childScopes": Array [ + Object { + "$id": 14, + "block": Object { + "range": Array [ + 153, + 158, + ], + "type": "FunctionExpression", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 23, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 13, + }, + }, + "variableScope": Object { + "$ref": 14, + }, + "variables": Array [ + Object { + "$id": 13, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 14, + }, + }, + ], + }, + Object { + "$id": 16, + "block": Object { + "range": Array [ + 176, + 181, + ], + "type": "FunctionExpression", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 23, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 15, + }, + }, + "variableScope": Object { + "$ref": 16, + }, + "variables": Array [ + Object { + "$id": 15, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 16, + }, + }, + ], + }, + Object { + "$id": 18, + "block": Object { + "range": Array [ + 217, + 222, + ], + "type": "FunctionExpression", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 23, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 17, + }, + }, + "variableScope": Object { + "$ref": 18, + }, + "variables": Array [ + Object { + "$id": 17, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 18, + }, + }, + ], + }, + Object { + "$id": 20, + "block": Object { + "range": Array [ + 239, + 244, + ], + "type": "FunctionExpression", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 23, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 19, + }, + }, + "variableScope": Object { + "$ref": 20, + }, + "variables": Array [ + Object { + "$id": 19, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 20, + }, + }, + ], + }, + Object { + "$id": 22, + "block": Object { + "range": Array [ + 274, + 279, + ], + "type": "FunctionExpression", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 23, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 21, + }, + }, + "variableScope": Object { + "$ref": 22, + }, + "variables": Array [ + Object { + "$id": 21, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 22, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [ + Object { + "$id": 8, + "from": Object { + "$ref": 23, + }, + "identifier": Object { + "name": "computed1", + "range": Array [ + 124, + 133, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": undefined, + }, + Object { + "$id": 9, + "from": Object { + "$ref": 23, + }, + "identifier": Object { + "name": "computed2", + "range": Array [ + 142, + 151, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 1, + }, + "writeExpr": undefined, + }, + Object { + "$id": 10, + "from": Object { + "$ref": 23, + }, + "identifier": Object { + "name": "obj", + "range": Array [ + 227, + 230, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 2, + }, + "writeExpr": undefined, + }, + Object { + "$id": 11, + "from": Object { + "$ref": 23, + }, + "identifier": Object { + "name": "obj", + "range": Array [ + 249, + 252, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 2, + }, + "writeExpr": undefined, + }, + Object { + "$id": 12, + "from": Object { + "$ref": 23, + }, + "identifier": Object { + "name": "f", + "range": Array [ + 269, + 270, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": null, + "writeExpr": undefined, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 8, + }, + Object { + "$ref": 9, + }, + Object { + "$ref": 10, + }, + Object { + "$ref": 11, + }, + Object { + "$ref": 12, + }, + ], + "type": "class", + "upperScope": Object { + "$ref": 24, + }, + "variableMap": Object { + "X": Object { + "$ref": 7, + }, + }, + "variableScope": Object { + "$ref": 24, + }, + "variables": Array [ + Object { + "$id": 7, + "defs": Array [ + Object { + "name": Object { + "name": "X", + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 111, + 281, + ], + "type": "ClassDeclaration", + }, + "parent": undefined, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "X", + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + }, + ], + "name": "X", + "references": Array [], + "scope": Object { + "$ref": 23, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [ + Object { + "$id": 4, + "from": Object { + "$ref": 24, + }, + "identifier": Object { + "name": "computed1", + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": Object { + "range": Array [ + 18, + 24, + ], + "type": "Literal", + }, + }, + Object { + "$id": 5, + "from": Object { + "$ref": 24, + }, + "identifier": Object { + "name": "computed2", + "range": Array [ + 32, + 41, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 1, + }, + "writeExpr": Object { + "range": Array [ + 44, + 50, + ], + "type": "Literal", + }, + }, + Object { + "$id": 6, + "from": Object { + "$ref": 24, + }, + "identifier": Object { + "name": "obj", + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + }, + "kind": "w", + "resolved": Object { + "$ref": 2, + }, + "writeExpr": Object { + "range": Array [ + 64, + 109, + ], + "type": "ObjectExpression", + }, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 12, + }, + ], + "type": "module", + "upperScope": Object { + "$ref": 25, + }, + "variableMap": Object { + "X": Object { + "$ref": 3, + }, + "computed1": Object { + "$ref": 0, + }, + "computed2": Object { + "$ref": 1, + }, + "obj": Object { + "$ref": 2, + }, + }, + "variableScope": Object { + "$ref": 24, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "computed1", + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 6, + 24, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 25, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "computed1", + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + }, + ], + "name": "computed1", + "references": Array [ + Object { + "$ref": 4, + }, + Object { + "$ref": 8, + }, + ], + "scope": Object { + "$ref": 24, + }, + }, + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "computed2", + "range": Array [ + 32, + 41, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 32, + 50, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 26, + 51, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "computed2", + "range": Array [ + 32, + 41, + ], + "type": "Identifier", + }, + ], + "name": "computed2", + "references": Array [ + Object { + "$ref": 5, + }, + Object { + "$ref": 9, + }, + ], + "scope": Object { + "$ref": 24, + }, + }, + Object { + "$id": 2, + "defs": Array [ + Object { + "name": Object { + "name": "obj", + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 58, + 109, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 52, + 110, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "obj", + "range": Array [ + 58, + 61, + ], + "type": "Identifier", + }, + ], + "name": "obj", + "references": Array [ + Object { + "$ref": 6, + }, + Object { + "$ref": 10, + }, + Object { + "$ref": 11, + }, + ], + "scope": Object { + "$ref": 24, + }, + }, + Object { + "$id": 3, + "defs": Array [ + Object { + "name": Object { + "name": "X", + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 111, + 281, + ], + "type": "ClassDeclaration", + }, + "parent": null, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "X", + "range": Array [ + 117, + 118, + ], + "type": "Identifier", + }, + ], + "name": "X", + "references": Array [], + "scope": Object { + "$ref": 24, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [ + Object { + "$ref": 12, + }, + ], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 25, + }, + "variables": Array [], +} +`; + exports[`typescript fixtures/basics/class-with-optional-computed-property.src 1`] = ` Object { "$id": 5, diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts index d8f20647788b..947cb550c2ce 100644 --- a/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-with-optional-computed-method.src.ts @@ -13,4 +13,5 @@ class X { ["literal2"]?() {}; [obj.member]?() {}; [obj.member2]?(); + [f()]?() {} } diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index cc38171caf13..648f4a32df7e 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1064,11 +1064,8 @@ export class Converter { } } - if ( - result.key.type === AST_NODE_TYPES.Identifier && - node.questionToken - ) { - result.key.optional = true; + if (node.questionToken) { + result.optional = true; } if (node.kind === SyntaxKind.GetAccessor) { diff --git a/packages/typescript-estree/src/ts-estree/ts-estree.ts b/packages/typescript-estree/src/ts-estree/ts-estree.ts index 94d4b7c24408..8de10a20de21 100644 --- a/packages/typescript-estree/src/ts-estree/ts-estree.ts +++ b/packages/typescript-estree/src/ts-estree/ts-estree.ts @@ -656,6 +656,7 @@ interface MethodDefinitionBase extends BaseNode { computed: boolean; static: boolean; kind: 'method' | 'get' | 'set' | 'constructor'; + optional?: boolean; decorators?: Decorator[]; accessibility?: Accessibility; typeParameters?: TSTypeParameterDeclaration; @@ -678,6 +679,7 @@ interface PropertyBase extends BaseNode { computed: boolean; method: boolean; shorthand: boolean; + optional?: boolean; kind: 'init' | 'get' | 'set'; } @@ -701,26 +703,26 @@ interface TSMethodSignatureBase extends BaseNode { key: PropertyName; computed: boolean; params: Parameter[]; - optional?: boolean; returnType?: TSTypeAnnotation; - readonly?: boolean; typeParameters?: TSTypeParameterDeclaration; accessibility?: Accessibility; + readonly?: boolean; export?: boolean; static?: boolean; + optional?: boolean; } interface TSPropertySignatureBase extends BaseNode { type: AST_NODE_TYPES.TSPropertySignature; key: PropertyName; - optional?: boolean; computed: boolean; typeAnnotation?: TSTypeAnnotation; initializer?: Expression; + accessibility?: Accessibility; readonly?: boolean; - static?: boolean; export?: boolean; - accessibility?: Accessibility; + static?: boolean; + optional?: boolean; } interface UnaryExpressionBase extends BaseNode { diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 1f0f082ffcf5..51241e015601 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -151,6 +151,16 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { }; } }, + MethodDefinition(node) { + /** + * Babel: MethodDefinition + abstract: true + * ts-estree: TSAbstractClassProperty + */ + if (node.abstract) { + node.type = 'TSAbstractMethodDefinition'; + delete node.abstract; + } + }, ClassProperty(node) { /** * Babel: ClassProperty + abstract: true diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 3654f109feaa..cf03adfb0fe4 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -3898,7 +3898,6 @@ Object { }, }, "name": "createSocket", - "optional": true, "range": Array [ 43, 55, @@ -3916,6 +3915,7 @@ Object { "line": 2, }, }, + "optional": true, "range": Array [ 43, 76, @@ -24141,7 +24141,6 @@ Object { }, }, "name": "computed1", - "optional": true, "range": Array [ 124, 133, @@ -24159,6 +24158,7 @@ Object { "line": 8, }, }, + "optional": true, "range": Array [ 123, 138, @@ -24203,7 +24203,6 @@ Object { }, }, "name": "computed2", - "optional": true, "range": Array [ 142, 151, @@ -24221,6 +24220,7 @@ Object { "line": 9, }, }, + "optional": true, "range": Array [ 141, 158, @@ -24300,6 +24300,7 @@ Object { "line": 10, }, }, + "optional": true, "range": Array [ 162, 169, @@ -24362,6 +24363,7 @@ Object { "line": 11, }, }, + "optional": true, "range": Array [ 172, 181, @@ -24441,6 +24443,7 @@ Object { "line": 12, }, }, + "optional": true, "range": Array [ 185, 201, @@ -24503,6 +24506,7 @@ Object { "line": 13, }, }, + "optional": true, "range": Array [ 204, 222, @@ -24618,6 +24622,7 @@ Object { "line": 14, }, }, + "optional": true, "range": Array [ 226, 244, @@ -24733,6 +24738,7 @@ Object { "line": 15, }, }, + "optional": true, "range": Array [ 248, 265, @@ -24763,11 +24769,109 @@ Object { "type": "FunctionExpression", }, }, + Object { + "computed": true, + "key": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 16, + }, + "start": Object { + "column": 3, + "line": 16, + }, + }, + "name": "f", + "range": Array [ + 269, + 270, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 6, + "line": 16, + }, + "start": Object { + "column": 3, + "line": 16, + }, + }, + "optional": false, + "range": Array [ + 269, + 272, + ], + "type": "CallExpression", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 13, + "line": 16, + }, + "start": Object { + "column": 2, + "line": 16, + }, + }, + "optional": true, + "range": Array [ + 268, + 279, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 13, + "line": 16, + }, + "start": Object { + "column": 11, + "line": 16, + }, + }, + "range": Array [ + 277, + 279, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 13, + "line": 16, + }, + "start": Object { + "column": 8, + "line": 16, + }, + }, + "params": Array [], + "range": Array [ + 274, + 279, + ], + "type": "FunctionExpression", + }, + }, ], "loc": Object { "end": Object { "column": 1, - "line": 16, + "line": 17, }, "start": Object { "column": 8, @@ -24776,7 +24880,7 @@ Object { }, "range": Array [ 119, - 267, + 281, ], "type": "ClassBody", }, @@ -24801,7 +24905,7 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 16, + "line": 17, }, "start": Object { "column": 0, @@ -24810,7 +24914,7 @@ Object { }, "range": Array [ 111, - 267, + 281, ], "superClass": null, "type": "ClassDeclaration", @@ -24819,7 +24923,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 17, + "line": 18, }, "start": Object { "column": 0, @@ -24828,7 +24932,7 @@ Object { }, "range": Array [ 0, - 268, + 282, ], "sourceType": "script", "tokens": Array [ @@ -26545,17 +26649,197 @@ Object { Object { "loc": Object { "end": Object { - "column": 1, + "column": 3, "line": 16, }, "start": Object { - "column": 0, + "column": 2, "line": 16, }, }, "range": Array [ - 266, - 267, + 268, + 269, + ], + "type": "Punctuator", + "value": "[", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 16, + }, + "start": Object { + "column": 3, + "line": 16, + }, + }, + "range": Array [ + 269, + 270, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 16, + }, + "start": Object { + "column": 4, + "line": 16, + }, + }, + "range": Array [ + 270, + 271, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 16, + }, + "start": Object { + "column": 5, + "line": 16, + }, + }, + "range": Array [ + 271, + 272, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 16, + }, + "start": Object { + "column": 6, + "line": 16, + }, + }, + "range": Array [ + 272, + 273, + ], + "type": "Punctuator", + "value": "]", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 16, + }, + "start": Object { + "column": 7, + "line": 16, + }, + }, + "range": Array [ + 273, + 274, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 16, + }, + "start": Object { + "column": 8, + "line": 16, + }, + }, + "range": Array [ + 274, + 275, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 16, + }, + "start": Object { + "column": 9, + "line": 16, + }, + }, + "range": Array [ + 275, + 276, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 16, + }, + "start": Object { + "column": 11, + "line": 16, + }, + }, + "range": Array [ + 277, + 278, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 16, + }, + "start": Object { + "column": 12, + "line": 16, + }, + }, + "range": Array [ + 278, + 279, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 17, + }, + "start": Object { + "column": 0, + "line": 17, + }, + }, + "range": Array [ + 280, + 281, ], "type": "Punctuator", "value": "}", @@ -26940,7 +27224,6 @@ Object { }, }, "name": "foo", - "optional": true, "range": Array [ 14, 17, @@ -26958,6 +27241,7 @@ Object { "line": 2, }, }, + "optional": true, "range": Array [ 14, 21, @@ -27002,7 +27286,6 @@ Object { }, }, "name": "bar", - "optional": true, "range": Array [ 24, 27, @@ -27020,6 +27303,7 @@ Object { "line": 3, }, }, + "optional": true, "range": Array [ 24, 39, @@ -27099,7 +27383,6 @@ Object { }, }, "name": "baz", - "optional": true, "range": Array [ 50, 53, @@ -27117,6 +27400,7 @@ Object { "line": 4, }, }, + "optional": true, "range": Array [ 42, 65, @@ -40959,7 +41243,6 @@ Object { }, }, "name": "bar", - "optional": true, "range": Array [ 24, 27, @@ -40977,6 +41260,7 @@ Object { "line": 2, }, }, + "optional": true, "range": Array [ 24, 36, From 9e23b4b1eb3283bac381cbec8a800cc3da4b9d77 Mon Sep 17 00:00:00 2001 From: Armano Date: Mon, 13 Jan 2020 22:12:18 +0100 Subject: [PATCH 4/5] feat(typescript-estree): reduce noise --- packages/typescript-estree/src/ts-estree/ts-estree.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/typescript-estree/src/ts-estree/ts-estree.ts b/packages/typescript-estree/src/ts-estree/ts-estree.ts index 8de10a20de21..514ea6e05a74 100644 --- a/packages/typescript-estree/src/ts-estree/ts-estree.ts +++ b/packages/typescript-estree/src/ts-estree/ts-estree.ts @@ -703,26 +703,26 @@ interface TSMethodSignatureBase extends BaseNode { key: PropertyName; computed: boolean; params: Parameter[]; + optional?: boolean; returnType?: TSTypeAnnotation; + readonly?: boolean; typeParameters?: TSTypeParameterDeclaration; accessibility?: Accessibility; - readonly?: boolean; export?: boolean; static?: boolean; - optional?: boolean; } interface TSPropertySignatureBase extends BaseNode { type: AST_NODE_TYPES.TSPropertySignature; key: PropertyName; + optional?: boolean; computed: boolean; typeAnnotation?: TSTypeAnnotation; initializer?: Expression; - accessibility?: Accessibility; readonly?: boolean; - export?: boolean; static?: boolean; - optional?: boolean; + export?: boolean; + accessibility?: Accessibility; } interface UnaryExpressionBase extends BaseNode { From 048a13304003bb78cdbe3f5b4818c672bfdd342a Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sat, 9 May 2020 18:32:18 -0700 Subject: [PATCH 5/5] test: snaps --- .../lib/__snapshots__/scope-analysis.ts.snap | 548 +++----------- .../lib/__snapshots__/typescript.ts.snap | 692 +++--------------- 2 files changed, 209 insertions(+), 1031 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap index 6062862165d9..78db01bfd950 100644 --- a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap @@ -205,7 +205,7 @@ Object { exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/abstract-class.ts 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -215,7 +215,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -225,7 +225,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 0, @@ -233,55 +233,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 56, - 66, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "A": Object { @@ -289,7 +248,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -329,7 +288,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -341,7 +300,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "A": Object { @@ -349,7 +308,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -389,7 +348,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -403,7 +362,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], } @@ -7385,7 +7344,7 @@ Object { exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/method-overload.ts 1`] = ` Object { - "$id": 16, + "$id": 11, "block": Object { "range": Array [ 0, @@ -7395,7 +7354,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 15, + "$id": 10, "block": Object { "range": Array [ 0, @@ -7405,7 +7364,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 14, + "$id": 9, "block": Object { "range": Array [ 19, @@ -7415,154 +7374,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 6, - "block": Object { - "range": Array [ - 34, - 42, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 14, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 5, - }, - }, - "variableScope": Object { - "$ref": 6, - }, - "variables": Array [ - Object { - "$id": 5, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 6, - }, - }, - ], - }, - Object { - "$id": 10, - "block": Object { - "range": Array [ - 48, - 67, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [ - Object { - "$id": 9, - "from": Object { - "$ref": 10, - }, - "identifier": Object { - "name": "s", - "range": Array [ - 59, - 60, - ], - "type": "Identifier", - }, - "kind": "r", - "resolved": Object { - "$ref": 0, - }, - "writeExpr": undefined, - }, - ], - "throughReferences": Array [ - Object { - "$ref": 9, - }, - ], - "type": "function", - "upperScope": Object { - "$ref": 14, - }, - "variableMap": Object { - "a": Object { - "$ref": 8, - }, - "arguments": Object { - "$ref": 7, - }, - }, - "variableScope": Object { - "$ref": 10, - }, - "variables": Array [ - Object { - "$id": 7, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 10, - }, - }, - Object { - "$id": 8, - "defs": Array [ - Object { - "name": Object { - "name": "a", - "range": Array [ - 49, - 60, - ], - "type": "Identifier", - }, - "node": Object { - "range": Array [ - 48, - 67, - ], - "type": "FunctionExpression", - }, - "parent": null, - "type": "Parameter", - }, - ], - "eslintUsed": undefined, - "identifiers": Array [ - Object { - "name": "a", - "range": Array [ - 49, - 60, - ], - "type": "Identifier", - }, - ], - "name": "a", - "references": Array [], - "scope": Object { - "$ref": 10, - }, - }, - ], - }, - Object { - "$id": 13, + "$id": 8, "block": Object { "range": Array [ 73, @@ -7577,33 +7389,33 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 14, + "$ref": 9, }, "variableMap": Object { "a": Object { - "$ref": 12, + "$ref": 7, }, "arguments": Object { - "$ref": 11, + "$ref": 6, }, }, "variableScope": Object { - "$ref": 13, + "$ref": 8, }, "variables": Array [ Object { - "$id": 11, + "$id": 6, "defs": Array [], "eslintUsed": undefined, "identifiers": Array [], "name": "arguments", "references": Array [], "scope": Object { - "$ref": 13, + "$ref": 8, }, }, Object { - "$id": 12, + "$id": 7, "defs": Array [ Object { "name": Object { @@ -7639,7 +7451,7 @@ Object { "name": "a", "references": Array [], "scope": Object { - "$ref": 13, + "$ref": 8, }, }, ], @@ -7647,15 +7459,35 @@ Object { ], "functionExpressionScope": false, "isStrict": true, - "references": Array [], + "references": Array [ + Object { + "$id": 5, + "from": Object { + "$ref": 9, + }, + "identifier": Object { + "name": "s", + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": undefined, + }, + ], "throughReferences": Array [ Object { - "$ref": 9, + "$ref": 5, }, ], "type": "class", "upperScope": Object { - "$ref": 15, + "$ref": 10, }, "variableMap": Object { "A": Object { @@ -7663,7 +7495,7 @@ Object { }, }, "variableScope": Object { - "$ref": 15, + "$ref": 10, }, "variables": Array [ Object { @@ -7703,7 +7535,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 14, + "$ref": 9, }, }, ], @@ -7715,7 +7547,7 @@ Object { Object { "$id": 2, "from": Object { - "$ref": 15, + "$ref": 10, }, "identifier": Object { "name": "s", @@ -7740,7 +7572,7 @@ Object { Object { "$id": 3, "from": Object { - "$ref": 15, + "$ref": 10, }, "identifier": Object { "name": "Symbol", @@ -7762,7 +7594,7 @@ Object { ], "type": "module", "upperScope": Object { - "$ref": 16, + "$ref": 11, }, "variableMap": Object { "A": Object { @@ -7773,7 +7605,7 @@ Object { }, }, "variableScope": Object { - "$ref": 15, + "$ref": 10, }, "variables": Array [ Object { @@ -7822,11 +7654,11 @@ Object { "$ref": 2, }, Object { - "$ref": 9, + "$ref": 5, }, ], "scope": Object { - "$ref": 15, + "$ref": 10, }, }, Object { @@ -7866,7 +7698,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 15, + "$ref": 10, }, }, ], @@ -7884,7 +7716,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 16, + "$ref": 11, }, "variables": Array [], } @@ -13292,7 +13124,7 @@ Object { exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/abstract-class.ts 1`] = ` Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -13302,7 +13134,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 0, @@ -13310,55 +13142,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 56, - 66, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "A": Object { @@ -13366,7 +13157,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -13406,7 +13197,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -13424,7 +13215,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -13464,7 +13255,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -19676,7 +19467,7 @@ Object { exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/method-overload.ts 1`] = ` Object { - "$id": 15, + "$id": 10, "block": Object { "range": Array [ 0, @@ -19686,7 +19477,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 14, + "$id": 9, "block": Object { "range": Array [ 19, @@ -19696,154 +19487,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 6, - "block": Object { - "range": Array [ - 34, - 42, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 14, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 5, - }, - }, - "variableScope": Object { - "$ref": 6, - }, - "variables": Array [ - Object { - "$id": 5, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 6, - }, - }, - ], - }, - Object { - "$id": 10, - "block": Object { - "range": Array [ - 48, - 67, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [ - Object { - "$id": 9, - "from": Object { - "$ref": 10, - }, - "identifier": Object { - "name": "s", - "range": Array [ - 59, - 60, - ], - "type": "Identifier", - }, - "kind": "r", - "resolved": Object { - "$ref": 0, - }, - "writeExpr": undefined, - }, - ], - "throughReferences": Array [ - Object { - "$ref": 9, - }, - ], - "type": "function", - "upperScope": Object { - "$ref": 14, - }, - "variableMap": Object { - "a": Object { - "$ref": 8, - }, - "arguments": Object { - "$ref": 7, - }, - }, - "variableScope": Object { - "$ref": 10, - }, - "variables": Array [ - Object { - "$id": 7, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 10, - }, - }, - Object { - "$id": 8, - "defs": Array [ - Object { - "name": Object { - "name": "a", - "range": Array [ - 49, - 60, - ], - "type": "Identifier", - }, - "node": Object { - "range": Array [ - 48, - 67, - ], - "type": "FunctionExpression", - }, - "parent": null, - "type": "Parameter", - }, - ], - "eslintUsed": undefined, - "identifiers": Array [ - Object { - "name": "a", - "range": Array [ - 49, - 60, - ], - "type": "Identifier", - }, - ], - "name": "a", - "references": Array [], - "scope": Object { - "$ref": 10, - }, - }, - ], - }, - Object { - "$id": 13, + "$id": 8, "block": Object { "range": Array [ 73, @@ -19858,33 +19502,33 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 14, + "$ref": 9, }, "variableMap": Object { "a": Object { - "$ref": 12, + "$ref": 7, }, "arguments": Object { - "$ref": 11, + "$ref": 6, }, }, "variableScope": Object { - "$ref": 13, + "$ref": 8, }, "variables": Array [ Object { - "$id": 11, + "$id": 6, "defs": Array [], "eslintUsed": undefined, "identifiers": Array [], "name": "arguments", "references": Array [], "scope": Object { - "$ref": 13, + "$ref": 8, }, }, Object { - "$id": 12, + "$id": 7, "defs": Array [ Object { "name": Object { @@ -19920,7 +19564,7 @@ Object { "name": "a", "references": Array [], "scope": Object { - "$ref": 13, + "$ref": 8, }, }, ], @@ -19928,15 +19572,35 @@ Object { ], "functionExpressionScope": false, "isStrict": true, - "references": Array [], + "references": Array [ + Object { + "$id": 5, + "from": Object { + "$ref": 9, + }, + "identifier": Object { + "name": "s", + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": Object { + "$ref": 0, + }, + "writeExpr": undefined, + }, + ], "throughReferences": Array [ Object { - "$ref": 9, + "$ref": 5, }, ], "type": "class", "upperScope": Object { - "$ref": 15, + "$ref": 10, }, "variableMap": Object { "A": Object { @@ -19944,7 +19608,7 @@ Object { }, }, "variableScope": Object { - "$ref": 15, + "$ref": 10, }, "variables": Array [ Object { @@ -19984,7 +19648,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 14, + "$ref": 9, }, }, ], @@ -19996,7 +19660,7 @@ Object { Object { "$id": 2, "from": Object { - "$ref": 15, + "$ref": 10, }, "identifier": Object { "name": "s", @@ -20021,7 +19685,7 @@ Object { Object { "$id": 3, "from": Object { - "$ref": 15, + "$ref": 10, }, "identifier": Object { "name": "Symbol", @@ -20052,7 +19716,7 @@ Object { }, }, "variableScope": Object { - "$ref": 15, + "$ref": 10, }, "variables": Array [ Object { @@ -20101,11 +19765,11 @@ Object { "$ref": 2, }, Object { - "$ref": 9, + "$ref": 5, }, ], "scope": Object { - "$ref": 15, + "$ref": 10, }, }, Object { @@ -20145,7 +19809,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 15, + "$ref": 10, }, }, ], diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 53abd7a380de..1b4db33ae920 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -274,7 +274,7 @@ Object { exports[`typescript fixtures/basics/abstract-class-with-abstract-constructor.src 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -284,7 +284,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -294,7 +294,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 7, @@ -302,55 +302,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 63, - 66, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "AbstractSocket": Object { @@ -358,7 +317,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -398,7 +357,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -410,7 +369,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "AbstractSocket": Object { @@ -418,7 +377,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -458,7 +417,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -472,7 +431,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], } @@ -480,7 +439,7 @@ Object { exports[`typescript fixtures/basics/abstract-class-with-abstract-method.src 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -490,7 +449,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -500,7 +459,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 7, @@ -508,55 +467,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 64, - 84, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "AbstractSocket": Object { @@ -564,7 +482,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -604,7 +522,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -616,7 +534,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "AbstractSocket": Object { @@ -624,7 +542,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -664,7 +582,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -678,7 +596,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], } @@ -1016,7 +934,7 @@ Object { exports[`typescript fixtures/basics/abstract-class-with-abstract-static-constructor.src 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -1026,7 +944,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -1036,7 +954,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 7, @@ -1044,55 +962,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 68, - 71, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "AbstractSocket": Object { @@ -1100,7 +977,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -1140,7 +1017,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -1152,7 +1029,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "AbstractSocket": Object { @@ -1160,7 +1037,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -1200,7 +1077,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -1214,7 +1091,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], } @@ -1387,7 +1264,7 @@ Object { exports[`typescript fixtures/basics/abstract-class-with-optional-method.src 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -1397,7 +1274,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -1407,7 +1284,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 7, @@ -1415,55 +1292,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 56, - 76, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "AbstractSocket": Object { @@ -1471,7 +1307,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -1511,7 +1347,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -1523,7 +1359,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "AbstractSocket": Object { @@ -1531,7 +1367,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -1571,7 +1407,7 @@ Object { "name": "AbstractSocket", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -1585,7 +1421,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], } @@ -8315,7 +8151,7 @@ Object { exports[`typescript fixtures/basics/class-with-optional-computed-method.src 1`] = ` Object { - "$id": 33, + "$id": 25, "block": Object { "range": Array [ 0, @@ -8325,7 +8161,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 32, + "$id": 24, "block": Object { "range": Array [ 0, @@ -8335,7 +8171,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 31, + "$id": 23, "block": Object { "range": Array [ 111, @@ -8348,9 +8184,9 @@ Object { "$id": 14, "block": Object { "range": Array [ - 135, - 138, - ], + 153, + 158, + ], "type": "FunctionExpression", }, "childScopes": Array [], @@ -8360,7 +8196,7 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 31, + "$ref": 23, }, "variableMap": Object { "arguments": Object { @@ -8388,8 +8224,8 @@ Object { "$id": 16, "block": Object { "range": Array [ - 153, - 158, + 176, + 181, ], "type": "FunctionExpression", }, @@ -8400,7 +8236,7 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 31, + "$ref": 23, }, "variableMap": Object { "arguments": Object { @@ -8428,8 +8264,8 @@ Object { "$id": 18, "block": Object { "range": Array [ - 166, - 169, + 217, + 222, ], "type": "FunctionExpression", }, @@ -8440,7 +8276,7 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 31, + "$ref": 23, }, "variableMap": Object { "arguments": Object { @@ -8468,8 +8304,8 @@ Object { "$id": 20, "block": Object { "range": Array [ - 176, - 181, + 239, + 244, ], "type": "FunctionExpression", }, @@ -8480,7 +8316,7 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 31, + "$ref": 23, }, "variableMap": Object { "arguments": Object { @@ -8508,8 +8344,8 @@ Object { "$id": 22, "block": Object { "range": Array [ - 198, - 201, + 274, + 279, ], "type": "FunctionExpression", }, @@ -8520,7 +8356,7 @@ Object { "throughReferences": Array [], "type": "function", "upperScope": Object { - "$ref": 31, + "$ref": 23, }, "variableMap": Object { "arguments": Object { @@ -8544,166 +8380,6 @@ Object { }, ], }, - Object { - "$id": 24, - "block": Object { - "range": Array [ - 217, - 222, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 31, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 23, - }, - }, - "variableScope": Object { - "$ref": 24, - }, - "variables": Array [ - Object { - "$id": 23, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 24, - }, - }, - ], - }, - Object { - "$id": 26, - "block": Object { - "range": Array [ - 239, - 244, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 31, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 25, - }, - }, - "variableScope": Object { - "$ref": 26, - }, - "variables": Array [ - Object { - "$id": 25, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 26, - }, - }, - ], - }, - Object { - "$id": 28, - "block": Object { - "range": Array [ - 262, - 265, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 31, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 27, - }, - }, - "variableScope": Object { - "$ref": 28, - }, - "variables": Array [ - Object { - "$id": 27, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 28, - }, - }, - ], - }, - Object { - "$id": 30, - "block": Object { - "range": Array [ - 274, - 279, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 31, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 29, - }, - }, - "variableScope": Object { - "$ref": 30, - }, - "variables": Array [ - Object { - "$id": 29, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 30, - }, - }, - ], - }, ], "functionExpressionScope": false, "isStrict": true, @@ -8711,7 +8387,7 @@ Object { Object { "$id": 8, "from": Object { - "$ref": 31, + "$ref": 23, }, "identifier": Object { "name": "computed1", @@ -8730,7 +8406,7 @@ Object { Object { "$id": 9, "from": Object { - "$ref": 31, + "$ref": 23, }, "identifier": Object { "name": "computed2", @@ -8749,7 +8425,7 @@ Object { Object { "$id": 10, "from": Object { - "$ref": 31, + "$ref": 23, }, "identifier": Object { "name": "obj", @@ -8768,7 +8444,7 @@ Object { Object { "$id": 11, "from": Object { - "$ref": 31, + "$ref": 23, }, "identifier": Object { "name": "obj", @@ -8787,7 +8463,7 @@ Object { Object { "$id": 12, "from": Object { - "$ref": 31, + "$ref": 23, }, "identifier": Object { "name": "f", @@ -8821,7 +8497,7 @@ Object { ], "type": "class", "upperScope": Object { - "$ref": 32, + "$ref": 24, }, "variableMap": Object { "X": Object { @@ -8829,7 +8505,7 @@ Object { }, }, "variableScope": Object { - "$ref": 32, + "$ref": 24, }, "variables": Array [ Object { @@ -8869,7 +8545,7 @@ Object { "name": "X", "references": Array [], "scope": Object { - "$ref": 31, + "$ref": 23, }, }, ], @@ -8881,7 +8557,7 @@ Object { Object { "$id": 4, "from": Object { - "$ref": 32, + "$ref": 24, }, "identifier": Object { "name": "computed1", @@ -8906,7 +8582,7 @@ Object { Object { "$id": 5, "from": Object { - "$ref": 32, + "$ref": 24, }, "identifier": Object { "name": "computed2", @@ -8931,7 +8607,7 @@ Object { Object { "$id": 6, "from": Object { - "$ref": 32, + "$ref": 24, }, "identifier": Object { "name": "obj", @@ -8961,7 +8637,7 @@ Object { ], "type": "module", "upperScope": Object { - "$ref": 33, + "$ref": 25, }, "variableMap": Object { "X": Object { @@ -8978,7 +8654,7 @@ Object { }, }, "variableScope": Object { - "$ref": 32, + "$ref": 24, }, "variables": Array [ Object { @@ -9031,7 +8707,7 @@ Object { }, ], "scope": Object { - "$ref": 32, + "$ref": 24, }, }, Object { @@ -9084,7 +8760,7 @@ Object { }, ], "scope": Object { - "$ref": 32, + "$ref": 24, }, }, Object { @@ -9140,7 +8816,7 @@ Object { }, ], "scope": Object { - "$ref": 32, + "$ref": 24, }, }, Object { @@ -9180,7 +8856,7 @@ Object { "name": "X", "references": Array [], "scope": Object { - "$ref": 32, + "$ref": 24, }, }, ], @@ -9198,7 +8874,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 33, + "$ref": 25, }, "variables": Array [], } @@ -9401,7 +9077,7 @@ Object { exports[`typescript fixtures/basics/class-with-optional-methods.src 1`] = ` Object { - "$id": 10, + "$id": 4, "block": Object { "range": Array [ 0, @@ -9411,7 +9087,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 9, + "$id": 3, "block": Object { "range": Array [ 0, @@ -9421,7 +9097,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 8, + "$id": 2, "block": Object { "range": Array [ 0, @@ -9429,135 +9105,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 18, - 21, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 8, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - Object { - "$id": 5, - "block": Object { - "range": Array [ - 28, - 39, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 8, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 4, - }, - }, - "variableScope": Object { - "$ref": 5, - }, - "variables": Array [ - Object { - "$id": 4, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 5, - }, - }, - ], - }, - Object { - "$id": 7, - "block": Object { - "range": Array [ - 54, - 65, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 8, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 6, - }, - }, - "variableScope": Object { - "$ref": 7, - }, - "variables": Array [ - Object { - "$id": 6, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 7, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 9, + "$ref": 3, }, "variableMap": Object { "Foo": Object { @@ -9565,7 +9120,7 @@ Object { }, }, "variableScope": Object { - "$ref": 9, + "$ref": 3, }, "variables": Array [ Object { @@ -9605,7 +9160,7 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 8, + "$ref": 2, }, }, ], @@ -9617,7 +9172,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 10, + "$ref": 4, }, "variableMap": Object { "Foo": Object { @@ -9625,7 +9180,7 @@ Object { }, }, "variableScope": Object { - "$ref": 9, + "$ref": 3, }, "variables": Array [ Object { @@ -9665,7 +9220,7 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 9, + "$ref": 3, }, }, ], @@ -9679,7 +9234,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 10, + "$ref": 4, }, "variables": Array [], } @@ -14195,7 +13750,7 @@ Object { exports[`typescript fixtures/basics/declare-class-with-optional-method.src 1`] = ` Object { - "$id": 6, + "$id": 4, "block": Object { "range": Array [ 0, @@ -14205,7 +13760,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 5, + "$id": 3, "block": Object { "range": Array [ 0, @@ -14215,7 +13770,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 4, + "$id": 2, "block": Object { "range": Array [ 0, @@ -14223,55 +13778,14 @@ Object { ], "type": "ClassDeclaration", }, - "childScopes": Array [ - Object { - "$id": 3, - "block": Object { - "range": Array [ - 28, - 36, - ], - "type": "FunctionExpression", - }, - "childScopes": Array [], - "functionExpressionScope": false, - "isStrict": true, - "references": Array [], - "throughReferences": Array [], - "type": "function", - "upperScope": Object { - "$ref": 4, - }, - "variableMap": Object { - "arguments": Object { - "$ref": 2, - }, - }, - "variableScope": Object { - "$ref": 3, - }, - "variables": Array [ - Object { - "$id": 2, - "defs": Array [], - "eslintUsed": undefined, - "identifiers": Array [], - "name": "arguments", - "references": Array [], - "scope": Object { - "$ref": 3, - }, - }, - ], - }, - ], + "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, "references": Array [], "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 5, + "$ref": 3, }, "variableMap": Object { "Foo": Object { @@ -14279,7 +13793,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -14319,7 +13833,7 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 4, + "$ref": 2, }, }, ], @@ -14331,7 +13845,7 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 6, + "$ref": 4, }, "variableMap": Object { "Foo": Object { @@ -14339,7 +13853,7 @@ Object { }, }, "variableScope": Object { - "$ref": 5, + "$ref": 3, }, "variables": Array [ Object { @@ -14379,7 +13893,7 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 5, + "$ref": 3, }, }, ], @@ -14393,7 +13907,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 6, + "$ref": 4, }, "variables": Array [], }