Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ad4867

Browse files
author
Max Schaefer
committed
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.
1 parent db9ac72 commit 1ad4867

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

javascript/extractor/src/com/semmle/jcorn/ESNextParser.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected MemberDefinition<?> parseClassMember(boolean hadConstructor) {
257257
return member;
258258
}
259259

260-
private List<Decorator> parseDecorators() {
260+
public List<Decorator> parseDecorators() {
261261
List<Decorator> result = new ArrayList<Decorator>();
262262
while (this.type == at)
263263
result.add(this.parseDecorator());
@@ -267,10 +267,23 @@ private List<Decorator> parseDecorators() {
267267
private Decorator parseDecorator() {
268268
Position start = startLoc;
269269
this.next();
270-
Decorator decorator = new Decorator(new SourceLocation(start), this.parseMaybeAssign(false, null, null));
270+
Expression body = parseDecoratorBody();
271+
Decorator decorator = new Decorator(new SourceLocation(start), body);
271272
return this.finishNode(decorator);
272273
}
273274

275+
protected Expression parseDecoratorBody() {
276+
Expression base;
277+
int startPos = this.start;
278+
Position startLoc = this.startLoc;
279+
if (this.type == TokenType.parenL) {
280+
base = parseParenExpression();
281+
} else {
282+
base = parseIdent(true);
283+
}
284+
return parseSubscripts(base, startPos, startLoc, false);
285+
}
286+
274287
/*
275288
* Support for proposed extensions to `export`
276289
* (http://leebyron.com/ecmascript-export-ns-from and http://leebyron.com/ecmascript-export-default-from)

0 commit comments

Comments
 (0)