mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 11:50:54 -06:00
Emit declaration if its identifier is used in export assignment of external module
This commit is contained in:
parent
ea7c23eb63
commit
063399d228
@ -5706,6 +5706,22 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isReferencedInExportAssignment(node: Declaration): boolean {
|
||||
var exportAssignedSymbol = getExportAssignmentSymbol(getSymbolOfNode(node.parent));
|
||||
if (exportAssignedSymbol) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
if (exportAssignedSymbol === symbol) {
|
||||
// This symbol was export assigned symbol
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO(shkamat): if export assignment is alias, the alias target would make the node as referenced in export assignment
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNodeCheckFlags(node: Node): NodeCheckFlags {
|
||||
return getNodeLinks(node).flags;
|
||||
}
|
||||
@ -5725,7 +5741,8 @@ module ts {
|
||||
getNodeCheckFlags: getNodeCheckFlags,
|
||||
getEnumMemberValue: getEnumMemberValue,
|
||||
isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName,
|
||||
shouldEmitDeclarations: shouldEmitDeclarations
|
||||
shouldEmitDeclarations: shouldEmitDeclarations,
|
||||
isReferencedInExportAssignment: isReferencedInExportAssignment
|
||||
};
|
||||
checkProgram();
|
||||
return emitFiles(resolver);
|
||||
|
||||
@ -1922,16 +1922,13 @@ module ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.parent.kind === SyntaxKind.SourceFile) {
|
||||
// Global context nodes - emit this declaration
|
||||
if (!(node.parent.flags & NodeFlags.ExternalModule)) {
|
||||
return true;
|
||||
}
|
||||
// If this node is in external module, check if this is export assigned
|
||||
if (node.parent.flags & NodeFlags.ExternalModule) {
|
||||
return resolver.isReferencedInExportAssignment(node);
|
||||
}
|
||||
|
||||
// TODO(shkamat): check if this node is part of export assignment in the external module
|
||||
|
||||
return false;
|
||||
// emit the declaration if this is global source file
|
||||
return node.parent.kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
|
||||
function emitDeclarationFlags(node: Declaration) {
|
||||
|
||||
@ -601,6 +601,7 @@ module ts {
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
shouldEmitDeclarations(): boolean;
|
||||
isReferencedInExportAssignment(node: Declaration): boolean;
|
||||
}
|
||||
|
||||
export enum SymbolFlags {
|
||||
|
||||
@ -23,6 +23,9 @@ define(["require", "exports"], function (require, exports) {
|
||||
|
||||
|
||||
//// [declFileExportAssignmentOfGenericInterface_0.d.ts]
|
||||
interface Foo<T> {
|
||||
a;
|
||||
}
|
||||
export = Foo;
|
||||
//// [declFileExportAssignmentOfGenericInterface_1.d.ts]
|
||||
export declare var x;
|
||||
|
||||
@ -59,6 +59,12 @@ define(["require", "exports"], function (require, exports) {
|
||||
|
||||
|
||||
//// [declFileExportImportChain_a.d.ts]
|
||||
declare module m1 {
|
||||
module m2 {
|
||||
class c1 {
|
||||
}
|
||||
}
|
||||
}
|
||||
export = m1;
|
||||
//// [declFileExportImportChain_b.d.ts]
|
||||
export import a = require("declFileExportImportChain_a");
|
||||
|
||||
@ -52,6 +52,12 @@ define(["require", "exports"], function (require, exports) {
|
||||
|
||||
|
||||
//// [declFileExportImportChain2_a.d.ts]
|
||||
declare module m1 {
|
||||
module m2 {
|
||||
class c1 {
|
||||
}
|
||||
}
|
||||
}
|
||||
export = m1;
|
||||
//// [declFileExportImportChain2_b.d.ts]
|
||||
export = a;
|
||||
|
||||
@ -36,6 +36,15 @@ exports.a.test1(null, null, null);
|
||||
|
||||
|
||||
//// [declFileImportModuleWithExportAssignment_0.d.ts]
|
||||
declare module m2 {
|
||||
interface connectModule {
|
||||
(res, req, next);
|
||||
}
|
||||
interface connectExport {
|
||||
use;
|
||||
listen;
|
||||
}
|
||||
}
|
||||
export = m2;
|
||||
//// [declFileImportModuleWithExportAssignment_1.d.ts]
|
||||
export declare var a;
|
||||
|
||||
@ -24,4 +24,13 @@ module.exports = m2;
|
||||
|
||||
|
||||
//// [declareFileExportAssignment.d.ts]
|
||||
declare module m2 {
|
||||
interface connectModule {
|
||||
(res, req, next);
|
||||
}
|
||||
interface connectExport {
|
||||
use;
|
||||
listen;
|
||||
}
|
||||
}
|
||||
export = m2;
|
||||
|
||||
@ -40,6 +40,9 @@ define(["require", "exports", './exporter'], function (require, exports, e) {
|
||||
|
||||
//// [w1.d.ts]
|
||||
export = Widget1;
|
||||
declare class Widget1 {
|
||||
name;
|
||||
}
|
||||
//// [exporter.d.ts]
|
||||
export import w = require('./w1');
|
||||
//// [consumer.d.ts]
|
||||
|
||||
@ -32,6 +32,9 @@ define(["require", "exports"], function (require, exports) {
|
||||
|
||||
//// [w1.d.ts]
|
||||
export = Widget1;
|
||||
interface Widget1 {
|
||||
name;
|
||||
}
|
||||
//// [exporter.d.ts]
|
||||
export import w = require('./w1');
|
||||
//// [consumer.d.ts]
|
||||
|
||||
@ -39,4 +39,8 @@ declare module "SubModule" {
|
||||
}
|
||||
//// [missingImportAfterModuleImport_1.d.ts]
|
||||
/// <reference path='missingImportAfterModuleImport_0.d.ts' />
|
||||
declare class MainModule {
|
||||
SubModule;
|
||||
constructor ();
|
||||
}
|
||||
export = MainModule;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user