Skip to content

Commit

Permalink
chore: 🤖 clean
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Dec 7, 2023
1 parent 986fa8a commit 5fca139
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 167 deletions.
12 changes: 1 addition & 11 deletions crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ fn samples(fixture_path: PathBuf) {
fn tree_shaking(fixture_path: PathBuf) {
// For each test case
// First test is old version tree shaking snapshot test
// TODO: recover
// test_fixture(&fixture_path, Box::new(|_, _| {}), None);
test_fixture(&fixture_path, Box::new(|_, _| {}), None);
// second test is webpack based tree shaking
IS_NEW_TREESHAKING.store(true, Ordering::SeqCst);
test_fixture(
Expand All @@ -67,15 +66,6 @@ fn tree_shaking(fixture_path: PathBuf) {
}
plugins.push(Box::<FlagDependencyExportsPlugin>::default());
plugins.push(Box::<FlagDependencyUsagePlugin>::default());
if options.optimization.mangle_exports.is_enable() {
plugins.push(
MangleExportsPlugin::new(!matches!(
options.optimization.mangle_exports,
MangleExportsOption::Size
))
.boxed(),
);
}
},
),
Some("new_treeshaking".to_string()),
Expand Down
5 changes: 2 additions & 3 deletions crates/rspack/tests/tree-shaking/basic/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import a from "./a.json";
a[2]

import { answer } from "./lib";
answer

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ source: crates/rspack_testing/src/run_fixture.rs
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
"./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; }
});
const answer = 103330;
}),
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _a_json__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./a.json */"./a.json");
/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib */"./answer.js");
_a_json__WEBPACK_IMPORTED_MODULE_0__["default"];
_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
}),
"./a.json": (function (module, exports, __webpack_require__) {
"use strict";
module.exports = {}}),
},function(__webpack_require__) {
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) }
Expand Down
27 changes: 6 additions & 21 deletions crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
--- expected
+++ actual
@@ -3,30 +3,16 @@
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
-"./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; }
-});
- const answer = 103330;
-}),
@@ -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 _a_json__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./a.json */"./a.json");
+/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib */"./answer.js");

-_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
+_a_json__WEBPACK_IMPORTED_MODULE_0__["2"].a;
}),
_lib__WEBPACK_IMPORTED_MODULE_0__.answer;
-}),
-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+"./a.json": (function (module, exports, __webpack_require__) {
"use strict";
-"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");
-
-}),
+module.exports = [{"a":1}]}),
}),

},function(__webpack_require__) {
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) }
3 changes: 1 addition & 2 deletions crates/rspack/tests/tree-shaking/basic/test.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"optimization": {
"sideEffects": "true",
"mangleExports": "true"
"sideEffects": "true"
},
"builtins": {
"treeShaking": "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,34 @@ impl<'a> FlagDependencyExportsProxy<'a> {
let module_graph_modules =
std::mem::take(&mut self.mg.module_identifier_to_module_graph_module);
for mgm in module_graph_modules.values() {
let exports_info_id = mgm.exports;
let is_module_without_exports = mgm
.build_meta
.as_ref()
.map(|build_meta| build_meta.exports_type == BuildMetaExportsType::Unset)
.unwrap_or(true);
if is_module_without_exports
&& !matches!(
exports_info_id
.get_exports_info(self.mg)
.other_exports_info
.get_export_info(self.mg)
.provided,
Some(ExportInfoProvided::Null)
)
{
exports_info_id.set_has_provide_info(self.mg);
exports_info_id.set_unknown_exports_provided(self.mg, false, None, None, None, None);
continue;
}
q.push_back(mgm.module_identifier);
exports_info_id.set_has_provide_info(self.mg);
let exports_id = mgm.exports;
let is_module_without_exports = if let Some(ref build_meta) = mgm.build_meta {
build_meta.exports_type == BuildMetaExportsType::Unset
} else {
true
} && {
let exports_info = self.mg.get_exports_info_by_id(&exports_id);
let other_exports_info_id = exports_info.other_exports_info;
let other_exports_info = self.mg.get_export_info_by_id(&other_exports_info_id);
other_exports_info.provided.is_some()
};

// TODO: mem cache
exports_id.set_has_provide_info(self.mg);
q.push_back(mgm.module_identifier);
if is_module_without_exports {
exports_id.set_unknown_exports_provided(self.mg, false, None, None, None, None);
}
}
self.mg.module_identifier_to_module_graph_module = module_graph_modules;
while let Some(module_id) = q.pop_back() {
self.changed = false;
self.current_module_id = module_id;
let mut exports_specs_of_dependencies: HashMap<DependencyId, ExportsSpec> =
let mut exports_specs_from_dependencies: HashMap<DependencyId, ExportsSpec> =
HashMap::default();
self.process_dependencies_block(&module_id, &mut exports_specs_of_dependencies);
self.process_dependencies_block(&module_id, &mut exports_specs_from_dependencies);
let exports_info_id = self.mg.get_exports_info(&module_id).id;
for (dep_id, exports_spec) in exports_specs_of_dependencies.into_iter() {
for (dep_id, exports_spec) in exports_specs_from_dependencies.into_iter() {
self.process_exports_spec(dep_id, exports_spec, exports_info_id);
}
if self.changed {
Expand All @@ -77,8 +72,8 @@ impl<'a> FlagDependencyExportsProxy<'a> {
}

pub fn notify_dependencies(&mut self, q: &mut VecDeque<ModuleIdentifier>) {
if let Some(deps) = self.dependencies.get(&self.current_module_id) {
for mi in deps.iter() {
if let Some(set) = self.dependencies.get(&self.current_module_id) {
for mi in set.iter() {
q.push_back(*mi);
}
}
Expand Down
27 changes: 0 additions & 27 deletions crates/rspack_plugin_json/src/json_exports_dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,3 @@ fn get_exports_from_data(data: &JsonValue) -> Option<ExportsOfExportsSpec> {
};
Some(ret)
}

// const getExportsFromData = data => {
// if (data && typeof data === "object") {
// if (Array.isArray(data)) {
// return data.length < 100
// ? data.map((item, idx) => {
// return {
// name: `${idx}`,
// canMangle: true,
// exports: getExportsFromData(item)
// };
// })
// : undefined;
// } else {
// const exports = [];
// for (const key of Object.keys(data)) {
// exports.push({
// name: key,
// canMangle: true,
// exports: getExportsFromData(data[key])
// });
// }
// return exports;
// }
// }
// return undefined;
// };
5 changes: 2 additions & 3 deletions crates/rspack_plugin_library/src/assign_library_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use once_cell::sync::Lazy;
use regex::Regex;
use rspack_core::tree_shaking::webpack_ext::ExportInfoExt;
use rspack_core::{
debug_all_exports_info, property_access, ChunkUkey, EntryData, LibraryExport, LibraryName,
LibraryNonUmdObject, UsageState,
property_access, ChunkUkey, EntryData, LibraryExport, LibraryName, LibraryNonUmdObject,
UsageState,
};
use rspack_core::{
rspack_sources::{ConcatSource, RawSource, SourceExt},
Expand Down Expand Up @@ -233,7 +233,6 @@ impl Plugin for AssignLibraryPlugin {
exports_info_id.set_used_in_unknown_way(&mut compilation.module_graph, Some(&runtime));
}
}

Ok(())
}

Expand Down
6 changes: 0 additions & 6 deletions examples/type-assign/index.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/type-assign/module.js

This file was deleted.

19 changes: 0 additions & 19 deletions examples/type-assign/package.json

This file was deleted.

27 changes: 0 additions & 27 deletions examples/type-assign/rspack.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
/**
* The following code is modified based on
* https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/lib/Server.js
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

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

5 changes: 0 additions & 5 deletions webpack-test/ConfigTestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ const describeCases = config => {
newTreeshaking: true
}
}

if (options?.experiments?.rspackFuture?.newTreeshaking) {
options.builtins = options.builtins || {}
options.builtins.treeShaking = false;
}
// if (options.optimization.minimizer === undefined) {
// options.optimization.minimizer = [
// new (require("terser-webpack-plugin"))({
Expand Down

0 comments on commit 5fca139

Please sign in to comment.