JavaScript: Make parsing of decorators more restrictive.

As per [the proposal](https://tc39.github.io/proposal-decorators/#sec-new-syntax), decorators can only contain identifiers or parenthesised expressions, optionally followed by property accesses and arguments.
This commit is contained in:
Max Schaefer
2019-01-29 15:00:33 +00:00
parent db9ac72e7a
commit 1ad4867f2a

View File

@@ -257,7 +257,7 @@ public class ESNextParser extends JSXParser {
return member;
}
private List<Decorator> parseDecorators() {
public List<Decorator> parseDecorators() {
List<Decorator> result = new ArrayList<Decorator>();
while (this.type == at)
result.add(this.parseDecorator());
@@ -267,10 +267,23 @@ public class ESNextParser extends JSXParser {
private Decorator parseDecorator() {
Position start = startLoc;
this.next();
Decorator decorator = new Decorator(new SourceLocation(start), this.parseMaybeAssign(false, null, null));
Expression body = parseDecoratorBody();
Decorator decorator = new Decorator(new SourceLocation(start), body);
return this.finishNode(decorator);
}
protected Expression parseDecoratorBody() {
Expression base;
int startPos = this.start;
Position startLoc = this.startLoc;
if (this.type == TokenType.parenL) {
base = parseParenExpression();
} else {
base = parseIdent(true);
}
return parseSubscripts(base, startPos, startLoc, false);
}
/*
* Support for proposed extensions to `export`
* (http://leebyron.com/ecmascript-export-ns-from and http://leebyron.com/ecmascript-export-default-from)