Skip to content

Commit 26eabde

Browse files
refactor(css): reach the halves through getters, as javascript does
syntax.js now exposes `parser` and `printer` the way lib/javascript's facade does, and every name it published before is a getter onto the half that owns it. Nothing loads until a name is read: requiring the facade loads neither half, and a walk that only fires visitors never loads the printer. SourceProcessor asks for its printer on the first print rather than naming it up front — util/SourceProcessor takes that loader as a third argument and calls it once per process, never per node. In-repo readers that never print (CssParser, CssIcssExportDependency, the html parser's css tokens) now import the parser half directly. `css.syntax.printer` is the printer half now, as in javascript; the print function it holds is `printer.printer`.
1 parent 17c35c0 commit 26eabde

13 files changed

Lines changed: 926 additions & 497 deletions

‎AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ The directory listings below are the canonical map of the repository. **Whenever
7171
- `lib/context/` — Context modules (`require.context`, dynamic request directories) and the plugins narrowing them.
7272
- `lib/css/` — CSS Modules, CSS parsing and generation. `syntax.js` names its two
7373
halves the way `javascript` does: `syntax-parser.js` reads a stylesheet and
74-
`syntax-printer.js` writes one back out. The facade holds `SourceProcessor` and
75-
re-exports both, so what a caller imports is unchanged.
74+
`syntax-printer.js` writes one back out. `syntax.js` reaches both through a
75+
getter, as `javascript` does, so a walk that never prints never loads the
76+
printer; it holds `SourceProcessor` and every name it published before.
7677
- `lib/debug/` — Debug helpers.
7778
- `lib/define/` — Replacing a free identifier with a constant at parse time:
7879
`DefinePlugin`, and the two plugins that are a `DefinePlugin` fed from somewhere

‎lib/css/CssParser.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ const {
2626
const memoize = require("../util/memoize");
2727
const topologicalSort = require("../util/topologicalSort");
2828
const { CSS_MODULES_KEYWORDS, CSS_MODULES_KEYWORD_OPTIONS } = require("./data");
29+
const { SourceProcessor } = require("./syntax");
2930
const {
3031
A,
3132
NodeType,
32-
SourceProcessor,
33+
_isWhiteSpace: isWhitespace,
3334
buildSkipSet,
3435
equalsLowerCase,
3536
isDashedIdentifier,
36-
isWhitespace,
3737
normalizeUrl,
3838
rangeEquals,
3939
rangeEqualsLowerCase,
4040
skipEscape,
4141
toLowerCaseIfNeeded,
4242
unescapeIdentifier
43-
} = require("./syntax");
43+
} = require("./syntax-parser");
4444

4545
const getUnsupportedFeatureWarning = memoize(() =>
4646
require("../errors/UnsupportedFeatureWarning")

0 commit comments

Comments
 (0)