Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3794,7 +3794,7 @@ module ts { | |
} | ||
return checkUntypedCall(node); | ||
} | ||
// If FuncExprs apparent type(section 3.8.1) is a function type, the call is a typed function call. | ||
// If FuncExpr's apparent type(section 3.8.1) is a function type, the call is a typed function call. | ||
// TypeScript employs overload resolution in typed function calls in order to support functions | ||
// with multiple call signatures. | ||
if (!signatures.length) { | ||
|
@@ -3826,7 +3826,7 @@ module ts { | |
return checkUntypedCall(node); | ||
} | ||
|
||
// If ConstructExprs apparent type(section 3.8.1) is an object type with one or | ||
// If ConstructExpr's apparent type(section 3.8.1) is an object type with one or | ||
// more construct signatures, the expression is processed in the same manner as a | ||
// function call, but using the construct signatures as the initial set of candidate | ||
// signatures for overload resolution.The result type of the function call becomes | ||
|
@@ -3847,7 +3847,7 @@ module ts { | |
return checkCall(node, constructSignatures); | ||
} | ||
|
||
// If ConstructExprs apparent type is an object type with no construct signatures but | ||
// If ConstructExpr's apparent type is an object type with no construct signatures but | ||
// one or more call signatures, the expression is processed as a function call. A compile-time | ||
// error occurs if the result of the function call is not Void. The type of the result of the | ||
// operation is Any. | ||
|
@@ -5981,14 +5981,53 @@ module ts { | |
|
||
// Emitter support | ||
|
||
function getModuleObjectName(node: ModuleDeclaration): string { | ||
return getSourceTextOfNode(node.name); | ||
} | ||
|
||
function isExternalModule(symbol: Symbol): boolean { | ||
return symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length === 1 && symbol.declarations[0].kind === SyntaxKind.SourceFile; | ||
} | ||
|
||
function isNodeParentedBy(node: Node, parent: Node): boolean { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
while (node) { | ||
if (node === parent) return true; | ||
node = node.parent; | ||
} | ||
return false; | ||
} | ||
|
||
function isUniqueLocalName(name: string, container: Node): boolean { | ||
name = escapeIdentifier(name); | ||
if (container.locals) { | ||
for (var node = container; isNodeParentedBy(node, container); node = node.nextLocals) { | ||
if (hasProperty(node.locals, name) && node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function getLocalNameOfContainer(container: Declaration): string { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ahejlsberg
Author
Member
|
||
var links = getNodeLinks(container); | ||
if (!links.localModuleName) { | ||
var name = container.name.text ? unescapeIdentifier(container.name.text) : "M"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
while (!isUniqueLocalName(name, container)) { | ||
name = "_" + name; | ||
} | ||
links.localModuleName = name; | ||
} | ||
return links.localModuleName; | ||
} | ||
|
||
function getLocalNameForSymbol(symbol: Symbol, location: Node): string { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ahejlsberg
Author
Member
|
||
var node = location; | ||
while (node) { | ||
if ((node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(node) === symbol) { | ||
return getLocalNameOfContainer(node); | ||
} | ||
node = node.parent; | ||
} | ||
Debug.fail("getLocalNameForSymbol failed"); | ||
} | ||
|
||
function getExpressionNamePrefix(node: Identifier): string { | ||
var symbol = getNodeLinks(node).resolvedSymbol; | ||
if (symbol) { | ||
|
@@ -5998,15 +6037,11 @@ module ts { | |
// kind of entity. SymbolFlags.ExportHasLocal encompasses all the kinds that we | ||
// do NOT prefix. | ||
var exportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); | ||
var isExportedSymbolFoundInLocalScope = exportSymbol !== symbol; | ||
var shouldEmitExportWithoutPrefix = (exportSymbol.flags & SymbolFlags.ExportHasLocal) !== 0; | ||
if (isExportedSymbolFoundInLocalScope && !shouldEmitExportWithoutPrefix) { | ||
if (symbol !== exportSymbol && !(exportSymbol.flags & SymbolFlags.ExportHasLocal)) { | ||
symbol = exportSymbol; | ||
} | ||
|
||
// symbol will have a parent if it is an export symbol | ||
if (symbol.parent) { | ||
return isExternalModule(symbol.parent) ? "exports" : symbolToString(symbol.parent); | ||
return isExternalModule(symbol.parent) ? "exports" : getLocalNameForSymbol(getParentOfSymbol(symbol), node.parent); | ||
} | ||
} | ||
} | ||
|
@@ -6093,7 +6128,7 @@ module ts { | |
function invokeEmitter() { | ||
var resolver: EmitResolver = { | ||
getProgram: () => program, | ||
getModuleObjectName: getModuleObjectName, | ||
getLocalNameOfContainer: getLocalNameOfContainer, | ||
getExpressionNamePrefix: getExpressionNamePrefix, | ||
getPropertyAccessSubstitution: getPropertyAccessSubstitution, | ||
getExportAssignmentName: getExportAssignmentName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,7 @@ module ts { | |
parent?: Node; // Parent node (initialized by binding) | ||
symbol?: Symbol; // Symbol declared by node (initialized by binding) | ||
locals?: SymbolTable; // Locals associated with node (initialized by binding) | ||
nextLocals?: Node; // Next node in declaration order with locals (initialized by binding) | ||
} | ||
|
||
export interface NodeArray<T> extends Array<T>, TextRange { } | ||
|
@@ -612,7 +613,7 @@ module ts { | |
|
||
export interface EmitResolver { | ||
getProgram(): Program; | ||
getModuleObjectName(node: ModuleDeclaration): string; | ||
getLocalNameOfContainer(container: Declaration): string; | ||
getExpressionNamePrefix(node: Identifier): string; | ||
getPropertyAccessSubstitution(node: PropertyAccess): string; | ||
getExportAssignmentName(node: SourceFile): string; | ||
|
@@ -688,7 +689,7 @@ module ts { | |
|
||
ExportHasLocal = Function | Class | Enum | ValueModule, | ||
|
||
HasLocals = Function | Module | Method | Constructor | Accessor | Signature, | ||
HasLocals = Function | Enum | Module | Method | Constructor | Accessor | Signature, | ||
This comment has been minimized.
Sorry, something went wrong.
JsonFreeman
Contributor
|
||
HasExports = Class | Enum | Module, | ||
HasMembers = Class | Interface | TypeLiteral | ObjectLiteral, | ||
|
||
|
@@ -740,7 +741,8 @@ module ts { | |
flags?: NodeCheckFlags; // Set of flags specific to Node | ||
enumMemberValue?: number; // Constant value of enum member | ||
isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list | ||
isVisible?: boolean; // Is this node visible | ||
isVisible?: boolean; // Is this node visible | ||
localModuleName?: string; // Local name for module instance | ||
} | ||
|
||
export enum TypeFlags { | ||
|
Ancestor, not parent