Skip to content

Commit c56affc

Browse files
authored
Implement ClassPrivateProperty + test (#62)
1 parent ce4678e commit c56affc

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src-transpiler/Stringifier.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,23 @@ class Stringifier {
413413
out += ';';
414414
return out;
415415
}
416+
/**
417+
* @param {import("@babel/types").ClassPrivateProperty} node - The Babel AST node.
418+
* @returns {string} Stringification of the node.
419+
*/
420+
ClassPrivateProperty(node) {
421+
const {static: static_, key, value} = node;
422+
let out = this.spaces;
423+
if (static_) {
424+
out += 'static ';
425+
}
426+
out += this.toSource(key);
427+
if (value) {
428+
out += ' = ' + this.toSource(value);
429+
}
430+
out += ';';
431+
return out;
432+
}
416433
/**
417434
* @param {import("@babel/types").ContinueStatement} node - The Babel AST node.
418435
* @returns {string} Stringification of the node.

test/typechecking.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"input": "./test/typechecking/ArrowFunctionExpression-foreach-input.mjs",
1212
"output": "./test/typechecking/ArrowFunctionExpression-foreach-output.mjs"
1313
},
14+
{
15+
"input": "./test/typechecking/ClassPrivateProperty-input.mjs",
16+
"output": "./test/typechecking/ClassPrivateProperty-output.mjs"
17+
},
1418
{
1519
"input": "./test/typechecking/ClassProperty-value-is-null-input.mjs",
1620
"output": "./test/typechecking/ClassProperty-value-is-null-output.mjs"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Test {
2+
#a;
3+
#b = 123;
4+
#c = this.#b * 2;
5+
static #d;
6+
static #e = 1;
7+
}
8+
const test = new Test();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Test {
2+
#a;
3+
#b = 123;
4+
#c = this.#b * 2;
5+
static #d;
6+
static #e = 1;
7+
}
8+
registerClass(Test);
9+
const test = new Test();

0 commit comments

Comments
 (0)