Skip to content

Commit

Permalink
Test printing definite class property
Browse files Browse the repository at this point in the history
  • Loading branch information
lokshunhung authored Apr 27, 2022
1 parent c327a5e commit e71ab9b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
27 changes: 27 additions & 0 deletions test/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e71ab9b

Please sign in to comment.