Skip to content

Replace TokenType and TokenizerState enums with literal union types - #123

Merged
ef4 merged 1 commit into
mainfrom
replace-enums
Oct 16, 2026
Merged

ef4 merged 1 commit into
mainfrom
replace-enums

Conversation

@ef4

@ef4 ef4 commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

TokenType and TokenizerState are now type-only exports (string literal unions) rather than TypeScript enums, so they no longer exist at runtime.

In modern typescript, string literal union types are a better alternative to exported enums. They don't have the same compilation caveats and they result in shorter, easier-to-read consumer code with no loss of safety.

BREAKING CHANGE: `TokenType` and `TokenizerState` are now type-only
exports (string literal unions) rather than TypeScript enums, so they no
longer exist at runtime.

The underlying values are unchanged: tokens still have `type: 'StartTag'`
etc., and tokenizer states are still the same camelCase strings, so code
that compares against string literals is unaffected.

Code that used the enums as values must switch to string literals:

    // before
    if (token.type === TokenType.StartTag) { ... }
    tokenizer.transitionTo(TokenizerState.data);

    // after
    if (token.type === 'StartTag') { ... }
    tokenizer.transitionTo('data');

Importing `TokenType` or `TokenizerState` for use in type positions
continues to work. Consumers compiling with `isolatedModules` or
`verbatimModuleSyntax` should re-export them with `export type`.

The tokenizer-states codegen now emits a union type as well.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ef4 ef4 added the breaking label Oct 16, 2026
@ef4
ef4 merged commit 476b929 into main Oct 16, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant