Disallow in object literals, params, class props

And add tests to reflect the same
This commit is contained in:
Peeyush Kushwaha
2017-06-17 17:49:33 +05:30
parent 162bc905a6
commit 9c639743dd
33 changed files with 727 additions and 178 deletions

View File

@@ -847,8 +847,16 @@ export default class ExpressionParser extends LValParser {
if (this.eat(tt.braceR)) break;
}
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
if (this.match(tt.at)) {
if (this.hasPlugin("decorators-stage-2")) {
this.raise(this.state.start, "decorators-stage-2 disallows 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
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}
}
}
let prop = this.startNode(), isGenerator = false, isAsync = false, startPos, startLoc;

View File

@@ -187,6 +187,9 @@ export default class LValParser extends NodeUtils {
break;
} else {
const decorators = [];
if (this.match(tt.at) && this.hasPlugin("decorators-stage-2")) {
this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
}
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}

View File

@@ -709,6 +709,10 @@ 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) {
this.raise(member.start, "Stage 2 decorators may only be used with a class or a class method");
}
}
if (decorators.length) {
@@ -776,6 +780,7 @@ export default class StatementParser extends ExpressionParser {
if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) {
this.raise(methodOrProp.key.start, "Classes may not have static property named prototype");
}
if (this.isClassMethod()) {
// a normal method
if (this.isNonstaticConstructor(method)) {