Skip to content
Open
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
19 changes: 11 additions & 8 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ impl Visit for Analyzer<'_> {
}
};

self.register_assignment_scope(id.clone());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we need to add some defense in depth

i think this would go in the get_export_ident_liveness function

in the else block for when there is no key in the map there are two theories for why we don't have a map entry, we should just debug_assert that that is the case (the var is free or is an import)

self.data.exports.insert(
rcstr!("default"),
Export::LocalBinding(RcStr::from(id.0.as_str()), false),
Expand All @@ -1090,18 +1091,20 @@ impl Visit for Analyzer<'_> {
fn visit_export_default_expr(&mut self, n: &ExportDefaultExpr) {
self.data.has_exports = true;

let default_id = (
MAGIC_IDENTIFIER_DEFAULT_EXPORT_ATOM.clone(),
SyntaxContext::empty(),
);

self.data.exports.insert(
rcstr!("default"),
Export::LocalBinding(MAGIC_IDENTIFIER_DEFAULT_EXPORT.clone(), false),
);
self.data.exports_ids.insert(
rcstr!("default"),
(
// `EsmModuleItem::code_generation` inserts this variable.
MAGIC_IDENTIFIER_DEFAULT_EXPORT_ATOM.clone(),
SyntaxContext::empty(),
),
);
self.data
.exports_ids
.insert(rcstr!("default"), default_id.clone());

self.register_assignment_scope(default_id);
n.visit_children_with(self);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import value from 'lib'

console.log(value)

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"removeUnusedExports": true
}

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1i9t_crates_turbopack-tests_tests_snapshot_basic_export-default_input_index_0va0_sb.js",
{"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_basic_export-default_input_1k9-ja7._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/export-default/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
Loading