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

fix: fix duplicated harmony exports with named exports and re-exports star #6962

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl HarmonyExportImportedSpecifierDependency {
);
// dbg!(
// self.request(),
// &ignored_exports,
// &exports,
// &imported_module_identifier,
// &checked,
Expand Down Expand Up @@ -526,7 +527,7 @@ impl HarmonyExportImportedSpecifierDependency {
let init_fragment = self
.get_reexport_fragment(
ctxt,
"reexport default from dynamic".to_string(),
"reexport default from dynamic",
key,
&import_var,
ValueKey::Null,
Expand All @@ -544,7 +545,7 @@ impl HarmonyExportImportedSpecifierDependency {
let init_fragment = self
.get_reexport_fragment(
ctxt,
"reexport default export from named module".to_string(),
"reexport default export from named module",
key,
&import_var,
ValueKey::Str("".into()),
Expand All @@ -563,7 +564,7 @@ impl HarmonyExportImportedSpecifierDependency {
let init_fragment = self
.get_reexport_fragment(
ctxt,
"reexport module object".to_string(),
"reexport module object",
key,
&import_var,
ValueKey::Str("".into()),
Expand Down Expand Up @@ -592,7 +593,7 @@ impl HarmonyExportImportedSpecifierDependency {
let init_fragment = self
.get_reexport_fragment(
ctxt,
"reexport non-default export from non-harmony".to_string(),
"reexport non-default export from non-harmony",
key,
"undefined",
ValueKey::Str("".into()),
Expand Down Expand Up @@ -650,13 +651,7 @@ impl HarmonyExportImportedSpecifierDependency {
.id
.get_used_name(mg, None, UsedName::Vec(ids));
let init_fragment = self
.get_reexport_fragment(
ctxt,
"reexport safe".to_string(),
key,
&import_var,
used_name.into(),
)
.get_reexport_fragment(ctxt, "reexport safe", key, &import_var, used_name.into())
.boxed();
fragments.push(init_fragment);
}
Expand Down Expand Up @@ -725,7 +720,7 @@ impl HarmonyExportImportedSpecifierDependency {
fn get_reexport_fragment(
&self,
ctxt: &mut TemplateContext,
comment: String,
comment: &str,
key: String,
name: &str,
value_key: ValueKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ impl JavascriptParserPlugin for HarmonyExportDependencyParserPlugin {
parser.javascript_options,
),
)));
parser
.build_info
.harmony_named_exports
.insert(export.clone());
} else {
parser
.dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const A = '1';
export const A2 = '2';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { A } from './a.js'
export { A };

export * from './a.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fs from 'fs';
import { A } from './b.js';
it("should not generate duplicated harmony exports when using named exports and named exports from", () => {
A;
let file = fs.readFileSync(__filename, "utf-8")
expect(file.split(`A: function() { return /* reexport safe */`)).toHaveLength(3)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
mode: "development"
}
Loading