Skip to content

Commit 28cdaf2

Browse files
committed
Address PR:fix find-all-refs and slim down code
Also add readonly to find-all-ref test
1 parent 6879bc1 commit 28cdaf2

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,7 +5495,7 @@ namespace ts {
54955495
prop.checkFlags = templateReadonly || modifiersProp && isReadonlySymbol(modifiersProp) ? CheckFlags.Readonly : 0;
54965496
prop.type = propType;
54975497
if (propertySymbol) {
5498-
prop.mappedTypeOrigin = propertySymbol;
5498+
prop.syntheticOrigin = propertySymbol;
54995499
}
55005500
members.set(propName, prop);
55015501
}
@@ -7449,7 +7449,6 @@ namespace ts {
74497449
const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations);
74507450
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
74517451
const result = createSymbol(flags, leftProp.name);
7452-
result.checkFlags = 0;
74537452
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]);
74547453
result.leftSpread = leftProp;
74557454
result.rightSpread = rightProp;
@@ -7465,15 +7464,14 @@ namespace ts {
74657464
}
74667465

74677466
function getNonReadonlySymbol(prop: Symbol) {
7468-
if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.Readonly)) {
7467+
if (!isReadonlySymbol(prop)) {
74697468
return prop;
74707469
}
7471-
const declarations: Declaration[] = prop.declarations;
74727470
const flags = SymbolFlags.Property | (prop.flags & SymbolFlags.Optional);
74737471
const result = createSymbol(flags, prop.name);
7474-
result.checkFlags = 0;
74757472
result.type = getTypeOfSymbol(prop);
7476-
result.declarations = declarations;
7473+
result.declarations = prop.declarations;
7474+
result.syntheticOrigin = prop;
74777475
return result;
74787476
}
74797477

@@ -22140,10 +22138,10 @@ namespace ts {
2214022138
else if (symbol.flags & SymbolFlags.Transient) {
2214122139
if ((symbol as SymbolLinks).leftSpread) {
2214222140
const links = symbol as SymbolLinks;
22143-
return [links.leftSpread, links.rightSpread];
22141+
return [...getRootSymbols(links.leftSpread), ...getRootSymbols(links.rightSpread)];
2214422142
}
22145-
if ((symbol as SymbolLinks).mappedTypeOrigin) {
22146-
return getRootSymbols((symbol as SymbolLinks).mappedTypeOrigin);
22143+
if ((symbol as SymbolLinks).syntheticOrigin) {
22144+
return getRootSymbols((symbol as SymbolLinks).syntheticOrigin);
2214722145
}
2214822146

2214922147
let target: Symbol;

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ namespace ts {
28522852
containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property
28532853
leftSpread?: Symbol; // Left source for synthetic spread property
28542854
rightSpread?: Symbol; // Right source for synthetic spread property
2855-
mappedTypeOrigin?: Symbol; // For a property on a mapped type, points back to the orignal 'T' from 'keyof T'.
2855+
syntheticOrigin?: Symbol; // For a property on a mapped or spread type, points back to the original property
28562856
isDiscriminantProperty?: boolean; // True if discriminant synthetic property
28572857
resolvedExports?: SymbolTable; // Resolved exports of module
28582858
exportsChecked?: boolean; // True if exports of external module have been checked
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/// <reference path='fourslash.ts'/>
22

3-
////interface A1 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string };
3+
////interface A1 { readonly [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string };
44
////interface A2 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]?: number };
55
////let a1: A1;
66
////let a2: A2;
77
////let a12 = { ...a1, ...a2 };
88
////a12.[|a|];
9+
////a1.[|a|];
910
const ranges = test.ranges();
10-
const [r0, r1, r2] = ranges;
11+
const [r0, r1, r2, r3] = ranges;
1112

1213
// members of spread types only refer to themselves and the resulting property
13-
verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2] }]);
14+
verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2, r3] }]);
1415
verify.referenceGroups(r1, [{ definition: "(property) A2.a: number", ranges: [r1, r2] }]);
1516

1617
// but the resulting property refers to everything
1718
verify.referenceGroups(r2, [
18-
{ definition: "(property) A1.a: string", ranges: [r0] },
19+
{ definition: "(property) A1.a: string", ranges: [r0, r3] },
1920
{ definition: "(property) A2.a: number", ranges: [r1] },
2021
{ definition: "(property) a: string | number", ranges: [r2] }
2122
]);

0 commit comments

Comments
 (0)