Test printing definite class property

This commit is contained in:
LS Hung 2021-12-11 21:35:05 +08:00 committed by GitHub
parent c327a5e289
commit e71ab9bc6a
2 changed files with 31 additions and 0 deletions

View file

@ -1449,6 +1449,10 @@ function genericPrintNoParens(path: any, options: any, print: any) {
parts.push("?");
}
if (n.definite) {
parts.push("!");
}
if (n.typeAnnotation) {
parts.push(path.call(print, "typeAnnotation"));
}

View file

@ -1206,6 +1206,33 @@ describe("printer", function () {
assert.strictEqual(pretty, code);
});
it("prints 'definite' ClassProperty correctly", function () {
const code = ["class A {", " foo!: string;", "}"].join(eol);
const ast = b.program([
b.classDeclaration(
b.identifier("A"),
b.classBody([
Object.assign(
b.classProperty(
b.identifier("foo"),
null,
b.typeAnnotation(b.stringTypeAnnotation()),
),
{ definite: true },
),
]),
),
]);
const printer = new Printer({
tabWidth: 2,
});
const pretty = printer.printGenerically(ast).code;
assert.strictEqual(pretty, code);
});
it("prints static ClassProperty correctly", function () {
const code = ["class A {", " static foo = Bar;", "}"].join(eol);