mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 01:13:56 +03:00
fix(strip): Don't treat type-only exports as concrete references (#1126)
Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
parent
ea091337d8
commit
e4b8a0cc1e
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecmascript"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.8.3"
|
||||
version = "0.8.4"
|
||||
|
||||
[features]
|
||||
codegen = ["swc_ecma_codegen"]
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.24.3"
|
||||
version = "0.24.4"
|
||||
|
||||
[features]
|
||||
const-modules = ["dashmap"]
|
||||
|
@ -41,9 +41,7 @@ pub struct Config {
|
||||
pub fn strip_with_config(config: Config) -> impl Fold {
|
||||
as_folder(Strip {
|
||||
config,
|
||||
non_top_level: Default::default(),
|
||||
scope: Default::default(),
|
||||
is_side_effect_import: Default::default(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,6 +56,7 @@ struct Strip {
|
||||
non_top_level: bool,
|
||||
scope: Scope,
|
||||
is_side_effect_import: bool,
|
||||
is_type_only_export: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -500,10 +499,11 @@ impl Strip {
|
||||
|
||||
impl Visit for Strip {
|
||||
fn visit_ident(&mut self, n: &Ident, _: &dyn Node) {
|
||||
let is_type_only_export = self.is_type_only_export;
|
||||
self.scope
|
||||
.imported_idents
|
||||
.entry((n.sym.clone(), n.span.ctxt()))
|
||||
.and_modify(|v| v.has_concrete = true);
|
||||
.and_modify(|v| v.has_concrete = !is_type_only_export);
|
||||
|
||||
n.visit_children_with(self);
|
||||
}
|
||||
@ -528,8 +528,13 @@ impl Visit for Strip {
|
||||
fn visit_module_items(&mut self, n: &[ModuleItem], _: &dyn Node) {
|
||||
let old = self.non_top_level;
|
||||
self.non_top_level = false;
|
||||
n.iter()
|
||||
.for_each(|n| n.visit_with(&Invalid { span: DUMMY_SP }, self));
|
||||
n.iter().for_each(|n| {
|
||||
if let ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(export)) = n {
|
||||
self.is_type_only_export = export.type_only;
|
||||
}
|
||||
n.visit_with(&Invalid { span: DUMMY_SP }, self);
|
||||
self.is_type_only_export = false;
|
||||
});
|
||||
self.non_top_level = old;
|
||||
}
|
||||
|
||||
@ -1050,6 +1055,9 @@ impl VisitMut for Strip {
|
||||
ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(mut export)) => {
|
||||
// if specifier become empty, we remove export statement.
|
||||
|
||||
if export.type_only {
|
||||
export.specifiers.clear();
|
||||
}
|
||||
export.specifiers.retain(|s| match *s {
|
||||
ExportSpecifier::Named(ExportNamedSpecifier { ref orig, .. }) => {
|
||||
if let Some(e) =
|
||||
|
@ -3095,3 +3095,18 @@ test!(
|
||||
import './types';
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
Syntax::Typescript(TsConfig {
|
||||
decorators: true,
|
||||
..Default::default()
|
||||
}),
|
||||
|_| strip(),
|
||||
issue_1124,
|
||||
"
|
||||
import { Type } from './types';
|
||||
export type { Type };
|
||||
",
|
||||
"
|
||||
"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user