mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-10 13:40:56 -06:00
Emit alias declaration if its name is used as identifier of export assignment
This commit is contained in:
parent
063399d228
commit
cd14e36460
@ -1895,28 +1895,7 @@ module ts {
|
||||
writeLine();
|
||||
}
|
||||
|
||||
function emitImportDeclaration(node: ImportDeclaration) {
|
||||
// TODO(shkamat): Emit if import decl is used to declare type in this context or as export assignment
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
//TODO: only emit when export flag once the above condition is modified
|
||||
write("export ");
|
||||
write("import ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
write(" = ");
|
||||
if (node.entityName) {
|
||||
emitSourceTextOfNode(node.entityName);
|
||||
write(";");
|
||||
}
|
||||
else {
|
||||
write("require(");
|
||||
emitSourceTextOfNode(node.externalModuleName);
|
||||
write(");");
|
||||
}
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function canEmitModuleElementDeclaration(node: Declaration) {
|
||||
function isModuleElementExternallyVisible(node: Declaration) {
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
// Exported member - emit this declaration
|
||||
return true;
|
||||
@ -1927,8 +1906,17 @@ module ts {
|
||||
return resolver.isReferencedInExportAssignment(node);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function canEmitModuleElementDeclaration(node: Declaration) {
|
||||
if (isModuleElementExternallyVisible(node)) {
|
||||
// Either exported module element or is referenced in export assignment
|
||||
return true;
|
||||
}
|
||||
|
||||
// emit the declaration if this is global source file
|
||||
return node.parent.kind === SyntaxKind.SourceFile;
|
||||
return node.parent.kind === SyntaxKind.SourceFile && !(node.parent.flags & NodeFlags.ExternalModule);
|
||||
}
|
||||
|
||||
function emitDeclarationFlags(node: Declaration) {
|
||||
@ -1955,6 +1943,28 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitImportDeclaration(node: ImportDeclaration) {
|
||||
// TODO(shkamat): Emit if import decl is used to declare type in this context
|
||||
if (isModuleElementExternallyVisible(node)) {
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
write("export ");
|
||||
}
|
||||
write("import ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
write(" = ");
|
||||
if (node.entityName) {
|
||||
emitSourceTextOfNode(node.entityName);
|
||||
write(";");
|
||||
}
|
||||
else {
|
||||
write("require(");
|
||||
emitSourceTextOfNode(node.externalModuleName);
|
||||
write(");");
|
||||
}
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
if (canEmitModuleElementDeclaration(node)) {
|
||||
|
||||
@ -31,4 +31,5 @@ module.exports = m;
|
||||
|
||||
|
||||
//// [declFileExportAssignmentImportInternalModule.d.ts]
|
||||
import m = m3;
|
||||
export = m;
|
||||
|
||||
@ -69,6 +69,7 @@ export = m1;
|
||||
//// [declFileExportImportChain_b.d.ts]
|
||||
export import a = require("declFileExportImportChain_a");
|
||||
//// [declFileExportImportChain_b1.d.ts]
|
||||
import b = require("declFileExportImportChain_b");
|
||||
export = b;
|
||||
//// [declFileExportImportChain_c.d.ts]
|
||||
export import b1 = require("declFileExportImportChain_b1");
|
||||
|
||||
@ -60,6 +60,7 @@ declare module m1 {
|
||||
}
|
||||
export = m1;
|
||||
//// [declFileExportImportChain2_b.d.ts]
|
||||
import a = require("declFileExportImportChain2_a");
|
||||
export = a;
|
||||
//// [declFileExportImportChain2_c.d.ts]
|
||||
export import b = require("declFileExportImportChain2_b");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user