Allow new.target in class properties (#759)
This commit is contained in:
parent
60ea39aa70
commit
b5e6ba62db
@ -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;
|
||||
|
||||
@ -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)"
|
||||
}
|
||||
|
||||
@ -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)"
|
||||
}
|
||||
|
||||
1
test/fixtures/experimental/class-properties/new-target-invalid/actual.js
vendored
Normal file
1
test/fixtures/experimental/class-properties/new-target-invalid/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var x = new.target;
|
||||
4
test/fixtures/experimental/class-properties/new-target-invalid/options.json
vendored
Normal file
4
test/fixtures/experimental/class-properties/new-target-invalid/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["classProperties"],
|
||||
"throws": "new.target can only be used in functions or class properties (1:8)"
|
||||
}
|
||||
10
test/fixtures/experimental/class-properties/new-target-with-flow/actual.js
vendored
Normal file
10
test/fixtures/experimental/class-properties/new-target-with-flow/actual.js
vendored
Normal file
@ -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) => {};
|
||||
}
|
||||
1150
test/fixtures/experimental/class-properties/new-target-with-flow/expected.json
vendored
Normal file
1150
test/fixtures/experimental/class-properties/new-target-with-flow/expected.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
test/fixtures/experimental/class-properties/new-target-with-flow/options.json
vendored
Normal file
3
test/fixtures/experimental/class-properties/new-target-with-flow/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties", "flow"]
|
||||
}
|
||||
10
test/fixtures/experimental/class-properties/new-target/actual.js
vendored
Normal file
10
test/fixtures/experimental/class-properties/new-target/actual.js
vendored
Normal file
@ -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) => {};
|
||||
}
|
||||
1142
test/fixtures/experimental/class-properties/new-target/expected.json
vendored
Normal file
1142
test/fixtures/experimental/class-properties/new-target/expected.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
test/fixtures/experimental/class-properties/new-target/options.json
vendored
Normal file
3
test/fixtures/experimental/class-properties/new-target/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user