Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support of set/get in interfaces #1401

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ function genericPrintNoParens(path: any, options: any, print: any) {
const separator = options.flowObjectCommas
? ","
: isTypeAnnotation
? ";"
: ",";
? ";"
: ",";
const fields = [];
let allowBreak = false;

Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 8 additions & 5 deletions test/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(["<>", " <td>Hello</td>", " <td>world!</td>", "</>"].join("\n"));
});
(/esprima/i.test(title) ? xit : it)(
"should parse and print fragments",
function () {
check(
["<>", " <td>Hello</td>", " <td>world!</td>", "</>"].join("\n"),
);
},
);
});
}
7 changes: 7 additions & 0 deletions test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"}",
]);

check([
"interface LabelledContainer<T> {",
" get label(): string;",
" set label(a: string);",
"}",
]);

check([
"interface Square<T, U> extends Shape<T, U>, Visible<T, U> {",
" sideLength: number;",
Expand Down
Loading