From 1ad4867f2a05e7e7828650894dff72edba6f72ac Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Tue, 29 Jan 2019 15:00:33 +0000 Subject: [PATCH] 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. --- .../src/com/semmle/jcorn/ESNextParser.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/javascript/extractor/src/com/semmle/jcorn/ESNextParser.java b/javascript/extractor/src/com/semmle/jcorn/ESNextParser.java index a11293ca05f..df6eec3df8f 100644 --- a/javascript/extractor/src/com/semmle/jcorn/ESNextParser.java +++ b/javascript/extractor/src/com/semmle/jcorn/ESNextParser.java @@ -257,7 +257,7 @@ public class ESNextParser extends JSXParser { return member; } - private List parseDecorators() { + public List parseDecorators() { List result = new ArrayList(); 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)