Repository navigation
refactor: type rule effect values, the typeof hook's node and the statement-type hook maps - #23309
alexander-akait wants to merge 2 commits into
Conversation
…ok's node A rule effect's value is only merged into the module's settings or handed on as a loader, so `NormalModuleFactory` reads it once as `unknown` instead of inheriting the `any` of the rule's open option bags. The `typeof` hook takes an `Expression`; the node the walk hands it is now typed `UnaryExpression`, which a typed interceptor `call` in tapable requires.
|
|
No actionable comments were generated in the recent review. Walkthrough
Change: Refactor Merge Risk:
|
|
Reports for 970c9cf, computed by this pull request's own code. Each section updates when its workflow finishes. Preview packageThis PR is packaged and the instant preview of its latest commit is available. Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@23309
yarn add -D webpack@https://pkg.pr.new/webpack@23309
pnpm add -D webpack@https://pkg.pr.new/webpack@23309From Preview package run #12849. Generated code sizeComparing base (
Read Sample appsNo sample app changed size. 26 unchanged app(s)
No asset changed size. No runtime gained or lost a runtime module. Built From Generated code size run #7484. Types CoverageTyped lines: 99.71% (184735 of 185274)
Changed by this pull request
Where this pull request adds them, in every column it grows
What the files this pull request changes still have
55 file(s) in
|
| File | Typed lines | any |
unknown |
object |
Function |
untyped |
|---|---|---|---|---|---|---|
lib/Compilation.js |
99.86% | 5 | 2 | 9 | ||
declarations/WebpackOptions.ts |
100.00% | 12 | 2 | |||
lib/javascript/syntax-parser.js |
100.00% | 11 | ||||
lib/asset/AssetModulesPlugin.js |
99.40% | 9 | ||||
lib/Compiler.js |
100.00% | 2 | 4 | |||
lib/javascript/syntax-printer.js |
100.00% | 1 | 5 | |||
lib/loaders/LoaderPlugin.js |
99.42% | 6 | ||||
lib/module/NormalModule.js |
100.00% | 4 | 1 | 1 | ||
lib/module/NormalModuleFactory.js |
100.00% | 3 (🔴 +3) | 3 (🟢 −12) | |||
lib/dependencies/amd/AMDPlugin.js |
99.35% | 5 | ||||
lib/util/SourceProcessor.js |
100.00% | 5 | ||||
lib/dependencies/amd/AMDRuntimeModules.js |
95.45% | 4 | ||||
lib/javascript/JavascriptModulesPlugin.js |
100.00% | 4 | ||||
lib/loaders/LoaderOptionsPlugin.js |
100.00% | 4 | ||||
lib/module/Module.js |
100.00% | 4 | ||||
lib/resolve/getResolveOptionsKey.js |
100.00% | 4 | ||||
lib/serialization/ObjectMiddleware.js |
100.00% | 4 | ||||
lib/util/SortableSet.js |
100.00% | 4 | ||||
lib/config/normalization.js |
99.57% | 3 | ||||
lib/css/syntax-parser.js |
100.00% | 3 | ||||
lib/hmr/HotModuleReplacement.runtime.js |
100.00% | 2 | 1 | |||
lib/html/syntax-parser.js |
100.00% | 3 | ||||
lib/stats/StatsFactory.js |
100.00% | 2 | 1 | |||
lib/config/defineConfig.js |
100.00% | 2 | ||||
lib/css/syntax.js |
100.00% | 2 | ||||
lib/define/DefinePlugin.js |
100.00% | 1 | 1 | |||
lib/hmr/HotModuleReplacementPlugin.js |
100.00% | 1 | 1 | |||
lib/hmr/JavascriptHotModuleReplacement.runtime.js |
100.00% | 2 | ||||
lib/html/syntax.js |
100.00% | 2 | ||||
lib/index.js |
100.00% | 2 | ||||
lib/loaders/LoaderRunner.js |
100.00% | 2 | ||||
lib/module/Parser.js |
100.00% | 2 | ||||
lib/node/nodeConsole.js |
100.00% | 2 | ||||
lib/rules/BasicEffectRulePlugin.js |
93.75% | 2 | ||||
lib/rules/UseEffectRulePlugin.js |
99.06% | 2 | ||||
lib/util/cleverMerge.js |
100.00% | 2 | ||||
lib/util/implicitTypeLoaderFallback.js |
100.00% | 2 | ||||
lib/config/WebpackOptionsApply.js |
100.00% | 1 | ||||
lib/config/cli.js |
100.00% | 1 | ||||
lib/dependencies/import/ImportParserPlugin.js |
100.00% | 1 | ||||
lib/dll/DllReferencePlugin.js |
100.00% | 1 | ||||
lib/errors/JSONParseError.js |
100.00% | 1 | ||||
lib/graph/ModuleGraph.js |
100.00% | 1 | ||||
lib/javascript/JavascriptParser.js |
100.00% | 1 | 0 (🟢 −2) | |||
lib/javascript/syntax.js |
100.00% | 1 | ||||
lib/logging/Logger.js |
100.00% | 1 | ||||
lib/logging/createConsoleLogger.js |
100.00% | 1 | ||||
lib/output/ManifestPlugin.js |
100.00% | 1 | ||||
lib/serialization/types.js |
100.00% | 1 | ||||
lib/stats/DefaultStatsFactoryPlugin.js |
100.00% | 1 | ||||
lib/stats/StatsPrinter.js |
100.00% | 1 | ||||
lib/template/Template.js |
100.00% | 1 | ||||
lib/util/magicComment.js |
100.00% | 1 | ||||
lib/util/makeSerializable.js |
100.00% | 1 | ||||
lib/util/terminalColors.js |
100.00% | 1 |
From Types Coverage run #3699.
Module loading
How many files a fresh Node.js process loads (require or import) to do each thing below; a change from the pull request's base is marked 🔴 when it grew and 🟢 when it shrank. Every file is startup time, so fewer is better. webpack files are this package's own (lib/, hot/); node_modules files are its dependencies'.
| What the process does | webpack files | node_modules files |
|---|---|---|
require("webpack") |
2 | 0 |
import "webpack" |
2 | 0 |
| JavaScript syntax | 11 | 0 |
| CSS syntax | 12 | 0 |
| HTML syntax | 11 | 0 |
| XML syntax | 11 | 0 |
| JavaScript minifier | 12 | 0 |
| CSS minifier | 14 | 0 |
| HTML minifier | 19 | 0 |
| XML minifier | 14 | 0 |
| JSON minifier | 1 | 0 |
| development build | 440 | 103 |
| production build | 447 | 133 |
| watch with HMR, one rebuild | 450 | 110 |
From Module loading run #943.
`preStatementByType` and `blockPreStatementByType` are keyed by a statement's type, so they are `TypedHookMap<Record<string, StatementHook>>`, and the interceptor that watches their keys gets a `string` rather than `any`.
Merging this PR will improve performance by 24.97%2 warnings, 1 note
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Summary
Three type fixes, with no runtime change:
NormalModuleFactoryreads each rule effect's value once, asunknown. The value is a loader for auseeffect, or else the rule's value for the setting the effect is named for. It's only merged into the module's settings or handed on, so it no longer inherits theanyof the rules' open option bags. This removes 12 untyped sites; the publicEffectBasic/EffectUsetypes are unchanged.preStatementByTypeandblockPreStatementByTypeare nowTypedHookMap<Record<string, StatementHook>>. They're keyed by a statement's type name, so the parser's own interceptor that watches their keys gets astringinstead ofany. That removes 2 untyped sites.StatementHooknames the hook type they already used.typeofhook is now handed aUnaryExpression. The hook takes[Expression], but the walk handed it a node typed only asNode. The interceptor'sany[]arguments hid the mismatch. With typed interceptor arguments in tapable (fix: type the call and loop interceptor arguments as the hook's own tapable#288) it becomes a type error, so this fixes it ahead of that.Untyped goes from 69 to 55. With webpack/tapable#288 it drops to 54 (the
callinterceptor inCompilation).What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
No, these are type-only changes. These pass:
NormalModuleFactory,RuleSetandJavascriptParserunit tests.Does this PR introduce a breaking change?
No runtime change. In
types.d.ts,preStatementByTypeandblockPreStatementByTypechange fromHookMap<StatementHook>toTypedHookMap<Record<string, StatementHook>>. Theirget/forkeys are now typedstring(a statement type name) instead ofany, and the hook each returns is the same. Nothing else changes.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Written with Claude Code (investigation, implementation, verification and this description), directed and reviewed by me.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HArJAXZagrHVVNLZZk9soh
Summary by CodeRabbit