From e1972baff51e838f226b6063026ed83e992b411a Mon Sep 17 00:00:00 2001 From: Peeyush Kushwaha Date: Thu, 22 Jun 2017 01:45:27 +0530 Subject: [PATCH] Decorated classes/methods start where the decorator starts --- src/parser/statement.js | 6 ++++++ .../class-decorator-call-expr/expected.json | 4 ++-- .../decorators-stage-2/class-decorator/expected.json | 4 ++-- .../decorators-stage-2/class-expression/expected.json | 8 ++++---- .../decorators-stage-2/class-generator/expected.json | 4 ++-- .../decorators-stage-2/complex-expr/expected.json | 4 ++-- .../export-decorated-class/expected.json | 4 ++-- .../decorators-stage-2/no-class-property/options.json | 2 +- .../no-computed-decorator-member/options.json | 2 +- .../no-constructor-decorators/options.json | 2 +- .../decorators-stage-2/no-private-property/options.json | 2 +- .../decorators-stage-2/no-static-property/options.json | 2 +- .../on-computed-name-method/expected.json | 4 ++-- 13 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index 2e887a7e85..74be753de9 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -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 = []; } } @@ -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 = []; } diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json index 291ef173cc..26d8fca5be 100644 --- a/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json @@ -30,11 +30,11 @@ "body": [ { "type": "ClassDeclaration", - "start": 12, + "start": 0, "end": 24, "loc": { "start": { - "line": 2, + "line": 1, "column": 0 }, "end": { diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json b/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json index 8299bdd639..b0570136eb 100644 --- a/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json @@ -30,11 +30,11 @@ "body": [ { "type": "ClassDeclaration", - "start": 5, + "start": 0, "end": 19, "loc": { "start": { - "line": 2, + "line": 1, "column": 0 }, "end": { diff --git a/test/fixtures/experimental/decorators-stage-2/class-expression/expected.json b/test/fixtures/experimental/decorators-stage-2/class-expression/expected.json index 338ad4e54c..af3ed887d2 100644 --- a/test/fixtures/experimental/decorators-stage-2/class-expression/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/class-expression/expected.json @@ -76,12 +76,12 @@ }, "init": { "type": "ClassExpression", - "start": 15, + "start": 10, "end": 58, "loc": { "start": { "line": 1, - "column": 15 + "column": 10 }, "end": { "line": 6, @@ -157,11 +157,11 @@ "body": [ { "type": "ClassMethod", - "start": 36, + "start": 29, "end": 56, "loc": { "start": { - "line": 3, + "line": 2, "column": 2 }, "end": { diff --git a/test/fixtures/experimental/decorators-stage-2/class-generator/expected.json b/test/fixtures/experimental/decorators-stage-2/class-generator/expected.json index a248b8b5ec..87b73b717a 100644 --- a/test/fixtures/experimental/decorators-stage-2/class-generator/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/class-generator/expected.json @@ -77,12 +77,12 @@ "body": [ { "type": "ClassMethod", - "start": 17, + "start": 12, "end": 23, "loc": { "start": { "line": 2, - "column": 7 + "column": 2 }, "end": { "line": 2, diff --git a/test/fixtures/experimental/decorators-stage-2/complex-expr/expected.json b/test/fixtures/experimental/decorators-stage-2/complex-expr/expected.json index bc2d356463..b048d367ee 100644 --- a/test/fixtures/experimental/decorators-stage-2/complex-expr/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/complex-expr/expected.json @@ -77,11 +77,11 @@ "body": [ { "type": "ClassMethod", - "start": 29, + "start": 12, "end": 34, "loc": { "start": { - "line": 3, + "line": 2, "column": 2 }, "end": { diff --git a/test/fixtures/experimental/decorators-stage-2/export-decorated-class/expected.json b/test/fixtures/experimental/decorators-stage-2/export-decorated-class/expected.json index a480a4682d..bbfcc7fcca 100644 --- a/test/fixtures/experimental/decorators-stage-2/export-decorated-class/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/export-decorated-class/expected.json @@ -44,12 +44,12 @@ }, "declaration": { "type": "ClassExpression", - "start": 21, + "start": 16, "end": 34, "loc": { "start": { "line": 2, - "column": 5 + "column": 0 }, "end": { "line": 2, diff --git a/test/fixtures/experimental/decorators-stage-2/no-class-property/options.json b/test/fixtures/experimental/decorators-stage-2/no-class-property/options.json index a22e3dad04..000a057244 100644 --- a/test/fixtures/experimental/decorators-stage-2/no-class-property/options.json +++ b/test/fixtures/experimental/decorators-stage-2/no-class-property/options.json @@ -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)" } diff --git a/test/fixtures/experimental/decorators-stage-2/no-computed-decorator-member/options.json b/test/fixtures/experimental/decorators-stage-2/no-computed-decorator-member/options.json index acf8362a77..1a919e297a 100644 --- a/test/fixtures/experimental/decorators-stage-2/no-computed-decorator-member/options.json +++ b/test/fixtures/experimental/decorators-stage-2/no-computed-decorator-member/options.json @@ -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)" } diff --git a/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json index c0baef5996..a26ed7cacb 100644 --- a/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json +++ b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json @@ -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)" } diff --git a/test/fixtures/experimental/decorators-stage-2/no-private-property/options.json b/test/fixtures/experimental/decorators-stage-2/no-private-property/options.json index 4f6c7c9e0e..4346ad3723 100644 --- a/test/fixtures/experimental/decorators-stage-2/no-private-property/options.json +++ b/test/fixtures/experimental/decorators-stage-2/no-private-property/options.json @@ -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)" } diff --git a/test/fixtures/experimental/decorators-stage-2/no-static-property/options.json b/test/fixtures/experimental/decorators-stage-2/no-static-property/options.json index a22e3dad04..000a057244 100644 --- a/test/fixtures/experimental/decorators-stage-2/no-static-property/options.json +++ b/test/fixtures/experimental/decorators-stage-2/no-static-property/options.json @@ -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)" } diff --git a/test/fixtures/experimental/decorators-stage-2/on-computed-name-method/expected.json b/test/fixtures/experimental/decorators-stage-2/on-computed-name-method/expected.json index a9f30a4ca9..7e9968743f 100644 --- a/test/fixtures/experimental/decorators-stage-2/on-computed-name-method/expected.json +++ b/test/fixtures/experimental/decorators-stage-2/on-computed-name-method/expected.json @@ -77,11 +77,11 @@ "body": [ { "type": "ClassMethod", - "start": 19, + "start": 12, "end": 31, "loc": { "start": { - "line": 3, + "line": 2, "column": 2 }, "end": {