Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw a syntax error for a parameter properties in not constructor (#…
- Loading branch information
1 parent
c8f0b6d
commit bbe0cf0
Showing
6 changed files
with
391 additions
and
2 deletions.
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
11 changes: 11 additions & 0 deletions
11
...babel-parser/test/fixtures/typescript/class/parameter-properties-not-constructor/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,11 @@ | ||
class C { | ||
not_constructor( | ||
readonly r, | ||
public pu: number, | ||
protected po?, | ||
private pi?: number, | ||
public readonly pur, | ||
// Also works on AssignmentPattern | ||
readonly x = 0, | ||
public y?: number = 0) {} | ||
} |
199 changes: 199 additions & 0 deletions
199
...el-parser/test/fixtures/typescript/class/parameter-properties-not-constructor/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,199 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":261,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (3:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (4:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (5:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (6:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (7:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (9:8)", | ||
"SyntaxError: A parameter property is only allowed in a constructor implementation. (10:8)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":261,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":261,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"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":261,"loc":{"start":{"line":1,"column":8},"end":{"line":11,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":14,"end":259,"loc":{"start":{"line":2,"column":4},"end":{"line":10,"column":33}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":14,"end":29,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":19},"identifierName":"not_constructor"}, | ||
"name": "not_constructor" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":39,"end":49,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":18}}, | ||
"readonly": true, | ||
"parameter": { | ||
"type": "Identifier", | ||
"start":48,"end":49,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":18},"identifierName":"r"}, | ||
"name": "r" | ||
} | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":59,"end":76,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":25}}, | ||
"accessibility": "public", | ||
"parameter": { | ||
"type": "Identifier", | ||
"start":66,"end":76,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":25},"identifierName":"pu"}, | ||
"name": "pu", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":68,"end":76,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":25}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":70,"end":76,"loc":{"start":{"line":4,"column":19},"end":{"line":4,"column":25}} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":86,"end":99,"loc":{"start":{"line":5,"column":8},"end":{"line":5,"column":21}}, | ||
"accessibility": "protected", | ||
"parameter": { | ||
"type": "Identifier", | ||
"start":96,"end":99,"loc":{"start":{"line":5,"column":18},"end":{"line":5,"column":21},"identifierName":"po"}, | ||
"name": "po", | ||
"optional": true | ||
} | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":109,"end":128,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":27}}, | ||
"accessibility": "private", | ||
"parameter": { | ||
"type": "Identifier", | ||
"start":117,"end":128,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":27},"identifierName":"pi"}, | ||
"name": "pi", | ||
"optional": true, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":120,"end":128,"loc":{"start":{"line":6,"column":19},"end":{"line":6,"column":27}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":122,"end":128,"loc":{"start":{"line":6,"column":21},"end":{"line":6,"column":27}} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":138,"end":157,"loc":{"start":{"line":7,"column":8},"end":{"line":7,"column":27}}, | ||
"accessibility": "public", | ||
"readonly": true, | ||
"parameter": { | ||
"type": "Identifier", | ||
"start":154,"end":157,"loc":{"start":{"line":7,"column":24},"end":{"line":7,"column":27},"identifierName":"pur"}, | ||
"name": "pur" | ||
} | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":210,"end":224,"loc":{"start":{"line":9,"column":8},"end":{"line":9,"column":22}}, | ||
"readonly": true, | ||
"parameter": { | ||
"type": "AssignmentPattern", | ||
"start":219,"end":224,"loc":{"start":{"line":9,"column":17},"end":{"line":9,"column":22}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":219,"end":220,"loc":{"start":{"line":9,"column":17},"end":{"line":9,"column":18},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":223,"end":224,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":22}}, | ||
"extra": { | ||
"rawValue": 0, | ||
"raw": "0" | ||
}, | ||
"value": 0 | ||
} | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " Also works on AssignmentPattern", | ||
"start":167,"end":201,"loc":{"start":{"line":8,"column":8},"end":{"line":8,"column":42}} | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "TSParameterProperty", | ||
"start":234,"end":255,"loc":{"start":{"line":10,"column":8},"end":{"line":10,"column":29}}, | ||
"accessibility": "public", | ||
"parameter": { | ||
"type": "AssignmentPattern", | ||
"start":241,"end":255,"loc":{"start":{"line":10,"column":15},"end":{"line":10,"column":29}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":241,"end":251,"loc":{"start":{"line":10,"column":15},"end":{"line":10,"column":25},"identifierName":"y"}, | ||
"name": "y", | ||
"optional": true, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":243,"end":251,"loc":{"start":{"line":10,"column":17},"end":{"line":10,"column":25}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":245,"end":251,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":25}} | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":254,"end":255,"loc":{"start":{"line":10,"column":28},"end":{"line":10,"column":29}}, | ||
"extra": { | ||
"rawValue": 0, | ||
"raw": "0" | ||
}, | ||
"value": 0 | ||
} | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":257,"end":259,"loc":{"start":{"line":10,"column":31},"end":{"line":10,"column":33}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " Also works on AssignmentPattern", | ||
"start":167,"end":201,"loc":{"start":{"line":8,"column":8},"end":{"line":8,"column":42}} | ||
} | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-parser/test/fixtures/typescript/function/parameter-properties/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,9 @@ | ||
function foo( | ||
readonly r, | ||
public pu: number, | ||
protected po?, | ||
private pi?: number, | ||
public readonly pur, | ||
readonly x = 0, | ||
public y?: number = 0 | ||
) {} |
Oops, something went wrong.