From 6141aebc8dfb000284754b45f09293587656bc75 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Wed, 13 Aug 2025 21:28:39 -0600 Subject: [PATCH 1/8] fix(typescript-estree): correct range of import assertion with trailing comma --- .../config.ts | 4 + .../fixture.ts | 1 + .../snapshots/1-TSESTree-AST.shot | 149 +++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 202 ++++++++++++++++++ .../snapshots/3-Babel-Error.shot | 4 + .../fixtures-with-differences-errors.shot | 3 +- .../tests/fixtures-without-babel-support.shot | 7 +- packages/ast-spec/tests/fixtures.test.ts | 2 +- .../tests/util/parsers/parser-types.ts | 21 -- packages/ast-spec/tsconfig.spec.json | 2 + packages/ast-spec/typings/global.d.ts | 20 ++ packages/typescript-estree/src/convert.ts | 12 +- 12 files changed, 398 insertions(+), 29 deletions(-) create mode 100644 packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts create mode 100644 packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts create mode 100644 packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/3-Babel-Error.shot create mode 100644 packages/ast-spec/typings/global.d.ts diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts new file mode 100644 index 000000000000..dd7a5ef3590b --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts @@ -0,0 +1,4 @@ +export default { + expectBabelToNotSupport: + 'Trailing commas in import attributes prohibited in https://github.com/babel/babel/pull/17193, but since supported in TS 5.9. See https://github.com/typescript-eslint/typescript-eslint/issues/11474#issuecomment-3186945237', +} satisfies ASTFixtureConfig; diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts new file mode 100644 index 000000000000..f5ad318ad5f4 --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts @@ -0,0 +1 @@ +type TrailingComma = import("A", { with: { "resolution-mode": "import", }, } ); diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..f1f332ffa5de --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,149 @@ +Program { + type: "Program", + body: [ + TSTypeAliasDeclaration { + type: "TSTypeAliasDeclaration", + declare: false, + id: Identifier { + type: "Identifier", + decorators: [], + name: "TrailingComma", + optional: false, + + range: [5, 18], + loc: { + start: { column: 5, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + typeAnnotation: TSImportType { + type: "TSImportType", + argument: TSLiteralType { + type: "TSLiteralType", + literal: Literal { + type: "Literal", + raw: ""A"", + value: "A", + + range: [28, 31], + loc: { + start: { column: 28, line: 1 }, + end: { column: 31, line: 1 }, + }, + }, + + range: [28, 31], + loc: { + start: { column: 28, line: 1 }, + end: { column: 31, line: 1 }, + }, + }, + options: ObjectExpression { + type: "ObjectExpression", + properties: [ + Property { + type: "Property", + computed: false, + key: Identifier { + type: "Identifier", + decorators: [], + name: "with", + optional: false, + + range: [35, 39], + loc: { + start: { column: 35, line: 1 }, + end: { column: 39, line: 1 }, + }, + }, + kind: "init", + method: false, + optional: false, + shorthand: false, + value: ObjectExpression { + type: "ObjectExpression", + properties: [ + Property { + type: "Property", + computed: false, + key: Literal { + type: "Literal", + raw: ""resolution-mode"", + value: "resolution-mode", + + range: [43, 60], + loc: { + start: { column: 43, line: 1 }, + end: { column: 60, line: 1 }, + }, + }, + kind: "init", + method: false, + optional: false, + shorthand: false, + value: Literal { + type: "Literal", + raw: ""import"", + value: "import", + + range: [62, 70], + loc: { + start: { column: 62, line: 1 }, + end: { column: 70, line: 1 }, + }, + }, + + range: [43, 70], + loc: { + start: { column: 43, line: 1 }, + end: { column: 70, line: 1 }, + }, + }, + ], + + range: [41, 73], + loc: { + start: { column: 41, line: 1 }, + end: { column: 73, line: 1 }, + }, + }, + + range: [35, 73], + loc: { + start: { column: 35, line: 1 }, + end: { column: 73, line: 1 }, + }, + }, + ], + + range: [33, 76], + loc: { + start: { column: 33, line: 1 }, + end: { column: 76, line: 1 }, + }, + }, + qualifier: null, + typeArguments: null, + + range: [21, 78], + loc: { + start: { column: 21, line: 1 }, + end: { column: 78, line: 1 }, + }, + }, + + range: [0, 79], + loc: { + start: { column: 0, line: 1 }, + end: { column: 79, line: 1 }, + }, + }, + ], + sourceType: "script", + + range: [0, 80], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 2 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..cae5e0bcfd9e --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,202 @@ +[ + Identifier { + type: "Identifier", + value: "type", + + range: [0, 4], + loc: { + start: { column: 0, line: 1 }, + end: { column: 4, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "TrailingComma", + + range: [5, 18], + loc: { + start: { column: 5, line: 1 }, + end: { column: 18, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "=", + + range: [19, 20], + loc: { + start: { column: 19, line: 1 }, + end: { column: 20, line: 1 }, + }, + }, + Keyword { + type: "Keyword", + value: "import", + + range: [21, 27], + loc: { + start: { column: 21, line: 1 }, + end: { column: 27, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [27, 28], + loc: { + start: { column: 27, line: 1 }, + end: { column: 28, line: 1 }, + }, + }, + String { + type: "String", + value: ""A"", + + range: [28, 31], + loc: { + start: { column: 28, line: 1 }, + end: { column: 31, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [31, 32], + loc: { + start: { column: 31, line: 1 }, + end: { column: 32, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [33, 34], + loc: { + start: { column: 33, line: 1 }, + end: { column: 34, line: 1 }, + }, + }, + Keyword { + type: "Keyword", + value: "with", + + range: [35, 39], + loc: { + start: { column: 35, line: 1 }, + end: { column: 39, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [39, 40], + loc: { + start: { column: 39, line: 1 }, + end: { column: 40, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [41, 42], + loc: { + start: { column: 41, line: 1 }, + end: { column: 42, line: 1 }, + }, + }, + String { + type: "String", + value: ""resolution-mode"", + + range: [43, 60], + loc: { + start: { column: 43, line: 1 }, + end: { column: 60, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ":", + + range: [60, 61], + loc: { + start: { column: 60, line: 1 }, + end: { column: 61, line: 1 }, + }, + }, + String { + type: "String", + value: ""import"", + + range: [62, 70], + loc: { + start: { column: 62, line: 1 }, + end: { column: 70, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [70, 71], + loc: { + start: { column: 70, line: 1 }, + end: { column: 71, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [72, 73], + loc: { + start: { column: 72, line: 1 }, + end: { column: 73, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ",", + + range: [73, 74], + loc: { + start: { column: 73, line: 1 }, + end: { column: 74, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [75, 76], + loc: { + start: { column: 75, line: 1 }, + end: { column: 76, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [77, 78], + loc: { + start: { column: 77, line: 1 }, + end: { column: 78, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ";", + + range: [78, 79], + loc: { + start: { column: 78, line: 1 }, + end: { column: 79, line: 1 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/3-Babel-Error.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/3-Babel-Error.shot new file mode 100644 index 000000000000..8f216bc26e47 --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/3-Babel-Error.shot @@ -0,0 +1,4 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AST Fixtures > type > TSImportType > type-import-type-with-trailing-comma-in-import-attributes > Babel - Error`] +SyntaxError: Unexpected token, expected "}" (1:73) diff --git a/packages/ast-spec/tests/fixtures-with-differences-errors.shot b/packages/ast-spec/tests/fixtures-with-differences-errors.shot index 7051aa777fbb..006a68578577 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-errors.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-errors.shot @@ -47,7 +47,8 @@ exports[`AST Fixtures > List fixtures with Error differences`] "legacy-fixtures/errorRecovery/fixtures/_error_/interface-with-optional-index-signature/fixture.ts", "legacy-fixtures/parameter-decorators/fixtures/_error_/parameter-array-pattern-decorator/fixture.ts", "legacy-fixtures/parameter-decorators/fixtures/_error_/parameter-rest-element-decorator/fixture.ts", - "type/TSImportType/fixtures/_error_/type-import-type-with-import-attributes-assert/fixture.ts" + "type/TSImportType/fixtures/_error_/type-import-type-with-import-attributes-assert/fixture.ts", + "type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts" ], "TSESTree errored but Babel didn't": [ "declaration/TSDeclareFunction/fixtures/_error_/generator-ambient/fixture.ts", diff --git a/packages/ast-spec/tests/fixtures-without-babel-support.shot b/packages/ast-spec/tests/fixtures-without-babel-support.shot index 0a63977a3f5e..2a9805dd8ca8 100644 --- a/packages/ast-spec/tests/fixtures-without-babel-support.shot +++ b/packages/ast-spec/tests/fixtures-without-babel-support.shot @@ -1,4 +1,9 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`AST Fixtures > List fixtures we expect babel to not support`] -[] +[ + [ + "type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts", + "Trailing commas in import attributes prohibited in https://github.com/babel/babel/pull/17193, but since supported in TS 5.9. See https://github.com/typescript-eslint/typescript-eslint/issues/11474#issuecomment-3186945237" + ] +] diff --git a/packages/ast-spec/tests/fixtures.test.ts b/packages/ast-spec/tests/fixtures.test.ts index 16534e6f0c1e..b6400540425c 100644 --- a/packages/ast-spec/tests/fixtures.test.ts +++ b/packages/ast-spec/tests/fixtures.test.ts @@ -4,7 +4,7 @@ import * as path from 'node:path'; import { pathToFileURL } from 'node:url'; import { VitestSnapshotEnvironment } from 'vitest/snapshot'; -import type { ASTFixtureConfig, Fixture } from './util/parsers/parser-types.js'; +import type { Fixture } from './util/parsers/parser-types.js'; import { getErrorLabel } from './util/getErrorLabel.js'; import { parseBabel } from './util/parsers/babel.js'; diff --git a/packages/ast-spec/tests/util/parsers/parser-types.ts b/packages/ast-spec/tests/util/parsers/parser-types.ts index e1d382876654..e95a648c6f24 100644 --- a/packages/ast-spec/tests/util/parsers/parser-types.ts +++ b/packages/ast-spec/tests/util/parsers/parser-types.ts @@ -5,27 +5,6 @@ interface SuccessSnapshotPaths { readonly tokens: SnapshotPathFn; } -/** - * We define this as a global type to make it easier to consume from fixtures. - * It saves us having to import the type into `src` files from a test utils folder. - * This is a convenient property because it saves us from a lot of `../`! - */ -export interface ASTFixtureConfig { - /** - * Prevents the parser from throwing an error if it receives an invalid AST from TypeScript. - * This case only usually occurs when attempting to lint invalid code. - */ - readonly allowInvalidAST?: boolean; - - /** - * Specifies that we expect that babel doesn't yet support the code in this fixture, so we expect that it will error. - * This should not be used if we expect babel to throw for this feature due to a valid parser error! - * - * The value should be a description of why there isn't support - for example a github issue URL. - */ - readonly expectBabelToNotSupport?: string; -} - export interface Fixture { readonly absolute: string; readonly babelParsed: ParserResponse; diff --git a/packages/ast-spec/tsconfig.spec.json b/packages/ast-spec/tsconfig.spec.json index fa52d4c4e988..31cca23d77ef 100644 --- a/packages/ast-spec/tsconfig.spec.json +++ b/packages/ast-spec/tsconfig.spec.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../../dist/packages/ast-spec" }, + "include": ["tests", "typings", "**/fixtures/**/config.ts"], + "exclude": ["**/fixtures/**/fixture.ts"], "references": [ { "path": "../typescript-estree/tsconfig.build.json" diff --git a/packages/ast-spec/typings/global.d.ts b/packages/ast-spec/typings/global.d.ts new file mode 100644 index 000000000000..7dd0713ea5d4 --- /dev/null +++ b/packages/ast-spec/typings/global.d.ts @@ -0,0 +1,20 @@ +/** + * We define this as a global type to make it easier to consume from fixtures. + * It saves us having to import the type into `src` files from a test utils folder. + * This is a convenient property because it saves us from a lot of `../`! + */ +interface ASTFixtureConfig { + /** + * Prevents the parser from throwing an error if it receives an invalid AST from TypeScript. + * This case only usually occurs when attempting to lint invalid code. + */ + readonly allowInvalidAST?: boolean; + + /** + * Specifies that we expect that babel doesn't yet support the code in this fixture, so we expect that it will error. + * This should not be used if we expect babel to throw for this feature due to a valid parser error! + * + * The value should be a description of why there isn't support - for example a github issue URL. + */ + readonly expectBabelToNotSupport?: string; +} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index e4564c92aa72..54d88990c583 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -3166,11 +3166,13 @@ export class Converter { const commaToken = findNextToken(node.argument, node, this.ast)!; const openBraceToken = findNextToken(commaToken, node, this.ast)!; - const closeBraceToken = findNextToken( - node.attributes, - node, - this.ast, - )!; + const closeBraceToken = (() => { + const nextToken = findNextToken(node.attributes, node, this.ast)!; + // Since TS 5.9, there could be a trailing comma like `{ with: { ... }, }` + return nextToken.kind === ts.SyntaxKind.CommaToken + ? findNextToken(nextToken, node, this.ast)! + : nextToken; + })(); const withOrAssertToken = findNextToken( openBraceToken, node, From fe50c5f7053bdfd5e412f3824f943b8394a6444b Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Wed, 13 Aug 2025 23:43:48 -0600 Subject: [PATCH 2/8] exempt from prettier --- .prettierignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index 77ec15cde8cf..c5f057dfff86 100644 --- a/.prettierignore +++ b/.prettierignore @@ -25,8 +25,9 @@ packages/ast-spec/src/special/ExportSpecifier/fixtures/value-export-specifier/fi # TODO - remove this once prettier supports it # https://github.com/prettier/prettier/issues/16072 -packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-assert/fixture.ts packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/fixture.ts +# https://github.com/prettier/prettier/issues/17405 +packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts # Ignore CHANGELOG.md files to avoid issues with automated release job CHANGELOG.md From 4c165defcdcc4eb2e3c68a15e3666191083e25fb Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 10:26:07 -0600 Subject: [PATCH 3/8] Avoid IIFE Co-authored-by: fisker Cheung --- packages/typescript-estree/src/convert.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 54d88990c583..713c1dfe0b07 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -3166,13 +3166,10 @@ export class Converter { const commaToken = findNextToken(node.argument, node, this.ast)!; const openBraceToken = findNextToken(commaToken, node, this.ast)!; - const closeBraceToken = (() => { - const nextToken = findNextToken(node.attributes, node, this.ast)!; - // Since TS 5.9, there could be a trailing comma like `{ with: { ... }, }` - return nextToken.kind === ts.SyntaxKind.CommaToken - ? findNextToken(nextToken, node, this.ast)! - : nextToken; - })(); + const tokenAfterAttributes = findNextToken(node.attributes, node, this.ast)!; + const closeBraceToken = tokenAfterAttributes.kind === ts.SyntaxKind.CommaToken + ? tokenAfterAttributes + : findNextToken(tokenAfterAttributes, node, this.ast)!; const withOrAssertToken = findNextToken( openBraceToken, node, From acfca960a166cb3fc0bd3e2016125b5ee160eb27 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:05:53 -0600 Subject: [PATCH 4/8] format --- packages/typescript-estree/src/convert.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 713c1dfe0b07..2689402397c8 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -3166,10 +3166,15 @@ export class Converter { const commaToken = findNextToken(node.argument, node, this.ast)!; const openBraceToken = findNextToken(commaToken, node, this.ast)!; - const tokenAfterAttributes = findNextToken(node.attributes, node, this.ast)!; - const closeBraceToken = tokenAfterAttributes.kind === ts.SyntaxKind.CommaToken - ? tokenAfterAttributes - : findNextToken(tokenAfterAttributes, node, this.ast)!; + const tokenAfterAttributes = findNextToken( + node.attributes, + node, + this.ast, + )!; + const closeBraceToken = + tokenAfterAttributes.kind === ts.SyntaxKind.CommaToken + ? tokenAfterAttributes + : findNextToken(tokenAfterAttributes, node, this.ast)!; const withOrAssertToken = findNextToken( openBraceToken, node, From e849a6fe481e52d55e2c3eef6189d662895f4015 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:16:00 -0600 Subject: [PATCH 5/8] fixup --- packages/ast-spec/tsconfig.spec.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/ast-spec/tsconfig.spec.json b/packages/ast-spec/tsconfig.spec.json index 31cca23d77ef..0f776aea58e3 100644 --- a/packages/ast-spec/tsconfig.spec.json +++ b/packages/ast-spec/tsconfig.spec.json @@ -3,7 +3,13 @@ "compilerOptions": { "outDir": "../../dist/packages/ast-spec" }, - "include": ["tests", "typings", "**/fixtures/**/config.ts"], + "include": [ + "tests", + "typings", + "**/fixtures/**/config.ts", + "vitest.config.mts", + "package.json" + ], "exclude": ["**/fixtures/**/fixture.ts"], "references": [ { From 120c5184ac46cf3a683963efcb2adcc30fd5d129 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:30:10 -0600 Subject: [PATCH 6/8] update snapshots --- .../snapshots/1-TSESTree-AST.shot | 4 ++-- .../snapshots/5-AST-Alignment-AST.shot | 18 ++++++++++-------- .../config.ts | 2 +- .../snapshots/1-TSESTree-AST.shot | 4 ++-- .../tests/fixtures-without-babel-support.shot | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot index 225e77e8303a..6b391689bbf9 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot @@ -117,10 +117,10 @@ Program { }, ], - range: [21, 47], + range: [21, 48], loc: { start: { column: 21, line: 1 }, - end: { column: 47, line: 1 }, + end: { column: 48, line: 1 }, }, }, qualifier: null, diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot index 31b5f49ee553..5445f192ebff 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot @@ -31,18 +31,18 @@ Snapshot Diff: - type: 'Literal', - raw: '"A"', - value: 'A', -+ argument: Literal { -+ type: 'Literal', -+ raw: '"A"', -+ value: 'A', - +- - range: [16, 19], - loc: { - start: { column: 16, line: 1 }, - end: { column: 19, line: 1 }, - }, - }, -- ++ argument: Literal { ++ type: 'Literal', ++ raw: '"A"', ++ value: 'A', + range: [16, 19], loc: { start: { column: 16, line: 1 }, @@ -128,10 +128,12 @@ Snapshot Diff: }, ], - range: [21, 47], +- range: [21, 48], ++ range: [21, 47], loc: { start: { column: 21, line: 1 }, - end: { column: 47, line: 1 }, +- end: { column: 48, line: 1 }, ++ end: { column: 47, line: 1 }, }, }, qualifier: null, diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts index dd7a5ef3590b..0b761eb56eb3 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/config.ts @@ -1,4 +1,4 @@ export default { expectBabelToNotSupport: - 'Trailing commas in import attributes prohibited in https://github.com/babel/babel/pull/17193, but since supported in TS 5.9. See https://github.com/typescript-eslint/typescript-eslint/issues/11474#issuecomment-3186945237', + 'waiting for https://github.com/babel/babel/pull/17465 to be released', } satisfies ASTFixtureConfig; diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot index f1f332ffa5de..9652836cfeba 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot @@ -116,10 +116,10 @@ Program { }, ], - range: [33, 76], + range: [33, 74], loc: { start: { column: 33, line: 1 }, - end: { column: 76, line: 1 }, + end: { column: 74, line: 1 }, }, }, qualifier: null, diff --git a/packages/ast-spec/tests/fixtures-without-babel-support.shot b/packages/ast-spec/tests/fixtures-without-babel-support.shot index 2a9805dd8ca8..a13f680d01a0 100644 --- a/packages/ast-spec/tests/fixtures-without-babel-support.shot +++ b/packages/ast-spec/tests/fixtures-without-babel-support.shot @@ -4,6 +4,6 @@ exports[`AST Fixtures > List fixtures we expect babel to not support`] [ [ "type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/fixture.ts", - "Trailing commas in import attributes prohibited in https://github.com/babel/babel/pull/17193, but since supported in TS 5.9. See https://github.com/typescript-eslint/typescript-eslint/issues/11474#issuecomment-3186945237" + "waiting for https://github.com/babel/babel/pull/17465 to be released" ] ] From 31c1b4bda380bf8611797464af60f98de8702615 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:41:49 -0600 Subject: [PATCH 7/8] fix up if/else mistake --- .../snapshots/1-TSESTree-AST.shot | 4 ++-- .../snapshots/5-AST-Alignment-AST.shot | 18 ++++++++---------- .../snapshots/1-TSESTree-AST.shot | 4 ++-- packages/typescript-estree/src/convert.ts | 5 +++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot index 6b391689bbf9..225e77e8303a 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/1-TSESTree-AST.shot @@ -117,10 +117,10 @@ Program { }, ], - range: [21, 48], + range: [21, 47], loc: { start: { column: 21, line: 1 }, - end: { column: 48, line: 1 }, + end: { column: 47, line: 1 }, }, }, qualifier: null, diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot index 5445f192ebff..31b5f49ee553 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-import-attributes-with/snapshots/5-AST-Alignment-AST.shot @@ -31,18 +31,18 @@ Snapshot Diff: - type: 'Literal', - raw: '"A"', - value: 'A', -- ++ argument: Literal { ++ type: 'Literal', ++ raw: '"A"', ++ value: 'A', + - range: [16, 19], - loc: { - start: { column: 16, line: 1 }, - end: { column: 19, line: 1 }, - }, - }, -+ argument: Literal { -+ type: 'Literal', -+ raw: '"A"', -+ value: 'A', - +- range: [16, 19], loc: { start: { column: 16, line: 1 }, @@ -128,12 +128,10 @@ Snapshot Diff: }, ], -- range: [21, 48], -+ range: [21, 47], + range: [21, 47], loc: { start: { column: 21, line: 1 }, -- end: { column: 48, line: 1 }, -+ end: { column: 47, line: 1 }, + end: { column: 47, line: 1 }, }, }, qualifier: null, diff --git a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot index 9652836cfeba..f1f332ffa5de 100644 --- a/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot +++ b/packages/ast-spec/src/type/TSImportType/fixtures/type-import-type-with-trailing-comma-in-import-attributes/snapshots/1-TSESTree-AST.shot @@ -116,10 +116,10 @@ Program { }, ], - range: [33, 74], + range: [33, 76], loc: { start: { column: 33, line: 1 }, - end: { column: 74, line: 1 }, + end: { column: 76, line: 1 }, }, }, qualifier: null, diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 2689402397c8..dccb674537c6 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -3171,10 +3171,11 @@ export class Converter { node, this.ast, )!; + // Since TS 5.9, there could be a trailing comma, i.e. `{ with: { ... }, }` const closeBraceToken = tokenAfterAttributes.kind === ts.SyntaxKind.CommaToken - ? tokenAfterAttributes - : findNextToken(tokenAfterAttributes, node, this.ast)!; + ? findNextToken(tokenAfterAttributes, node, this.ast)! + : tokenAfterAttributes; const withOrAssertToken = findNextToken( openBraceToken, node, From 7a6f2f20e95372aac8d995f2e1797baa3d8d2189 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:50:48 -0600 Subject: [PATCH 8/8] empty commit again