Fix escaping and follow symbols for element access

This commit is contained in:
Ron Buckton
2017-06-09 14:58:19 -07:00
parent 3f83b55899
commit 38ee4751bf
5 changed files with 56 additions and 4 deletions

View File

@@ -5463,7 +5463,7 @@ namespace ts {
return `__@${type.symbol.name}@${getSymbolId(type.symbol)}`;
}
if (type.flags & TypeFlags.StringOrNumberLiteral) {
return escapeIdentifier("" + (<LiteralType>type).value);
return "" + (<LiteralType>type).value;
}
}
@@ -7686,8 +7686,8 @@ namespace ts {
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode, cacheSymbol: boolean) {
const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? <ElementAccessExpression>accessNode : undefined;
const propName = indexType.flags & TypeFlags.StringOrNumberLiteral ?
"" + (<LiteralType>indexType).value :
const propName = indexType.flags & TypeFlags.StringOrNumberLiteralOrUnique ?
getLateBoundNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
undefined;

View File

@@ -123,6 +123,11 @@ export const o1 = {
[s2]: true
};
// check element access types
export const o1_c4 = o1[c4];
export const o1_c5 = o1[c5];
export const o1_s2 = o1[s2];
export const o2: T0 = o1;
//// [module.js]
@@ -174,6 +179,10 @@ exports.o1 = {
[exports.c5]: "a",
[exports.s2]: true
};
// check element access types
exports.o1_c4 = exports.o1[exports.c4];
exports.o1_c5 = exports.o1[exports.c5];
exports.o1_s2 = exports.o1[exports.s2];
exports.o2 = exports.o1;
@@ -208,4 +217,7 @@ export declare const o1: {
[c5]: string;
[s2]: boolean;
};
export declare const o1_c4: number;
export declare const o1_c5: string;
export declare const o1_s2: boolean;
export declare const o2: T0;

View File

@@ -404,8 +404,24 @@ export const o1 = {
};
// check element access types
export const o1_c4 = o1[c4];
>o1_c4 : Symbol(o1_c4, Decl(main.ts, 101, 12))
>o1 : Symbol(o1, Decl(main.ts, 94, 12))
>c4 : Symbol(c4, Decl(main.ts, 27, 12))
export const o1_c5 = o1[c5];
>o1_c5 : Symbol(o1_c5, Decl(main.ts, 102, 12))
>o1 : Symbol(o1, Decl(main.ts, 94, 12))
>c5 : Symbol(c5, Decl(main.ts, 28, 12))
export const o1_s2 = o1[s2];
>o1_s2 : Symbol(o1_s2, Decl(main.ts, 103, 12))
>o1 : Symbol(o1, Decl(main.ts, 94, 12))
>s2 : Symbol(s2, Decl(main.ts, 29, 12))
export const o2: T0 = o1;
>o2 : Symbol(o2, Decl(main.ts, 100, 12))
>o2 : Symbol(o2, Decl(main.ts, 105, 12))
>T0 : Symbol(T0, Decl(main.ts, 0, 20))
>o1 : Symbol(o1, Decl(main.ts, 94, 12))

View File

@@ -476,6 +476,25 @@ export const o1 = {
};
// check element access types
export const o1_c4 = o1[c4];
>o1_c4 : number
>o1[c4] : number
>o1 : { [c4]: number; [c5]: string; [s2]: boolean; }
>c4 : "a"
export const o1_c5 = o1[c5];
>o1_c5 : string
>o1[c5] : string
>o1 : { [c4]: number; [c5]: string; [s2]: boolean; }
>c5 : 1
export const o1_s2 = o1[s2];
>o1_s2 : boolean
>o1[s2] : boolean
>o1 : { [c4]: number; [c5]: string; [s2]: boolean; }
>s2 : typeof s0
export const o2: T0 = o1;
>o2 : T0
>T0 : T0

View File

@@ -125,4 +125,9 @@ export const o1 = {
[s2]: true
};
// check element access types
export const o1_c4 = o1[c4];
export const o1_c5 = o1[c5];
export const o1_s2 = o1[s2];
export const o2: T0 = o1;