Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Allow new.target in class properties (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism authored and hzoo committed Oct 14, 2017
1 parent 60ea39a commit b5e6ba6
Show file tree
Hide file tree
Showing 11 changed files with 2,333 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,14 @@ export default class ExpressionParser extends LValParser {
if (this.eat(tt.dot)) {
const metaProp = this.parseMetaProperty(node, meta, "target");

if (!this.state.inFunction) {
this.raise(
metaProp.property.start,
"new.target can only be used in functions",
);
if (!this.state.inFunction && !this.state.inClassProperty) {
let error = "new.target can only be used in functions";

if (this.hasPlugin("classProperties")) {
error += " or class properties";
}

this.raise(metaProp.start, error);
}

return metaProp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "new.target can only be used in functions (1:4)"
"throws": "new.target can only be used in functions (1:0)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "new.target can only be used in functions (1:12)"
"throws": "new.target can only be used in functions (1:8)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = new.target;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["classProperties"],
"throws": "new.target can only be used in functions or class properties (1:8)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class X {
static a = new.target;
static b = (foo = 1 + bar(new.target));
static c = () => new.target;
static d = (foo = new.target) => {};
e = new.target;
f = (foo = 1 + bar(new.target));
g = () => new.target;
h = (foo = new.target) => {};
}
Loading

0 comments on commit b5e6ba6

Please sign in to comment.