From c63581e2e5dd0cc105458631b6f921ffa93c7c30 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 22 Feb 2019 14:46:44 -0800 Subject: [PATCH 1/3] [Theo]: Fix registerTransform generic typing error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixes issue with the generic type on `registerTransform` --- types/theo/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/theo/index.d.ts b/types/theo/index.d.ts index de15c0238a..842aa4c3ea 100644 --- a/types/theo/index.d.ts +++ b/types/theo/index.d.ts @@ -93,10 +93,10 @@ export function registerFormat( name: Format | T, format: FormatResultFn | string ): void; -export function registerTransform( - name: Transform | T, - valueTransforms: ValueTransform[] | T[] -): void; +export function registerTransform< + T extends string = never, + V extends string[] = never +>(name: Transform | T, valueTransforms: ValueTransform[] | V): void; export function registerValueTransform( name: ValueTransform | T, predicate: (prop: Prop) => boolean, From dba15653b3912daa60900160dec8f814d9373540 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 22 Feb 2019 14:54:13 -0800 Subject: [PATCH 2/3] Add more test coverage for custom use cases --- types/theo/theo-tests.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/types/theo/theo-tests.ts b/types/theo/theo-tests.ts index ceaaf9649c..c854fc0dc3 100644 --- a/types/theo/theo-tests.ts +++ b/types/theo/theo-tests.ts @@ -11,8 +11,30 @@ theo.convert({ } }); +theo.convertSync({ + transform: { + type: "raw", + file: "file", + data: "data" + }, + format: { + type: "custom-properties.css" + } +}); + +// Register a provided transform with a provided value transform +theo.registerTransform("web", ["color/hex"]); + +// Register a provided transform with custom value transform theo.registerTransform("web", ["relative/pixelValue"]); +// Register a custom transform with custom value transform +theo.registerTransform("custom", ["relative/pixelValue"]); + +// Register a custom transform with provided value transform +theo.registerTransform("custom", ["color/rgb"]); + +// Register custom formatting function for a provided format theo.registerFormat( "cssmodules.css", `{{#each props as |prop|}} @@ -20,6 +42,7 @@ theo.registerFormat( {{/each}}` ); +// Register a custom value transform theo.registerValueTransform( "relative/pixelValue", prop => prop.get("category") === "sizing", @@ -28,3 +51,13 @@ theo.registerValueTransform( return parseFloat(value.replace(/rem/g, "")) * 16; } ); + +// Override a custom value transform +theo.registerValueTransform( + "relative/pixel", + prop => prop.get("category") === "sizing", + prop => { + const value = prop.get("value").toString(); + return `${parseFloat(value.replace(/rem/g, "")) * 16}px`; + } +); From a9193f42af5e2a301ecd22eeb65a6d1839426730 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 22 Feb 2019 18:38:54 -0800 Subject: [PATCH 3/3] Edit registerTransform typing --- types/theo/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/theo/index.d.ts b/types/theo/index.d.ts index 842aa4c3ea..dc67721b95 100644 --- a/types/theo/index.d.ts +++ b/types/theo/index.d.ts @@ -95,8 +95,8 @@ export function registerFormat( ): void; export function registerTransform< T extends string = never, - V extends string[] = never ->(name: Transform | T, valueTransforms: ValueTransform[] | V): void; + V extends string = never +>(name: Transform | T, valueTransforms: ValueTransform[] | V[]): void; export function registerValueTransform( name: ValueTransform | T, predicate: (prop: Prop) => boolean,