From 14b33a43f86f1aebc39a9b4d4462aa41c50f392d Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 29 Aug 2022 12:25:46 +0930 Subject: [PATCH] test: add fixtures for exported classes with decorators (#5558) --- .../export-default-class-decorator.src.ts | 2 + .../export-named-class-decorator.src.ts | 2 + .../tests/ast-alignment/fixtures-to-test.ts | 8 + .../semantic-diagnostics-enabled.test.ts.snap | 4 + ...export-default-class-decorator.src.ts.shot | 280 ++++++++++++++++++ .../export-named-class-decorator.src.ts.shot | 265 +++++++++++++++++ 6 files changed, 561 insertions(+) create mode 100644 packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-default-class-decorator.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-named-class-decorator.src.ts create mode 100644 packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-default-class-decorator.src.ts.shot create mode 100644 packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-named-class-decorator.src.ts.shot diff --git a/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-default-class-decorator.src.ts b/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-default-class-decorator.src.ts new file mode 100644 index 00000000000..92c9258b9e0 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-default-class-decorator.src.ts @@ -0,0 +1,2 @@ +@sealed +export default class Qux {} diff --git a/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-named-class-decorator.src.ts b/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-named-class-decorator.src.ts new file mode 100644 index 00000000000..53ef2e4d568 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/decorators/class-decorators/export-named-class-decorator.src.ts @@ -0,0 +1,2 @@ +@sealed +export class Qux {} 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 850ac470fad..08755211aa0 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -437,6 +437,14 @@ tester.addFixturePatternConfig('typescript/decorators/accessor-decorators', { }); tester.addFixturePatternConfig('typescript/decorators/class-decorators', { fileType: 'ts', + ignore: [ + /** + * babel sets the range of the export node to the start of the decorator + * TSESTree sets it to the start of the export keyword + */ + 'export-default-class-decorator', + 'export-named-class-decorator', + ], }); tester.addFixturePatternConfig('typescript/decorators/method-decorators', { fileType: 'ts', diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 6cabb17f516..e5f3da4da62 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -2224,6 +2224,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/class-decorators/class-decorator-factory.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/class-decorators/export-default-class-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/class-decorators/export-named-class-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-default-class-decorator.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-default-class-decorator.src.ts.shot new file mode 100644 index 00000000000..031962dfb27 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-default-class-decorator.src.ts.shot @@ -0,0 +1,280 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript decorators class-decorators export-default-class-decorator.src 1`] = ` +Object { + "body": Array [ + Object { + "declaration": Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 25, + "line": 2, + }, + }, + "range": Array [ + 33, + 35, + ], + "type": "ClassBody", + }, + "decorators": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "sealed", + "range": Array [ + 1, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "Decorator", + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "name": "Qux", + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 23, + 35, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + "exportKind": "value", + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 35, + ], + "type": "ExportDefaultDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 36, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 7, + ], + "type": "Identifier", + "value": "sealed", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 14, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 15, + 22, + ], + "type": "Keyword", + "value": "default", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 23, + 28, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + "value": "Qux", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 25, + "line": 2, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-named-class-decorator.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-named-class-decorator.src.ts.shot new file mode 100644 index 00000000000..f3b1a4c1ed5 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/decorators/class-decorators/export-named-class-decorator.src.ts.shot @@ -0,0 +1,265 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript decorators class-decorators export-named-class-decorator.src 1`] = ` +Object { + "body": Array [ + Object { + "assertions": Array [], + "declaration": Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 25, + 27, + ], + "type": "ClassBody", + }, + "decorators": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "sealed", + "range": Array [ + 1, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "Decorator", + }, + ], + "id": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "name": "Qux", + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 15, + 27, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + "exportKind": "value", + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 27, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 7, + ], + "type": "Identifier", + "value": "sealed", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 14, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 21, + 24, + ], + "type": "Identifier", + "value": "Qux", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`;