Skip to content

Commit

Permalink
fix: typeArguments on decorator structure should output type arguments
Browse files Browse the repository at this point in the history
Ref #1205
  • Loading branch information
dsherret committed Oct 22, 2021
1 parent dabba30 commit ad4fdbd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Expand Up @@ -13,10 +13,23 @@ export class DecoratorStructurePrinter extends NodePrinter<OptionalKind<Decorato

protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind<DecoratorStructure>) {
writer.write(`@${structure.name}`);
this.printTypeArguments(writer, structure);
this.printArguments(writer, structure);
}

printArguments(writer: CodeBlockWriter, structure: OptionalKind<DecoratorStructure>) {
private printTypeArguments(writer: CodeBlockWriter, structure: OptionalKind<DecoratorStructure>) {
if (structure.typeArguments == null || structure.typeArguments.length === 0)
return;

writer.write("<");
for (let i = 0; i < structure.typeArguments.length; i++) {
writer.conditionalWrite(i > 0, ", ");
writer.write(this.getTextWithQueuedChildIndentation(writer, structure.typeArguments[i]));
}
writer.write(">");
}

private printArguments(writer: CodeBlockWriter, structure: OptionalKind<DecoratorStructure>) {
if (structure.arguments == null)
return;

Expand Down
Expand Up @@ -27,5 +27,19 @@ describe(nameof(DecoratorStructurePrinter), () => {
doTest({ name: "dec", arguments: writer => writer.writeLine("1,").write("2") }, `@dec(1,\n 2)`);
});
});

describe("type arguments", () => {
it("should not write when empty", () => {
doTest({ name: "dec", typeArguments: [] }, `@dec`);
});

it("should write", () => {
doTest({ name: "dec", typeArguments: ["string"], arguments: ["1"] }, `@dec<string>(1)`);
});

it("should write multiple", () => {
doTest({ name: "dec", typeArguments: ["string", "number"] }, `@dec<string, number>`);
});
});
});
});

0 comments on commit ad4fdbd

Please sign in to comment.