From 28cdaf24e9ea61e091378f205c4f6129db4bd2b5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 12 Apr 2017 11:31:52 -0700 Subject: [PATCH] Address PR:fix find-all-refs and slim down code Also add readonly to find-all-ref test --- src/compiler/checker.ts | 16 +++++++--------- src/compiler/types.ts | 2 +- .../fourslash/findAllRefsForObjectSpread.ts | 9 +++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8011e35dede..d4b37ba0d99 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5495,7 +5495,7 @@ namespace ts { prop.checkFlags = templateReadonly || modifiersProp && isReadonlySymbol(modifiersProp) ? CheckFlags.Readonly : 0; prop.type = propType; if (propertySymbol) { - prop.mappedTypeOrigin = propertySymbol; + prop.syntheticOrigin = propertySymbol; } members.set(propName, prop); } @@ -7449,7 +7449,6 @@ namespace ts { const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations); const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional); const result = createSymbol(flags, leftProp.name); - result.checkFlags = 0; result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]); result.leftSpread = leftProp; result.rightSpread = rightProp; @@ -7465,15 +7464,14 @@ namespace ts { } function getNonReadonlySymbol(prop: Symbol) { - if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.Readonly)) { + if (!isReadonlySymbol(prop)) { return prop; } - const declarations: Declaration[] = prop.declarations; const flags = SymbolFlags.Property | (prop.flags & SymbolFlags.Optional); const result = createSymbol(flags, prop.name); - result.checkFlags = 0; result.type = getTypeOfSymbol(prop); - result.declarations = declarations; + result.declarations = prop.declarations; + result.syntheticOrigin = prop; return result; } @@ -22140,10 +22138,10 @@ namespace ts { else if (symbol.flags & SymbolFlags.Transient) { if ((symbol as SymbolLinks).leftSpread) { const links = symbol as SymbolLinks; - return [links.leftSpread, links.rightSpread]; + return [...getRootSymbols(links.leftSpread), ...getRootSymbols(links.rightSpread)]; } - if ((symbol as SymbolLinks).mappedTypeOrigin) { - return getRootSymbols((symbol as SymbolLinks).mappedTypeOrigin); + if ((symbol as SymbolLinks).syntheticOrigin) { + return getRootSymbols((symbol as SymbolLinks).syntheticOrigin); } let target: Symbol; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 354ef9d8b10..df28717db4b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2852,7 +2852,7 @@ namespace ts { containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property leftSpread?: Symbol; // Left source for synthetic spread property rightSpread?: Symbol; // Right source for synthetic spread property - mappedTypeOrigin?: Symbol; // For a property on a mapped type, points back to the orignal 'T' from 'keyof T'. + syntheticOrigin?: Symbol; // For a property on a mapped or spread type, points back to the original property isDiscriminantProperty?: boolean; // True if discriminant synthetic property resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked diff --git a/tests/cases/fourslash/findAllRefsForObjectSpread.ts b/tests/cases/fourslash/findAllRefsForObjectSpread.ts index a65f18ef57c..29fc813ba5e 100644 --- a/tests/cases/fourslash/findAllRefsForObjectSpread.ts +++ b/tests/cases/fourslash/findAllRefsForObjectSpread.ts @@ -1,21 +1,22 @@ /// -////interface A1 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string }; +////interface A1 { readonly [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string }; ////interface A2 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]?: number }; ////let a1: A1; ////let a2: A2; ////let a12 = { ...a1, ...a2 }; ////a12.[|a|]; +////a1.[|a|]; const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0, r1, r2, r3] = ranges; // members of spread types only refer to themselves and the resulting property -verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2] }]); +verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2, r3] }]); verify.referenceGroups(r1, [{ definition: "(property) A2.a: number", ranges: [r1, r2] }]); // but the resulting property refers to everything verify.referenceGroups(r2, [ - { definition: "(property) A1.a: string", ranges: [r0] }, + { definition: "(property) A1.a: string", ranges: [r0, r3] }, { definition: "(property) A2.a: number", ranges: [r1] }, { definition: "(property) a: string | number", ranges: [r2] } ]);