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
Reorganize tests; camelCase plugin name
  • Loading branch information
peey committed Jun 17, 2017
commit 38c417e9710c0672eaea2e1ea66540095630fef0
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parse
pluginList.unshift("estree");
}

if (pluginList.indexOf("decorators") >= 0 && pluginList.indexOf("decorators-stage-2") >= 0) {
throw new Error("Cannot use decorators and decorators-stage-2 plugin together");
if (pluginList.indexOf("decorators") >= 0 && pluginList.indexOf("decoratorsStage2") >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have to do this now, but we should figure out a better solution to this in the future (regarding multiple versions of the same kind plugin). Same kind of error as TS + Flow

throw new Error("Cannot use decorators and decoratorsStage2 plugin together");
}

const key = pluginList.join("/");
Expand Down
4 changes: 2 additions & 2 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ export default class ExpressionParser extends LValParser {
}

if (this.match(tt.at)) {
if (this.hasPlugin("decorators-stage-2")) {
this.raise(this.state.start, "decorators-stage-2 disallows object literal property decorators");
if (this.hasPlugin("decoratorsStage2")) {
this.raise(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
Expand Down
2 changes: 1 addition & 1 deletion src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class LValParser extends NodeUtils {
break;
} else {
const decorators = [];
if (this.match(tt.at) && this.hasPlugin("decorators-stage-2")) {
if (this.match(tt.at) && this.hasPlugin("decoratorsStage2")) {
this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
}
while (this.match(tt.at)) {
Expand Down
8 changes: 4 additions & 4 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class StatementParser extends ExpressionParser {
}

parseDecorators(allowExport?: boolean): void {
if (this.hasPlugin("decorators-stage-2")) {
if (this.hasPlugin("decoratorsStage2")) {
allowExport = false;
}

Expand All @@ -176,14 +176,14 @@ export default class StatementParser extends ExpressionParser {
}

parseDecorator(): N.Decorator {
if (!(this.hasPlugin("decorators") || this.hasPlugin("decorators-stage-2"))) {
if (!(this.hasPlugin("decorators") || this.hasPlugin("decoratorsStage2"))) {
this.unexpected();
}

const node = this.startNode();
this.next();

if (this.hasPlugin("decorators-stage-2")) {
if (this.hasPlugin("decoratorsStage2")) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
Expand Down Expand Up @@ -714,7 +714,7 @@ export default class StatementParser extends ExpressionParser {

this.parseClassMember(classBody, member, state);

if (this.hasPlugin("decorators-stage-2") && member.kind != "method" && member.decorators && member.decorators.length > 0) {
if (this.hasPlugin("decoratorsStage2") && member.kind != "method" && member.decorators && member.decorators.length > 0) {
this.raise(member.start, "Stage 2 decorators may only be used with a class or a class method");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["decorators-stage-2", "classProperties"],
"plugins": ["decoratorsStage2", "classProperties"],
"throws": "Unexpected token (2:12)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["decorators-stage-2", "classProperties"],
"plugins": ["decoratorsStage2", "classProperties"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:6)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["classProperties", "decorators-stage-2"],
"plugins": ["classProperties", "decoratorsStage2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:7)"
}
2 changes: 1 addition & 1 deletion test/fixtures/experimental/decorators-stage-2/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["decorators-stage-2"]
"plugins": ["decoratorsStage2"]
}