Cleanup {JSXOpeningElement,TSClassImplements,TSInterfaceHeritage}.typeParameters (#18028)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-10-10 16:41:24 +08:00
1 parent a8c033a493
commit 65d1dfb422
3 files changed
+4 -22

No files matched your search

+4 -11
View File
@@ -616,18 +616,11 @@ function printJsxOpeningElement(path, options, print) {
const { node } = path; const { node } = path;
const nameHasComments = const nameHasComments =
hasComment(node.name) || hasComment(node.name) || hasComment(node.typeArguments);
hasComment(node.typeParameters) ||
hasComment(node.typeArguments);
// Don't break self-closing elements with no attributes and no comments // Don't break self-closing elements with no attributes and no comments
if (node.selfClosing && node.attributes.length === 0 && !nameHasComments) { if (node.selfClosing && node.attributes.length === 0 && !nameHasComments) {
return [ return ["<", print("name"), print("typeArguments"), " />"];
"<",
print("name"),
node.typeArguments ? print("typeArguments") : print("typeParameters"),
" />",
];
} }
// don't break up opening elements with a single long text attribute // don't break up opening elements with a single long text attribute
@@ -650,7 +643,7 @@ function printJsxOpeningElement(path, options, print) {
return group([ return group([
"<", "<",
print("name"), print("name"),
node.typeArguments ? print("typeArguments") : print("typeParameters"), print("typeArguments"),
" ", " ",
...path.map(print, "attributes"), ...path.map(print, "attributes"),
node.selfClosing ? " />" : ">", node.selfClosing ? " />" : ">",
@@ -672,7 +665,7 @@ function printJsxOpeningElement(path, options, print) {
[ [
"<", "<",
print("name"), print("name"),
node.typeArguments ? print("typeArguments") : print("typeParameters"), print("typeArguments"),
indent(path.map(() => [attributeLine, print()], "attributes")), indent(path.map(() => [attributeLine, print()], "attributes")),
...printEndOfOpeningTag(node, options, nameHasComments), ...printEndOfOpeningTag(node, options, nameHasComments),
], ],
@@ -16,12 +16,6 @@ const additionalVisitorKeys = {
TSJSDocNullableType: ["typeAnnotation"], TSJSDocNullableType: ["typeAnnotation"],
TSJSDocNonNullableType: ["typeAnnotation"], TSJSDocNonNullableType: ["typeAnnotation"],
// `@typescript-eslint/typescript-estree` v6 renamed `typeParameters` to `typeArguments`
// Remove those when babel update AST
JSXOpeningElement: ["typeParameters"],
TSClassImplements: ["typeParameters"],
TSInterfaceHeritage: ["typeParameters"],
// Flow, missed in `flowVisitorKeys` // Flow, missed in `flowVisitorKeys`
NeverTypeAnnotation: [], NeverTypeAnnotation: [],
SatisfiesExpression: ["expression", "typeAnnotation"], SatisfiesExpression: ["expression", "typeAnnotation"],
@@ -38,8 +32,6 @@ const excludeKeys = {
// From `flowVisitorKeys` // From `flowVisitorKeys`
ArrowFunctionExpression: ["id"], ArrowFunctionExpression: ["id"],
FunctionExpression: ["predicate"], FunctionExpression: ["predicate"],
// Flow don't use it, but `typescript-eslint` v6 switched to `typeArguments`
// JSXOpeningElement: ["typeArguments"],
// TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation` // TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation`
// Flow parser changed `.types` to `.elementTypes` https://github.com/facebook/flow/commit/5b60e6a81dc277dfab2e88fa3737a4dc9aafdcab // Flow parser changed `.types` to `.elementTypes` https://github.com/facebook/flow/commit/5b60e6a81dc277dfab2e88fa3737a4dc9aafdcab
// TupleTypeAnnotation: ["types"], // TupleTypeAnnotation: ["types"],
@@ -496,7 +496,6 @@ exports[`visitor keys estree 1`] = `
"attributes", "attributes",
"name", "name",
"typeArguments", "typeArguments",
"typeParameters",
], ],
"JSXOpeningFragment": [], "JSXOpeningFragment": [],
"JSXSpreadAttribute": [ "JSXSpreadAttribute": [
@@ -826,7 +825,6 @@ exports[`visitor keys estree 1`] = `
"TSClassImplements": [ "TSClassImplements": [
"expression", "expression",
"typeArguments", "typeArguments",
"typeParameters",
], ],
"TSConditionalType": [ "TSConditionalType": [
"checkType", "checkType",
@@ -925,7 +923,6 @@ exports[`visitor keys estree 1`] = `
"TSInterfaceHeritage": [ "TSInterfaceHeritage": [
"expression", "expression",
"typeArguments", "typeArguments",
"typeParameters",
], ],
"TSIntersectionType": [ "TSIntersectionType": [
"types", "types",