Add support for ClassPrivateProperty (#2837)
parent
68d1b56696
commit
2be986d0d7
|
@ -622,6 +622,7 @@ function isStatement(node) {
|
|||
node.type === "ClassDeclaration" ||
|
||||
node.type === "ClassMethod" ||
|
||||
node.type === "ClassProperty" ||
|
||||
node.type === "ClassPrivateProperty" ||
|
||||
node.type === "ContinueStatement" ||
|
||||
node.type === "DebuggerStatement" ||
|
||||
node.type === "DeclareClass" ||
|
||||
|
|
|
@ -25,7 +25,8 @@ function parse(text, parsers, opts) {
|
|||
"numericSeparator",
|
||||
"importMeta",
|
||||
"optionalCatchBinding",
|
||||
"optionalChaining"
|
||||
"optionalChaining",
|
||||
"classPrivateProperties"
|
||||
]
|
||||
};
|
||||
|
||||
|
|
|
@ -1809,7 +1809,8 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
"}"
|
||||
]);
|
||||
case "ClassProperty":
|
||||
case "TSAbstractClassProperty": {
|
||||
case "TSAbstractClassProperty":
|
||||
case "ClassPrivateProperty": {
|
||||
if (n.accessibility) {
|
||||
parts.push(n.accessibility + " ");
|
||||
}
|
||||
|
@ -2725,6 +2726,9 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return printStatementSequence(bodyPath, options, print);
|
||||
}, "body");
|
||||
|
||||
case "PrivateName":
|
||||
return concat(["#", path.call(print, "id")]);
|
||||
|
||||
default:
|
||||
/* istanbul ignore next */
|
||||
throw new Error("unknown type: " + JSON.stringify(n.type));
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`private_fields.js 1`] = `
|
||||
class A { #x; #y; }
|
||||
class B { #x = 0; #y = 1; }
|
||||
|
||||
class C {
|
||||
static #x;
|
||||
static #y = 1;
|
||||
}
|
||||
|
||||
class D {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
|
||||
class Point {
|
||||
#x = 1;
|
||||
#y = 2;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.#x = +x;
|
||||
this.#y = +y;
|
||||
}
|
||||
|
||||
get x() { return this.#x }
|
||||
set x(value) { this.#x = +value }
|
||||
|
||||
get y() { return this.#y }
|
||||
set y(value) { this.#y = +value }
|
||||
|
||||
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
||||
|
||||
toString() { return \`Point<\${ this.#x },\${ this.#y }>\` }
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class A {
|
||||
#x;
|
||||
#y;
|
||||
}
|
||||
class B {
|
||||
#x = 0;
|
||||
#y = 1;
|
||||
}
|
||||
|
||||
class C {
|
||||
static #x;
|
||||
static #y = 1;
|
||||
}
|
||||
|
||||
class D {
|
||||
#x;
|
||||
#y;
|
||||
}
|
||||
|
||||
class Point {
|
||||
#x = 1;
|
||||
#y = 2;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.#x = +x;
|
||||
this.#y = +y;
|
||||
}
|
||||
|
||||
get x() {
|
||||
return this.#x;
|
||||
}
|
||||
set x(value) {
|
||||
this.#x = +value;
|
||||
}
|
||||
|
||||
get y() {
|
||||
return this.#y;
|
||||
}
|
||||
set y(value) {
|
||||
this.#y = +value;
|
||||
}
|
||||
|
||||
equals(p) {
|
||||
return this.#x === p.#x && this.#y === p.#y;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return \`Point<\${this.#x},\${this.#y}>\`;
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`private_fields.js 2`] = `
|
||||
class A { #x; #y; }
|
||||
class B { #x = 0; #y = 1; }
|
||||
|
||||
class C {
|
||||
static #x;
|
||||
static #y = 1;
|
||||
}
|
||||
|
||||
class D {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
|
||||
class Point {
|
||||
#x = 1;
|
||||
#y = 2;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.#x = +x;
|
||||
this.#y = +y;
|
||||
}
|
||||
|
||||
get x() { return this.#x }
|
||||
set x(value) { this.#x = +value }
|
||||
|
||||
get y() { return this.#y }
|
||||
set y(value) { this.#y = +value }
|
||||
|
||||
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
||||
|
||||
toString() { return \`Point<\${ this.#x },\${ this.#y }>\` }
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class A {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
class B {
|
||||
#x = 0
|
||||
#y = 1
|
||||
}
|
||||
|
||||
class C {
|
||||
static #x
|
||||
static #y = 1
|
||||
}
|
||||
|
||||
class D {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
|
||||
class Point {
|
||||
#x = 1
|
||||
#y = 2
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.#x = +x
|
||||
this.#y = +y
|
||||
}
|
||||
|
||||
get x() {
|
||||
return this.#x
|
||||
}
|
||||
set x(value) {
|
||||
this.#x = +value
|
||||
}
|
||||
|
||||
get y() {
|
||||
return this.#y
|
||||
}
|
||||
set y(value) {
|
||||
this.#y = +value
|
||||
}
|
||||
|
||||
equals(p) {
|
||||
return this.#x === p.#x && this.#y === p.#y
|
||||
}
|
||||
|
||||
toString() {
|
||||
return \`Point<\${this.#x},\${this.#y}>\`
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
|
@ -0,0 +1,2 @@
|
|||
run_spec(__dirname, { parser: "babylon" });
|
||||
run_spec(__dirname, { semi: false, parser: "babylon" });
|
|
@ -0,0 +1,32 @@
|
|||
class A { #x; #y; }
|
||||
class B { #x = 0; #y = 1; }
|
||||
|
||||
class C {
|
||||
static #x;
|
||||
static #y = 1;
|
||||
}
|
||||
|
||||
class D {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
|
||||
class Point {
|
||||
#x = 1;
|
||||
#y = 2;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.#x = +x;
|
||||
this.#y = +y;
|
||||
}
|
||||
|
||||
get x() { return this.#x }
|
||||
set x(value) { this.#x = +value }
|
||||
|
||||
get y() { return this.#y }
|
||||
set y(value) { this.#y = +value }
|
||||
|
||||
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
||||
|
||||
toString() { return `Point<${ this.#x },${ this.#y }>` }
|
||||
}
|
Loading…
Reference in New Issue