From 539b8d3230e1fd11cefd8496034b41c2d0d6f270 Mon Sep 17 00:00:00 2001 From: ssomaiya Date: Mon, 25 Nov 2024 22:17:40 +1100 Subject: [PATCH] Feat: support Typescript type arguments on tagged template literals --- lib/printer.ts | 7 ++++++- test/typescript.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/printer.ts b/lib/printer.ts index e3f834f0..04ade584 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -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. diff --git a/test/typescript.ts b/test/typescript.ts index 1a3dc9b6..2b6b37de 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -331,6 +331,14 @@ const nodeMajorVersion = parseInt(process.versions.node, 10); check(["type Class = new (...args: any) => T;"]); check(["type T1 = [...Array];", "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];",