Skip to content

Commit 306b6dc

Browse files
authored
fix: type_name union instead of string (#47)
closes #46
1 parent fa554e0 commit 306b6dc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/css-node.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { CHAR_MINUS_HYPHEN, CHAR_PLUS, is_whitespace } from './string-utils'
4949
import { parse_dimension } from './parse-utils'
5050

5151
// Type name lookup table - maps numeric type to CSSTree-compatible strings
52-
export const TYPE_NAMES: Record<number, string> = {
52+
export const TYPE_NAMES = {
5353
[STYLESHEET]: 'StyleSheet',
5454
[STYLE_RULE]: 'Rule',
5555
[AT_RULE]: 'Atrule',
@@ -88,6 +88,8 @@ export const TYPE_NAMES: Record<number, string> = {
8888
[PRELUDE_OPERATOR]: 'Operator',
8989
} as const
9090

91+
export type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown'
92+
9193
// Node type constants (numeric for performance)
9294
export type CSSNodeType =
9395
| typeof STYLESHEET
@@ -145,7 +147,7 @@ export interface CloneOptions {
145147
export type PlainCSSNode = {
146148
// Core properties (always present)
147149
type: number
148-
type_name: string
150+
type_name: TypeName
149151
text: string
150152
children: PlainCSSNode[]
151153

@@ -196,7 +198,7 @@ export class CSSNode {
196198
}
197199

198200
// Get node type as human-readable string
199-
get type_name(): string {
201+
get type_name(): TypeName {
200202
return TYPE_NAMES[this.type] || 'unknown'
201203
}
202204

0 commit comments

Comments
 (0)