Skip to content

Commit bbe5b33

Browse files
Downlevel export * as ns in es2015.
1 parent a5e1d49 commit bbe5b33

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/compiler/transformers/module/es2015.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ namespace ts {
4444
return undefined;
4545
case SyntaxKind.ExportAssignment:
4646
return visitExportAssignment(<ExportAssignment>node);
47+
case SyntaxKind.ExportDeclaration:
48+
const exportDecl = (node as ExportDeclaration);
49+
return visitExportDeclaration(exportDecl);
4750
}
4851

4952
return node;
@@ -54,6 +57,41 @@ namespace ts {
5457
return node.isExportEquals ? undefined : node;
5558
}
5659

60+
function visitExportDeclaration(node: ExportDeclaration) {
61+
// `export * as ns` only needs to be transformed in ES2015
62+
if (compilerOptions.module !== undefined && compilerOptions.module > ModuleKind.ES2015) {
63+
return node;
64+
}
65+
66+
// Either ill-formed or don't need to be tranformed.
67+
if (!node.exportClause || !isNamespaceExport(node.exportClause) || !node.moduleSpecifier) {
68+
return node;
69+
}
70+
71+
const oldIdentifier = node.exportClause.name;
72+
const synthName = getGeneratedNameForNode(oldIdentifier);
73+
const importDecl = createImportDeclaration(
74+
/*decorators*/ undefined,
75+
/*modifiers*/ undefined,
76+
createImportClause(/*name*/ undefined,
77+
createNamespaceImport(
78+
synthName
79+
)
80+
),
81+
node.moduleSpecifier,
82+
);
83+
setOriginalNode(importDecl, node.exportClause);
84+
85+
const exportDecl = createExportDeclaration(
86+
/*decorators*/ undefined,
87+
/*modifiers*/ undefined,
88+
createNamedExports([createExportSpecifier(synthName, oldIdentifier)]),
89+
);
90+
setOriginalNode(exportDecl, node);
91+
92+
return [importDecl, exportDecl];
93+
}
94+
5795
//
5896
// Emit Notification
5997
//

0 commit comments

Comments
 (0)