Skip to content

Commit 0e0bd79

Browse files
refactor(css): split syntax into syntax-parser and syntax-printer (#22222)
* refactor(css): split syntax into syntax-parser and syntax-printer The CSS engine and its default printer now live in files of their own, with lib/css/syntax.js keeping the public surface: it loads both, binds SourceProcessor to them and re-exports what it always did. Module state the walk writes and the printer reads moved into one initialized object, so the two files share it without a stale copy; the streaming writer sits in a second one to keep CssPath out of its type. Dependencies run one way — printer to parser, facade to both. * 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`. * test(css): cover the printer a processor asks for on its first print * test(css): assert the whole facade surface, not two names of it The surface test read `parseAStylesheet` and `NodeType`, leaving the other 53 getters unexecuted. Walk every published name instead: each resolves to a defined value, and each one the parser half spells the same way is identical to it. * test(css): state each facade binding instead of counting them Deriving the expected names from the facade only checked how many there are: a renamed getter and an alias repointed at another export of the same module both kept the counts at 55 and 49. Spell out the source of each of the 55. * refactor(css): keep the printer's parser imports sorted `_anyUnordered`, which the ported seam fix reaches across the cut, was inserted ahead of `_alphaByteText` rather than after it.
1 parent bb2c8dd commit 0e0bd79

14 files changed

Lines changed: 20778 additions & 19727 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Split the CSS syntax module into a parser file and a printer file.

‎AGENTS.md‎

Lines changed: 7 additions & 3 deletions
Large diffs are not rendered by default.

‎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)