From c197ba98709e31a9ebb6fc99389379dd3142e494 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Wed, 17 Dec 2025 20:06:07 +0100 Subject: [PATCH] fix: type_name union instead of string --- src/css-node.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/css-node.ts b/src/css-node.ts index b2f82aa..b53706b 100644 --- a/src/css-node.ts +++ b/src/css-node.ts @@ -49,7 +49,7 @@ import { CHAR_MINUS_HYPHEN, CHAR_PLUS, is_whitespace } from './string-utils' import { parse_dimension } from './parse-utils' // Type name lookup table - maps numeric type to CSSTree-compatible strings -export const TYPE_NAMES: Record = { +export const TYPE_NAMES = { [STYLESHEET]: 'StyleSheet', [STYLE_RULE]: 'Rule', [AT_RULE]: 'Atrule', @@ -88,6 +88,8 @@ export const TYPE_NAMES: Record = { [PRELUDE_OPERATOR]: 'Operator', } as const +export type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown' + // Node type constants (numeric for performance) export type CSSNodeType = | typeof STYLESHEET @@ -145,7 +147,7 @@ export interface CloneOptions { export type PlainCSSNode = { // Core properties (always present) type: number - type_name: string + type_name: TypeName text: string children: PlainCSSNode[] @@ -196,7 +198,7 @@ export class CSSNode { } // Get node type as human-readable string - get type_name(): string { + get type_name(): TypeName { return TYPE_NAMES[this.type] || 'unknown' }