From add8e4ad13b4a44de409e283e99679a904012317 Mon Sep 17 00:00:00 2001 From: Peeyush Kushwaha Date: Fri, 23 Jun 2017 02:19:08 +0530 Subject: [PATCH] Helpful error message for @dec export class --- src/parser/statement.js | 5 +++++ .../decorators-2/no-export-decorators-on-class/options.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index 2cbfa3b52c..5f40ddb277 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -173,6 +173,11 @@ export default class StatementParser extends ExpressionParser { return; } + // special error for the common case of @dec export class + if (!allowExport && this.match(tt._export)) { + this.raise(this.state.start, "Using the export keyword between decorators and class is disallowed. Please use `export @dec class` instead"); + } + if (!this.match(tt._class)) { this.raise(this.state.start, "Leading decorators must be attached to a class declaration"); } diff --git a/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json b/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json index 43922816e1..4c5c609080 100644 --- a/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json +++ b/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Leading decorators must be attached to a class declaration (2:0)" + "throws": "Using the export keyword between decorators and class is disallowed. Please use `export @dec class` instead (2:0)" }