TS: Fix handling of erroneous rest pattern with default

This commit is contained in:
Asger F
2019-08-19 17:26:25 +01:00
parent 4ea999872b
commit 75e85e4402
3 changed files with 54 additions and 3 deletions

View File

@@ -2220,7 +2220,7 @@ public class TypeScriptASTConverter {
* ObjectExpression} with {@link ObjectPattern} and {@link SpreadElement} with {@link
* RestElement}.
*/
private Expression convertLValue(Expression e) {
private Expression convertLValue(Expression e) throws ParseError {
if (e == null) return null;
SourceLocation loc = e.getLoc();
@@ -2249,8 +2249,14 @@ public class TypeScriptASTConverter {
if (e instanceof ParenthesizedExpression)
return new ParenthesizedExpression(
loc, convertLValue(((ParenthesizedExpression) e).getExpression()));
if (e instanceof SpreadElement)
return new RestElement(e.getLoc(), convertLValue(((SpreadElement) e).getArgument()));
if (e instanceof SpreadElement) {
Expression argument = convertLValue(((SpreadElement) e).getArgument());
if (argument instanceof AssignmentPattern) {
throw new ParseError(
"Rest patterns cannot have a default value", argument.getLoc().getStart());
}
return new RestElement(e.getLoc(), argument);
}
return e;
}