Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align module order with esbuild when mixed load esm and cjs modules. #1740

Open
7086cmd opened this issue Jul 26, 2024 · 1 comment
Open

Comments

@7086cmd
Copy link
Collaborator

7086cmd commented Jul 26, 2024

Not hurry to solve it, but this open for tracking it.

In Rolldown, the generated code order is firstly y that x.


Actually this is not same with esbuild:

TestLoaderDataURLCommonJSAndES6
---------- /out.js ----------
// x.txt
var require_x = __commonJS({
  "x.txt"(exports, module) {
    module.exports = "data:text/plain;charset=utf-8,x";
  }
});

// y.txt
var y_default = "data:text/plain;charset=utf-8,y";

// entry.js
var x_url = require_x();
console.log(x_url, y_default);

you could open an issue to track, it is not related to dataurl encoding.

Originally posted by @IWANABETHATGUY in #1729 (comment)

@IWANABETHATGUY IWANABETHATGUY changed the title Normalize the order of performing CodeGen. Align module order with esbuild whem mixed load **esm** and **cjs** module. Jul 28, 2024
@IWANABETHATGUY
Copy link
Contributor

more generate case:

// index.js
import {a} from './a.js'
import {b} from './b.js'
console.log(a, b, c);
// a.js
export const a = 1000;
// b.js
export const b = 10000;

rolldown

//#region a.js
const a = 1000;

//#endregion
//#region b.js
const b = 10000;

//#endregion
//#region index.js
console.log(a, b, c);

//#endregion

esbuild

// a.js
var a = 1e3;

// b.js
var b = 1e4;

// entry.js
console.log(a, b, c);

Mixed cjs and esm

// index.js
const a = require('./a.js')
import {b} from './b.js'
console.log(b, a);
// a.js
export const a = 1000;
// b.js
export const b = 10000;

rolldown

// ...snip runtime
//#endregion
//#region b.js
const b = 10000;

//#endregion
//#region a.js
var a_ns, a$1;
var init_a = __esmMin(() => {
	a_ns = {};
	__export(a_ns, {a: () => a$1});
	a$1 = 1000;
});

//#endregion
//#region index.js
const a = (init_a(), __toCommonJS(a_ns));
console.log(b, a);

//#endregion

esbuild

// a.js
var a_exports = {};
__export(a_exports, {
  a: () => a
});
var a;
var init_a = __esm({
  "a.js"() {
    a = 1e3;
  }
});

// b.js
var b = 1e4;

// entry.js
var a2 = (init_a(), __toCommonJS(a_exports));
console.log(a2, b, c);

@IWANABETHATGUY IWANABETHATGUY changed the title Align module order with esbuild whem mixed load **esm** and **cjs** module. Align module order with esbuild whem mixed load esm and cjs module. Jul 28, 2024
@7086cmd 7086cmd changed the title Align module order with esbuild whem mixed load esm and cjs module. Align module order with esbuild when mixed load esm and cjs modules. Aug 13, 2024
@github-actions github-actions bot added the stale label Sep 12, 2024
@7086cmd 7086cmd removed the stale label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants