@@ -2278,7 +2278,7 @@ namespace ts {
2278
2278
result |= NodeBuilderFlags.AddUndefined;
2279
2279
}
2280
2280
2281
- return result;
2281
+ return result;
2282
2282
}
2283
2283
2284
2284
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
@@ -2325,7 +2325,7 @@ namespace ts {
2325
2325
};
2326
2326
2327
2327
interface NodeBuilderContext {
2328
- readonly enclosingDeclaration: Node | undefined;
2328
+ enclosingDeclaration: Node | undefined;
2329
2329
readonly flags: NodeBuilderFlags | undefined;
2330
2330
2331
2331
// State
@@ -2382,7 +2382,7 @@ namespace ts {
2382
2382
return createKeywordTypeNode(SyntaxKind.BooleanKeyword);
2383
2383
}
2384
2384
if (type.flags & TypeFlags.Enum) {
2385
- const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, context);
2385
+ const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2386
2386
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
2387
2387
}
2388
2388
if (type.flags & (TypeFlags.StringLiteral)) {
@@ -2396,7 +2396,7 @@ namespace ts {
2396
2396
}
2397
2397
if (type.flags & TypeFlags.EnumLiteral) {
2398
2398
const parentSymbol = getParentOfSymbol(type.symbol);
2399
- const parentName = symbolToName(parentSymbol, /*expectsIdentifier*/ false, context);
2399
+ const parentName = symbolToName(parentSymbol, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2400
2400
const name = getNameOfSymbol(type.symbol, context);
2401
2401
const enumLiteralName = createQualifiedName(parentName, name);
2402
2402
return createTypeReferenceNode(enumLiteralName, /*typeArguments*/ undefined);
@@ -2436,19 +2436,19 @@ namespace ts {
2436
2436
}
2437
2437
if (objectFlags & ObjectFlags.ClassOrInterface) {
2438
2438
Debug.assert(!!(type.flags & TypeFlags.Object));
2439
- const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, context);
2439
+ const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2440
2440
// TODO(aozgaa): handle type arguments.
2441
2441
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
2442
2442
}
2443
2443
if (type.flags & TypeFlags.TypeParameter) {
2444
- const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, context);
2444
+ const name = symbolToName(type.symbol, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2445
2445
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
2446
2446
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
2447
2447
}
2448
2448
2449
2449
if (!inTypeAlias && type.aliasSymbol &&
2450
2450
isSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
2451
- const name = symbolToName(type.aliasSymbol, /*expectsIdentifier*/ false, context);
2451
+ const name = symbolToName(type.aliasSymbol, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2452
2452
const typeArgumentNodes = type.aliasTypeArguments && mapToTypeNodeArray(type.aliasTypeArguments, /*addInElementTypeFlag*/ false);
2453
2453
return createTypeReferenceNode(name, typeArgumentNodes);
2454
2454
}
@@ -2526,14 +2526,14 @@ namespace ts {
2526
2526
if (symbol.flags & SymbolFlags.Class && !getBaseTypeVariableOfClass(symbol) ||
2527
2527
symbol.flags & (SymbolFlags.Enum | SymbolFlags.ValueModule) ||
2528
2528
shouldWriteTypeOfFunctionSymbol()) {
2529
- return createTypeQueryNodeFromSymbol(symbol);
2529
+ return createTypeQueryNodeFromSymbol(symbol, SymbolFlags.Value );
2530
2530
}
2531
2531
else if (contains(context.symbolStack, symbol)) {
2532
2532
// If type is an anonymous type literal in a type alias declaration, use type alias name
2533
2533
const typeAlias = getTypeAliasForTypeLiteral(type);
2534
2534
if (typeAlias) {
2535
2535
// The specified symbol flags need to be reinterpreted as type flags
2536
- const entityName = symbolToName(typeAlias, /*expectsIdentifier*/ false, context);
2536
+ const entityName = symbolToName(typeAlias, /*expectsIdentifier*/ false, SymbolFlags.Type, context);
2537
2537
return createTypeReferenceNode(entityName, /*typeArguments*/ undefined);
2538
2538
}
2539
2539
else {
@@ -2618,8 +2618,8 @@ namespace ts {
2618
2618
return false;
2619
2619
}
2620
2620
2621
- function createTypeQueryNodeFromSymbol(symbol: Symbol) {
2622
- const entityName = symbolToName(symbol, /*expectsIdentifier*/ false, context);
2621
+ function createTypeQueryNodeFromSymbol(symbol: Symbol, symbolFlags: SymbolFlags ) {
2622
+ const entityName = symbolToName(symbol, /*expectsIdentifier*/ false, symbolFlags, context);
2623
2623
return createTypeQueryNode(entityName);
2624
2624
}
2625
2625
@@ -2665,7 +2665,7 @@ namespace ts {
2665
2665
// the default outer type arguments), we don't show the group.
2666
2666
if (!rangeEquals(outerTypeParameters, typeArguments, start, i)) {
2667
2667
// inFirstTypeArgument???
2668
- const qualifiedNamePart = symbolToName(parent, /*expectsIdentifier*/ true, context);
2668
+ const qualifiedNamePart = symbolToName(parent, /*expectsIdentifier*/ true, SymbolFlags.Type, context);
2669
2669
if (!qualifiedName) {
2670
2670
qualifiedName = createQualifiedName(qualifiedNamePart, /*right*/ undefined);
2671
2671
}
@@ -2679,7 +2679,7 @@ namespace ts {
2679
2679
}
2680
2680
}
2681
2681
let entityName: EntityName = undefined;
2682
- const nameIdentifier = symbolToName(type.symbol, /*expectsIdentifier*/ true, context);
2682
+ const nameIdentifier = symbolToName(type.symbol, /*expectsIdentifier*/ true, SymbolFlags.Type, context);
2683
2683
if (qualifiedName) {
2684
2684
Debug.assert(!qualifiedName.right);
2685
2685
qualifiedName.right = nameIdentifier;
@@ -2717,7 +2717,10 @@ namespace ts {
2717
2717
// TODO: make logic mirror that of writeObjectLiteralType
2718
2718
for (const propertySymbol of properties) {
2719
2719
const propertyType = getTypeOfSymbol(propertySymbol);
2720
- const propertyName = symbolToName(propertySymbol, /*expectsIdentifier*/ true, context);
2720
+ const saveEnclosingDeclaration = context.enclosingDeclaration;
2721
+ context.enclosingDeclaration = undefined;
2722
+ const propertyName = symbolToName(propertySymbol, /*expectsIdentifier*/ true, SymbolFlags.Value, context);
2723
+ context.enclosingDeclaration = saveEnclosingDeclaration;
2721
2724
const optionalToken = propertySymbol.flags & SymbolFlags.Optional ? createToken(SyntaxKind.QuestionToken) : undefined;
2722
2725
if (propertySymbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(propertyType).length) {
2723
2726
const signatures = getSignaturesOfType(propertyType, SignatureKind.Call);
@@ -2767,7 +2770,6 @@ namespace ts {
2767
2770
}
2768
2771
2769
2772
function signatureToSignatureDeclarationHelper(signature: Signature, kind: SyntaxKind, context: NodeBuilderContext): SignatureDeclaration {
2770
-
2771
2773
const typeParameters = signature.typeParameters && signature.typeParameters.map(parameter => typeParameterToDeclaration(parameter, context));
2772
2774
const parameters = signature.parameters.map(parameter => symbolToParameterDeclaration(parameter, context));
2773
2775
if (signature.thisParameter) {
@@ -2801,7 +2803,7 @@ namespace ts {
2801
2803
const constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
2802
2804
const defaultParameter = getDefaultFromTypeParameter(type);
2803
2805
const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
2804
- const name = symbolToName(type.symbol, /*expectsIdentifier*/ true, context);
2806
+ const name = symbolToName(type.symbol, /*expectsIdentifier*/ true, SymbolFlags.Type, context);
2805
2807
return createTypeParameterDeclaration(name, constraintNode, defaultParameterNode);
2806
2808
}
2807
2809
@@ -2825,15 +2827,15 @@ namespace ts {
2825
2827
2826
2828
// TODO: add meaning: SymbolFlags argument.
2827
2829
// TODO: add SymbolFormatFlags?? Yes to add outer type parameters. Defer UseOnlyExternalAliasing until a separate symbolbuilder PR.
2828
- function symbolToName(symbol: Symbol, expectsIdentifier: true, context: NodeBuilderContext): Identifier;
2829
- function symbolToName(symbol: Symbol, expectsIdentifier: false, context: NodeBuilderContext): EntityName;
2830
- function symbolToName(symbol: Symbol, expectsIdentifier: boolean, context: NodeBuilderContext): EntityName {
2830
+ function symbolToName(symbol: Symbol, expectsIdentifier: true, meaning: SymbolFlags, context: NodeBuilderContext): Identifier;
2831
+ function symbolToName(symbol: Symbol, expectsIdentifier: false, meaning: SymbolFlags, context: NodeBuilderContext): EntityName;
2832
+ function symbolToName(symbol: Symbol, expectsIdentifier: boolean, meaning: SymbolFlags, context: NodeBuilderContext): EntityName {
2831
2833
2832
2834
// Try to get qualified name if the symbol is not a type parameter and there is an enclosing declaration.
2833
2835
let chain: Symbol[];
2834
2836
const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
2835
2837
if (!isTypeParameter && context.enclosingDeclaration) {
2836
- chain = getSymbolChain(symbol, SymbolFlags.None , /*endOfChain*/ true);
2838
+ chain = getSymbolChain(symbol, meaning , /*endOfChain*/ true);
2837
2839
Debug.assert(chain && chain.length > 0);
2838
2840
}
2839
2841
else {
0 commit comments