From 3b9c065e7283cdbfd80b0ee8a7551b34282d6cbe Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 06:56:08 +0000 Subject: [PATCH 1/6] Add node-types, string-utils and token-types subpath exports Move TYPE_NAMES to the ./nodes entry so it can be imported without the barrel. --- README.md | 4 ++-- package.json | 12 ++++++++++++ src/node-types.ts | 2 ++ test/build/bundle-sizes.ts | 3 +++ tsdown.config.ts | 3 +++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97ce78c..b22968c 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ for (const token of tokenize('a { color: red }')) { ### Node types, type guards and `clone()` -Node type constants (`STYLE_RULE`, `DECLARATION`, `DIMENSION`, …) and `NODE_TYPES` are exported from the root, as are type guards such as `is_declaration()` and `is_dimension()` that narrow a node to its specific type. `node.clone({ deep?, locations? })` returns a mutable plain-object copy of a node. +Node type constants (`STYLE_RULE`, `DECLARATION`, `DIMENSION`, …) and `NODE_TYPES` are exported from the root and from `@projectwallace/css-parser/nodes`. Type guards such as `is_declaration()` and `is_dimension()` that narrow a node to its specific type are exported from the root and from `@projectwallace/css-parser/node-types`. `node.clone({ deep?, locations? })` returns a mutable plain-object copy of a node. ```typescript import { parse, is_declaration } from '@projectwallace/css-parser' @@ -228,7 +228,7 @@ decl.clone({ deep: false }).property // "color" ### String helpers -Allocation-free helpers, handy when working with node names. The lowercase argument is the first one for `str_equals` and the second one for `str_starts_with` and `str_index_of`. This inconsistency will be fixed in a future breaking change. +Allocation-free helpers, handy when working with node names. Also available from `@projectwallace/css-parser/string-utils`; token type constants (`TOKEN_*`) are available from `@projectwallace/css-parser/token-types`. The lowercase argument is the first one for `str_equals` and the second one for `str_starts_with` and `str_index_of`. This inconsistency will be fixed in a future breaking change. ```typescript import { diff --git a/package.json b/package.json index 92210dd..c89a252 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,18 @@ "./nodes": { "types": "./dist/constants.d.ts", "import": "./dist/constants.js" + }, + "./node-types": { + "types": "./dist/node-types.d.ts", + "import": "./dist/node-types.js" + }, + "./string-utils": { + "types": "./dist/string-utils.d.ts", + "import": "./dist/string-utils.js" + }, + "./token-types": { + "types": "./dist/token-types.d.ts", + "import": "./dist/token-types.js" } }, "publishConfig": { diff --git a/src/node-types.ts b/src/node-types.ts index 3d34052..54549bb 100644 --- a/src/node-types.ts +++ b/src/node-types.ts @@ -17,6 +17,8 @@ // Type predicates compile to a single integer comparison each. import type { CSSNodeType, TypeName, CloneOptions, PlainCSSNode } from './css-node' + +export type { CloneOptions, PlainCSSNode } import { STYLESHEET, STYLE_RULE, diff --git a/test/build/bundle-sizes.ts b/test/build/bundle-sizes.ts index 14c2fcf..f3b880e 100644 --- a/test/build/bundle-sizes.ts +++ b/test/build/bundle-sizes.ts @@ -31,6 +31,9 @@ const DESCRIPTIONS: Record = { './parse-dimension': 'Dimension parser', './walker': 'AST walker', './nodes': 'Node type constants', + './node-types': 'Node type guards', + './string-utils': 'String helpers', + './token-types': 'Token type constants', } const exports_to_measure = Object.keys(pkg.exports).filter((k: string) => k !== './package.json') diff --git a/tsdown.config.ts b/tsdown.config.ts index 8824abe..24c7319 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -13,6 +13,9 @@ export default defineConfig({ './src/parse-dimension.ts', './src/walk.ts', './src/constants.ts', + './src/node-types.ts', + './src/string-utils.ts', + './src/token-types.ts', ], platform: 'neutral', dts: true, From 2d510bb6987671579eb8375b87e990eeba7b1256 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 07:01:40 +0000 Subject: [PATCH 2/6] Limit ./string-utils subpath to the public string helpers --- package.json | 4 ++-- src/index.ts | 2 +- src/string-helpers.ts | 9 +++++++++ test/build/bundle-sizes.ts | 1 + tsdown.config.ts | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/string-helpers.ts diff --git a/package.json b/package.json index c89a252..f021a4c 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "import": "./dist/node-types.js" }, "./string-utils": { - "types": "./dist/string-utils.d.ts", - "import": "./dist/string-utils.js" + "types": "./dist/string-helpers.d.ts", + "import": "./dist/string-helpers.js" }, "./token-types": { "types": "./dist/token-types.d.ts", diff --git a/src/index.ts b/src/index.ts index 190bc6c..dbfe0b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ export { str_equals, str_starts_with, str_index_of, -} from './string-utils' +} from './string-helpers' // Advanced/class-based API export { type ParserOptions } from './parse' diff --git a/src/string-helpers.ts b/src/string-helpers.ts new file mode 100644 index 0000000..697a8d7 --- /dev/null +++ b/src/string-helpers.ts @@ -0,0 +1,9 @@ +// Public string helpers - the subset of string-utils that is part of the public API. +// Kept separate so the rest of string-utils (CHAR_* constants, range helpers) stays internal. +export { + is_custom, + is_vendor_prefixed, + str_equals, + str_starts_with, + str_index_of, +} from './string-utils' diff --git a/test/build/bundle-sizes.ts b/test/build/bundle-sizes.ts index f3b880e..a08e12f 100644 --- a/test/build/bundle-sizes.ts +++ b/test/build/bundle-sizes.ts @@ -17,6 +17,7 @@ const SOURCE_OVERRIDES: Record = { './tokenizer': 'src/tokenize.ts', './walker': 'src/walk.ts', './nodes': 'src/constants.ts', + './string-utils': 'src/string-helpers.ts', } const DESCRIPTIONS: Record = { diff --git a/tsdown.config.ts b/tsdown.config.ts index 24c7319..b9d5f66 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -14,7 +14,7 @@ export default defineConfig({ './src/walk.ts', './src/constants.ts', './src/node-types.ts', - './src/string-utils.ts', + './src/string-helpers.ts', './src/token-types.ts', ], platform: 'neutral', From b760c5ffe65faeea3a317086d645e74d9a6990da Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 07:02:18 +0000 Subject: [PATCH 3/6] Export strip_vendor_prefix from the root and ./string-utils --- README.md | 2 ++ src/index.ts | 1 + src/string-helpers.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/README.md b/README.md index b22968c..00dcb24 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,7 @@ Allocation-free helpers, handy when working with node names. Also available from import { is_custom, is_vendor_prefixed, + strip_vendor_prefix, str_equals, str_starts_with, str_index_of, @@ -241,6 +242,7 @@ import { is_custom('--primary') // true is_vendor_prefixed('-webkit-transform') // true +strip_vendor_prefix('-webkit-transform') // "transform" str_equals('media', 'MEDIA') // true str_starts_with('WEBKIT-transform', 'webkit') // true str_index_of('background-COLOR', 'color') // 11 diff --git a/src/index.ts b/src/index.ts index dbfe0b4..63d595a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ export { walk, traverse, SKIP, BREAK } from './walk' export { is_custom, is_vendor_prefixed, + strip_vendor_prefix, str_equals, str_starts_with, str_index_of, diff --git a/src/string-helpers.ts b/src/string-helpers.ts index 697a8d7..8eddc34 100644 --- a/src/string-helpers.ts +++ b/src/string-helpers.ts @@ -3,6 +3,7 @@ export { is_custom, is_vendor_prefixed, + strip_vendor_prefix, str_equals, str_starts_with, str_index_of, From d3c8cb3a35b75fa2cb3588eb79917ea5a82d8f25 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 07:15:46 +0000 Subject: [PATCH 4/6] Replace README bundle sizes table with an entry points table --- README.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 00dcb24..7771bda 100644 --- a/README.md +++ b/README.md @@ -63,25 +63,28 @@ for (const rule of ast) { - **Location tracking with no penalty** — full line, column, and offset data without slowing the parser down - **No syntax validation** — skipping spec checks and MDN data means nothing gets in the way of speed -### Bundle sizes - -All sizes are minified and bundled with dependencies. Import only what you need — bundlers will tree-shake the rest. - -| Import | Description | Minified | Gzip | -| ------------------------------------------------- | ---------------------------- | -------- | ------- | -| `@projectwallace/css-parser` | Full parser (all subparsers) | 68.9 kB | 15.5 kB | -| `@projectwallace/css-parser/parse` | CSS stylesheet parser | 62.2 kB | 13.3 kB | -| `@projectwallace/css-parser/parse-atrule-prelude` | At-rule prelude parser | 35.4 kB | 8.4 kB | -| `@projectwallace/css-parser/parse-selector` | Selector parser | 37.7 kB | 8.9 kB | -| `@projectwallace/css-parser/parse-anplusb` | An+B syntax parser | 26.1 kB | 6.6 kB | -| `@projectwallace/css-parser/parse-declaration` | Declaration parser | 28.3 kB | 7.3 kB | -| `@projectwallace/css-parser/parse-value` | Value parser | 25.2 kB | 6.6 kB | -| `@projectwallace/css-parser/parse-dimension` | Dimension parser | 0.4 kB | 0.3 kB | -| `@projectwallace/css-parser/tokenizer` | Tokenizer | 9.8 kB | 2.4 kB | - ## API -Every function is exported from the package root and, where listed in [Bundle sizes](#bundle-sizes), from its own entry point. Node properties and return types ship as TypeScript types, so this section sticks to short examples. +Everything is exported from the package root. Each part is also available from its own entry point, so you can import only what you need and skip evaluating the rest of the package. Node properties and return types ship as TypeScript types, so this section sticks to short examples. + +### Entry points + +| Import | Exports | +| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | +| `@projectwallace/css-parser` | Everything below, except the `Lexer` and `Parser` classes | | +| `@projectwallace/css-parser/parse` | `parse`, `Parser`, `ParserOptions` | +| `@projectwallace/css-parser/parse-selector` | `parse_selector`, `parse_selector_list` | +| `@projectwallace/css-parser/parse-atrule-prelude` | `parse_atrule_prelude` | +| `@projectwallace/css-parser/parse-declaration` | `parse_declaration` | +| `@projectwallace/css-parser/parse-value` | `parse_value` | +| `@projectwallace/css-parser/parse-anplusb` | `parse_anplusb` | +| `@projectwallace/css-parser/parse-dimension` | `parse_dimension` | +| `@projectwallace/css-parser/tokenizer` | `tokenize`, `Lexer` | +| `@projectwallace/css-parser/walker` | `walk`, `traverse`, `SKIP`, `BREAK` | +| `@projectwallace/css-parser/nodes` | Node type constants (`STYLE_RULE`, `DECLARATION`, …), `NODE_TYPES`, `TYPE_NAMES` | +| `@projectwallace/css-parser/node-types` | Type guards (`is_declaration`, `is_rule`, …) and node types (`CSSNode`, `Rule`, `Declaration`, …) | +| `@projectwallace/css-parser/string-utils` | `is_custom`, `is_vendor_prefixed`, `strip_vendor_prefix`, `str_equals`, `str_starts_with`, `str_index_of` | +| `@projectwallace/css-parser/token-types` | Token type constants (`TOKEN_*`) | ### `parse(source, options?)` From df317458c532a323403a97498f3b0f9b652b3f2a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 07:15:57 +0000 Subject: [PATCH 5/6] Fix entry points table row --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7771bda..cca4de0 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Everything is exported from the package root. Each part is also available from i | Import | Exports | | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | -| `@projectwallace/css-parser` | Everything below, except the `Lexer` and `Parser` classes | | +| `@projectwallace/css-parser` | Everything below, except the `Lexer` and `Parser` classes | | `@projectwallace/css-parser/parse` | `parse`, `Parser`, `ParserOptions` | | `@projectwallace/css-parser/parse-selector` | `parse_selector`, `parse_selector_list` | | `@projectwallace/css-parser/parse-atrule-prelude` | `parse_atrule_prelude` | From 71b41b80a635a71a4b1ffde3f9e637ba4cce38d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 07:29:33 +0000 Subject: [PATCH 6/6] Remove TYPE_NAMES from entry points table --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cca4de0..0f9c33a 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Everything is exported from the package root. Each part is also available from i | `@projectwallace/css-parser/parse-dimension` | `parse_dimension` | | `@projectwallace/css-parser/tokenizer` | `tokenize`, `Lexer` | | `@projectwallace/css-parser/walker` | `walk`, `traverse`, `SKIP`, `BREAK` | -| `@projectwallace/css-parser/nodes` | Node type constants (`STYLE_RULE`, `DECLARATION`, …), `NODE_TYPES`, `TYPE_NAMES` | +| `@projectwallace/css-parser/nodes` | Node type constants (`STYLE_RULE`, `DECLARATION`, …), `NODE_TYPES` | | `@projectwallace/css-parser/node-types` | Type guards (`is_declaration`, `is_rule`, …) and node types (`CSSNode`, `Rule`, `Declaration`, …) | | `@projectwallace/css-parser/string-utils` | `is_custom`, `is_vendor_prefixed`, `strip_vendor_prefix`, `str_equals`, `str_starts_with`, `str_index_of` | | `@projectwallace/css-parser/token-types` | Token type constants (`TOKEN_*`) |