Skip to content

Commit

Permalink
feat: don't render empty module. Closes #440, #162
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Mar 6, 2024
1 parent f8433bd commit b310a9a
Show file tree
Hide file tree
Showing 36 changed files with 8 additions and 98 deletions.
12 changes: 8 additions & 4 deletions crates/rolldown/src/utils/render_normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ pub fn render_normal_module(
_ctx: &ModuleRenderContext<'_>,
ast: &OxcProgram,
) -> Option<RenderedNormalModuleOutput> {
let generated_code = OxcCompiler::print(ast);
let mut source = MagicString::new(generated_code);
if ast.program().body.is_empty() {
None
} else {
let generated_code = OxcCompiler::print(ast);
let mut source = MagicString::new(generated_code);

source.prepend(format!("// {}\n", module.pretty_path));
source.prepend(format!("// {}\n", module.pretty_path));

Some(RenderedNormalModuleOutput { code: source, map: None })
Some(RenderedNormalModuleOutput { code: source, map: None })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ let b = 3;
// c.js
let c = 4, x = 5;
// entry.js
export { a, b, c };
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ import "http://example.com/code.js";
import "https://example.com/code.js";
import "//example.com/code.js";
import "data:application/javascript;base64,ZXhwb3J0IGRlZmF1bHQgMTIz";
// entry.js
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ input_file: crates/rolldown/tests/esbuild/default/export_chain
// bar.js
const c = 123;
// foo.js
// entry.js
export { c as a };
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ var foo_default = 'foo';
// bar.js
var bar_default = 'bar';
// entry.js
export { bar_default as bar, foo_default as foo };
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ statement();
statement();
const bar = 123;
// foo.js
// entry.js
console.log(bar);
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_of_export_star_of_i
// baz.js
const value = 123;
// bar.js
// foo.js
statement();
statement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo_ns, foo_ns.foo, foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo_ns.foo, foo_ns.foo, foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo_ns, foo_ns.foo, foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo_ns.foo, foo_ns.foo, foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(foo_ns, {
});
const foo$1 = 123;
// bar.js
// entry.js
let foo = 234;
console.log(foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { __export } from "./$runtime$.mjs";
// folders/child/foo.js
const foo = () => 'hi there';
// folders/child/index.js
// folders/index.js
var folders_index_ns = {};
__export(folders_index_ns, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ __export(foo_ns, {
});
const foo = 123;
// entry.js
export { foo };
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ __export(foo_ns, {
});
const foo = 123;
// entry.js
export { foo };
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(bar_ns, {
});
const x = 123;
// foo.js
// entry.js
console.log(bar_ns, bar_ns.foo);
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ __export(bar_ns, {
});
const x = 123;
// foo.js
// entry.js
console.log(bar_ns.foo);
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ __export(foo_ns, {
});
const foo = 123;
// entry.js
export { foo, foo_ns as ns };
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ __export(foo_ns, {
});
const foo = 123;
// entry.js
export { foo, foo_ns as ns };
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_external_es

```js
import "foo";
// entry.js
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_collis
// c.js
let x = 1, y = 2;
// a.js
// b.js
// entry.js
export { x, y };
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_collis
// c.js
let x = 1, y = 2;
// a.js
// b.js
// common.js
// entry.js
console.log(x, y);
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_shadow
## entry_js.mjs

```js
// b.js
// a.js
let x = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ input_file: crates/rolldown/tests/esbuild/import_star/re_export_star_name_shadow
## entry_js.mjs

```js
// c.js
// b.js
let x = 1;
// a.js
// entry.js
console.log(x);
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ setValue(123);

```js
import "./shared_js.mjs";
// b.js
```
## shared_js.mjs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ input_file: crates/rolldown/tests/esbuild/splitting/duplicate_chunk_collision

```js
import "./ab_js.mjs";
// a.js
```
## ab_js.mjs

Expand All @@ -22,8 +20,6 @@ console.log(123);

```js
import "./ab_js.mjs";
// b.js
```
## c.mjs

Expand All @@ -35,8 +31,6 @@ import "./cd_js.mjs";
```js
// cd.js
console.log(123);
// d.js
```
## d.mjs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ export { a };
```js
import { a } from "./a_js.mjs";
// b.js
export { a };
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@ input_file: crates/rolldown/tests/fixtures/ambiguous_star_export
let x = 1;
let y = 2;
// a.js
// b.js
// main.js
export { x, y };
```
2 changes: 0 additions & 2 deletions crates/rolldown/tests/fixtures/basic_re_export/artifacts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ input_file: crates/rolldown/tests/fixtures/basic_re_export
// a.js
const a = 'a.js';
// proxy.js
// main.js
const a$1 = 'index.js';
console.log(a$1, a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import('./dynamic_js.mjs');

```js
import "./share_js.mjs";
// main2.js
```
## share_js.mjs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ input_file: crates/rolldown/tests/fixtures/code_splitting/ensure_side_effect_exe

```js
import "./shared_js.mjs";
// a.js
```
## b.mjs

```js
import "./shared_js.mjs";
// b.js
```
## shared_js.mjs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ globalThis.order += 'b';
// c.js
globalThis.order += 'c';
// main.js
```
4 changes: 0 additions & 4 deletions crates/rolldown/tests/fixtures/reexport_star/artifacts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ export { a_ns };
```js
import { a_ns } from "./a_js.mjs";
// entry.js
export { a_ns as a };
```
## main.mjs

```js
import { a_ns } from "./a_js.mjs";
// main.js
export { a_ns as a };
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ input_file: crates/rolldown/tests/fixtures/reexport_star_from_local_named_export
// foo.js
const value = 1;
// main.js
export { value as foo };
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ function isPlainObject(value) {
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
}
// main.js
export { isPlainObject as default };
```

0 comments on commit b310a9a

Please sign in to comment.