Skip to content

Commit 456b9f2

Browse files
test: add test case for static flag tree-shaking (#8476)
related to #7235
1 parent e35d082 commit 456b9f2

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"_comment": "Test for issue #7235: Static flags imported from another file should be tree-shaken",
3+
"config": {}
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import nodeFs from 'node:fs';
2+
import nodePath from 'node:path';
3+
import assert from 'node:assert';
4+
5+
const distDir = nodePath.join(import.meta.dirname, 'dist');
6+
const mainFile = nodePath.join(distDir, 'main.js');
7+
const content = nodeFs.readFileSync(mainFile, 'utf8');
8+
9+
// The dead branch should be eliminated by DCE
10+
assert(!content.includes('should not see me in bundle'), 'dead branch should be tree-shaken');
11+
// The live branch should remain
12+
assert(content.includes('flag is false correctly'), 'live branch should be kept');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/rolldown_testing/src/integration_test.rs
3+
---
4+
# Assets
5+
6+
## main.js
7+
8+
```js
9+
console.log("flag is false correctly");
10+
//#endregion
11+
12+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const flag = false;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { flag } from './flags.js';
2+
3+
if (flag) {
4+
console.log('should not see me in bundle!');
5+
} else {
6+
console.log('flag is false correctly');
7+
}

crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4931,6 +4931,10 @@ expression: output
49314931
- middle-!~{003}~.js => middle-CMhJ5DMW.js
49324932
- server-!~{002}~.js => server-DfC8g3sb.js
49334933
4934+
# tests/rolldown/issues/7235
4935+
4936+
- main-!~{000}~.js => main-Bo1PArHf.js
4937+
49344938
# tests/rolldown/issues/7286
49354939
49364940
- main-!~{000}~.js => main-2AMGYXtd.js

0 commit comments

Comments
 (0)