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: concatenation module part two #5415

Merged
merged 59 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift click to select a range
20495e4
chore: 🤖 init
IWANABETHATGUY Jan 23, 2024
5f29f82
test: 💍 class naming
IWANABETHATGUY Jan 23, 2024
0930a7f
chore: 🤖 basic test
IWANABETHATGUY Jan 23, 2024
022740f
chore: 🤖 add bailout msg
IWANABETHATGUY Jan 23, 2024
b261fb7
chore: 🤖 compile boolean matcher
IWANABETHATGUY Jan 23, 2024
faa2efc
chore: 🤖 add external module
IWANABETHATGUY Jan 23, 2024
0e60520
chore: 🤖 remove comments
IWANABETHATGUY Jan 23, 2024
162e2b3
chore: 🤖 ck point
IWANABETHATGUY Jan 23, 2024
a71ab50
chore: 🤖 comments
IWANABETHATGUY Jan 23, 2024
5821940
chore: 🤖 ck point
IWANABETHATGUY Jan 24, 2024
2c8f8f8
chore: 🤖 ck point
IWANABETHATGUY Jan 24, 2024
b9378ed
chore: 🤖 register scope
IWANABETHATGUY Jan 24, 2024
02c1553
chore: 🤖 ck point
IWANABETHATGUY Jan 24, 2024
627d7a6
chore: 🤖 ck point
IWANABETHATGUY Jan 24, 2024
54677b6
chore: 🤖 more tests got passed
IWANABETHATGUY Jan 24, 2024
f535700
fix: 🐛 class expr with super
IWANABETHATGUY Jan 25, 2024
e185b39
fix: 🐛 dep to module id
IWANABETHATGUY Jan 25, 2024
4ba1f31
test: 💍 enable more test
IWANABETHATGUY Jan 25, 2024
66c9ce2
test: 💍 enable more tests
IWANABETHATGUY Jan 25, 2024
08a0d47
test: 💍 define getter with first param
IWANABETHATGUY Jan 25, 2024
7f00680
chore: 🤖 clean
IWANABETHATGUY Jan 25, 2024
0c39c2a
fix: 🐛 assignment pattern property
IWANABETHATGUY Jan 25, 2024
93a0a3b
test: 💍 more tests
IWANABETHATGUY Jan 25, 2024
0a68f57
fix: 🐛 orphan
IWANABETHATGUY Jan 25, 2024
3c0d5ba
fix: 🐛 allow iterate needNamespaceObject and mutate at the same
IWANABETHATGUY Jan 25, 2024
c7cafce
chore: 🤖 use index set
IWANABETHATGUY Jan 25, 2024
572f76b
chore: 🤖 refactor name
IWANABETHATGUY Jan 25, 2024
2020acb
chore: 🤖 git cz
IWANABETHATGUY Jan 25, 2024
1521e6e
fix: 🐛 order
IWANABETHATGUY Jan 25, 2024
8d0acee
fix: 🐛 more order fixing
IWANABETHATGUY Jan 25, 2024
1096b43
test: 💍 more test
IWANABETHATGUY Jan 25, 2024
d687761
fix: 🐛 json register
IWANABETHATGUY Jan 25, 2024
70601f2
chore: 🤖 clean
IWANABETHATGUY Jan 25, 2024
859ad14
chore: 🤖 ck point
IWANABETHATGUY Jan 25, 2024
e41e0b7
chore: 🤖 update test case
IWANABETHATGUY Jan 26, 2024
99a4898
chore: 🤖 update case
IWANABETHATGUY Jan 26, 2024
9b05e21
fix: 🐛 conflicting with inner scope
IWANABETHATGUY Jan 28, 2024
e07c42c
fix: 🐛 find name
IWANABETHATGUY Jan 28, 2024
2a324ae
chore: 🤖 merge main
IWANABETHATGUY Jan 31, 2024
52c05b5
chore: 🤖 fix compile err
IWANABETHATGUY Jan 31, 2024
8444f73
chore: 🤖 lint
IWANABETHATGUY Jan 31, 2024
be88e42
chore: 🤖 partial pass
IWANABETHATGUY Jan 31, 2024
62bd546
chore: 🤖 update lock
IWANABETHATGUY Jan 31, 2024
b62f250
Merge branch 'main' into feat/concatenate-plugin3
IWANABETHATGUY Jan 31, 2024
9b9f962
chore: 🤖 update snap
IWANABETHATGUY Jan 31, 2024
e952b47
chore: 🤖 update d.ts
IWANABETHATGUY Jan 31, 2024
f5e577b
chore: 🤖 update snap
IWANABETHATGUY Jan 31, 2024
b94f23d
fix: 🐛 test case
IWANABETHATGUY Jan 31, 2024
a4d9fdc
chore: 🤖 remove snap.diff
IWANABETHATGUY Jan 31, 2024
2c8ed77
chore: 🤖 remove diff
IWANABETHATGUY Jan 31, 2024
d4bc179
Merge branch 'main' into feat/concatenate-plugin3
IWANABETHATGUY Jan 31, 2024
95cbf33
chore(deps): update swc
renovate[bot] Jan 31, 2024
608bd7e
fix: 🐛 compile err
IWANABETHATGUY Jan 31, 2024
4349503
chore: 🤖 lint
IWANABETHATGUY Jan 31, 2024
c2543ba
fix: 🐛 fixer should pass comments
IWANABETHATGUY Jan 31, 2024
bc2aa24
chore: 🤖 lint
IWANABETHATGUY Jan 31, 2024
e4a1e5b
Merge branch 'main' into feat/concatenate-plugin3
IWANABETHATGUY Jan 31, 2024
97e8153
fix: 🐛 todo
IWANABETHATGUY Jan 31, 2024
c9f8d78
fix: 🐛 lint
IWANABETHATGUY Jan 31, 2024
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
Prev Previous commit
Next Next commit
fix: 🐛 dep to module id
  • Loading branch information
IWANABETHATGUY committed Jan 25, 2024
commit e185b39a581c9986a2405b92746a3439b570fd2e
23 changes: 8 additions & 15 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,7 @@ use swc_core::{
use swc_node_comments::SwcComments;

use crate::{
filter_runtime, impl_source_map_config, merge_runtime_condition,
define_es_module_flag_statement, filter_runtime, impl_source_map_config, merge_runtime_condition,
merge_runtime_condition_non_false, property_access, property_name,
reserved_names::RESERVED_NAMES, returning_function, runtime_condition_expression,
subtract_runtime_condition, AsyncDependenciesBlockId, BoxDependency, BuildContext, BuildInfo,
Expand Down Expand Up @@ -629,9 629,7 @@ impl Module for ConcatenatedModule {
module_to_info_map.insert(id, module_info);
}

// TODO: recover
// let mut all_used_names = HashSet::from_iter(RESERVED_NAMES.iter().map(|item| item.to_string()));
let mut all_used_names = HashSet::from_iter([]);
let mut all_used_names = HashSet::from_iter(RESERVED_NAMES.iter().map(|item| item.to_string()));

for module in modules_with_info.iter() {
let ModuleInfoOrReference::Concatenated(m) = module else {
Expand Down Expand Up @@ -673,7 671,6 @@ impl Module for ConcatenatedModule {
info.binding_to_ref = binding_to_ref;
}
}
dbg!(&all_used_names);

for info in module_to_info_map.values_mut() {
// Get used names in the scope
Expand Down Expand Up @@ -752,7 749,6 @@ impl Module for ConcatenatedModule {
info.name = Some(external_name.as_str().into());
}
}
// dbg!(&exports_type, info.id());
// Handle additional logic based on module build meta
if exports_type != Some(BuildMetaExportsType::Namespace) {
let external_name_interop = Self::find_new_name(
Expand Down Expand Up @@ -845,8 841,7 @@ impl Module for ConcatenatedModule {
let final_name = Self::get_final_name(
&compilation.module_graph,
&referenced_info_id,
// TODO: remove clone
export_name.clone(),
export_name,
&mut module_to_info_map,
runtime,
&mut needed_namespace_objects,
Expand All @@ -856,7 851,6 @@ impl Module for ConcatenatedModule {
asi_safe,
&context,
);
// dbg!(&reference_ident, &final_name, &export_name);
// We assume this should be concatenated module info because previous loop
let info = module_to_info_map
.get_mut(&module_info_id)
Expand Down Expand Up @@ -940,14 934,13 @@ impl Module for ConcatenatedModule {
!= UsageState::Unused
{
result.add(RawSource::from("// ESM COMPAT FLAG\n"));
// TODO:
// result.add(
// &runtime_template
// .define_es_module_flag_statement(this.exports_argument, runtime_requirements),
// );
result.add(RawSource::from(define_es_module_flag_statement(
self.get_exports_argument(),
&mut runtime_requirements,
)));
}

// Assuming the necessary Rust imports and dependencies are declared
// Assuming the necessary imports and dependencies are declared

// Define exports
if !exports_map.is_empty() {
Expand Down
24 changes: 21 additions & 3 deletions crates/rspack_core/src/dependency/runtime_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 11,10 @@ use tracing::instrument::WithSubscriber;

use crate::{
get_import_var, property_access, to_comment, to_normal_comment, AsyncDependenciesBlockId,
ChunkGraph, Compilation, DependenciesBlock, DependencyId, ExportsType, FakeNamespaceObjectMode,
InitFragmentExt, InitFragmentKey, InitFragmentStage, ModuleGraph, ModuleIdentifier,
NormalInitFragment, RuntimeCondition, RuntimeGlobals, RuntimeSpec, TemplateContext,
ChunkGraph, Compilation, DependenciesBlock, DependencyId, ExportsArgument, ExportsType,
FakeNamespaceObjectMode, InitFragmentExt, InitFragmentKey, InitFragmentStage, ModuleGraph,
ModuleIdentifier, NormalInitFragment, RuntimeCondition, RuntimeGlobals, RuntimeSpec,
TemplateContext,
};

pub fn runtime_condition_expression(
Expand Down Expand Up @@ -569,6 570,9 @@ pub fn module_id(
request: &str,
weak: bool,
) -> String {
dbg!(&compilation
.module_graph
.module_identifier_by_dependency_id(id));
if let Some(module_identifier) = compilation
.module_graph
.module_identifier_by_dependency_id(id)
Expand Down Expand Up @@ -648,6 652,7 @@ pub fn module_namespace_promise(
.module_identifier_by_dependency_id(dep_id)
.is_none()
{
dbg!(&dep_id.get_dependency(&compilation.module_graph));
return missing_module_promise(request);
};

Expand Down Expand Up @@ -898,6 903,19 @@ pub fn async_module_factory(
)
}

pub fn define_es_module_flag_statement(
exports_argument: ExportsArgument,
runtime_requirements: &mut RuntimeGlobals,
) -> String {
runtime_requirements.insert(RuntimeGlobals::MAKE_NAMESPACE_OBJECT);
runtime_requirements.insert(RuntimeGlobals::EXPORTS);

format!(
"{}({});\n",
RuntimeGlobals::MAKE_NAMESPACE_OBJECT,
exports_argument
)
}
mod test_items_to_regexp {

use super::items_to_regexp;
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 302,9 @@ impl ModuleGraph {
.insert(new_connection, condition.clone());
}

// self
// .dependency_id_to_connection_id
// .insert(new_connection.dependency_id, new_connection_id);
self
.dependency_id_to_module_identifier
.insert(new_connection.dependency_id, module_identifier);

self
.connection_id_to_dependency_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 45,7 @@ impl Visit for IdentCollector {
}
}

/// https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/optimize/ConcatenatedModule.js#L1173-L1197
fn visit_class_expr(&mut self, node: &ClassExpr) {
if let Some(ref ident) = node.ident
&& node.class.super_class.is_some()
Expand Down
6 changes: 6 additions & 0 deletions examples/esModule/index.js
Original file line number Diff line number Diff line change
@@ -0,0 1,6 @@
it("should have the __esModule flag", () => {
return import("./module").then(mod => {
expect(mod.__esModule).toBe(true);
expect(mod.default).toBe(84);
})
})
3 changes: 3 additions & 0 deletions examples/esModule/module.js
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
import other from "./other";

export default other * 2;
1 change: 1 addition & 0 deletions examples/esModule/other.js
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
export default 42;
8 changes: 8 additions & 0 deletions examples/esModule/package.json
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
{
"scripts": {
"build": "rspack build"
},
"dependencies": {
"@rspack/cli": "workspace:^"
}
}
22 changes: 22 additions & 0 deletions examples/esModule/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 1,22 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
mode: 'production',
entry: {
"main": "./index.js"
},
experiments: {
rspackFuture: {
newTreeshaking: true,
}
},
optimization: {
mangleExports: false,
moduleIds: 'named',
concatenateModules: true,
usedExports: true,
sideEffects: true,
providedExports: true,
minimize: false,

}
};
13 changes: 6 additions & 7 deletions examples/harmony-pure-default/index.js
Original file line number Diff line number Diff line change
@@ -1,16 1,15 @@
import x1, { value as v1 } from "./module1";
import x2, { value as v2 } from "./module2";
// import { value as v3 } from "./module3";
// import x1, { value as v1 } from "./module1";
// import x2, { value as v2 } from "./module2";
import { value as v3 } from "./module3";
// import x4, { value as v4 } from "./module4";

it("should not execute exports when annotated with pure comment", () => {
expect(v1).toBe(42);
expect(v2).toBe(42);
// expect(v3).toBe(42);
// expect(v4).toBe(42);
expect(v3).toBe(42);
expect(v4).toBe(42);
});

var x = (function() {
var x = /*#__PURE__*/(function() {
return x1 x2 x4;
});
x
2 changes: 2 additions & 0 deletions examples/harmony-pure-default/module3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 7,5 @@ const inc = () => {
export default /*#__PURE__*/(inc());

export { value };

export const cccc = inc();
3 changes: 1 addition & 2 deletions examples/harmony-pure-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,5 @@
},
"dependencies": {
"@rspack/cli": "workspace:^"
},
"sideEffects": true
}
}
Original file line number Diff line number Diff line change
@@ -1 1,8 @@
module.exports = () => {return true}
const { FilteredStatus } = require("../../../lib/util/filterUtil")

module.exports = () => {
return [
FilteredStatus.PARTIAL_PASS,
"https://github.com/web-infra-dev/rspack/issues/5460"
]
}