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

fix: flag side effects plugin update dep #4747

Merged
merged 19 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 46 additions & 12 deletions crates/rspack/tests/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,48 @@ const falsePositiveMap = {
"var-function-expr": "align webpack unused binding behavior",
"webpack-innergraph-no-side-effects": "align webpack unused binding behavior",
"side-effects-export-default-expr": "align webpack unused binding behavior",
"webpack-innergraph-circular": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"static-class": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"webpack-inner-graph-export-default-named": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"class-extend": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4481/files",
"export_star": "same as webpack https://gist.github.com/IWANABETHATGUY/1ee8aa4c2889a9246d19d7be0ac75bb7",
"issue-4637": "align webpack https://github.com/web-infra-dev/rspack/pull/4637/files#diff-d434486532fb1507da93a26ce108dca465337b6af0ee86b4ab94fd788810d288",
"named-export-decl-with-src-eval": "align to webpack: https://github.com/web-infra-dev/rspack/pull/4629/files#r1393574682",
"rollup-unused-var": "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393575194",
"ts-target-es5": "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1392268704",
"webpack-reexport-namespace-and-default": "align to webapck, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393576913"

"webpack-innergraph-circular":
"align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"static-class":
"align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"webpack-inner-graph-export-default-named":
"align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files",
"class-extend":
"align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4481/files",
export_star:
"same as webpack https://gist.github.com/IWANABETHATGUY/1ee8aa4c2889a9246d19d7be0ac75bb7",
"issue-4637":
"align webpack https://github.com/web-infra-dev/rspack/pull/4637/files#diff-d434486532fb1507da93a26ce108dca465337b6af0ee86b4ab94fd788810d288",
"named-export-decl-with-src-eval":
"align to webpack: https://github.com/web-infra-dev/rspack/pull/4629/files#r1393574682",
"rollup-unused-var":
"align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393575194",
"ts-target-es5":
"align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1392268704",
"webpack-reexport-namespace-and-default":
"align to webapck, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393576913",
bb: "update dep",
"cjs-tree-shaking-basic": "update dep",
"cyclic-reference-export-all":
"redundant `usePlatform: function() { return usePlatform;`",
"export-imported-import-all-as": "update dep",
"import-var-assign-side-effects": "update dep",
"nested-import-3": "update dep",
"nested-import-4": "update dep",
"prune-bailout-module": "update dep",
pure_comments_magic_comments: "update dep",
"reexport-all-as": "update dep",
reexport_entry_elimination: "update dep",
"side-effects-analyzed": "update dep",
"side-effects-prune": "update dep",
"side-effects-two": "update dep",
"export-star-chain": "update dep",
"import-export-all-as-a-empty-module": "update dep",
"import-star-as-and-export": "update dep",
"module-rule-side-effects2": "align with webpack",
"react-redux-like": "update dep",
"webpack-side-effects-all-used": "update dep",
"webpack-side-effects-simple-unused": "update dep",
};

const normalizedList = filteredList.map((item) => {
Expand Down Expand Up @@ -69,5 +100,8 @@ let failedCases = normalizedList

console.log(`failed: ${filteredList.length - successedCount}`);
console.log(`passed: ${successedCount}`);
console.log(`fasePositiveCases: ${fasePositiveCases.length}\n`, fasePositiveCases);
console.log(
`fasePositiveCases: ${fasePositiveCases.length}\n`,
fasePositiveCases,
);
console.log(`failedCases: ${failedCases.length}\n`, failedCases);
10 changes: 6 additions & 4 deletions crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::sync::atomic::Ordering;

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

Expand Down Expand Up @@ -38,9 +40,9 @@ fn tree_shaking(fixture_path: PathBuf) {
options.optimization.used_exports = UsedExportsOption::True;
options.builtins.tree_shaking = TreeShaking::False;

// if options.optimization.side_effects.is_enable() {
// plugins.push(Box::<SideEffectsFlagPlugin>::default());
// }
if options.optimization.side_effects.is_enable() {
plugins.push(Box::<SideEffectsFlagPlugin>::default());
}
plugins.push(Box::<FlagDependencyExportsPlugin>::default());
plugins.push(Box::<FlagDependencyUsagePlugin>::default());
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./src/a */"./src/a.js");
/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./src/a */"./src/a.js");


}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./src/a */"./src/a.js");
/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./src/a */"./src/a.js");


}),
Expand Down
4 changes: 3 additions & 1 deletion crates/rspack/tests/tree-shaking/basic/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import * as test from "./app";
import { answer } from "./lib";
answer

5 changes: 1 addition & 4 deletions crates/rspack/tests/tree-shaking/basic/lib.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import { answer } from "./answer";
export const secret = "888";
export const myanswer = answer,
result = 20000;
export {answer} from './answer'
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,12 @@ __webpack_require__.d(__webpack_exports__, {
});
const answer = 103330;
}),
"./app.js": (function (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");

setTimeout(()=>{
console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer);
}, 1000);
function render() {
function test() {
const container = document.getElementById("root");
container.innerHTML = `adddd333:${secret}:${myanswer}`;
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
console.log("xxx:", module1);
});
}),
"./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");

}),
"./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; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js");
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js");

const secret = "888";
const myanswer = _answer__WEBPACK_IMPORTED_MODULE_0__.answer, result = 20000;
_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
}),

},function(__webpack_require__) {
Expand Down
25 changes: 3 additions & 22 deletions crates/rspack/tests/tree-shaking/basic/snapshot/output.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,21 @@ __webpack_require__.d(__webpack_exports__, {
});
const answer = 103330;
}),
"./app.js": (function (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");

setTimeout(()=>{
console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer);
}, 1000);
function render() {
function test() {
const container = document.getElementById("root");
container.innerHTML = `adddd333:${/* "./lib" unused */null}:${_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer}`;
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
console.log("xxx:", module1);
});
}),
"./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 _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js");

_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
}),
"./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; }
answer: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__.answer; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js");

const secret = "888";
const myanswer = _answer__WEBPACK_IMPORTED_MODULE_0__.answer, result = 20000;
}),

},function(__webpack_require__) {
Expand Down
29 changes: 20 additions & 9 deletions crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
--- expected
+++ actual
@@ -22,7 +22,7 @@
function render() {
function test() {
const container = document.getElementById("root");
- container.innerHTML = `adddd333:${/* "./lib" unused */null}:${_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer}`;
+ container.innerHTML = `adddd333:${secret}:${myanswer}`;
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
@@ -14,18 +14,9 @@
"./index.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");
+/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js");

_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
-}),
-"./lib.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__WEBPACK_IMPORTED_MODULE_0__.answer; }
-});
-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js");
-
}),

},function(__webpack_require__) {
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
"./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");
/* 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__);


const a = 3;
_b_js__WEBPACK_IMPORTED_MODULE_0__.d;

}),
"./b.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; }
});
const d = 3;
const c = 100;
}),
"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
Expand All @@ -35,7 +14,7 @@ __webpack_require__.d(__webpack_exports__, {
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js");
/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./c.js");

_a_js__WEBPACK_IMPORTED_MODULE_0__.ccc;
}),
Expand Down
39 changes: 39 additions & 0 deletions crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- expected
+++ actual
@@ -3,27 +3,6 @@
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
-"./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");
-/* 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__);
-
-
- const a = 3;
-_b_js__WEBPACK_IMPORTED_MODULE_0__.d;
-
-}),
-"./b.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; }
-});
- const d = 3;
- const c = 100;
-}),
"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
@@ -35,7 +14,7 @@
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js");
+/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./c.js");

_a_js__WEBPACK_IMPORTED_MODULE_0__.ccc;
}),
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ __webpack_require__.d(__webpack_exports__, {
});

const answer = 42;
}),
"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
myanswer: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.myanswer; }
});
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js");

}),
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js");
/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js");

__webpack_require__(/* ./answer */"./answer.js");
(0, _app__WEBPACK_IMPORTED_MODULE_1__.myanswer)();
(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)();
}),
"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ __webpack_require__.d(__webpack_exports__, {
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js");
/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js");

__webpack_require__(/* ./answer */"./answer.js");
(0, _app__WEBPACK_IMPORTED_MODULE_1__.myanswer)();
(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)();
}),
"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- expected
+++ actual
@@ -12,19 +12,10 @@

const answer = 42;
}),
-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
-"use strict";
-__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- myanswer: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.myanswer; }
-});
-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js");
-
-}),
"./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 _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js");

__webpack_require__(/* ./answer */"./answer.js");
(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)();
Loading
Loading