Forbid type parameters on constructor (#18686)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-01-20 21:59:28 +08:00
1 parent 1487718705
commit cc7c47455e
3 files changed
+37 -2

No files matched your search

-2
View File
@@ -192,8 +192,6 @@ const allowedReasonCodes = new Set([
"StrictFunction",
"ForInOfLoopInitializer",
"ConstructorHasTypeParameters",
"DecoratorExportClass",
"ParamDupe",
"InvalidDecimal",
@@ -14,6 +14,13 @@ exports[`snippet: #0 [babel-ts] format 2`] = `
Cause: A required element cannot follow an optional element. (1:17)"
`;
exports[`snippet: #0 [babel-ts] format 3`] = `
"Type parameters cannot appear on a constructor declaration. (1:24)
> 1 | class A { 'constructor'<a>() {} }
| ^
Cause: Type parameters cannot appear on a constructor declaration. (1:23)"
`;
exports[`snippet: #0 [oxc-ts] format 1`] = `
"Expected \`,\` or \`]\` but found \`:\` (1:14)
> 1 | type T = [x.y: A];
@@ -40,12 +47,25 @@ exports[`snippet: #1 [babel-ts] format 1`] = `
Cause: Tuple members must be labeled with a simple identifier. (1:10)"
`;
exports[`snippet: #1 [babel-ts] format 2`] = `
"Type parameters cannot appear on a constructor declaration. (1:22)
> 1 | class A { constructor<a>() {} }
| ^
Cause: Type parameters cannot appear on a constructor declaration. (1:21)"
`;
exports[`snippet: #1 [oxc-ts] format 1`] = `
"Expected \`,\` or \`]\` but found \`:\` (1:15)
> 1 | type T = [x<y>: A];
| ^"
`;
exports[`snippet: #1 [oxc-ts] format 2`] = `
"Type parameters cannot appear on a constructor declaration (1:22)
> 1 | class A { constructor<a>() {} }
| ^^^"
`;
exports[`snippet: #1 [typescript] format 1`] = `
"',' expected. (1:15)
> 1 | type T = [x<y>: A];
@@ -17,6 +17,8 @@ runFormatTest(
snippets: [
// A required element cannot follow an optional element.
"type T = [x?: A, y: B];",
// Type parameters cannot appear on a constructor declaration.
"class A { constructor<a>() {} }",
],
},
[
@@ -25,3 +27,18 @@ runFormatTest(
"oxc-ts",
],
);
runFormatTest(
{
importMeta: import.meta,
snippets: [
// Type parameters cannot appear on a constructor declaration.
"class A { 'constructor'<a>() {} }",
],
},
[
// "typescript",
"babel-ts",
// "oxc-ts",
],
);