From 0852b673fdc76de8a12c1ad15de449d985787035 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 23 Jan 2019 00:02:44 +0100 Subject: [PATCH 1/2] test(ts-estree): test cases for comments in parameters --- .../lib/__snapshots__/typescript.ts.snap | 2113 +++++++++++++++++ .../type-parameters-comments-heritage.src.ts | 4 + .../tests/ast-alignment/fixtures-to-test.ts | 1 + .../semantic-diagnostics-enabled.ts.snap | 2 + .../lib/__snapshots__/typescript.ts.snap | 1787 ++++++++++++++ 5 files changed, 3907 insertions(+) create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 046f4e2081a2..745b2faf112f 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -66551,6 +66551,2119 @@ Object { } `; +exports[`typescript fixtures/basics/type-parameters-comments-heritage.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 72, + "line": 1, + }, + }, + "range": Array [ + 72, + 74, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 74, + ], + "superClass": Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 43, + "line": 1, + }, + }, + "name": "bar", + "range": Array [ + 43, + 46, + ], + "type": "Identifier", + }, + "superTypeParameters": Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 47, + 61, + ], + "type": "TSTypeParameterInstantiation", + }, + "type": "ClassDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 22, + 23, + ], + "type": "Identifier", + }, + "range": Array [ + 22, + 23, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 10, + 34, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 87, + "line": 2, + }, + }, + "range": Array [ + 162, + 164, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "foo2", + "range": Array [ + 81, + 85, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 75, + 164, + ], + "superClass": Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 2, + }, + "start": Object { + "column": 58, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 133, + 136, + ], + "type": "Identifier", + }, + "superTypeParameters": Object { + "loc": Object { + "end": Object { + "column": 76, + "line": 2, + }, + "start": Object { + "column": 62, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "range": Array [ + 149, + 150, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "name": "A", + "range": Array [ + 149, + 150, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 137, + 151, + ], + "type": "TSTypeParameterInstantiation", + }, + "type": "ClassDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "params": Array [ + Object { + "default": Object { + "literal": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "TSLiteralType", + }, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "A", + "range": Array [ + 98, + 99, + ], + "type": "Identifier", + }, + "range": Array [ + 98, + 113, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 86, + 124, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 77, + "line": 3, + }, + }, + "range": Array [ + 242, + 244, + ], + "type": "TSInterfaceBody", + }, + "extends": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 51, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "name": "bar2", + "range": Array [ + 212, + 216, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 76, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "range": Array [ + 212, + 241, + ], + "type": "TSInterfaceHeritage", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 66, + "line": 3, + }, + "start": Object { + "column": 52, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "range": Array [ + 229, + 230, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "name": "A", + "range": Array [ + 229, + 230, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 217, + 231, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "name": "bar", + "range": Array [ + 175, + 178, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 165, + 244, + ], + "type": "TSInterfaceDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "A", + "range": Array [ + 191, + 192, + ], + "type": "Identifier", + }, + "range": Array [ + 191, + 192, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 179, + 203, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 91, + "line": 4, + }, + }, + "range": Array [ + 336, + 338, + ], + "type": "TSInterfaceBody", + }, + "extends": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "name": "bar", + "range": Array [ + 307, + 310, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 90, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "range": Array [ + 307, + 335, + ], + "type": "TSInterfaceHeritage", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 80, + "line": 4, + }, + "start": Object { + "column": 66, + "line": 4, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "range": Array [ + 323, + 324, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "name": "A", + "range": Array [ + 323, + 324, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 311, + 325, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "name": "bar2", + "range": Array [ + 255, + 259, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 245, + 338, + ], + "type": "TSInterfaceDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "params": Array [ + Object { + "default": Object { + "literal": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "type": "TSLiteralType", + }, + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "name": "A", + "range": Array [ + 272, + 273, + ], + "type": "Identifier", + }, + "range": Array [ + 272, + 287, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 260, + 298, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "comments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 21, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 33, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 58, + "line": 1, + }, + "start": Object { + "column": 49, + "line": 1, + }, + }, + "range": Array [ + 49, + 58, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 70, + "line": 1, + }, + "start": Object { + "column": 61, + "line": 1, + }, + }, + "range": Array [ + 61, + 70, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 88, + 97, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 25, + "line": 2, + }, + }, + "range": Array [ + 100, + 109, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 2, + }, + "start": Object { + "column": 39, + "line": 2, + }, + }, + "range": Array [ + 114, + 123, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 73, + "line": 2, + }, + "start": Object { + "column": 64, + "line": 2, + }, + }, + "range": Array [ + 139, + 148, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 85, + "line": 2, + }, + "start": Object { + "column": 76, + "line": 2, + }, + }, + "range": Array [ + 151, + 160, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "range": Array [ + 181, + 190, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "range": Array [ + 193, + 202, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 63, + "line": 3, + }, + "start": Object { + "column": 54, + "line": 3, + }, + }, + "range": Array [ + 219, + 228, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 3, + }, + "start": Object { + "column": 66, + "line": 3, + }, + }, + "range": Array [ + 231, + 240, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 4, + }, + "start": Object { + "column": 17, + "line": 4, + }, + }, + "range": Array [ + 262, + 271, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 4, + }, + "start": Object { + "column": 29, + "line": 4, + }, + }, + "range": Array [ + 274, + 283, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 52, + "line": 4, + }, + "start": Object { + "column": 43, + "line": 4, + }, + }, + "range": Array [ + 288, + 297, + ], + "type": "Block", + "value": " bbb ", + }, + Object { + "loc": Object { + "end": Object { + "column": 77, + "line": 4, + }, + "start": Object { + "column": 68, + "line": 4, + }, + }, + "range": Array [ + 313, + 322, + ], + "type": "Block", + "value": " aaa ", + }, + Object { + "loc": Object { + "end": Object { + "column": 89, + "line": 4, + }, + "start": Object { + "column": 80, + "line": 4, + }, + }, + "range": Array [ + 325, + 334, + ], + "type": "Block", + "value": " bbb ", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 339, + ], + "sourceType": "module", + "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": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 33, + "line": 1, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 43, + "line": 1, + }, + }, + "range": Array [ + 43, + 46, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 71, + "line": 1, + }, + "start": Object { + "column": 70, + "line": 1, + }, + }, + "range": Array [ + 70, + 71, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 73, + "line": 1, + }, + "start": Object { + "column": 72, + "line": 1, + }, + }, + "range": Array [ + 72, + 73, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 73, + "line": 1, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 75, + 80, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "Identifier", + "value": "foo2", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 86, + 87, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 98, + 99, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 110, + 111, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 48, + "line": 2, + }, + }, + "range": Array [ + 123, + 124, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "range": Array [ + 125, + 132, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 2, + }, + "start": Object { + "column": 58, + "line": 2, + }, + }, + "range": Array [ + 133, + 136, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 63, + "line": 2, + }, + "start": Object { + "column": 62, + "line": 2, + }, + }, + "range": Array [ + 137, + 138, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "range": Array [ + 149, + 150, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 86, + "line": 2, + }, + "start": Object { + "column": 85, + "line": 2, + }, + }, + "range": Array [ + 160, + 161, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 88, + "line": 2, + }, + "start": Object { + "column": 87, + "line": 2, + }, + }, + "range": Array [ + 162, + 163, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 88, + "line": 2, + }, + }, + "range": Array [ + 163, + 164, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 165, + 174, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 175, + 178, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 179, + 180, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "range": Array [ + 191, + 192, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 202, + 203, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 204, + 211, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 51, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "range": Array [ + 212, + 216, + ], + "type": "Identifier", + "value": "bar2", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 3, + }, + "start": Object { + "column": 52, + "line": 3, + }, + }, + "range": Array [ + 217, + 218, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "range": Array [ + 229, + 230, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 76, + "line": 3, + }, + "start": Object { + "column": 75, + "line": 3, + }, + }, + "range": Array [ + 240, + 241, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 78, + "line": 3, + }, + "start": Object { + "column": 77, + "line": 3, + }, + }, + "range": Array [ + 242, + 243, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 78, + "line": 3, + }, + }, + "range": Array [ + 243, + 244, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 245, + 254, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 255, + 259, + ], + "type": "Identifier", + "value": "bar2", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "range": Array [ + 260, + 261, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "range": Array [ + 272, + 273, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 40, + "line": 4, + }, + "start": Object { + "column": 39, + "line": 4, + }, + }, + "range": Array [ + 284, + 285, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 4, + }, + "start": Object { + "column": 52, + "line": 4, + }, + }, + "range": Array [ + 297, + 298, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 4, + }, + "start": Object { + "column": 54, + "line": 4, + }, + }, + "range": Array [ + 299, + 306, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "range": Array [ + 307, + 310, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 67, + "line": 4, + }, + "start": Object { + "column": 66, + "line": 4, + }, + }, + "range": Array [ + 311, + 312, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "range": Array [ + 323, + 324, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 90, + "line": 4, + }, + "start": Object { + "column": 89, + "line": 4, + }, + }, + "range": Array [ + 334, + 335, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 92, + "line": 4, + }, + "start": Object { + "column": 91, + "line": 4, + }, + }, + "range": Array [ + 336, + 337, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 92, + "line": 4, + }, + }, + "range": Array [ + 337, + 338, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/type-reference-comments.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts new file mode 100644 index 000000000000..986f4826089f --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts @@ -0,0 +1,4 @@ +class foo < /* aaa */ A /* bbb */> extends bar < /* aaa */ A /* bbb */> {} +class foo2 < /* aaa */ A /* bbb */ = 2 /* bbb */> extends bar < /* aaa */ A /* bbb */> {} +interface bar < /* aaa */ A /* bbb */> extends bar2 < /* aaa */ A /* bbb */> {} +interface bar2 < /* aaa */ A /* bbb */ = 2 /* bbb */> extends bar < /* aaa */ A /* bbb */> {} 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 3b1a21e43d80..2924ac8f5f6e 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -328,6 +328,7 @@ tester.addFixturePatternConfig('typescript/basics', { */ 'export-declare-const-named-enum', 'interface-with-optional-properties', + 'type-parameters-comments-heritage', /** * Babel parses it as TSQualifiedName * ts parses it as MemberExpression 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 dfd7dbf783d0..e7254e6b15fb 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 @@ -2120,6 +2120,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-parameters-comments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-parameters-comments-heritage.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-reference-comments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/typed-keyword-bigint.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 6341ffcd7d74..49f647abc3d6 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -66263,6 +66263,1793 @@ Object { } `; +exports[`typescript fixtures/basics/type-parameters-comments-heritage.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 72, + "line": 1, + }, + }, + "range": Array [ + 72, + 74, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 74, + ], + "superClass": Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 43, + "line": 1, + }, + }, + "name": "bar", + "range": Array [ + 43, + 46, + ], + "type": "Identifier", + }, + "superTypeParameters": Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 47, + 61, + ], + "type": "TSTypeParameterInstantiation", + }, + "type": "ClassDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 22, + 23, + ], + "type": "Identifier", + }, + "range": Array [ + 22, + 23, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 10, + 34, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 87, + "line": 2, + }, + }, + "range": Array [ + 162, + 164, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "foo2", + "range": Array [ + 81, + 85, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 75, + 164, + ], + "superClass": Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 2, + }, + "start": Object { + "column": 58, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 133, + 136, + ], + "type": "Identifier", + }, + "superTypeParameters": Object { + "loc": Object { + "end": Object { + "column": 76, + "line": 2, + }, + "start": Object { + "column": 62, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "range": Array [ + 149, + 150, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "name": "A", + "range": Array [ + 149, + 150, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 137, + 151, + ], + "type": "TSTypeParameterInstantiation", + }, + "type": "ClassDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "params": Array [ + Object { + "default": Object { + "literal": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "TSLiteralType", + }, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "A", + "range": Array [ + 98, + 99, + ], + "type": "Identifier", + }, + "range": Array [ + 98, + 113, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 86, + 124, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 77, + "line": 3, + }, + }, + "range": Array [ + 242, + 244, + ], + "type": "TSInterfaceBody", + }, + "extends": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 51, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "name": "bar2", + "range": Array [ + 212, + 216, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 76, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "range": Array [ + 212, + 241, + ], + "type": "TSInterfaceHeritage", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 66, + "line": 3, + }, + "start": Object { + "column": 52, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "range": Array [ + 229, + 230, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "name": "A", + "range": Array [ + 229, + 230, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 217, + 231, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "name": "bar", + "range": Array [ + 175, + 178, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 165, + 244, + ], + "type": "TSInterfaceDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "A", + "range": Array [ + 191, + 192, + ], + "type": "Identifier", + }, + "range": Array [ + 191, + 192, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 179, + 203, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 91, + "line": 4, + }, + }, + "range": Array [ + 336, + 338, + ], + "type": "TSInterfaceBody", + }, + "extends": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "name": "bar", + "range": Array [ + 307, + 310, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 90, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "range": Array [ + 307, + 335, + ], + "type": "TSInterfaceHeritage", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 80, + "line": 4, + }, + "start": Object { + "column": 66, + "line": 4, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "range": Array [ + 323, + 324, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "name": "A", + "range": Array [ + 323, + 324, + ], + "type": "Identifier", + }, + }, + ], + "range": Array [ + 311, + 325, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "name": "bar2", + "range": Array [ + 255, + 259, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 245, + 338, + ], + "type": "TSInterfaceDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "params": Array [ + Object { + "default": Object { + "literal": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "type": "TSLiteralType", + }, + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "name": "A", + "range": Array [ + 272, + 273, + ], + "type": "Identifier", + }, + "range": Array [ + 272, + 287, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 260, + 298, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 339, + ], + "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": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 33, + "line": 1, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 43, + "line": 1, + }, + }, + "range": Array [ + 43, + 46, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 60, + "line": 1, + }, + "start": Object { + "column": 59, + "line": 1, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 71, + "line": 1, + }, + "start": Object { + "column": 70, + "line": 1, + }, + }, + "range": Array [ + 70, + 71, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 73, + "line": 1, + }, + "start": Object { + "column": 72, + "line": 1, + }, + }, + "range": Array [ + 72, + 73, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 74, + "line": 1, + }, + "start": Object { + "column": 73, + "line": 1, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 75, + 80, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "Identifier", + "value": "foo2", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 86, + 87, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 98, + 99, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 110, + 111, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 48, + "line": 2, + }, + }, + "range": Array [ + 123, + 124, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "range": Array [ + 125, + 132, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 2, + }, + "start": Object { + "column": 58, + "line": 2, + }, + }, + "range": Array [ + 133, + 136, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 63, + "line": 2, + }, + "start": Object { + "column": 62, + "line": 2, + }, + }, + "range": Array [ + 137, + 138, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 75, + "line": 2, + }, + "start": Object { + "column": 74, + "line": 2, + }, + }, + "range": Array [ + 149, + 150, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 86, + "line": 2, + }, + "start": Object { + "column": 85, + "line": 2, + }, + }, + "range": Array [ + 160, + 161, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 88, + "line": 2, + }, + "start": Object { + "column": 87, + "line": 2, + }, + }, + "range": Array [ + 162, + 163, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 89, + "line": 2, + }, + "start": Object { + "column": 88, + "line": 2, + }, + }, + "range": Array [ + 163, + 164, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 165, + 174, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 175, + 178, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 179, + 180, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "range": Array [ + 191, + 192, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 202, + 203, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 204, + 211, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 51, + "line": 3, + }, + "start": Object { + "column": 47, + "line": 3, + }, + }, + "range": Array [ + 212, + 216, + ], + "type": "Identifier", + "value": "bar2", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 3, + }, + "start": Object { + "column": 52, + "line": 3, + }, + }, + "range": Array [ + 217, + 218, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 3, + }, + "start": Object { + "column": 64, + "line": 3, + }, + }, + "range": Array [ + 229, + 230, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 76, + "line": 3, + }, + "start": Object { + "column": 75, + "line": 3, + }, + }, + "range": Array [ + 240, + 241, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 78, + "line": 3, + }, + "start": Object { + "column": 77, + "line": 3, + }, + }, + "range": Array [ + 242, + 243, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 3, + }, + "start": Object { + "column": 78, + "line": 3, + }, + }, + "range": Array [ + 243, + 244, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 245, + 254, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 255, + 259, + ], + "type": "Identifier", + "value": "bar2", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "range": Array [ + 260, + 261, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 4, + }, + "start": Object { + "column": 27, + "line": 4, + }, + }, + "range": Array [ + 272, + 273, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 40, + "line": 4, + }, + "start": Object { + "column": 39, + "line": 4, + }, + }, + "range": Array [ + 284, + 285, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 4, + }, + "start": Object { + "column": 41, + "line": 4, + }, + }, + "range": Array [ + 286, + 287, + ], + "type": "Numeric", + "value": "2", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 4, + }, + "start": Object { + "column": 52, + "line": 4, + }, + }, + "range": Array [ + 297, + 298, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 61, + "line": 4, + }, + "start": Object { + "column": 54, + "line": 4, + }, + }, + "range": Array [ + 299, + 306, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 65, + "line": 4, + }, + "start": Object { + "column": 62, + "line": 4, + }, + }, + "range": Array [ + 307, + 310, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 67, + "line": 4, + }, + "start": Object { + "column": 66, + "line": 4, + }, + }, + "range": Array [ + 311, + 312, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 79, + "line": 4, + }, + "start": Object { + "column": 78, + "line": 4, + }, + }, + "range": Array [ + 323, + 324, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 90, + "line": 4, + }, + "start": Object { + "column": 89, + "line": 4, + }, + }, + "range": Array [ + 334, + 335, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 92, + "line": 4, + }, + "start": Object { + "column": 91, + "line": 4, + }, + }, + "range": Array [ + 336, + 337, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 93, + "line": 4, + }, + "start": Object { + "column": 92, + "line": 4, + }, + }, + "range": Array [ + 337, + 338, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/type-reference-comments.src 1`] = ` Object { "body": Array [ From 82490020660d695dbc25a030fce93fbd21f889bc Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 23 Jan 2019 00:14:15 +0100 Subject: [PATCH 2/2] fix(ts-estree): correct range of parameters with comments --- .../lib/__snapshots__/typescript.ts.snap | 16 +++---- packages/typescript-estree/src/convert.ts | 42 ++++--------------- packages/typescript-estree/src/node-utils.ts | 4 +- .../tests/ast-alignment/fixtures-to-test.ts | 1 - .../lib/__snapshots__/typescript.ts.snap | 16 +++---- 5 files changed, 27 insertions(+), 52 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 745b2faf112f..989b484d64bf 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -66626,7 +66626,7 @@ Object { "superTypeParameters": Object { "loc": Object { "end": Object { - "column": 61, + "column": 71, "line": 1, }, "start": Object { @@ -66673,7 +66673,7 @@ Object { ], "range": Array [ 47, - 61, + 71, ], "type": "TSTypeParameterInstantiation", }, @@ -66805,7 +66805,7 @@ Object { "superTypeParameters": Object { "loc": Object { "end": Object { - "column": 76, + "column": 86, "line": 2, }, "start": Object { @@ -66852,7 +66852,7 @@ Object { ], "range": Array [ 137, - 151, + 161, ], "type": "TSTypeParameterInstantiation", }, @@ -67005,7 +67005,7 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 66, + "column": 76, "line": 3, }, "start": Object { @@ -67052,7 +67052,7 @@ Object { ], "range": Array [ 217, - 231, + 241, ], "type": "TSTypeParameterInstantiation", }, @@ -67203,7 +67203,7 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 80, + "column": 90, "line": 4, }, "start": Object { @@ -67250,7 +67250,7 @@ Object { ], "range": Array [ 311, - 325, + 335, ], "type": "TSTypeParameterInstantiation", }, diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index c02a2eece24a..ba292b464c57 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -211,61 +211,37 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { } /** - * Converts a ts.Node's typeArguments ts.NodeArray to a flow-like typeParameters node + * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node * @param {ts.NodeArray} typeArguments ts.Node typeArguments * @returns {ESTreeNode} TypeParameterInstantiation node */ function convertTypeArgumentsToTypeParameters( typeArguments: ts.NodeArray ): ESTreeNode { - /** - * Even if typeArguments is an empty array, TypeScript sets a `pos` and `end` - * property on the array object so we can safely read the values here - */ - const start = typeArguments.pos - 1; - let end = typeArguments.end + 1; - if (typeArguments && typeArguments.length) { - const firstTypeArgument = typeArguments[0]; - const typeArgumentsParent = firstTypeArgument.parent; - /** - * In the case of the parent being a CallExpression or a TypeReference we have to use - * slightly different logic to calculate the correct end position - */ - if ( - typeArgumentsParent && - (typeArgumentsParent.kind === SyntaxKind.CallExpression || - typeArgumentsParent.kind === SyntaxKind.TypeReference) - ) { - const lastTypeArgument = typeArguments[typeArguments.length - 1]; - const greaterThanToken = findNextToken(lastTypeArgument, ast, ast); - end = greaterThanToken!.end; - } - } + const greaterThanToken = findNextToken(typeArguments, ast, ast)!; + return { type: AST_NODE_TYPES.TSTypeParameterInstantiation, - range: [start, end], - loc: getLocFor(start, end, ast), + range: [typeArguments.pos - 1, greaterThanToken.end], + loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, ast), params: typeArguments.map(typeArgument => convertChildType(typeArgument)) }; } /** - * Converts a ts.Node's typeParameters ts.ts.NodeArray to a flow-like TypeParameterDeclaration node + * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node * @param {ts.NodeArray} typeParameters ts.Node typeParameters * @returns {ESTreeNode} TypeParameterDeclaration node */ function convertTSTypeParametersToTypeParametersDeclaration( typeParameters: ts.NodeArray ): ESTreeNode { - const firstTypeParameter = typeParameters[0]; - const lastTypeParameter = typeParameters[typeParameters.length - 1]; - - const greaterThanToken = findNextToken(lastTypeParameter, ast, ast); + const greaterThanToken = findNextToken(typeParameters, ast, ast)!; return { type: AST_NODE_TYPES.TSTypeParameterDeclaration, - range: [firstTypeParameter.pos - 1, greaterThanToken!.end], - loc: getLocFor(firstTypeParameter.pos - 1, greaterThanToken!.end, ast), + range: [typeParameters.pos - 1, greaterThanToken.end], + loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, ast), params: typeParameters.map(typeParameter => convertChildType(typeParameter) ) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index fa780cfe8e97..240c4d1c9f71 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -359,13 +359,13 @@ export function getTSNodeAccessibility( /** * Finds the next token based on the previous one and its parent * Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren - * @param {ts.Node} previousToken The previous TSToken + * @param {ts.TextRange} previousToken The previous TSToken * @param {ts.Node} parent The parent TSNode * @param {ts.SourceFile} ast The TS AST * @returns {ts.Node|undefined} the next TSToken */ export function findNextToken( - previousToken: ts.Node, + previousToken: ts.TextRange, parent: ts.Node, ast: ts.SourceFile ): ts.Node | undefined { 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 2924ac8f5f6e..3b1a21e43d80 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -328,7 +328,6 @@ tester.addFixturePatternConfig('typescript/basics', { */ 'export-declare-const-named-enum', 'interface-with-optional-properties', - 'type-parameters-comments-heritage', /** * Babel parses it as TSQualifiedName * ts parses it as MemberExpression diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 49f647abc3d6..c74a01db5d5a 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -66338,7 +66338,7 @@ Object { "superTypeParameters": Object { "loc": Object { "end": Object { - "column": 61, + "column": 71, "line": 1, }, "start": Object { @@ -66385,7 +66385,7 @@ Object { ], "range": Array [ 47, - 61, + 71, ], "type": "TSTypeParameterInstantiation", }, @@ -66517,7 +66517,7 @@ Object { "superTypeParameters": Object { "loc": Object { "end": Object { - "column": 76, + "column": 86, "line": 2, }, "start": Object { @@ -66564,7 +66564,7 @@ Object { ], "range": Array [ 137, - 151, + 161, ], "type": "TSTypeParameterInstantiation", }, @@ -66717,7 +66717,7 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 66, + "column": 76, "line": 3, }, "start": Object { @@ -66764,7 +66764,7 @@ Object { ], "range": Array [ 217, - 231, + 241, ], "type": "TSTypeParameterInstantiation", }, @@ -66915,7 +66915,7 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 80, + "column": 90, "line": 4, }, "start": Object { @@ -66962,7 +66962,7 @@ Object { ], "range": Array [ 311, - 325, + 335, ], "type": "TSTypeParameterInstantiation", },