feat: support #__NO_SIDE_EFFECTS__ annotation#20775
Conversation
🦋 Changeset detectedLatest commit: e6b4eb2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (3825d6a). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@3825d6a
yarn add -D webpack@https://pkg.pr.new/webpack@3825d6a
pnpm add -D webpack@https://pkg.pr.new/webpack@3825d6a |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20775 +/- ##
==========================================
+ Coverage 91.40% 91.42% +0.01%
==========================================
Files 561 561
Lines 55359 55408 +49
Branches 14610 14630 +20
==========================================
+ Hits 50603 50656 +53
+ Misses 4756 4752 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7817a3b to
8277c9e
Compare
| "index" | ||
| ]), | ||
| /** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */ | ||
| /** @type {SyncBailHook<[VariableDeclarator, VariableDeclaration], boolean | void>} */ |
There was a problem hiding this comment.
Looks like a type fix right?
There was a problem hiding this comment.
Yes, it's a one-line type fix. _preWalkVariableDeclaration should accept a parameter of type VariableDeclaration, so it will pass a VariableDeclaration as the statement argument to preDeclarator.
| this.destructuringAssignmentProperties = new WeakMap(); | ||
| this.detectMode(ast.body); | ||
| this.modulePreWalkStatements(ast.body); | ||
| this.prevStatement = undefined; |
There was a problem hiding this comment.
do we need it here right?
There was a problem hiding this comment.
Yeah, it's one bug fix. When we enter parsing for an import/export statement of module, prevStatement will be assigned, but currently it's never cleared then. This causes incorrect behavior in anything that relies on prevStatement at preWalk stage.
0e9bc31 to
c6e0016
Compare
c6e0016 to
e6b4eb2
Compare
|
Let's merge after the next patch release (Monday/Tuesday) |
Webpack 5.107 supports the #__NO_SIDE_EFFECTS__ annotation from the compiler-notations-spec, letting authors mark function declarations as side-effect-free so calls can be tree-shaken when their return value is unused. Adds a new subsection in the tree shaking guide right after the existing /*#__PURE__*/ section, with the caveat that propagation is currently intra-module only. Refs: webpack/webpack#20775
Summary
What kind of change does this PR introduce?
Support #NO_SIDE_EFFECTS annotation. To be mentioned, the annotation can't take effect across modules and it's applied only within the module where it is declared. We will support it in another PR in future.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No
Use of AI
Partial