diff --git a/src/expression.js b/src/expression.js index b84117e756..8eaeab610f 100755 --- a/src/expression.js +++ b/src/expression.js @@ -509,22 +509,24 @@ pp.parseTemplate = function() { pp.parseObj = function(isPattern, refShorthandDefaultPos) { let node = this.startNode(), first = true, propHash = {} node.properties = [] + let decorators = [] this.next() while (!this.eat(tt.braceR)) { if (!first) { this.expect(tt.comma) if (this.afterTrailingComma(tt.braceR)) break } else first = false - while (this.type === tt.at) { - this.decorators.push(this.parseDecorator()) + decorators.push(this.parseDecorator()) } - let prop = this.startNode(), isGenerator = false, isAsync = false, start + if (decorators.length) { + prop.decorators = decorators + decorators = [] + } if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) { prop = this.parseSpread() prop.type = "SpreadProperty" - this.takeDecorators(prop) node.properties.push(prop) continue } @@ -550,10 +552,9 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) { } this.parseObjPropValue(prop, start, isGenerator, isAsync, isPattern, refShorthandDefaultPos); this.checkPropClash(prop, propHash) - this.takeDecorators(prop) node.properties.push(this.finishNode(prop, "Property")) } - if (this.decorators.length) { + if (decorators.length) { this.raise(this.start, "You have trailing decorators with no property"); } return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") diff --git a/src/statement.js b/src/statement.js index 9490e25e3c..cf351718f3 100755 --- a/src/statement.js +++ b/src/statement.js @@ -471,14 +471,18 @@ pp.parseClass = function(node, isStatement) { var classBody = this.startNode() classBody.body = [] this.expect(tt.braceL) + let decorators = [] while (!this.eat(tt.braceR)) { if (this.eat(tt.semi)) continue if (this.type === tt.at) { - this.decorators.push(this.parseDecorator()) + decorators.push(this.parseDecorator()) continue } var method = this.startNode() - this.takeDecorators(method) + if (decorators.length) { + method.decorators = decorators + decorators = [] + } var isGenerator = this.eat(tt.star), isAsync = false this.parsePropertyName(method) if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" && @@ -517,7 +521,7 @@ pp.parseClass = function(node, isStatement) { } this.parseClassMethod(classBody, method, isGenerator, isAsync) } - if (this.decorators.length) { + if (decorators.length) { this.raise(this.start, "You have trailing decorators with no method"); } node.body = this.finishNode(classBody, "ClassBody")