Skip to content
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 @@ -76,6 +76,34 @@ impl CompatibilityPlugin {
}),
);
}

/// Materialize the declaration replacement before an export records the nested name.
/// A non-self-referential function would not otherwise visit the identifier hook.
pub(crate) fn update_nested_binding_declaration(
parser: &mut JavascriptParser,
name: &Atom,
) -> Option<Atom> {
let (nested_name, dep) = {
let data = parser.get_tag_data_mut::<NestedRequireData>(name, NESTED_IDENTIFIER_TAG)?;
let nested_name = Atom::from(data.name.as_str());
let content = if data.in_short_hand {
format!("{name}: {}", data.name).into()
} else {
data.name.clone().into()
};
let dep = if data.update {
None
} else {
Some(ConstDependency::new(data.loc, content))
};
data.update = true;
(nested_name, dep)
};
if let Some(dep) = dep {
parser.add_presentational_dependency(Box::new(dep));
}
Some(nested_name)
}
}

#[rspack_macros::implemented_javascript_parser_hooks]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
ESMExportImportedSpecifierDependency, ESMExportSpecifierDependency,
ESMImportSideEffectDependency,
},
parser_plugin::compatibility_plugin::{NESTED_IDENTIFIER_TAG, NestedRequireData},
parser_plugin::compatibility_plugin::CompatibilityPlugin,
utils::object_properties::get_attributes,
visitors::{
ExportDefaultDeclaration, ExportDefaultExpression, ExportImport, ExportLocal, JavascriptParser,
Expand Down Expand Up @@ -187,16 +187,14 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for ESMExportDependencyParserPlugin
.collected_typescript_info
.as_ref()
.and_then(|info| info.exported_enums.get(local_id).cloned());
let variable = parser
.get_tag_data::<NestedRequireData>(local_id, NESTED_IDENTIFIER_TAG)
.map(|data| data.name.clone());
let variable = CompatibilityPlugin::update_nested_binding_declaration(parser, local_id);
Comment thread
LingyuCoder marked this conversation as resolved.

let range = DependencyRange::from(statement.span());
let loc = parser.to_dependency_location(range);
Box::new(ESMExportSpecifierDependency::new(
export_name.clone(),
if let Some(variable) = variable {
variable.into()
variable
} else {
local_id.clone()
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```mjs title=main.mjs
// ./index.js
function rspackRequire() {}

export { rspackRequire };

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```mjs title=main.mjs
// ./index.js
function __nested_rspack_require_16_29__() {}

export { __nested_rspack_require_16_29__ as rspackRequire };

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function rspackRequire() {}
Loading