Make the selector and at-rule prelude parsers tree-shakable
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 43/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- css, javascript
- 領域
- tooling
調査の方向性
Start by reading parse.js, ValueNodeParser in the at-rule prelude chunk, and the constructors for ConditionParser and AtRulePreludeParser. Trace how the root entry and /parse assemble the parser, then check the package entry-point and build configuration before adding the lean entry. Done means existing parse() behavior remains intact and a core-only consumer can omit selector and prelude code from its bundle.
索引モデルが issue の本文から書いたものです。
説明
Problem
Bundling parse() always includes the selector parser and the at-rule prelude parser, even when parse_selectors and parse_atrule_preludes are never enabled. The options only switch them on at runtime, so a bundler cannot remove them.
Found while working on css-analyzer v10. Its engine only enables the parsers its collectors need, so a bundle with just a z-index collector should not carry selector or prelude code. It does carry it, all of it coming from this package.
Measurements
Minified rolldown bundles, @projectwallace/css-parser 0.19.7 bundled in:
| Entry | As published | With the lazy parsers cut loose (see below) |
|---|---|---|
parse('a{}') only |
74.3 KB (15.4 gzip) | 42.4 KB (10.2 gzip) |
css-analyzer, z_indexes only |
84.3 KB (19.1 gzip) | 52.5 KB (13.8 gzip) |
css-analyzer, colors only |
85.3 KB (19.5 gzip) | 53.5 KB (14.2 gzip) |
css-analyzer, specificity only (needs selectors) |
86.2 KB (19.8 gzip) | 68.8 KB (17.0 gzip) |
| css-analyzer, everything | 107.2 KB (25.4 gzip) | 107.3 KB (25.4 gzip) |
The right-hand column came from a patched copy of dist/ that stubs out the constructors described below. It breaks selector and prelude parsing, so read it as an upper bound on what a real change can save: about 32 KB (minified) for anything that only needs declarations and values.
Cause
package.json has sideEffects: false and the build is split into chunks, so this is not a packaging mistake. It is coupling inside the code:
dist/parse.jsimportsSelectorParser,AtRulePreludeParserandDeclarationParserat the top and constructs them behindparse_selectors_enabledandparse_atrule_preludes_enabled.- Stubbing only those two imports in
parse.jschanged nothing (84.3 KB before and after). The classes stay reachable another way. ValueNodeParser, the base ofValueParser, lives in the same chunk as the at-rule prelude parser (parse-atrule-prelude-*.js). It creates two parsers on demand:ConditionParser, in its condition getter (_condition_parser);AtRulePreludeParser, in its media prelude getter (_media_prelude_parser).
ConditionParserandAtRulePreludeParserboth construct aSelectorParser.
So every ValueParser, and therefore every parse() that parses values, statically reaches the prelude parser and the selector parser.
Proposal
ValueNodeParsergets the condition and media-prelude parsers from the outside (factories passed to its constructor or set when the full parser is assembled), instead of callingnew ConditionParser(...)andnew AtRulePreludeParser(...)itself. When a factory is missing, fail with a clear error. These are only reached for syntax likeif()/media()inside values.- Move
ValueNodeParserinto its own module, out of the prelude chunk. parse()receives the selector and prelude parsers instead of importing them. The root entry and/parsekeep behaving exactly as today by wiring everything in. Add a lean entry (name up for discussion, for example@projectwallace/css-parser/parse-core) where the caller passes only what it needs.
Step 3 alone does not help, because of step 1.
Nothing changes for current users of parse() or the root entry. Only consumers of the new entry opt in.
- 主要言語
- CSS
- スター
- 4
- フォーク
- 0
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 27
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
projectwallace/css-parser のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
メンテナーはふだん 1 日以内に返信
projectwallace/css-parser の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
facebookresearch/atlas-lean#20218 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
sveltejs/eslint-plugin-svelte#1746 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
bruits/satteri#400 · コメント 2 件 ·
メンテナーはふだん 5 日以内に返信
-
area:boot area:ci phase:2 priority:P1 type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
wenkais196-Gabriel/T-City#504 ·
メンテナーはふだん 1 日以内に返信