From 1d940756ea164b611a133b8288330b1b736e4e71 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Tue, 16 Sep 2025 10:05:04 +0200 Subject: [PATCH 1/2] fix: `ColorToken[]` should include `BaseToken` extentions --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index ffa36a4..42679cb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -45,7 +45,7 @@ export type ColorValue = { export type ColorToken = BaseToken & { $type: 'color' $value: ColorValue, - $extensions: { + $extensions: BaseToken['$extensions'] & { [EXTENSION_CSS_PROPERTIES]: Array } } From 3256559d076bf6560910b9aa981fb2003151a5d0 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Tue, 16 Sep 2025 10:19:34 +0200 Subject: [PATCH 2/2] make sure we always pass a ColorToken, never an UnparsedToken --- src/destructure-box-shadow.test.ts | 2 +- src/index.test.ts | 7 +++++++ src/index.ts | 4 ++-- src/types.ts | 2 +- tsconfig.json | 1 - 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/destructure-box-shadow.test.ts b/src/destructure-box-shadow.test.ts index 8b722ca..aad5eb2 100644 --- a/src/destructure-box-shadow.test.ts +++ b/src/destructure-box-shadow.test.ts @@ -1,6 +1,6 @@ import { test, expect, describe } from 'vitest' import { destructure_box_shadow } from './destructure-box-shadow.js' -import { ColorValue, EXTENSION_AUTHORED_AS } from './types.js' +import type { ColorValue } from './types.js' import { color_to_token } from './colors.js' function create_px_length(value: number): { value: number, unit: string } { diff --git a/src/index.test.ts b/src/index.test.ts index 71f45a5..740f5b3 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -155,6 +155,13 @@ describe('css_to_tokens', () => { `) expect(actual.color).toEqual({}) }) + + test('extensions[css-properties] does not yield a type error', () => { + let actual = css_to_tokens('a { color: green; }') + // Not so much interested in the test result, more looking that this isn't giving a type error + let properties = actual.color['green-5e0cf03']!['$extensions'][EXTENSION_CSS_PROPERTIES] + expect(properties).toEqual(['color']) + }) }) describe('font sizes', () => { diff --git a/src/index.ts b/src/index.ts index 2d050fe..ba928ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ type ItemsPerContext = Record + color: Record font_size: Record font_family: Record line_height: Record @@ -86,7 +86,7 @@ function get_count(collection_item: number | CssLocation[]) { export function analysis_to_tokens(analysis: CssAnalysis): Tokens { return { color: (() => { - let colors = Object.create(null) as Record + let colors = Object.create(null) as Record let unique = get_unique(analysis.values.colors) let color_groups = group_colors(unique) diff --git a/src/types.ts b/src/types.ts index 42679cb..ffa36a4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -45,7 +45,7 @@ export type ColorValue = { export type ColorToken = BaseToken & { $type: 'color' $value: ColorValue, - $extensions: BaseToken['$extensions'] & { + $extensions: { [EXTENSION_CSS_PROPERTIES]: Array } } diff --git a/tsconfig.json b/tsconfig.json index 3904641..59e2b2c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,6 +27,5 @@ ], "exclude": [ "node_modules", - "src/**/*.test.ts" ] } \ No newline at end of file