Skip to content

Commit 114437e

Browse files
test: add test for why PureAnnotation is needed in execution order check (#8933)
## Summary - Adds an integration test combining scenarios from #4920 and #5303 to demonstrate that `PureAnnotation` must be included in the `ExecutionOrderSensitive` check. - A `/*#__PURE__*/` call to a local function that reads a global variable set by another module must still trigger wrapping, otherwise execution order is broken. Ref: #8909 (comment) ## Test plan - [x] New test `pure_annotation_local_fn_reads_global` passes with `just dt` - [x] Snapshot confirms `dep.js` is wrapped with `__esmMin` in both default and `onDemandWrapping` variants 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent cffcd5e commit 114437e

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"config": {
3+
"strictExecutionOrder": true,
4+
"experimental": {
5+
"onDemandWrapping": true
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: crates/rolldown_testing/src/integration_test.rs
3+
---
4+
# Assets
5+
6+
## main.js
7+
8+
```js
9+
import assert from "node:assert";
10+
// HIDDEN [\0rolldown/runtime.js]
11+
function getGlobalValue() {
12+
return globalValue;
13+
}
14+
var dep_default;
15+
__esmMin((() => {
16+
//#region setup.js
17+
globalThis.globalValue = "foo";
18+
//#endregion
19+
//#region dep.js
20+
dep_default = /* @__PURE__ */ getGlobalValue();
21+
//#endregion
22+
//#region main.js
23+
assert.strictEqual(dep_default, "foo");
24+
//#endregion
25+
}))();
26+
27+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// `getGlobalValue` is a local function whose body accesses a global variable.
2+
// The `/*#__PURE__*/` annotation means the call itself is not treated as
3+
// having side effects (`Unknown`), and because the callee is a local
4+
// identifier (not a global like `Reflect.something`), there is no
5+
// `GlobalVarAccess` flag on this statement either.
6+
//
7+
// Without the `PureAnnotation` flag in the `ExecutionOrderSensitive` check,
8+
// this module would NOT be wrapped, and `getGlobalValue()` would execute
9+
// before `setup.js` has a chance to set `globalThis.globalValue`, producing
10+
// `undefined` instead of `'foo'`.
11+
function getGlobalValue() {
12+
return globalValue;
13+
}
14+
15+
export default /*#__PURE__*/ getGlobalValue();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import assert from 'node:assert';
2+
import './setup.js';
3+
import value from './dep.js';
4+
5+
assert.strictEqual(value, 'foo');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
globalThis.globalValue = 'foo';

0 commit comments

Comments
 (0)