Skip to content

Commit

Permalink
test: pass more tree shaking test case (#4191)
Browse files Browse the repository at this point in the history
* chore: πŸ€– ck point

* chore: πŸ€– remove temp file

* chore: πŸ€– get used name

* chore: πŸ€– update

* chore: πŸ€– update doc

* chore: πŸ€– update

* chore: πŸ€– update snapshot

* chore: πŸ€– update snap

* chore: πŸ€– lint

* chore: πŸ€– refactor

* chore: πŸ€– update schema

* chore: πŸ€– update snap

* chore: πŸ€– lint

βœ… Closes: \

* chore: πŸ€– update

* chore: πŸ€– update snap

* chore: πŸ€– update diff

* chore: πŸ€– recover

* chore: πŸ€– update snapshot

* chore: πŸ€– update debug info

* chore: πŸ€– update snap

* chore: πŸ€– more get condition

* chore: πŸ€– add condition

* chore: πŸ€– use hashmap based condition store

* chore: πŸ€– recover testing

* chore: πŸ€– recover

* chore: πŸ€– lint

* chore: πŸ€– disable debug
  • Loading branch information
IWANABETHATGUY authored Sep 17, 2023
1 parent 0e9b4ab commit 9d910ae
Show file tree
Hide file tree
Showing 155 changed files with 876 additions and 1,356 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions crates/rspack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ rspack_fs = { path = "../rspack_fs", features = ["async", "rspack-error"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] }

[dev-dependencies]
rspack_binding_options = { path = "../rspack_binding_options" }
rspack_testing = { path = "../rspack_testing" }
rspack_tracing = { path = "../rspack_tracing" }
rspack_binding_options = { path = "../rspack_binding_options" }
rspack_plugin_javascript = { path = "../rspack_plugin_javascript" }
rspack_testing = { path = "../rspack_testing" }
rspack_tracing = { path = "../rspack_tracing" }


cargo-rst = { path = "../cargo-rst" }
Expand Down
29 changes: 20 additions & 9 deletions crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;

use cargo_rst::git_diff;
use insta::Settings;
use rspack_core::{CompilerOptions, TreeShaking, UsedExportsOption};
use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption};
use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin};
use rspack_testing::test_fixture;
use testing_macros::fixture;

Expand All @@ -28,12 +28,17 @@ fn tree_shaking(fixture_path: PathBuf) {
// second test is webpack based tree shaking
test_fixture(
&fixture_path,
Box::new(|_: &mut Settings, options: &mut CompilerOptions| {
options.experiments.rspack_future.new_treeshaking = true;
options.optimization.provided_exports = true;
options.optimization.used_exports = UsedExportsOption::True;
options.builtins.tree_shaking = TreeShaking::False;
}),
Box::new(
|plugins: &mut Vec<BoxPlugin>, options: &mut CompilerOptions| {
options.experiments.rspack_future.new_treeshaking = true;
options.optimization.provided_exports = true;
options.optimization.used_exports = UsedExportsOption::True;
options.builtins.tree_shaking = TreeShaking::False;

plugins.push(Box::<FlagDependencyExportsPlugin>::default());
plugins.push(Box::<FlagDependencyUsagePlugin>::default());
},
),
Some("new_treeshaking".to_string()),
);

Expand All @@ -45,5 +50,11 @@ fn tree_shaking(fixture_path: PathBuf) {
let new_treeshaking_snapshot =
std::fs::read_to_string(new_treeshaking_snapshot_path).expect("should have snapshot");
let diff = git_diff(&old_snapshot, &new_treeshaking_snapshot);
std::fs::write(fixture_path.join("snapshot/snap.diff"), diff).expect("should write successfully");
let diff_path = fixture_path.join("snapshot/snap.diff");
if diff_path.exists() {
std::fs::remove_file(diff_path.clone()).expect("remove file failed");
}
if !diff.is_empty() {
std::fs::write(diff_path, diff).expect("should write successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ __webpack_require__.r(__webpack_exports__);
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'secret': function() { return secret; },
'result': function() { return result; },
'something': function() { return something; }
'result': function() { return result; }
});
const secret = "888";
const result = 20000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@
/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js");


@@ -25,7 +26,9 @@
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
- 'result': function() { return result; }
+ 'secret': function() { return secret; },
+ 'result': function() { return result; },
+ 'something': function() { return something; }
});
const secret = "888";
const result = 20000;
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ __webpack_require__.r(__webpack_exports__);
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'secret': function() { return secret; },
'result': function() { return result; },
'something': function() { return something; }
'result': function() { return result; }
});
const secret = "888";
const result = 20000;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ __webpack_require__.d(__webpack_exports__, {
"./app.js": function (module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'render': function() { return render; }
});
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");
setTimeout(()=>{
Expand All @@ -43,8 +40,7 @@ __webpack_require__.r(__webpack_exports__);
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'secret': function() { return secret; },
'myanswer': function() { return myanswer; },
'result': function() { return result; }
'myanswer': function() { return myanswer; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js");
Expand Down
19 changes: 3 additions & 16 deletions crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
--- expected
+++ actual
@@ -14,6 +14,9 @@
"./app.js": function (module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'render': function() { return render; }
+});
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");

setTimeout(()=>{
@@ -22,7 +25,7 @@
@@ -22,7 +22,7 @@
function render() {
function test() {
const container = document.getElementById("root");
Expand All @@ -19,14 +9,11 @@
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
@@ -39,7 +42,9 @@
@@ -39,6 +39,7 @@
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
- 'myanswer': function() { return myanswer; }
+ 'secret': function() { return secret; },
+ 'myanswer': function() { return myanswer; },
+ 'result': function() { return result; }
'myanswer': function() { return myanswer; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js");

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'a': function() { return a; },
'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; }
});
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");
Expand All @@ -23,18 +22,14 @@ _b_js__WEBPACK_IMPORTED_MODULE_0_.d;
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'd': function() { return d; },
'c': function() { return c; }
'd': function() { return d; }
});
const d = 3;
const c = 100;
},
"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'ccc': function() { return ccc; }
});
const ccc = 30;
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Expand Down
19 changes: 9 additions & 10 deletions crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
--- expected
+++ actual
@@ -6,6 +6,10 @@
@@ -6,6 +6,9 @@
"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'a': function() { return a; },
+ 'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; }
+});
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");
/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js");
__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);
@@ -19,7 +23,8 @@
@@ -27,9 +30,6 @@
"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
- 'd': function() { return d; }
+ 'd': function() { return d; },
+ 'c': function() { return c; }
});
const d = 3;
const c = 100;
-__webpack_require__.d(__webpack_exports__, {
- 'ccc': function() { return ccc; }
-});
const ccc = 30;
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ const locales = {
"./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'test': function() { return test; }
});
/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./antd/index */"./antd/index.ts");
_antd_index__WEBPACK_IMPORTED_MODULE_0_.locales.zh_CN;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- expected
+++ actual
@@ -28,9 +28,6 @@
"./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'test': function() { return test; }
-});
/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./antd/index */"./antd/index.ts");

_antd_index__WEBPACK_IMPORTED_MODULE_0_.locales.zh_CN;
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs
"./a/aaa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'aaa': function() { return aaa; }
});
function aaa() {}
},
"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'bbb': function() { return bbb; }
});
function bbb() {}
},
"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Expand Down Expand Up @@ -59,9 +53,6 @@ __webpack_require__(/* ./answer */"./answer.js");
"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'myanswer': function() { return myanswer; }
});
const myanswer = 'anyser';
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
--- expected
+++ actual
@@ -3,12 +3,39 @@
@@ -3,12 +3,33 @@
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
+"./a/aaa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'aaa': function() { return aaa; }
+});
+ function aaa() {}
+},
+"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'bbb': function() { return bbb; }
+});
+ function bbb() {}
+},
+"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Expand All @@ -40,3 +34,13 @@

const answer = 42;
},
@@ -32,9 +53,6 @@
"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'myanswer': function() { return myanswer; }
-});
const myanswer = 'anyser';
},

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'Lib': function() { return Lib; },
'v': function() { return v; }
});
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
--- expected
+++ actual
@@ -7,15 +7,16 @@
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
+ 'Lib': function() { return Lib; },
'v': function() { return v; }
@@ -11,11 +11,11 @@
});
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");

Expand All @@ -19,7 +14,7 @@
};
}
const v = _lib__WEBPACK_IMPORTED_MODULE_0_.value;
@@ -31,6 +32,7 @@
@@ -31,6 +31,7 @@
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs
"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'a': function() { return a; }
});
const a = 'bar';
},
"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'a': function() { return a; },
'b': function() { return b; }
});
const a = 'foo';
const b = 'foo';
},
Expand Down

This file was deleted.

Empty file.
Loading

0 comments on commit 9d910ae

Please sign in to comment.