Skip to content

Commit

Permalink
fix: module execute order (#148)
Browse files Browse the repository at this point in the history
* fix: module execute order

* Update snapshot

* Add the asserting test

* Rebase main
  • Loading branch information
hyf0 committed Nov 2, 2023
1 parent c75e380 commit 7ef1c20
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 119 deletions.
1 change: 1 addition & 0 deletions crates/rolldown/src/bundler/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl Graph {
.iter()
.filter(|rec| rec.kind.is_static())
.filter_map(|rec| rec.resolved_module.is_valid().then_some(rec.resolved_module))
.rev()
.map(Action::Enter),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ input_file: crates/rolldown/tests/esbuild/default/ambiguous_reexport_msg
## entry_js.mjs

```js
// c.js
let c = 4, x$1 = 5
// a.js
let a = 1, x$1 = 2
// b.js
let b = 3;
// a.js
let a = 1, x = 2
// c.js
let c = 4, x = 5
// entry.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ input_file: crates/rolldown/tests/esbuild/default/es6_from_common_js
```js
import { __commonJS, __toESM } from "./_rolldown_runtime.mjs";
// bar.js
var require_bar = __commonJS({
'bar.js'(exports, module) {
exports.bar = function() {
return 'bar'
}
}
});
// foo.js
var require_foo = __commonJS({
'foo.js'(exports, module) {
Expand All @@ -26,6 +18,14 @@ exports.foo = function() {
}
}
});
// bar.js
var require_bar = __commonJS({
'bar.js'(exports, module) {
exports.bar = function() {
return 'bar'
}
}
});
// entry.js
var import_foo = __toESM(require_foo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,14 @@ input_file: crates/rolldown/tests/esbuild/default/export_forms_common_js
```js
import { __esm, __toCommonJS } from "./_rolldown_runtime.mjs";
// h.js
async function foo$1() {}
var h_ns = {
get default() { return foo$1 }
};
var init_h = __esm({
'h.js'() {
foo$1.prop = 123
}
});
// g.js
async function g_default() {}
var g_ns = {
get default() { return g_default }
};
var init_g = __esm({
'g.js'() {
}
});
// f.js
function foo() {}
var f_ns = {
get default() { return foo }
};
var init_f = __esm({
'f.js'() {
foo.prop = 123
}
});
// e.js
function e_default() {}
var e_ns = {
get default() { return e_default }
};
var init_e = __esm({
'e.js'() {
}
});
// d.js
var Foo;
var d_ns = {
get default() { return Foo }
};
var init_d = __esm({
'd.js'() {
Foo = class Foo {}
Foo.prop = 123
}
});
// c.js
var c_default;
var c_ns = {
get default() { return c_default }
// a.js
var abc;
var a_ns = {
get abc() { return abc }
};
var init_c = __esm({
'c.js'() {
c_default = class {}
var init_a = __esm({
'a.js'() {
abc = undefined
}
});
// b.js
Expand All @@ -82,16 +30,6 @@ var init_b = __esm({
xyz = null
}
});
// a.js
var abc;
var a_ns = {
get abc() { return abc }
};
var init_a = __esm({
'a.js'() {
abc = undefined
}
});
// commonjs.js
function Fn() {}
var commonjs_default,v,l,c,Class;
Expand All @@ -117,6 +55,68 @@ Class = class Class {}
}
});
// c.js
var c_default;
var c_ns = {
get default() { return c_default }
};
var init_c = __esm({
'c.js'() {
c_default = class {}
}
});
// d.js
var Foo;
var d_ns = {
get default() { return Foo }
};
var init_d = __esm({
'd.js'() {
Foo = class Foo {}
Foo.prop = 123
}
});
// e.js
function e_default() {}
var e_ns = {
get default() { return e_default }
};
var init_e = __esm({
'e.js'() {
}
});
// f.js
function foo$1() {}
var f_ns = {
get default() { return foo$1 }
};
var init_f = __esm({
'f.js'() {
foo$1.prop = 123
}
});
// g.js
async function g_default() {}
var g_ns = {
get default() { return g_default }
};
var init_g = __esm({
'g.js'() {
}
});
// h.js
async function foo() {}
var h_ns = {
get default() { return foo }
};
var init_h = __esm({
'h.js'() {
foo.prop = 123
}
});
// entry.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ input_file: crates/rolldown/tests/esbuild/default/export_forms_es6
## entry_js.mjs

```js
// a.js
const abc = undefined
// b.js
var b_ns = {
get xyz() { return xyz }
};
const xyz = null
// a.js
const abc = undefined
// entry.js
var entry_default = 123
var v = 234
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ input_file: crates/rolldown/tests/esbuild/default/re_export_default_internal
## entry_js.mjs

```js
// bar.js
var bar_default = 'bar'
// foo.js
var foo_default = 'foo'
// bar.js
var bar_default = 'bar'
// entry.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_export_star_ambiguo
## entry_js.mjs

```js
// bar.js
const y$1 = 3
const z = 4
// foo.js
const x = 1
const y = 2
const y$1 = 2
// bar.js
const y = 3
const z = 4
// common.js
var common_ns = {
get x() { return x },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_star_export_star_om
## entry_js.mjs

```js
// bar.js
const y$1 = 3
const z = 4
// foo.js
const x = 1
const y = 2
const y$1 = 2
// bar.js
const y = 3
const z = 4
// common.js
var common_ns = {
get x() { return x },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_collis
```js
// c.js
let x = 1, y = 2
// b.js
// a.js
// b.js
// entry.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_collis
```js
// c.js
let x = 1, y = 2
// b.js
// a.js
// b.js
// common.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ input_file: crates/rolldown/tests/fixtures/ambiguous_star_export
// c.js
let x = 1;
let y = 2;
// b.js
// a.js
// b.js
// main.js
Expand Down
3 changes: 3 additions & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (globalThis.order !== 'abc') {
throw new Error('exec order is wrong')
}
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.order += 'a'
24 changes: 24 additions & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/artifacts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/rolldown/tests/common/case.rs
expression: content
input_file: crates/rolldown/tests/fixtures/exec_order/baisic
---
# Assets

## main.mjs

```js
// init.js
globalThis.order = ''
// a.js
globalThis.order += 'a'
// b.js
globalThis.order += 'b'
// c.js
globalThis.order += 'c'
// main.js
```
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.order += 'b'
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.order += 'c'
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.order = ''
4 changes: 4 additions & 0 deletions crates/rolldown/tests/fixtures/exec_order/baisic/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './init.js'
import './a.js'
import './b.js'
import './c.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e
```js
import { __commonJS, __reExport, __toESM } from "./_rolldown_runtime.mjs";
// commonjs2.js
var require_commonjs2 = __commonJS({
'commonjs2.js'(exports, module) {
exports.a = 2
}
});
// commonjs.js
var require_commonjs = __commonJS({
'commonjs.js'(exports, module) {
exports.a = 1
}
});
// commonjs2.js
var require_commonjs2 = __commonJS({
'commonjs2.js'(exports, module) {
exports.a = 2
}
});
// proxy.js
var proxy_ns = {
Expand Down

0 comments on commit 7ef1c20

Please sign in to comment.