Skip to content

Commit e6e2ef0

Browse files
authored
fix: inline value with export as (#11687)
1 parent ada32f9 commit e6e2ef0

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

crates/rspack_plugin_javascript/src/parser_plugin/esm_export_dependency_parser_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ impl JavascriptParserPlugin for ESMExportDependencyParserPlugin {
122122
Box::new(dep) as BoxDependency
123123
} else {
124124
let inlinable = parser
125-
.get_tag_data(export_name, INLINABLE_CONST_TAG)
125+
.get_tag_data(local_id, INLINABLE_CONST_TAG)
126126
.map(InlinableConstData::downcast)
127127
.map(|data| data.value);
128128
let enum_value = parser
129129
.build_info
130130
.collected_typescript_info
131131
.as_ref()
132-
.and_then(|info| info.exported_enums.get(export_name).cloned());
132+
.and_then(|info| info.exported_enums.get(local_id).cloned());
133133
if enum_value.is_some() && !parser.compiler_options.experiments.inline_enum {
134134
parser.add_error(rspack_error::error!("inlineEnum is still an experimental feature. To continue using it, please enable 'experiments.inlineEnum'.").into());
135135
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const INLINE_1 = 1;
2+
const NOINLINE_1 = {};
3+
export { NOINLINE_1 as INLINE_1 }

tests/rspack-test/configCases/inline-const/basic/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as reexportedSideEffects from "./re-export.side-effects.js";
66
import * as reexportedBarrelSideEffects from "./re-export.barrel-side-effects.js";
77
import * as reexportedDestructingBarrelSideEffects from "./re-export.destructing-barrel-side-effects.js";
88
import * as constantsCjs from "./constants.cjs";
9+
import * as constantsNoInline from "./constants.no-inline.js";
910

1011
const generated = /** @type {string} */ (__non_webpack_require__("fs").readFileSync(__filename, "utf-8"));
1112

@@ -175,3 +176,7 @@ it("should keep the module if part of the exports is inlined and side effects fr
175176
})
176177
}
177178
})
179+
180+
it("should not inline no-inlinable constants", () => {
181+
expect(constantsNoInline.INLINE_1).toEqual({});
182+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum InlineE1 {
2+
A,
3+
}
4+
5+
const InlineE = {
6+
A: {},
7+
}
8+
9+
export { InlineE1 as InlineE }
10+
export { InlineE as InlineE1 }

tests/rspack-test/configCases/inline-enum/basic/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as destructing from "./enum.destructing";
44
import * as sideEffects from "./enum.side-effects";
55
import * as reexportedSideEffects from "./re-export.side-effects";
66
import * as notOnlyPropertiesUsed from "./enum.not-only-properties-used";
7+
import * as exportAs from "./enum.export-as";
78

89
const generated = /** @type {string} */ (__non_webpack_require__("fs").readFileSync(__filename, "utf-8"));
910

@@ -117,3 +118,8 @@ it("should keep the module if part of the enum members are inlined and side effe
117118
})
118119
}
119120
})
121+
122+
it("should not inline no-inlinable enums", () => {
123+
expect(exportAs.InlineE1.A).toEqual({});
124+
expect(exportAs.InlineE.A).toBe(0);
125+
})

0 commit comments

Comments
 (0)