Merge pull request #1013 from lokshunhung/fix/ts-class-prop-definite
Print class property definite assignment assertions
This commit is contained in:
commit
06eca93f28
2 changed files with 31 additions and 0 deletions
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue