Skip to content

Commit

Permalink
refactor: remove get presentational dependencies for block (#7502)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Aug 8, 2024
1 parent 8572bc3 commit ea126bb
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc-macro2 = { version = "1.0.79" }
quote = { version = "1.0.35" }
rayon = { version = "1.10.0" }
regex = { version = "1.10.4" }
rspack_sources = { version = "=0.2.16" }
rspack_sources = { version = "=0.2.17" }
rustc-hash = { version = "1.1.0" }
schemars = { version = "0.8.16" }
serde = { version = "1.0.197" }
Expand Down
6 changes: 1 addition & 5 deletions crates/rspack_core/src/dependencies_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use swc_core::common::{BytePos, SourceMap};

use crate::{
update_hash::{UpdateHashContext, UpdateRspackHash},
BoxDependency, DependencyId, DependencyTemplate, GroupOptions, ModuleIdentifier,
BoxDependency, DependencyId, GroupOptions, ModuleIdentifier,
};

pub trait DependenciesBlock {
Expand All @@ -26,10 +26,6 @@ pub trait DependenciesBlock {
fn add_dependency_id(&mut self, dependency: DependencyId);

fn get_dependencies(&self) -> &[DependencyId];

fn get_presentational_dependencies_for_block(&self) -> Option<&[Box<dyn DependencyTemplate>]> {
None
}
}

#[derive(Derivative)]
Expand Down
4 changes: 0 additions & 4 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ impl DependenciesBlock for NormalModule {
fn get_dependencies(&self) -> &[DependencyId] {
&self.dependencies
}

fn get_presentational_dependencies_for_block(&self) -> Option<&[Box<dyn DependencyTemplate>]> {
self.get_presentational_dependencies()
}
}

#[async_trait::async_trait]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use itertools::Itertools;
use rspack_collections::{Identifier, IdentifierSet};
use rspack_core::rspack_sources::ReplacementEnforce;
use rspack_core::{
property_access, AsContextDependency, AsModuleDependency, Compilation, Dependency,
DependencyType, ErrorSpan, ExportNameOrSpec, ExportsOfExportsSpec, ExportsSpec,
Expand Down Expand Up @@ -229,7 +230,13 @@ impl DependencyTemplate for HarmonyExportExpressionDependency {
&format!("{}(", content),
None,
);
source.replace(self.range.end, self.range_stmt.end, ");", None);
source.replace_with_enforce(
self.range.end,
self.range_stmt.end,
");",
None,
ReplacementEnforce::Post,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin {
ExportDefaultExpression::Expr(_) => None,
},
);
parser.presentational_dependencies.push(Box::new(dep));
parser.dependencies.push(Box::new(dep));
InnerGraphPlugin::add_variable_usage(
parser,
expr.ident().unwrap_or_else(|| &DEFAULT_STAR_JS_WORD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ impl<'a> FlagDependencyExportsProxy<'a> {
exports_specs_from_dependencies,
);
}
if let Some(deps) = block.get_presentational_dependencies_for_block() {
for dep in deps {
let Some(dep) = dep.as_dependency() else {
continue;
};
self.process_dependency(
*dep.id(),
dep.get_exports(self.mg),
exports_specs_from_dependencies,
);
}
}
for block_id in block.get_blocks() {
let block = self.mg.block_by_id(block_id)?;
self.process_dependencies_block_inner(block, exports_specs_from_dependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Object {
"main.js",
],
"filteredModules": undefined,
"hash": "1a1a0e7e40773bc0ec98",
"hash": "6264df4ebe23175182cf",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -175,7 +175,7 @@ Object {
"errorsCount": 0,
"filteredAssets": undefined,
"filteredModules": undefined,
"hash": "4bbdb7fecd05e748d349",
"hash": "614628b5932899e281aa",
"modules": Array [
Object {
"assets": Array [],
Expand Down Expand Up @@ -1454,7 +1454,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "1a1a0e7e40773bc0ec98",
"hash": "6264df4ebe23175182cf",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -1710,7 +1710,7 @@ Object {
"main.js",
],
"filteredModules": undefined,
"hash": "1e0c30224b6f262ceab9",
"hash": "507b35a9bc223de6c9b0",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -2058,7 +2058,7 @@ exports.c = require(\\"./c?c=3\\");
"errorsCount": 0,
"filteredAssets": undefined,
"filteredModules": undefined,
"hash": "5525d52cb2b45dde27cc",
"hash": "f155d1e27c19baefa4cc",
"modules": Array [
Object {
"assets": Array [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```html title=default.8141a25c9252be74.html
```html title=default.28094d62af6f500a.html
<!DOCTYPE html>
<html>
<head>
Expand All @@ -10,7 +10,7 @@
</body></html>
```

```html title=index.8141a25c9252be74.html
```html title=index.28094d62af6f500a.html
<!DOCTYPE html>
<html>
<head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```javascript
Array [
Object {
"main.7b570f0d0981bf98432a.js": (() => { // webpackBootstrap
"main.b3ac23329906ebf4b74c.js": (() => { // webpackBootstrap
var __webpack_modules__ = ({
"600": (function (module) {
module.exports = "This is hook"
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/tests/statsAPICases/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
entry ./fixtures/a
cjs self exports reference self [585] ./fixtures/a.js
Rspack compiled successfully (4bbdb7fecd05e748d349)"
Rspack compiled successfully (614628b5932899e281aa)"
`);
}
};
12 changes: 6 additions & 6 deletions packages/rspack-test-tools/tests/statsAPICases/chunk-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ module.exports = {
"auxiliaryAssets": Array [
Object {
"name": "chunk.js.map",
"size": 508,
"size": 514,
},
],
"auxiliaryAssetsSize": 508,
"auxiliaryAssetsSize": 514,
"chunks": Array [
"919",
],
Expand Down Expand Up @@ -83,10 +83,10 @@ module.exports = {
"auxiliaryAssets": Array [
Object {
"name": "chunk.js.map",
"size": 508,
"size": 514,
},
],
"auxiliaryAssetsSize": 508,
"auxiliaryAssetsSize": 514,
"children": Object {
"prefetch": Array [
Object {
Expand Down Expand Up @@ -227,10 +227,10 @@ module.exports = {
"auxiliaryAssets": Array [
Object {
"name": "chunk.js.map",
"size": 508,
"size": 514,
},
],
"auxiliaryAssetsSize": 508,
"auxiliaryAssetsSize": 514,
"chunks": Array [
"919",
],
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/tests/statsAPICases/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
"chunkB.js",
],
"filteredModules": undefined,
"hash": "36e51594c399b87d3359",
"hash": "3cd21283efb6761456db",
"id": "250",
"idHints": Array [],
"initial": false,
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports = {
"main.js",
],
"filteredModules": undefined,
"hash": "01e6f2d43ab22f972871",
"hash": "a18b3c5199301c15e563",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ __webpack_require__.e = function (chunkId) {
// webpack/runtime/get_full_hash
(() => {
__webpack_require__.h = function () {
return "3dffc962ae8728258d81";
return "e656e7b0eadf5ce68b0a";
};

})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ __webpack_require__.e = function (chunkId) {
// return url for filenames not based on template

// return url for filenames based on template
return "" + chunkId + ".$" + {"\\css\\chunk": "54c1620e9adda545f913","\\js\\chunk": "b523517f75dc2dc67471",}[chunkId] + "$.js";
return "" + chunkId + ".$" + {"\\css\\chunk": "1125e48ec9bbf02757b9","\\js\\chunk": "5e09106ce9333fd4f337",}[chunkId] + "$.js";
};

})();
Expand All @@ -107,7 +107,7 @@ __webpack_require__.e = function (chunkId) {
// webpack/runtime/get_full_hash
(() => {
__webpack_require__.h = function () {
return "6e5a487e296e19337ffa";
return "9795acfd15167201fff0";
};

})();
Expand Down
20 changes: 10 additions & 10 deletions tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ Rspack x.x.x compiled successfully in X.23"
`;

exports[`StatsTestCases should print correct stats for commons-plugin-issue-4980 1`] = `
"asset app.a0eb2e6ed70cc52bcbd6-1.js 52 bytes [emitted] [immutable] (name: app)
"asset app.a2b33d68d19a51d80c75-1.js 52 bytes [emitted] [immutable] (name: app)
orphan modules 205 bytes [orphan] 3 modules
./entry-1.js 67 bytes [built] [code generated]
Rspack x.x.x compiled successfully in X.23
asset app.3c507db620931e296fff-2.js 52 bytes [emitted] [immutable] (name: app)
asset app.c9a900954668dd3f351f-2.js 52 bytes [emitted] [immutable] (name: app)
orphan modules 212 bytes [orphan] 3 modules
./entry-2.js 67 bytes [built] [code generated]
Rspack x.x.x compiled successfully in X.23"
Expand Down Expand Up @@ -456,7 +456,7 @@ Rspack x.x.x compiled successfully in X.23"
`;

exports[`StatsTestCases should print correct stats for immutable 1`] = `
"asset f3307ed29b63fe6a26b3.js 10.1 KiB [emitted] [immutable] (name: main)
"asset 8d1f2e276fe3fe134c74.js 10.1 KiB [emitted] [immutable] (name: main)
asset 9ec5fb56454bddf305ec.js 167 bytes [emitted] [immutable]"
`;

Expand Down Expand Up @@ -548,24 +548,24 @@ runtime modules 2.59 KiB 3 modules
./a.js 18 bytes [built] [code generated]
Rspack x.x.x compiled successfully in X.23
asset b-runtime~main-48886b0bb08b3987a553.js 4.39 KiB [emitted] [immutable] (name: runtime~main)
asset b-all-b_js-242da217bb553f79303f.js 461 bytes [emitted] [immutable] (id hint: all)
asset b-runtime~main-eb1e55e9714495b68bff.js 4.39 KiB [emitted] [immutable] (name: runtime~main)
asset b-all-b_js-468c0f551eefc9f96f0b.js 461 bytes [emitted] [immutable] (id hint: all)
asset b-main-72ac2a7c5326395bcc89.js 420 bytes [emitted] [immutable] (name: main)
asset b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes [emitted] [immutable] (id hint: vendors)
Entrypoint main 5.42 KiB = b-runtime~main-48886b0bb08b3987a553.js 4.39 KiB b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes b-all-b_js-242da217bb553f79303f.js 461 bytes b-main-72ac2a7c5326395bcc89.js 420 bytes
Entrypoint main 5.42 KiB = b-runtime~main-eb1e55e9714495b68bff.js 4.39 KiB b-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes b-all-b_js-468c0f551eefc9f96f0b.js 461 bytes b-main-72ac2a7c5326395bcc89.js 420 bytes
runtime modules 3.17 KiB 5 modules
cacheable modules 40 bytes
./b.js 17 bytes [built] [code generated]
./node_modules/vendor.js 23 bytes [built] [code generated]
Rspack x.x.x compiled successfully in X.23
assets by chunk 870 bytes (id hint: all)
asset c-all-b_js-a364a38577953cc2ab7c.js 488 bytes [emitted] [immutable] (id hint: all)
asset c-all-c_js-a54d408465645a2aea4f.js 382 bytes [emitted] [immutable] (id hint: all)
asset c-runtime~main-13146ab0d777c036e368.js 10.8 KiB [emitted] [immutable] (name: runtime~main)
asset c-all-b_js-80b9441ad56b464b76b4.js 488 bytes [emitted] [immutable] (id hint: all)
asset c-all-c_js-3551be145d84dbf7a4c1.js 382 bytes [emitted] [immutable] (id hint: all)
asset c-runtime~main-28951df259d8af6cbc58.js 10.8 KiB [emitted] [immutable] (name: runtime~main)
asset c-main-4bdbd2cfa296de1ab23e.js 643 bytes [emitted] [immutable] (name: main)
asset c-vendors-node_modules_vendor_js-97d43f84c65cc0e25938.js 173 bytes [emitted] [immutable] (id hint: vendors)
Entrypoint main 11.8 KiB = c-runtime~main-13146ab0d777c036e368.js 10.8 KiB c-all-c_js-a54d408465645a2aea4f.js 382 bytes c-main-4bdbd2cfa296de1ab23e.js 643 bytes
Entrypoint main 11.8 KiB = c-runtime~main-28951df259d8af6cbc58.js 10.8 KiB c-all-c_js-3551be145d84dbf7a4c1.js 382 bytes c-main-4bdbd2cfa296de1ab23e.js 643 bytes
runtime modules 9.38 KiB 13 modules
cacheable modules 101 bytes
./c.js 61 bytes [built] [code generated]
Expand Down

1 comment on commit ea126bb

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ❌ failure
rsbuild ❌ failure
examples ❌ failure

Please sign in to comment.