Repository navigation
refactor(types): type parsers and generators by their language's module - #22752
Conversation
Parser and Generator become generic over the module they handle. Each language's parser and generator reads its own build info and build meta types instead of casting module.buildInfo, and public methods still accept a plain NormalModule.
|
| Name | Type |
|---|---|
| webpack | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
|
This PR is packaged and the instant preview is available (9f25e90). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@9f25e90
yarn add -D webpack@https://pkg.pr.new/webpack@9f25e90
pnpm add -D webpack@https://pkg.pr.new/webpack@9f25e90 |
Types CoverageCoverage after merging refactor/generic-build-info into main will be
Coverage Report |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Change: Refactor Merge Risk: ⚪ Minimal · up to
|
Generated code sizeComparing base (
Read No asset changed size. No runtime gained or lost a runtime module. Built |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22752 +/- ##
=======================================
Coverage 96.47% 96.47%
=======================================
Files 778 778
Lines 137268 137261 -7
Branches 46537 46529 -8
=======================================
- Hits 132427 132424 -3
+ Misses 4841 4837 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Follow-up to #22742. Each language's parser and generator only ever sees its own module type, but read
module.buildInfoas the openBuildInfoand cast it at every use.ParserandGeneratorare now generic over the module they handle, and each language binds them to its module's own build info and build meta:Parser<TModule>,ParserState<TModule>,Generator<TModule>,ByTypeGenerator<TModule>(defaults:NormalModule).XNormalModule(open view,buildInfooptional, what public methods accept) andBuiltXModule(after build,buildInfo/buildMetarequired, read once inside methods). JS, CSS, asset, HTML, JSON and wasm.parser.state.module; custom build info keys still type-check..buildInfo/.buildMetainlib/: 124 → 87.Compatibility: existing type names and shapes are unchanged, public methods still take a plain
NormalModule, module classes stay mutually assignable (new Map([["css", CssModule], ["html", HtmlModule]])). One narrow type change: assigning a plainParserStateobject directly tojavascriptParser.stateno longer type-checks (parse(source, state)is unchanged). JSDoc and casts only; no runtime change.What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
No, types only; the
lint:types*projects check them, and the JS parser, serialization and asset/css/html/json/wasm config cases pass.Does this PR introduce a breaking change?
No. Types only get more precise; the one narrowing is direct assignment of a plain state object to
javascriptParser.state, which webpack's own code, tests and examples never do.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Claude Code wrote the types, ran lint, tests and a TypeScript compatibility probe against the published types; I set the design (generic parsers/generators per language, no breaking changes) and reviewed the result.
Generated by Claude Code
Summary by CodeRabbit