Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: throw for constructors with type parameters (#12065)
* Throw a syntax error for a constructor with type parameters * Modify to match error location with TypeScript * Update typescript parser tests Update allowlist.txt
- Loading branch information
1 parent
69e98fc
commit 7028a14
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ges/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class C { | ||
constructor<T>(foo: T) {} | ||
} |
84 changes: 84 additions & 0 deletions
84
.../babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Type parameters cannot appear on a constructor declaration. (2:13)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":8,"end":39,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":12,"end":37,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":27}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":12,"end":23,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":13},"identifierName":"constructor"}, | ||
"name": "constructor" | ||
}, | ||
"computed": false, | ||
"kind": "constructor", | ||
"typeParameters": { | ||
"type": "TSTypeParameterDeclaration", | ||
"start":23,"end":26,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeParameter", | ||
"start":24,"end":25,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, | ||
"name": "T" | ||
} | ||
] | ||
}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":27,"end":33,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":23},"identifierName":"foo"}, | ||
"name": "foo", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":30,"end":33,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":23}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeReference", | ||
"start":32,"end":33,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":23}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":32,"end":33,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":23},"identifierName":"T"}, | ||
"name": "T" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":35,"end":37,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":27}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters