From 85f2e79f959327423546c02b1e4dfbb0e82a1825 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 11 Apr 2015 16:30:55 -0700 Subject: [PATCH] add support for object literal decorators - fixes #1154 --- src/expression.js | 9 +++++++++ src/statement.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/expression.js b/src/expression.js index 9309f2e3e7..7d62e0cc90 100755 --- a/src/expression.js +++ b/src/expression.js @@ -516,10 +516,15 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) { if (this.afterTrailingComma(tt.braceR)) break } else first = false + while (this.type === tt.at) { + this.decorators.push(this.parseDecorator()) + } + let prop = this.startNode(), isGenerator = false, isAsync = false, start if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) { prop = this.parseSpread() prop.type = "SpreadProperty" + this.takeDecorators(prop) node.properties.push(prop) continue } @@ -545,8 +550,12 @@ 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) { + 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 08ae517d3d..35104336d9 100755 --- a/src/statement.js +++ b/src/statement.js @@ -475,7 +475,7 @@ pp.parseClass = function(node, isStatement) { if (this.eat(tt.semi)) continue if (this.type === tt.at) { this.decorators.push(this.parseDecorator()) - continue; + continue } var method = this.startNode() this.takeDecorators(method)