Skip to content

Commit da7bf75

Browse files
committed
Merge branch 'master' of https://github.com/rollup/rollup into sync-b7c7c115
2 parents 200c8bc + b7c7c11 commit da7bf75

7 files changed

Lines changed: 62 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# rollup changelog
22

3+
## 4.45.0
4+
5+
_2025-07-12_
6+
7+
### Features
8+
9+
- Improve tree-shaking when both branches of a conditional expression return the same boolean value (#6000)
10+
- In environments that support both CJS and ESM, prefer the ESM build of Rollup (#6005)
11+
12+
### Bug Fixes
13+
14+
- Ensure static blocks do not prevent tree-shaking if they access `this` (#6001)
15+
16+
### Pull Requests
17+
18+
- [#6000](https://github.com/rollup/rollup/pull/6000): feat: improve get literal value for conditional expression (@ahabhgk, @lukastaegert)
19+
- [#6001](https://github.com/rollup/rollup/pull/6001): Correct the parent scope for static blocks (@TrickyPi, @lukastaegert)
20+
- [#6005](https://github.com/rollup/rollup/pull/6005): fix: export field order prefer esm (@DylanPiercey)
21+
322
## 4.44.2
423

524
_2025-07-04_

browser/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rollup/browser",
3-
"version": "4.44.2",
3+
"version": "4.45.0",
44
"description": "Next-generation ES module bundler browser build",
55
"main": "dist/rollup.browser.js",
66
"module": "dist/es/rollup.browser.js",
@@ -32,8 +32,8 @@
3232
"exports": {
3333
".": {
3434
"types": "./dist/rollup.browser.d.ts",
35-
"require": "./dist/rollup.browser.js",
36-
"import": "./dist/es/rollup.browser.js"
35+
"import": "./dist/es/rollup.browser.js",
36+
"require": "./dist/rollup.browser.js"
3737
},
3838
"./dist/*": "./dist/*"
3939
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup",
3-
"version": "4.44.2",
3+
"version": "4.45.0",
44
"description": "Next-generation ES module bundler",
55
"main": "dist/rollup.js",
66
"module": "dist/es/rollup.js",
@@ -227,8 +227,8 @@
227227
"exports": {
228228
".": {
229229
"types": "./dist/rollup.d.ts",
230-
"require": "./dist/rollup.js",
231-
"import": "./dist/es/rollup.js"
230+
"import": "./dist/es/rollup.js",
231+
"require": "./dist/rollup.js"
232232
},
233233
"./loadConfigFile": {
234234
"types": "./dist/loadConfigFile.d.ts",
@@ -237,13 +237,13 @@
237237
},
238238
"./getLogFilter": {
239239
"types": "./dist/getLogFilter.d.ts",
240-
"require": "./dist/getLogFilter.js",
241-
"import": "./dist/es/getLogFilter.js"
240+
"import": "./dist/es/getLogFilter.js",
241+
"require": "./dist/getLogFilter.js"
242242
},
243243
"./parseAst": {
244244
"types": "./dist/parseAst.d.ts",
245-
"require": "./dist/parseAst.js",
246-
"import": "./dist/es/parseAst.js"
245+
"import": "./dist/es/parseAst.js",
246+
"require": "./dist/parseAst.js"
247247
},
248248
"./dist/*": "./dist/*",
249249
"./package.json": "./package.json"

src/ast/nodes/ConditionalExpression.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { tryCastLiteralValueToBoolean } from '../utils/tryCastLiteralValueToBool
1616
import type * as NodeType from './NodeType';
1717
import { Flag, isFlagSet, setFlag } from './shared/BitFlags';
1818
import type { ExpressionEntity, LiteralValueOrUnknown } from './shared/Expression';
19-
import { UnknownValue } from './shared/Expression';
19+
import { UnknownFalsyValue, UnknownTruthyValue, UnknownValue } from './shared/Expression';
2020
import { MultiExpression } from './shared/MultiExpression';
2121
import type { ExpressionNode, IncludeChildren } from './shared/Node';
2222
import { doNotDeoptimize, NodeBase, onlyIncludeSelfNoDeoptimize } from './shared/Node';
@@ -78,7 +78,18 @@ export default class ConditionalExpression extends NodeBase implements Deoptimiz
7878
origin: DeoptimizableEntity
7979
): LiteralValueOrUnknown {
8080
const usedBranch = this.getUsedBranch();
81-
if (!usedBranch) return UnknownValue;
81+
if (!usedBranch) {
82+
const consequentValue = this.consequent.getLiteralValueAtPath(path, recursionTracker, origin);
83+
const castedConsequentValue = tryCastLiteralValueToBoolean(consequentValue);
84+
if (castedConsequentValue === UnknownValue) return UnknownValue;
85+
const alternateValue = this.alternate.getLiteralValueAtPath(path, recursionTracker, origin);
86+
const castedAlternateValue = tryCastLiteralValueToBoolean(alternateValue);
87+
if (castedConsequentValue !== castedAlternateValue) return UnknownValue;
88+
this.expressionsToBeDeoptimized.push(origin);
89+
if (consequentValue !== alternateValue)
90+
return castedConsequentValue ? UnknownTruthyValue : UnknownFalsyValue;
91+
return consequentValue;
92+
}
8293
this.expressionsToBeDeoptimized.push(origin);
8394
return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
8495
}

test/form/samples/treeshake-if-statement/_expected.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
if (typeof parseInt === 'function' ?? 'a' === 'a') {
66
assert.ok(true);
77
}
8+
9+
if (!(unknownGlobal ? 'asdf' : true)) ;
10+
11+
if (unknownGlobal ? 0 : false) ;
12+
13+
if (!(unknownGlobal ? 'a' === 'a' : true)) ;

test/form/samples/treeshake-if-statement/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ if (typeof parseInt === 'function' || 'a' === 'a') {
99
if (typeof parseInt === 'function' ?? 'a' === 'a') {
1010
assert.ok(true);
1111
}
12+
13+
if (!(unknownGlobal ? 'asdf' : true)) {
14+
assert.ok(false);
15+
}
16+
17+
if (unknownGlobal ? 0 : false) {
18+
assert.ok(false);
19+
}
20+
21+
if (!(unknownGlobal ? 'a' === 'a' : true)) {
22+
assert.ok(false);
23+
}

0 commit comments

Comments
 (0)