Throw error if new.target is used outside of a function (#402)

This commit is contained in:
Brian Ng
2017-03-08 09:34:22 -06:00
committed by Daniel Tschinder
parent 35e7732156
commit ca652bd934
5 changed files with 163 additions and 96 deletions

View File

@@ -662,7 +662,13 @@ pp.parseNew = function () {
const meta = this.parseIdentifier(true);
if (this.eat(tt.dot)) {
return this.parseMetaProperty(node, meta, "target");
const metaProp = this.parseMetaProperty(node, meta, "target");
if (!this.state.inFunction) {
this.raise(metaProp.property.start, "new.target can only be used in functions");
}
return metaProp;
}
node.callee = this.parseNoCallExpr();