fix(es/typescript): Preserve referenced imports for namespace (#4759)

This commit is contained in:
OJ Kwon 2022-05-23 13:12:39 -07:00 committed by GitHub
parent ae39b02df3
commit 065b2a514f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -1658,6 +1658,17 @@ where
match name {
TsEntityName::Ident(ref i) => {
entry.maybe_dependency = Some(i.clone());
// Eagerly update referenced idents for the concrete exports
// resolves https://github.com/swc-project/swc/issues/4481, if we
// know reference exists & reexports.
// when referenced idents are scoped in ts namespace, its references
// is updated _after_ visiting import decl which strips out imports
// already.
if n.is_export && !n.is_type_only {
let entry =
self.scope.referenced_idents.entry(i.to_id()).or_default();
entry.has_concrete = true;
}
break;
}
TsEntityName::TsQualifiedName(ref q) => name = &q.left,

View File

@ -0,0 +1,7 @@
import * as I from "./ABC";
export namespace IE {
export import A = I.A;
export import C = I.C;
export import D = I.D;
}

View File

@ -0,0 +1,10 @@
import * as I from "./ABC";
export var IE;
(function(IE1) {
var A = I.A;
IE1.A = A;
var C = I.C;
IE1.C = C;
var D = I.D;
IE1.D = D;
})(IE || (IE = {}));