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
rename decoratorsStage2 -> decorators2
  • Loading branch information
peey committed Jun 21, 2017
commit e5fdb3448dcdf2b6ceb33ad9dd1a078e38a4d27d
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const parserClassCache: { [key: string]: Class<Parser> } = {};
/** Get a Parser class with plugins applied. */
function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parser> {

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

Choose a reason for hiding this comment

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

I'd say to use Array.prototype.includes instead...... but that doesn't work on Node 4 😢

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

// Filter out just the plugins that have an actual mixin associated with them.
Expand Down
2 changes: 1 addition & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ export default class ExpressionParser extends LValParser {
}

if (this.match(tt.at)) {
if (this.hasPlugin("decoratorsStage2")) {
if (this.hasPlugin("decorators2")) {
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
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("decoratorsStage2")) {
if (this.match(tt.at) && this.hasPlugin("decorators2")) {
this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
}
while (this.match(tt.at)) {
Expand Down
12 changes: 6 additions & 6 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ 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")) {
if (this.hasPlugin("decorators2")) {
this.resetStartLocationFromNode(node, this.state.decorators[0]);
}
this.state.decorators = [];
}
}

parseDecorators(allowExport?: boolean): void {
if (this.hasPlugin("decoratorsStage2")) {
if (this.hasPlugin("decorators2")) {
allowExport = false;
}

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

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

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

if (this.hasPlugin("decoratorsStage2")) {
if (this.hasPlugin("decorators2")) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
Expand Down Expand Up @@ -712,15 +712,15 @@ export default class StatementParser extends ExpressionParser {
// steal the decorators if there are any
if (decorators.length) {
member.decorators = decorators;
if (this.hasPlugin("decoratorsStage2")) {
if (this.hasPlugin("decorators2")) {
this.resetStartLocationFromNode(member, decorators[0]);
}
decorators = [];
}

this.parseClassMember(classBody, member, state);

if (this.hasPlugin("decoratorsStage2") && member.kind != "method" && member.decorators && member.decorators.length > 0) {
if (this.hasPlugin("decorators2") && 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": ["classProperties", "decoratorsStage2"],
"plugins": ["classProperties", "decorators2"],
"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"],
"plugins": ["decorators2", "classProperties"],
"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", "classPrivateProperties", "decoratorsStage2"],
"plugins": ["classProperties", "classPrivateProperties", "decorators2"],
"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"],
"plugins": ["classProperties", "decorators2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}
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": ["decoratorsStage2"]
"plugins": ["decorators2"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["decorators", "decoratorsStage2"],
"throws": "Cannot use decorators and decoratorsStage2 plugin together"
"plugins": ["decorators", "decorators2"],
"throws": "Cannot use decorators and decorators2 plugin together"
}