From 0ce9dd558a0323b034a83a07d8fc67c12fca224e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 27 May 2024 22:05:02 +0300 Subject: [PATCH 1/2] feature: add support of set/get in interfaces --- lib/printer.ts | 5 +++++ test/typescript.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/printer.ts b/lib/printer.ts index df020115..b27fabd7 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -2333,6 +2333,11 @@ function genericPrintNoParens(path: any, options: any, print: any) { return concat(parts); case "TSMethodSignature": + if (n.kind === 'get') { + parts.push('get ') + } else if (n.kind === 'set') { + parts.push('set ') + } if (n.computed) { parts.push("[", path.call(print, "key"), "]"); } else { diff --git a/test/typescript.ts b/test/typescript.ts index ddbce81a..410fa9ac 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -244,6 +244,13 @@ const nodeMajorVersion = parseInt(process.versions.node, 10); " a(c: (this: void, e: E) => void): void;", "}", ]); + + check([ + "interface LabelledContainer {", + " get label(): string;", + " set label(a: string);", + "}", + ]); check([ "interface Square extends Shape, Visible {", From 828e94ff9cef8e421a4139e2eb504c69d8a070a6 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 27 May 2024 22:14:57 +0300 Subject: [PATCH 2/2] chore: codestyle --- lib/lines.ts | 5 ++++- lib/printer.ts | 12 ++++++------ test/jsx.ts | 13 ++++++++----- test/typescript.ts | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/lines.ts b/lib/lines.ts index 22719536..f4216841 100644 --- a/lib/lines.ts +++ b/lib/lines.ts @@ -29,7 +29,10 @@ export class Lines { private cachedSourceMap: any = null; private cachedTabWidth: number | void = void 0; - constructor(private infos: LineInfo[], sourceFileName: string | null = null) { + constructor( + private infos: LineInfo[], + sourceFileName: string | null = null, + ) { invariant(infos.length > 0); this.length = infos.length; this.name = sourceFileName || null; diff --git a/lib/printer.ts b/lib/printer.ts index b27fabd7..5663fbec 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -712,8 +712,8 @@ function genericPrintNoParens(path: any, options: any, print: any) { const separator = options.flowObjectCommas ? "," : isTypeAnnotation - ? ";" - : ","; + ? ";" + : ","; const fields = []; let allowBreak = false; @@ -2333,10 +2333,10 @@ function genericPrintNoParens(path: any, options: any, print: any) { return concat(parts); case "TSMethodSignature": - if (n.kind === 'get') { - parts.push('get ') - } else if (n.kind === 'set') { - parts.push('set ') + if (n.kind === "get") { + parts.push("get "); + } else if (n.kind === "set") { + parts.push("set "); } if (n.computed) { parts.push("[", path.call(print, "key"), "]"); diff --git a/test/jsx.ts b/test/jsx.ts index d4d2e466..70d85fec 100644 --- a/test/jsx.ts +++ b/test/jsx.ts @@ -54,10 +54,13 @@ for (const { title, parser } of [ }); // Esprima does not parse JSX fragments: https://github.com/jquery/esprima/issues/2020 - (/esprima/i.test(title) - ? xit - : it)("should parse and print fragments", function () { - check(["<>", " Hello", " world!", ""].join("\n")); - }); + (/esprima/i.test(title) ? xit : it)( + "should parse and print fragments", + function () { + check( + ["<>", " Hello", " world!", ""].join("\n"), + ); + }, + ); }); } diff --git a/test/typescript.ts b/test/typescript.ts index 410fa9ac..2caafc03 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -244,7 +244,7 @@ const nodeMajorVersion = parseInt(process.versions.node, 10); " a(c: (this: void, e: E) => void): void;", "}", ]); - + check([ "interface LabelledContainer {", " get label(): string;",