diff --git a/package.json b/package.json index ba0a1b5e6..02900f546 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "@iarna/toml": "2.2.5", "@prettier/is-es5-identifier-name": "0.2.0", "@prettier/parse-srcset": "3.1.0", - "@typescript-eslint/typescript-estree": "7.13.0", - "@typescript-eslint/visitor-keys": "7.13.0", + "@typescript-eslint/typescript-estree": "8.0.0-alpha.30", + "@typescript-eslint/visitor-keys": "8.0.0-alpha.30", "acorn": "8.11.3", "acorn-jsx": "5.3.2", "angular-estree-parser": "10.0.3", @@ -116,7 +116,7 @@ "@types/estree": "1.0.5", "@types/file-entry-cache": "5.0.4", "@types/jest": "29.5.12", - "@typescript-eslint/eslint-plugin": "7.13.0", + "@typescript-eslint/eslint-plugin": "8.0.0-alpha.30", "benchmark": "2.1.4", "browserslist": "4.23.1", "browserslist-to-esbuild": "2.1.1", diff --git a/src/language-js/clean.js b/src/language-js/clean.js index 987fd0593..60104c6f7 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -213,6 +213,17 @@ function clean(original, cloned, parent) { cloned.type = "TSNonNullExpression"; cloned.expression.type = "ChainExpression"; } + + // `@typescript-eslint/typescript-estree` v8 + if (original.type === "TSMappedType") { + delete cloned.key; + delete cloned.constraint; + } + + // `@typescript-eslint/typescript-estree` v8 + if (original.type === "TSEnumDeclaration") { + delete cloned.body; + } } clean.ignoredProperties = ignoredProperties; diff --git a/src/language-js/print/assignment.js b/src/language-js/print/assignment.js index 2c89f59c6..c52cb6187 100644 --- a/src/language-js/print/assignment.js +++ b/src/language-js/print/assignment.js @@ -345,7 +345,7 @@ const isTypeReference = createTypeCheckFunction([ ]); function getTypeParametersFromTypeReference(node) { if (isTypeReference(node)) { - return node.typeParameters?.params; + return (node.typeArguments ?? node.typeParameters)?.params; } } @@ -453,8 +453,12 @@ function shouldBreakBeforeConditionalType(node) { case "FunctionTypeAnnotation": case "GenericTypeAnnotation": case "TSFunctionType": - case "TSTypeReference": return Boolean(subNode.typeParameters); + case "TSTypeReference": + return Boolean( + // TODO: Use `typeArguments` only when babel align with TS. + subNode.typeArguments ?? subNode.typeParameters, + ); default: return false; } diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index affc3320c..6876d737a 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -307,11 +307,14 @@ function isHopefullyShortCallArgument(node) { } } if ( - (typeAnnotation.type === "GenericTypeAnnotation" || - typeAnnotation.type === "TSTypeReference") && - typeAnnotation.typeParameters?.params.length === 1 + typeAnnotation.type === "GenericTypeAnnotation" || + typeAnnotation.type === "TSTypeReference" ) { - typeAnnotation = typeAnnotation.typeParameters.params[0]; + const typeArguments = + typeAnnotation.typeArguments ?? typeAnnotation.typeParameters; + if (typeArguments?.params.length === 1) { + typeAnnotation = typeArguments.params[0]; + } } return ( isSimpleType(typeAnnotation) && isSimpleCallArgument(node.expression, 1) diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index bbcb24670..cb50ad1c0 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -79,7 +79,10 @@ function printClass(path, options, print) { if (node.superClass) { const printed = [ printSuperClass(path, options, print), - print("superTypeParameters"), + print( + // TODO: Use `superTypeArguments` only when babel align with TS. + node.superTypeArguments ? "superTypeArguments" : "superTypeParameters", + ), ]; const printedWithComments = path.call( (superClass) => ["extends ", printComments(superClass, printed, options)], diff --git a/src/language-js/print/estree.js b/src/language-js/print/estree.js index 5d9921f0b..865c76fa1 100644 --- a/src/language-js/print/estree.js +++ b/src/language-js/print/estree.js @@ -623,7 +623,7 @@ function printEstree(path, options, print, args) { case "TemplateLiteral": return printTemplateLiteral(path, print, options); case "TaggedTemplateExpression": - return printTaggedTemplateLiteral(print); + return printTaggedTemplateLiteral(path, print); case "PrivateIdentifier": return ["#", node.name]; case "PrivateName": diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index eddb9d289..26359fd39 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -122,11 +122,11 @@ function printTemplateLiteral(path, print, options) { return parts; } -function printTaggedTemplateLiteral(print) { +function printTaggedTemplateLiteral(path, print) { const quasiDoc = print("quasi"); return label(quasiDoc.label && { tagged: true, ...quasiDoc.label }, [ print("tag"), - print("typeParameters"), + print(path.node.typeArguments ? "typeArguments" : "typeParameters"), lineSuffixBoundary, quasiDoc, ]); diff --git a/src/language-js/print/type-annotation.js b/src/language-js/print/type-annotation.js index 504bf3ebf..d5a9134b9 100644 --- a/src/language-js/print/type-annotation.js +++ b/src/language-js/print/type-annotation.js @@ -549,7 +549,10 @@ function printTypeQuery({ node }, print) { const argumentPropertyName = node.type === "TSTypeQuery" ? "exprName" : "argument"; const typeArgsPropertyName = - node.type === "TSTypeQuery" ? "typeParameters" : "typeArguments"; + // TODO: Use `typeArguments` only when babel align with TS. + node.type === "TypeofTypeAnnotation" || node.typeArguments + ? "typeArguments" + : "typeParameters"; return ["typeof ", print(argumentPropertyName), print(typeArgsPropertyName)]; } diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 0e7e7db71..d2a73790f 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -127,7 +127,13 @@ function printTypescript(path, options, print) { case "TSClassImplements": case "TSExpressionWithTypeArguments": // Babel AST case "TSInstantiationExpression": - return [print("expression"), print("typeParameters")]; + return [ + print("expression"), + print( + // TODO: Use `typeArguments` only when babel align with TS. + node.typeArguments ? "typeArguments" : "typeParameters", + ), + ]; case "TSTemplateLiteralType": return printTemplateLiteral(path, print, options); case "TSNamedTupleMember": @@ -353,7 +359,13 @@ function printTypescript(path, options, print) { case "TSTypeReference": return [ print("typeName"), - printTypeParameters(path, options, print, "typeParameters"), + printTypeParameters( + path, + options, + print, + // TODO: Use `typeArguments` only when babel align with TS. + node.typeArguments ? "typeArguments" : "typeParameters", + ), ]; case "TSTypeAnnotation": return printTypeAnnotation(path, options, print); diff --git a/src/language-js/traverse/visitor-keys.evaluate.js b/src/language-js/traverse/visitor-keys.evaluate.js index 9e074605c..686576760 100644 --- a/src/language-js/traverse/visitor-keys.evaluate.js +++ b/src/language-js/traverse/visitor-keys.evaluate.js @@ -66,6 +66,15 @@ const excludeKeys = { ExportAllDeclaration: ["assertions"], ExportNamedDeclaration: ["assertions"], ImportDeclaration: ["assertions"], + + // `key` and `constraint` added in `@typescript-eslint/typescript-estree` v8 + // https://github.com/typescript-eslint/typescript-eslint/pull/7065 + // TODO: Use the new AST properties instead + TSMappedType: ["key", "constraint"], + // `body` added in `@typescript-eslint/typescript-estree` v8 + // https://github.com/typescript-eslint/typescript-eslint/pull/8920 + // TODO: Use the new AST properties instead + TSEnumDeclaration: ["body"], }; const visitorKeys = Object.fromEntries( diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index 9cf33716f..394e3d112 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -319,7 +319,10 @@ function isSimpleType(node) { isSimpleTypeAnnotation(node) || ((node.type === "GenericTypeAnnotation" || node.type === "TSTypeReference") && - !node.typeParameters) + // @ts-expect-error -- `GenericTypeAnnotation` + !node.typeParameters && + // @ts-expect-error -- `TSTypeReference` + !node.typeArguments) ); } diff --git a/tests/unit/__snapshots__/visitor-keys.js.snap b/tests/unit/__snapshots__/visitor-keys.js.snap index d783e8526..f26eae456 100644 --- a/tests/unit/__snapshots__/visitor-keys.js.snap +++ b/tests/unit/__snapshots__/visitor-keys.js.snap @@ -821,6 +821,9 @@ exports[`visitor keys estree 1`] = ` "params", "returnType", ], + "TSEnumBody": [ + "members", + ], "TSEnumDeclaration": [ "id", "members", diff --git a/yarn.lock b/yarn.lock index 7a573ab13..2becf971e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1999,26 +1999,26 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:7.13.0": - version: 7.13.0 - resolution: "@typescript-eslint/eslint-plugin@npm:7.13.0" +"@typescript-eslint/eslint-plugin@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/eslint-plugin@npm:8.0.0-alpha.30" dependencies: "@eslint-community/regexpp": "npm:^4.10.0" - "@typescript-eslint/scope-manager": "npm:7.13.0" - "@typescript-eslint/type-utils": "npm:7.13.0" - "@typescript-eslint/utils": "npm:7.13.0" - "@typescript-eslint/visitor-keys": "npm:7.13.0" + "@typescript-eslint/scope-manager": "npm:8.0.0-alpha.30" + "@typescript-eslint/type-utils": "npm:8.0.0-alpha.30" + "@typescript-eslint/utils": "npm:8.0.0-alpha.30" + "@typescript-eslint/visitor-keys": "npm:8.0.0-alpha.30" graphemer: "npm:^1.4.0" ignore: "npm:^5.3.1" natural-compare: "npm:^1.4.0" ts-api-utils: "npm:^1.3.0" peerDependencies: - "@typescript-eslint/parser": ^7.0.0 - eslint: ^8.56.0 + "@typescript-eslint/parser": ^8.0.0 || ^8.0.0-alpha.0 + eslint: ^8.57.0 || ^9.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 10/93c3a0d8871d8351187503152a6c5199714eb62c96991e0d3e0caaee6881839dee4ad55e5de5d1a4389ae12ed10d3a845603de1f2f581337f782f19113022a65 + checksum: 10/8d38f0d350d1a78ae4ab0295c1891ee4dd9a4a5287b9f7cc3d8399e731d4e4d96abf947166293af9c9221291ca6d9937e5427b3d44b6d98005c1ddb5e1ab4a14 languageName: node linkType: hard @@ -2032,20 +2032,28 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:7.13.0": - version: 7.13.0 - resolution: "@typescript-eslint/type-utils@npm:7.13.0" +"@typescript-eslint/scope-manager@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/scope-manager@npm:8.0.0-alpha.30" dependencies: - "@typescript-eslint/typescript-estree": "npm:7.13.0" - "@typescript-eslint/utils": "npm:7.13.0" + "@typescript-eslint/types": "npm:8.0.0-alpha.30" + "@typescript-eslint/visitor-keys": "npm:8.0.0-alpha.30" + checksum: 10/9ca4c7ef13e3f68b829a8446d8d2bae150d87dd2c2ca3dea44f8bd22056ba6d13c6f69e8d9891712d94410e7e365cef79a4d05fa33bd0665cd96dcfe508c3143 + languageName: node + linkType: hard + +"@typescript-eslint/type-utils@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/type-utils@npm:8.0.0-alpha.30" + dependencies: + "@typescript-eslint/typescript-estree": "npm:8.0.0-alpha.30" + "@typescript-eslint/utils": "npm:8.0.0-alpha.30" debug: "npm:^4.3.4" ts-api-utils: "npm:^1.3.0" - peerDependencies: - eslint: ^8.56.0 peerDependenciesMeta: typescript: optional: true - checksum: 10/f51ccb3c59963db82a504b02c8d15bc518137c176b8d39891f7bcb7b4b02ca0fa918a3754781f198f592f1047dc24c49086430bbef857d877d085e14d33f7a6c + checksum: 10/4f69cd52e1ead98a5a09d75ff1b1ad2848f937a0c7bd3a777ee155354e44c99f76548337c3c9f5db4a843ea0b6cab3d4bd95ef84be8bf9ee3359ba3c02d60931 languageName: node linkType: hard @@ -2056,6 +2064,13 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/types@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/types@npm:8.0.0-alpha.30" + checksum: 10/2cd0ee0258cd0c61aa1475944e4545d7a982e6a6aa7606f1328ff3253fd368ef9799e6dd60a81ec61101214d30f5ee2254abbcdaec2b671352b9cd5908f9cba8 + languageName: node + linkType: hard + "@typescript-eslint/typescript-estree@npm:7.13.0": version: 7.13.0 resolution: "@typescript-eslint/typescript-estree@npm:7.13.0" @@ -2075,7 +2090,40 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/utils@npm:7.13.0, @typescript-eslint/utils@npm:^6.0.0 || ^7.0.0": +"@typescript-eslint/typescript-estree@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/typescript-estree@npm:8.0.0-alpha.30" + dependencies: + "@typescript-eslint/types": "npm:8.0.0-alpha.30" + "@typescript-eslint/visitor-keys": "npm:8.0.0-alpha.30" + debug: "npm:^4.3.4" + globby: "npm:^11.1.0" + is-glob: "npm:^4.0.3" + minimatch: "npm:^9.0.4" + semver: "npm:^7.6.0" + ts-api-utils: "npm:^1.3.0" + peerDependenciesMeta: + typescript: + optional: true + checksum: 10/cbd7821fd2500afbb1bcd61afcf39950288c95479112c34dfc4d3d866a261c1816baba22330866873eedc6a37af559e7fcfdac2429438350fd6da1ad11ddba2e + languageName: node + linkType: hard + +"@typescript-eslint/utils@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/utils@npm:8.0.0-alpha.30" + dependencies: + "@eslint-community/eslint-utils": "npm:^4.4.0" + "@typescript-eslint/scope-manager": "npm:8.0.0-alpha.30" + "@typescript-eslint/types": "npm:8.0.0-alpha.30" + "@typescript-eslint/typescript-estree": "npm:8.0.0-alpha.30" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + checksum: 10/51ad6d641b76aeb14ccb8396eef3e9828413e56b949ab922291f7144c9c019d28ebc11e9b08b9d825abfb45350dedeff4aad501280d4f7508cb8468584048372 + languageName: node + linkType: hard + +"@typescript-eslint/utils@npm:^6.0.0 || ^7.0.0": version: 7.13.0 resolution: "@typescript-eslint/utils@npm:7.13.0" dependencies: @@ -2099,6 +2147,16 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/visitor-keys@npm:8.0.0-alpha.30": + version: 8.0.0-alpha.30 + resolution: "@typescript-eslint/visitor-keys@npm:8.0.0-alpha.30" + dependencies: + "@typescript-eslint/types": "npm:8.0.0-alpha.30" + eslint-visitor-keys: "npm:^3.4.3" + checksum: 10/7700cfd08808b204319a914d6089510626693e12c73ce9a80aa5e10ff459908fad048fb4b3dceedd8fff893817375ed48e69b163cd7beb5fd5edaa34df904077 + languageName: node + linkType: hard + "abbrev@npm:^2.0.0": version: 2.0.0 resolution: "abbrev@npm:2.0.0" @@ -6378,9 +6436,9 @@ __metadata: linkType: hard "meow@npm:^13.0.0": - version: 13.1.0 - resolution: "meow@npm:13.1.0" - checksum: 10/8fbdedddd01904aaa055d09a3c141bbf7453e9be193b1566d286615824af7f2e08a9a9d6b660cea9e59e3cf89c547535533b894e443417fa9b1f9aa2cf1375c4 + version: 13.2.0 + resolution: "meow@npm:13.2.0" + checksum: 10/4eff5bc921fed0b8a471ad79069d741a0210036d717547d0c7f36fdaf84ef7a3036225f38b6a53830d84dc9cbf8b944b097fde62381b8b5b215119e735ce1063 languageName: node linkType: hard @@ -7274,9 +7332,9 @@ __metadata: "@types/estree": "npm:1.0.5" "@types/file-entry-cache": "npm:5.0.4" "@types/jest": "npm:29.5.12" - "@typescript-eslint/eslint-plugin": "npm:7.13.0" - "@typescript-eslint/typescript-estree": "npm:7.13.0" - "@typescript-eslint/visitor-keys": "npm:7.13.0" + "@typescript-eslint/eslint-plugin": "npm:8.0.0-alpha.30" + "@typescript-eslint/typescript-estree": "npm:8.0.0-alpha.30" + "@typescript-eslint/visitor-keys": "npm:8.0.0-alpha.30" acorn: "npm:8.11.3" acorn-jsx: "npm:5.3.2" angular-estree-parser: "npm:10.0.3"