Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/css-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, string> = {
export const TYPE_NAMES = {
[STYLESHEET]: 'StyleSheet',
[STYLE_RULE]: 'Rule',
[AT_RULE]: 'Atrule',
Expand Down Expand Up @@ -88,6 +88,8 @@ export const TYPE_NAMES: Record<number, string> = {
[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
Expand Down Expand Up @@ -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[]

Expand Down Expand Up @@ -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'
}

Expand Down