diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index dc8b9db9a83..1d7c6fd1725 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -3502,6 +3502,462 @@ Object { } `; +exports[`typescript fixtures/basics/catch-clause-with-annotation.src 1`] = ` +Object { + "$id": 9, + "block": Object { + "range": Array [ + 0, + 63, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 8, + "block": Object { + "range": Array [ + 0, + 63, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 0, + "block": Object { + "range": Array [ + 4, + 8, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 8, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [], + }, + Object { + "$id": 3, + "block": Object { + "range": Array [ + 9, + 28, + ], + "type": "CatchClause", + }, + "childScopes": Array [ + Object { + "$id": 2, + "block": Object { + "range": Array [ + 24, + 28, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 3, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "catch", + "upperScope": Object { + "$ref": 8, + }, + "variableMap": Object { + "e": Object { + "$ref": 1, + }, + }, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [ + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "e", + "range": Array [ + 16, + 22, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 9, + 28, + ], + "type": "CatchClause", + }, + "parent": null, + "type": "CatchClause", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "e", + "range": Array [ + 16, + 22, + ], + "type": "Identifier", + }, + ], + "name": "e", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], + }, + Object { + "$id": 4, + "block": Object { + "range": Array [ + 34, + 38, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 8, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [], + }, + Object { + "$id": 7, + "block": Object { + "range": Array [ + 39, + 62, + ], + "type": "CatchClause", + }, + "childScopes": Array [ + Object { + "$id": 6, + "block": Object { + "range": Array [ + 58, + 62, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 7, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "catch", + "upperScope": Object { + "$ref": 8, + }, + "variableMap": Object { + "e": Object { + "$ref": 5, + }, + }, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [ + Object { + "$id": 5, + "defs": Array [ + Object { + "name": Object { + "name": "e", + "range": Array [ + 46, + 56, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 39, + 62, + ], + "type": "CatchClause", + }, + "parent": null, + "type": "CatchClause", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "e", + "range": Array [ + 46, + 56, + ], + "type": "Identifier", + }, + ], + "name": "e", + "references": Array [], + "scope": Object { + "$ref": 7, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 9, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 8, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 9, + }, + "variables": Array [], +} +`; + +exports[`typescript fixtures/basics/catch-clause-with-invalid-annotation.src 1`] = ` +Object { + "$id": 5, + "block": Object { + "range": Array [ + 0, + 32, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 4, + "block": Object { + "range": Array [ + 0, + 32, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 0, + "block": Object { + "range": Array [ + 4, + 8, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 4, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [], + }, + Object { + "$id": 3, + "block": Object { + "range": Array [ + 9, + 31, + ], + "type": "CatchClause", + }, + "childScopes": Array [ + Object { + "$id": 2, + "block": Object { + "range": Array [ + 27, + 31, + ], + "type": "BlockStatement", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "block", + "upperScope": Object { + "$ref": 3, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "catch", + "upperScope": Object { + "$ref": 4, + }, + "variableMap": Object { + "e": Object { + "$ref": 1, + }, + }, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [ + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "e", + "range": Array [ + 16, + 25, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 9, + 31, + ], + "type": "CatchClause", + }, + "parent": null, + "type": "CatchClause", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "e", + "range": Array [ + 16, + 25, + ], + "type": "Identifier", + }, + ], + "name": "e", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": true, + "references": Array [], + "throughReferences": Array [], + "type": "module", + "upperScope": Object { + "$ref": 5, + }, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 5, + }, + "variables": Array [], +} +`; + exports[`typescript fixtures/basics/class-multi-line-keyword-abstract.src 1`] = ` Object { "$id": 5, diff --git a/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-annotation.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-annotation.src.ts new file mode 100644 index 00000000000..8b6c766f2d7 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-annotation.src.ts @@ -0,0 +1,11 @@ +try { + +} catch (e: any) { + +} + +try { + +} catch (e: unknown) { + +} diff --git a/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-invalid-annotation.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-invalid-annotation.src.ts new file mode 100644 index 00000000000..28f8b6280b2 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/catch-clause-with-invalid-annotation.src.ts @@ -0,0 +1,5 @@ +try { + +} catch (e: string) { + +} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 4a5b9f513d6..470a9108aef 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -258,6 +258,21 @@ export class Converter { return result as T; } + private convertBindingNameWithTypeAnnotation( + name: ts.BindingName, + tsType: ts.TypeNode | undefined, + parent?: ts.Node, + ): TSESTree.BindingName { + const id = this.convertPattern(name); + + if (tsType) { + id.typeAnnotation = this.convertTypeAnnotation(tsType, parent); + this.fixParentLocation(id, id.typeAnnotation.range); + } + + return id; + } + /** * Converts a child into a type annotation. This creates an intermediary * TypeAnnotation node to match what Flow does. @@ -267,12 +282,12 @@ export class Converter { */ private convertTypeAnnotation( child: ts.TypeNode, - parent: ts.Node, + parent: ts.Node | undefined, ): TSESTree.TSTypeAnnotation { // in FunctionType and ConstructorType typeAnnotation has 2 characters `=>` and in other places is just colon const offset = - parent.kind === SyntaxKind.FunctionType || - parent.kind === SyntaxKind.ConstructorType + parent?.kind === SyntaxKind.FunctionType || + parent?.kind === SyntaxKind.ConstructorType ? 2 : 1; const annotationStartCol = child.getFullStart() - offset; @@ -697,7 +712,10 @@ export class Converter { return this.createNode(node, { type: AST_NODE_TYPES.CatchClause, param: node.variableDeclaration - ? this.convertChild(node.variableDeclaration.name) + ? this.convertBindingNameWithTypeAnnotation( + node.variableDeclaration.name, + node.variableDeclaration.type, + ) : null, body: this.convertChild(node.block), }); @@ -805,7 +823,11 @@ export class Converter { case SyntaxKind.VariableDeclaration: { const result = this.createNode(node, { type: AST_NODE_TYPES.VariableDeclarator, - id: this.convertPattern(node.name), + id: this.convertBindingNameWithTypeAnnotation( + node.name, + node.type, + node, + ), init: this.convertChild(node.initializer), }); @@ -813,13 +835,6 @@ export class Converter { result.definite = true; } - if (node.type) { - result.id.typeAnnotation = this.convertTypeAnnotation( - node.type, - node, - ); - this.fixParentLocation(result.id, result.id.typeAnnotation.range); - } return result; } diff --git a/packages/typescript-estree/src/semantic-or-syntactic-errors.ts b/packages/typescript-estree/src/semantic-or-syntactic-errors.ts index f8a6e5be467..023d7e3faf8 100644 --- a/packages/typescript-estree/src/semantic-or-syntactic-errors.ts +++ b/packages/typescript-estree/src/semantic-or-syntactic-errors.ts @@ -81,6 +81,7 @@ function whitelistSupportedDiagnostics( case 1175: // "'implements' clause already seen." case 1176: // "Interface declaration cannot have 'implements' clause." case 1190: // "The variable declaration of a 'for...of' statement cannot have an initializer." + case 1196: // "Catch clause variable type annotation must be 'any' or 'unknown' if specified." case 1200: // "Line terminator not permitted before arrow." case 1206: // "Decorators are not valid here." case 1211: // "A class declaration without the 'default' modifier must have a name." 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 eb247042a8f..71d43e07b11 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -418,6 +418,12 @@ tester.addFixturePatternConfig('typescript/basics', { * babel uses a representation that does not match the ESTree spec: https://github.com/estree/estree/pull/205 */ 'export-star-as-ns-from', + /** + * TS 4.0 catch clause with type annotation + * Not supported in babel yet + */ + 'catch-clause-with-annotation', + 'catch-clause-with-invalid-annotation', ], ignoreSourceType: [ /** 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 df2e9b945df..6b681dda87a 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 @@ -1736,6 +1736,17 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/cast-as-simple.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/catch-clause-with-annotation.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/catch-clause-with-invalid-annotation.src 1`] = ` +Object { + "column": 12, + "index": 19, + "lineNumber": 3, + "message": "Catch clause variable type annotation must be 'any' or 'unknown' if specified.", +} +`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-multi-line-keyword-abstract.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-multi-line-keyword-declare.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-annotation.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-annotation.src.ts.shot new file mode 100644 index 00000000000..7626acea9a8 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-annotation.src.ts.shot @@ -0,0 +1,669 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics catch-clause-with-annotation.src 1`] = ` +Object { + "body": Array [ + Object { + "block": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 8, + ], + "type": "BlockStatement", + }, + "finalizer": null, + "handler": Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 24, + 28, + ], + "type": "BlockStatement", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "param": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "name": "e", + "range": Array [ + 16, + 22, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 17, + 22, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 19, + 22, + ], + "type": "TSAnyKeyword", + }, + }, + }, + "range": Array [ + 9, + 28, + ], + "type": "CatchClause", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "type": "TryStatement", + }, + Object { + "block": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 9, + }, + "start": Object { + "column": 4, + "line": 7, + }, + }, + "range": Array [ + 34, + 38, + ], + "type": "BlockStatement", + }, + "finalizer": null, + "handler": Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 11, + }, + "start": Object { + "column": 21, + "line": 9, + }, + }, + "range": Array [ + 58, + 62, + ], + "type": "BlockStatement", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "param": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 9, + "line": 9, + }, + }, + "name": "e", + "range": Array [ + 46, + 56, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 10, + "line": 9, + }, + }, + "range": Array [ + 47, + 56, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 12, + "line": 9, + }, + }, + "range": Array [ + 49, + 56, + ], + "type": "TSUnknownKeyword", + }, + }, + }, + "range": Array [ + 39, + 62, + ], + "type": "CatchClause", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 11, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 30, + 62, + ], + "type": "TryStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 12, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 63, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Keyword", + "value": "try", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 9, + 14, + ], + "type": "Keyword", + "value": "catch", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 19, + 22, + ], + "type": "Identifier", + "value": "any", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 30, + 33, + ], + "type": "Keyword", + "value": "try", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 7, + }, + "start": Object { + "column": 4, + "line": 7, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "range": Array [ + 37, + 38, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "range": Array [ + 39, + 44, + ], + "type": "Keyword", + "value": "catch", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 9, + }, + "start": Object { + "column": 8, + "line": 9, + }, + }, + "range": Array [ + 45, + 46, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 9, + }, + "start": Object { + "column": 9, + "line": 9, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "Identifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 9, + }, + "start": Object { + "column": 10, + "line": 9, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 12, + "line": 9, + }, + }, + "range": Array [ + 49, + 56, + ], + "type": "Identifier", + "value": "unknown", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 9, + }, + "start": Object { + "column": 19, + "line": 9, + }, + }, + "range": Array [ + 56, + 57, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 9, + }, + "start": Object { + "column": 21, + "line": 9, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 11, + }, + "start": Object { + "column": 0, + "line": 11, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-invalid-annotation.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-invalid-annotation.src.ts.shot new file mode 100644 index 00000000000..6c7105ea336 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/catch-clause-with-invalid-annotation.src.ts.shot @@ -0,0 +1,348 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics catch-clause-with-invalid-annotation.src 1`] = ` +Object { + "body": Array [ + Object { + "block": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 8, + ], + "type": "BlockStatement", + }, + "finalizer": null, + "handler": Object { + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 27, + 31, + ], + "type": "BlockStatement", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "param": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "name": "e", + "range": Array [ + 16, + 25, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 17, + 25, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 19, + 25, + ], + "type": "TSStringKeyword", + }, + }, + }, + "range": Array [ + 9, + 31, + ], + "type": "CatchClause", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 31, + ], + "type": "TryStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 32, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Keyword", + "value": "try", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 9, + 14, + ], + "type": "Keyword", + "value": "catch", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 19, + 25, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 30, + 31, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`;