mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(codegen): minify export { 's' as 's' } -> export { 's' } (#8093)
This commit is contained in:
parent
fccfda91c1
commit
6355b7ca70
2 changed files with 8 additions and 8 deletions
|
|
@ -914,7 +914,7 @@ impl Gen for ImportDeclaration<'_> {
|
||||||
spec.imported.print(p, ctx);
|
spec.imported.print(p, ctx);
|
||||||
let local_name = p.get_binding_identifier_name(&spec.local);
|
let local_name = p.get_binding_identifier_name(&spec.local);
|
||||||
let imported_name = get_module_export_name(&spec.imported, p);
|
let imported_name = get_module_export_name(&spec.imported, p);
|
||||||
if imported_name.is_none() || imported_name != Some(local_name) {
|
if imported_name != local_name {
|
||||||
p.print_str(" as ");
|
p.print_str(" as ");
|
||||||
spec.local.print(p, ctx);
|
spec.local.print(p, ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -1060,13 +1060,11 @@ impl Gen for TSNamespaceExportDeclaration<'_> {
|
||||||
fn get_module_export_name<'a>(
|
fn get_module_export_name<'a>(
|
||||||
module_export_name: &ModuleExportName<'a>,
|
module_export_name: &ModuleExportName<'a>,
|
||||||
p: &Codegen<'a>,
|
p: &Codegen<'a>,
|
||||||
) -> Option<&'a str> {
|
) -> &'a str {
|
||||||
match module_export_name {
|
match module_export_name {
|
||||||
ModuleExportName::IdentifierName(ident) => Some(ident.name.as_str()),
|
ModuleExportName::IdentifierName(ident) => ident.name.as_str(),
|
||||||
ModuleExportName::IdentifierReference(ident) => {
|
ModuleExportName::IdentifierReference(ident) => p.get_identifier_reference_name(ident),
|
||||||
Some(p.get_identifier_reference_name(ident))
|
ModuleExportName::StringLiteral(s) => s.value.as_str(),
|
||||||
}
|
|
||||||
ModuleExportName::StringLiteral(_) => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1078,7 +1076,7 @@ impl Gen for ExportSpecifier<'_> {
|
||||||
self.local.print(p, ctx);
|
self.local.print(p, ctx);
|
||||||
let local_name = get_module_export_name(&self.local, p);
|
let local_name = get_module_export_name(&self.local, p);
|
||||||
let exported_name = get_module_export_name(&self.exported, p);
|
let exported_name = get_module_export_name(&self.exported, p);
|
||||||
if exported_name.is_none() || local_name != exported_name {
|
if local_name != exported_name {
|
||||||
p.print_str(" as ");
|
p.print_str(" as ");
|
||||||
self.exported.print(p, ctx);
|
self.exported.print(p, ctx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ fn module_decl() {
|
||||||
test("import x from './foo.js' with {}", "import x from \"./foo.js\" with {};\n");
|
test("import x from './foo.js' with {}", "import x from \"./foo.js\" with {};\n");
|
||||||
test("import {} from './foo.js' with {}", "import {} from \"./foo.js\" with {};\n");
|
test("import {} from './foo.js' with {}", "import {} from \"./foo.js\" with {};\n");
|
||||||
test("export * from './foo.js' with {}", "export * from \"./foo.js\" with {};\n");
|
test("export * from './foo.js' with {}", "export * from \"./foo.js\" with {};\n");
|
||||||
|
test_minify("export { '☿' } from 'mod';", "export{\"☿\"}from\"mod\";");
|
||||||
|
test_minify("export { '☿' as '☿' } from 'mod';", "export{\"☿\"}from\"mod\";");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue