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

test: pass more tree shaking test case #4191

Merged
merged 27 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
554f753
chore: 🤖 ck point
IWANABETHATGUY Sep 14, 2023
86fe0fc
chore: 🤖 remove temp file
IWANABETHATGUY Sep 14, 2023
faa957d
chore: 🤖 get used name
IWANABETHATGUY Sep 14, 2023
6d6b25c
chore: 🤖 update
IWANABETHATGUY Sep 14, 2023
1eeb835
chore: 🤖 update doc
IWANABETHATGUY Sep 14, 2023
f60af1f
chore: 🤖 update
IWANABETHATGUY Sep 14, 2023
d564c4f
chore: 🤖 update snapshot
IWANABETHATGUY Sep 14, 2023
455e338
chore: 🤖 update snap
IWANABETHATGUY Sep 14, 2023
07975c5
chore: 🤖 lint
IWANABETHATGUY Sep 14, 2023
ea5cf28
chore: 🤖 refactor
IWANABETHATGUY Sep 14, 2023
b0fb55a
chore: 🤖 update schema
IWANABETHATGUY Sep 14, 2023
5e0b291
chore: 🤖 update snap
IWANABETHATGUY Sep 14, 2023
90aa2eb
chore: 🤖 lint
IWANABETHATGUY Sep 14, 2023
725823c
chore: 🤖 update
IWANABETHATGUY Sep 14, 2023
3cdd358
chore: 🤖 update snap
IWANABETHATGUY Sep 15, 2023
8fb8588
chore: 🤖 update diff
IWANABETHATGUY Sep 15, 2023
bc37d49
chore: 🤖 recover
IWANABETHATGUY Sep 15, 2023
2c63179
chore: 🤖 update snapshot
IWANABETHATGUY Sep 15, 2023
8303646
chore: 🤖 update debug info
IWANABETHATGUY Sep 15, 2023
97c80df
chore: 🤖 update snap
IWANABETHATGUY Sep 17, 2023
4035553
chore: 🤖 more get condition
IWANABETHATGUY Sep 17, 2023
e7d103c
chore: 🤖 add condition
IWANABETHATGUY Sep 17, 2023
f263f81
chore: 🤖 use hashmap based condition store
IWANABETHATGUY Sep 17, 2023
8d9fb2f
chore: 🤖 recover testing
IWANABETHATGUY Sep 17, 2023
9b40582
chore: 🤖 recover
IWANABETHATGUY Sep 17, 2023
5fe6925
chore: 🤖 lint
IWANABETHATGUY Sep 17, 2023
f09d82f
chore: 🤖 disable debug
IWANABETHATGUY Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading