Skip to content
This repository was archived by the owner on May 19, 2018. It is now read-only.

Decorators Stage 2 Parsing #587

Merged
merged 14 commits into from
Jun 22, 2017
Merged
Prev Previous commit
Next Next commit
Decorated classes/methods start where the decorator starts
  • Loading branch information
peey committed Jun 21, 2017
commit e1972baff51e838f226b6063026ed83e992b411a
6 changes: 6 additions & 0 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export default class StatementParser extends ExpressionParser {
takeDecorators(node: N.HasDecorators): void {
if (this.state.decorators.length) {
node.decorators = this.state.decorators;
if (this.hasPlugin("decoratorsStage2")) {
this.resetStartLocationFromNode(node, this.state.decorators[0]);
}
this.state.decorators = [];
}
}
Expand Down Expand Up @@ -709,6 +712,9 @@ export default class StatementParser extends ExpressionParser {
// steal the decorators if there are any
if (decorators.length) {
member.decorators = decorators;
if (this.hasPlugin("decoratorsStage2")) {
this.resetStartLocationFromNode(member, decorators[0]);
}
decorators = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"body": [
{
"type": "ClassDeclaration",
"start": 12,
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 2,
"line": 1,
"column": 0
},
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"body": [
{
"type": "ClassDeclaration",
"start": 5,
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 2,
"line": 1,
"column": 0
},
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
},
"init": {
"type": "ClassExpression",
"start": 15,
"start": 10,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 15
"column": 10
},
"end": {
"line": 6,
Expand Down Expand Up @@ -157,11 +157,11 @@
"body": [
{
"type": "ClassMethod",
"start": 36,
"start": 29,
"end": 56,
"loc": {
"start": {
"line": 3,
"line": 2,
"column": 2
},
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
"body": [
{
"type": "ClassMethod",
"start": 17,
"start": 12,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 7
"column": 2
},
"end": {
"line": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
"body": [
{
"type": "ClassMethod",
"start": 29,
"start": 12,
"end": 34,
"loc": {
"start": {
"line": 3,
"line": 2,
"column": 2
},
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
},
"declaration": {
"type": "ClassExpression",
"start": 21,
"start": 16,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 5
"column": 0
},
"end": {
"line": 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["classProperties", "decoratorsStage2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:7)"
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["decoratorsStage2", "classProperties"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:6)"
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "You can't attach decorators to a class constructor (3:2)"
"throws": "You can't attach decorators to a class constructor (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["classProperties", "classPrivateProperties", "decoratorsStage2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:7)"
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["classProperties", "decoratorsStage2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:7)"
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
"body": [
{
"type": "ClassMethod",
"start": 19,
"start": 12,
"end": 31,
"loc": {
"start": {
"line": 3,
"line": 2,
"column": 2
},
"end": {
Expand Down