Skip to content

Commit 8913728

Browse files
authored
fix: inline enum module should populate its collected_typescript_info (#12252)
1 parent d8cd46f commit 8913728

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

crates/rspack_core/src/concatenated_module.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,16 @@ impl Module for ConcatenatedModule {
692692
.iter()
693693
.map(|item| Some(&item.id))
694694
.collect::<HashSet<_>>();
695+
696+
let root_module = module_graph
697+
.module_by_identifier(&self.root_module_ctxt.id)
698+
.expect("should have root module");
699+
700+
// populate root collected_typescript_info
701+
if let Some(collected_typescript_info) = &root_module.build_info().collected_typescript_info {
702+
self.build_info.collected_typescript_info = Some(collected_typescript_info.clone());
703+
}
704+
695705
for m in self.modules.iter() {
696706
let module = module_graph
697707
.module_by_identifier(&m.id)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log()
2+
export const foo = 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { INLINE } from "./lib.ts";
2+
3+
it("should work", () => {
4+
expect(INLINE.Foo).toBe(0);
5+
});
6+
7+
import "./foo?a";
8+
9+
import("./module.js");
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import './foo?1'
2+
3+
export enum INLINE {
4+
Foo,
5+
Bar,
6+
}
7+
8+
export const NO_INLINE = () => 42
9+
module;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NO_INLINE } from "./lib.ts";
2+
3+
import "./foo?22";
4+
5+
console.log(NO_INLINE);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = {
2+
entry: {
3+
main: './index.js',
4+
},
5+
module: {
6+
parser: {
7+
javascript: {
8+
inlineEnum: true,
9+
},
10+
},
11+
rules: [
12+
{
13+
test: /\.ts/,
14+
sideEffects: false,
15+
use: [
16+
{
17+
loader: "builtin:swc-loader",
18+
options: {
19+
jsc: {
20+
parser: {
21+
syntax: "typescript",
22+
}
23+
},
24+
rspackExperiments: {
25+
collectTypeScriptInfo: {
26+
exportedEnum: true,
27+
},
28+
},
29+
},
30+
},
31+
],
32+
},
33+
],
34+
},
35+
optimization: {
36+
concatenateModules: true,
37+
},
38+
experiments: {
39+
inlineEnum: true,
40+
}
41+
}

0 commit comments

Comments
 (0)