Skip to content

Commit

Permalink
Don't fail for object decorators with stage 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 31, 2019
1 parent 43f7bcd commit 9f985e0
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -1505,12 +1505,12 @@ export default class ExpressionParser extends LValParser {
this.state.start,
"Stage 2 decorators disallow object literal property decorators",
);
} else {
// we needn't check if decorators (stage 0) plugin is enabled since it's checked by
// the call to this.parseDecorator
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}
}

// we needn't check if decorators (stage 0) plugin is enabled since it's checked by
// the call to this.parseDecorator
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}
}

Expand Down
Expand Up @@ -6,6 +6,5 @@
"decoratorsBeforeExport": false
}
]
],
"throws": "Unexpected token (2:2)"
]
}
@@ -0,0 +1,195 @@
{
"type": "File",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"errors": [
"SyntaxError: Stage 2 decorators disallow object literal property decorators (2:2)"
],
"program": {
"type": "Program",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 5,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "o"
},
"name": "o"
},
"init": {
"type": "ObjectExpression",
"start": 8,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 5,
"column": 1
}
},
"properties": [
{
"type": "ObjectMethod",
"start": 19,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 4,
"column": 3
}
},
"decorators": [
{
"type": "Decorator",
"start": 12,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"expression": {
"type": "Identifier",
"start": 13,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "baz"
},
"name": "baz"
}
}
],
"method": true,
"key": {
"type": "Identifier",
"start": 19,
"end": 22,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 25,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 4,
"column": 3
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"kind": "var"
}
],
"directives": []
}
}

0 comments on commit 9f985e0

Please sign in to comment.