mirror of
https://github.com/github/codeql.git
synced 2026-01-07 03:30:24 +01:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user