Skip to content

Commit

Permalink
feat(output): make output folding-friendly using #region
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Jun 3, 2024
1 parent 9219b19 commit 09ac115
Show file tree
Hide file tree
Showing 337 changed files with 2,262 additions and 1,623 deletions.
4 changes: 3 additions & 1 deletion crates/rolldown/src/utils/render_normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn render_normal_module(
} else {
let mut sources: Vec<Box<dyn rolldown_sourcemap::Source + Send>> = vec![];
sources.push(Box::new(RawSource::new(format!(
"// {debug_resource_id}",
"//#region {debug_resource_id}",
debug_resource_id = module.debug_resource_id
))));

Expand Down Expand Up @@ -51,6 +51,8 @@ pub fn render_normal_module(
sources.push(Box::new(RawSource::new(render_output.source_text)));
}

sources.push(Box::new(RawSource::new("//#endregion".to_string())));

Some(sources)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ input_file: crates/rolldown/tests/esbuild/dce/dce_of_destructuring

```js
// entry.js
//#region entry.js
var KEEP1 = x;
var [remove3] = [];
var [remove4,...remove5] = [...[1, 2], 3];
var [,,remove6] = [, , 3];
var [KEEP2] = [x];
var [KEEP3] = [...{}];
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ input_file: crates/rolldown/tests/esbuild/dce/dce_of_symbol_instances

```js
// class.js
//#region class.js
class Keep1 {
*[Symbol.iterator](){
}
Expand All @@ -23,12 +23,13 @@ class Keep2 {
}
}
//#endregion
```
## object_js.mjs

```js
// object.js
//#region object.js
let remove2 = {
*[Symbol.iterator](){
}
Expand All @@ -52,4 +53,5 @@ let keep3 = {
}
};
//#endregion
```
3 changes: 2 additions & 1 deletion crates/rolldown/tests/esbuild/dce/dce_type_of/artifacts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/dce_type_of

```js
// entry.js
//#region entry.js
typeof x_REMOVE;
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ input_file: crates/rolldown/tests/esbuild/dce/dce_type_of_equals_string

```js
// entry.js
//#region entry.js
var hasBar = typeof bar !== 'undefined';
if (false) console.log(hasBar);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ input_file: crates/rolldown/tests/esbuild/dce/drop_label_tree_shaking_bug_issue3

```js
// entry.js
//#region entry.js
const myFunc = () => {
DROP: {
console.log('drop');
Expand All @@ -18,5 +18,6 @@ const myFunc = () => {
};
var entry_default = myFunc;
//#endregion
export { entry_default as default };
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ input_file: crates/rolldown/tests/esbuild/dce/import_re_export_of_namespace_impo
```js
import { __commonJSMin, __export, __toESM } from "./$runtime$.mjs";
// node_modules/pkg/foo.js
//#region node_modules/pkg/foo.js
var require_foo = __commonJSMin((exports, module) => {
module.exports = 123;
});
// node_modules/pkg/bar.js
//#endregion
//#region node_modules/pkg/bar.js
var require_bar = __commonJSMin((exports, module) => {
module.exports = 'abc';
});
// node_modules/pkg/index.js
//#endregion
//#region node_modules/pkg/index.js
var pkg_index_ns = {};
__export(pkg_index_ns, {
bar:() => import_bar.default,
Expand All @@ -29,7 +31,9 @@ __export(pkg_index_ns, {
var import_foo = __toESM(require_foo());
var import_bar = __toESM(require_bar());
// entry.js
//#endregion
//#region entry.js
console.log(pkg_index_ns.foo);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ input_file: crates/rolldown/tests/esbuild/dce/inline_function_call_for_init_decl

```js
// entry.js
//#region entry.js
function empty() {
}
function id(x) {
return x;
}
for (var y = empty(); false;) ;for (var z = id(123); false;) ;
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/json_loader_remove_unused

```js
// entry.js
//#region entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_gl

```js
// node_modules/demo-pkg/keep/this/file.js
//#region node_modules/demo-pkg/keep/this/file.js
console.log('this should be kept');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke

```js
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
console.log('hello');
// src/entry.js
//#endregion
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke
```js
import { __esmMin, __export, __toCommonJS } from "./$runtime$.mjs";
// node_modules/demo-pkg/index-module.js
//#region node_modules/demo-pkg/index-module.js
var index_module_ns, foo;
var init_index_module = __esmMin(() => {
index_module_ns = {};
Expand All @@ -21,11 +21,14 @@ var init_index_module = __esmMin(() => {
console.log('TEST FAILED');
});
// src/require-demo-pkg.js
//#endregion
//#region src/require-demo-pkg.js
init_index_module(),__toCommonJS(index_module_ns);
// src/entry.js
//#endregion
//#region src/entry.js
init_index_module();
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke

```js
// node_modules/demo-pkg/index-module.js
//#region node_modules/demo-pkg/index-module.js
console.log('this should be kept');
// src/entry.js
//#endregion
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_ke

```js
// node_modules/demo-pkg/index-module.js
//#region node_modules/demo-pkg/index-module.js
console.log('this should be kept');
// src/entry.js
//#endregion
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_array_re

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_ke
```js
import { __commonJSMin, __toESM } from "./$runtime$.mjs";
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
var require_demo_pkg_index = __commonJSMin((exports, module) => {
exports.foo = 123;
console.log('hello');
});
// src/entry.js
//#endregion
//#region src/entry.js
var import_demo_pkg_index = __toESM(require_demo_pkg_index());
console.log(import_demo_pkg_index.foo);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_ke

```js
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
const foo = 123;
console.log('hello');
// src/entry.js
//#endregion
//#region src/entry.js
console.log(foo);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_ke
```js
import { __commonJSMin, __toESM } from "./$runtime$.mjs";
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
var require_demo_pkg_index = __commonJSMin((exports, module) => {
exports.foo = 123;
console.log('hello');
});
// src/entry.js
//#endregion
//#region src/entry.js
var import_demo_pkg_index = __toESM(require_demo_pkg_index());
console.log(import_demo_pkg_index);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_ke
```js
import { __export } from "./$runtime$.mjs";
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
var demo_pkg_index_ns = {};
__export(demo_pkg_index_ns, {
foo:() => foo
});
const foo = 123;
console.log('hello');
// src/entry.js
//#endregion
//#region src/entry.js
console.log(demo_pkg_index_ns);
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_no

```js
// node_modules/demo-pkg/index.js
//#region node_modules/demo-pkg/index.js
console.log('unused import');
// src/entry.js
//#endregion
//#region src/entry.js
console.log('used import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_re

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_re

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ input_file: crates/rolldown/tests/esbuild/dce/package_json_side_effects_false_re

```js
// src/entry.js
//#region src/entry.js
console.log('unused import');
//#endregion
```
Loading

0 comments on commit 09ac115

Please sign in to comment.