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

feat: add side effects detect #4215

Merged
merged 24 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ jobs:
echo 'debug = false' >> Cargo.toml

- name: Run test
run: cargo test --workspace -- --nocapture
run: IS_NEW_TREESHAKING=1 cargo test --workspace -- --nocapture
29 changes: 29 additions & 0 deletions crates/rspack/tests/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const path = require("path");
const fs = require("fs");

const currentDir = path.resolve(__dirname, "./tree-shaking");
const dirList = fs.readdirSync(currentDir);
const excludeList = ["node_modules"]


const filteredList = dirList.filter((dir) => {
if (dir.startsWith(".")) {
return false;
}
if (excludeList.includes(dir)) {
return false;
}

return true;
});

console.log(`total: ${filteredList.length}`)

const failedList = filteredList.filter(item => {
const abPath = path.join(currentDir, item, "snapshot", "snap.diff")
return fs.existsSync(abPath)
})

console.log(`failed: ${failedList.length}`)
console.log(`passed: ${filteredList.length - failedList.length}`)
console.log(failedList)
5 changes: 4 additions & 1 deletion crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::PathBuf;
use std::sync::atomic::Ordering;

use cargo_rst::git_diff;
use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption};
use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption, IS_NEW_TREESHAKING};
use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin};
use rspack_testing::test_fixture;
use testing_macros::fixture;
Expand All @@ -22,10 +23,12 @@ fn samples(fixture_path: PathBuf) {

#[fixture("tests/tree-shaking/*", exclude("node_modules"))]
fn tree_shaking(fixture_path: PathBuf) {
std::env::set_var("IS_NEW_TREESHAKING", "1");
// For each test case
// First test is old version tree shaking snapshot test
test_fixture(&fixture_path, Box::new(|_, _| {}), None);
// second test is webpack based tree shaking
IS_NEW_TREESHAKING.store(true, Ordering::SeqCst);
test_fixture(
&fixture_path,
Box::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0_.result;
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js");
/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js");


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ __webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'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__);
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");


const a = 3;
Expand Down
8 changes: 6 additions & 2 deletions crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
--- expected
+++ actual
@@ -6,6 +6,9 @@
@@ -6,9 +6,12 @@
"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");
+__webpack_require__.d(__webpack_exports__, {
+ '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__);
+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");


const a = 3;
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs
---
```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__);
function aaa() {}
},
"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
function bbb() {}
},
"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _aaa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aaa */"./a/aaa.js");
__webpack_require__.es(_aaa__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);
/* harmony import */var _bbb__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bbb */"./a/bbb.js");
__webpack_require__.es(_bbb__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);


},
"./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'answer': function() { return answer; }
});
/* harmony import */var _a_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a/index */"./a/index.js");

const answer = 42;
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = Index;
"./src/containers/containers.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js");
__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);
/* harmony import */var _page_container__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./page-container */"./src/containers/page-container/index.js");
__webpack_require__.es(_page_container__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);


},
Expand All @@ -37,22 +33,6 @@ __webpack_require__.d(__webpack_exports__, {
/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js");


},
"./src/containers/page-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../containers */"./src/containers/containers.js");

_containers__WEBPACK_IMPORTED_MODULE_0_.usePlatform;
},
"./src/containers/platform-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'usePlatform': function() { return usePlatform; }
});
const usePlatform = 3;
const PlatformProvider = 1000;
},
"./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
--- expected
+++ actual
@@ -23,6 +23,8 @@
@@ -21,8 +21,6 @@
"./src/containers/containers.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js");
__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);
+/* harmony import */var _page_container__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./page-container */"./src/containers/page-container/index.js");
+__webpack_require__.es(_page_container__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);
-/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js");
-__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);


},
@@ -36,12 +38,18 @@
@@ -35,16 +33,6 @@
/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js");


},
+"./src/containers/page-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../containers */"./src/containers/containers.js");
+
+_containers__WEBPACK_IMPORTED_MODULE_0_.usePlatform;
+},
"./src/containers/platform-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
-},
-"./src/containers/platform-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
-'use strict';
-__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'usePlatform': function() { return usePlatform; },
- 'PlatformProvider': function() { return PlatformProvider; }
+ 'usePlatform': function() { return usePlatform; }
});
const usePlatform = 3;
const PlatformProvider = 1000;
-});
- const usePlatform = 3;
- const PlatformProvider = 1000;
},
"./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs
"./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");
__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);

},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Expand All @@ -17,22 +15,6 @@ __webpack_require__.r(__webpack_exports__);

_answer__WEBPACK_IMPORTED_MODULE_0_.filter;
},
"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; }
});
/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js");
const a = 3;


},
"./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
const result = "";
},

},function(__webpack_require__) {
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
--- expected
+++ actual
@@ -31,9 +31,6 @@
"./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
@@ -6,8 +6,6 @@
"./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js");
-__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);

},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
@@ -16,25 +14,6 @@
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js");

_answer__WEBPACK_IMPORTED_MODULE_0_.filter;
-},
-"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
-'use strict';
-__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; }
-});
-/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js");
- const a = 3;
-
-
-},
-"./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
-'use strict';
-__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'result': function() { return result; }
-});
const result = "";
- const result = "";
},

},function(__webpack_require__) {
Loading
Loading