diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/1-TSESTree-Error.shot index 292b542dcf5..bc87ac74bbf 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ interface-implements TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ interface-implements TSESTree - Error 1`] = ` +"TSError + 1 | // TODO: This fixture might be too large, and if so should be split up. + 2 | +> 3 | interface d implements e {} + | ^^^^^^^^^^^^ Interface declaration cannot have 'implements' clause. + 4 |" +`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/3-Alignment-Error.shot index 53470554fd3..15d3db96bf3 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ interface-implements Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ interface-implements Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-errors.shot b/packages/ast-spec/tests/fixtures-with-differences-errors.shot index ed482bcd2f9..7cb75118045 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-errors.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-errors.shot @@ -56,7 +56,6 @@ Object { "legacy-fixtures/errorRecovery/fixtures/_error_/enum-with-keywords/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/index-signature-parameters/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/interface-empty-extends/fixture.ts", - "legacy-fixtures/errorRecovery/fixtures/_error_/interface-implements/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/interface-index-signature-private/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/interface-index-signature-protected/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/interface-index-signature-public/fixture.ts", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 5d7558dae43..ce716e69707 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2623,6 +2623,28 @@ export class Converter { this.#checkIllegalDecorators(node); const interfaceHeritageClauses = node.heritageClauses ?? []; + const interfaceExtends: TSESTree.TSInterfaceHeritage[] = []; + + for (const heritageClause of interfaceHeritageClauses) { + if (heritageClause.token !== SyntaxKind.ExtendsKeyword) { + this.#throwError( + heritageClause, + heritageClause.token === SyntaxKind.ImplementsKeyword + ? "Interface declaration cannot have 'implements' clause." + : 'Unexpected token.', + ); + } + + for (const heritageType of heritageClause.types) { + interfaceExtends.push( + this.convertChild( + heritageType, + node, + ) as TSESTree.TSInterfaceHeritage, + ); + } + } + const result = this.createNode(node, { type: AST_NODE_TYPES.TSInterfaceDeclaration, body: this.createNode(node, { @@ -2631,17 +2653,7 @@ export class Converter { range: [node.members.pos - 1, node.end], }), declare: hasModifier(SyntaxKind.DeclareKeyword, node), - extends: interfaceHeritageClauses - .filter( - heritageClause => - heritageClause.token === SyntaxKind.ExtendsKeyword, - ) - .flatMap(heritageClause => - heritageClause.types.map( - n => this.convertChild(n, node) as TSESTree.TSInterfaceHeritage, - ), - ), - + extends: interfaceExtends, id: this.convertChild(node.name), typeParameters: node.typeParameters &&