Skip to content

Commit

Permalink
Feat: support Typescript type arguments on tagged template literals
Browse files Browse the repository at this point in the history
  • Loading branch information
SpanishPear committed Nov 25, 2024
1 parent 26f21ab commit 539b8d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,12 @@ function genericPrintNoParens(path: any, options: any, print: any) {
}

case "TaggedTemplateExpression":
return concat([path.call(print, "tag"), path.call(print, "quasi")]);
parts.push(path.call(print, "tag"));
if (n.typeParameters) {
parts.push(path.call(print, "typeParameters"));
}
parts.push(path.call(print, "quasi"));
return concat(parts);

// These types are unprintable because they serve as abstract
// supertypes for other (printable) types.
Expand Down
8 changes: 8 additions & 0 deletions test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
check(["type Class<T> = new (...args: any) => T;"]);

check(["type T1 = [...Array<any>];", "type T2 = [...any[]];"]);
check([
"const a = styled.h1<{",
" $upsideDown?: boolean;",
"}>`",
' ${props => props.$upsideDown && "transform: rotate(180deg);"}',
" text-align: center;",
"`;",
]);

check([
"type Color = [r: number, g: number, b: number, a?: number];",
Expand Down

0 comments on commit 539b8d3

Please sign in to comment.