Merge pull request #16059 from Microsoft/mappedTypeDeclarations

Set '.declarations' on a property of a homomorphic mapped type
This commit is contained in:
Andy 2017-05-25 09:43:36 -07:00 committed by GitHub
commit 2ceb350bac
9 changed files with 70 additions and 42 deletions

View File

@ -5692,6 +5692,7 @@ namespace ts {
prop.type = propType;
if (propertySymbol) {
prop.syntheticOrigin = propertySymbol;
prop.declarations = propertySymbol.declarations;
}
members.set(propName, prop);
}

View File

@ -650,10 +650,12 @@ namespace ts.FindAllReferences.Core {
// If this is private property or method, the scope is the containing class
if (flags & (SymbolFlags.Property | SymbolFlags.Method)) {
const privateDeclaration = find(declarations, d => !!(getModifierFlags(d) & ModifierFlags.Private));
const privateDeclaration = find(declarations, d => hasModifier(d, ModifierFlags.Private));
if (privateDeclaration) {
return getAncestor(privateDeclaration, SyntaxKind.ClassDeclaration);
}
// Else this is a public property and could be accessed from anywhere.
return undefined;
}
// If symbol is of object binding pattern element without property name we would want to
@ -669,11 +671,6 @@ namespace ts.FindAllReferences.Core {
return undefined;
}
// If this is a synthetic property, it's a property and must be searched for globally.
if ((flags & SymbolFlags.Transient && (<TransientSymbol>symbol).checkFlags & CheckFlags.Synthetic)) {
return undefined;
}
let scope: Node | undefined;
for (const declaration of declarations) {
const container = getContainerNode(declaration);

View File

@ -149,9 +149,9 @@ function f1() {
let x: number = b.a.value;
>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 45, 7))
>b.a.value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
>b.a : Symbol(a)
>b.a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 44, 7))
>a : Symbol(a)
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
}

View File

@ -820,19 +820,19 @@ function f71(func: <T, U>(x: T, y: U) => Partial<T & U>) {
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
x.a; // number | undefined
>x.a : Symbol(a)
>x.a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>a : Symbol(a)
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))
x.b; // string | undefined
>x.b : Symbol(b)
>x.b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>b : Symbol(b)
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))
x.c; // boolean | undefined
>x.c : Symbol(c)
>x.c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>c : Symbol(c)
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
}
function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]) {
@ -1951,11 +1951,11 @@ class AnotherSampleClass<T> extends SampleClass<T & Foo> {
this.props.foo.concat;
>this.props.foo.concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
>this.props.foo : Symbol(foo)
>this.props.foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
>this.props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
>this : Symbol(AnotherSampleClass, Decl(keyofAndIndexedAccess.ts, 540, 54))
>props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
>foo : Symbol(foo)
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
>concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
}
}

View File

@ -364,9 +364,9 @@ function f1(x: Partial<Foo>) {
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 78, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
(x["other"] || 0).toFixed();
>(x["other"] || 0).toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@ -381,9 +381,9 @@ function f2(x: Readonly<Foo>) {
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 83, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
x["other"].toFixed();
>x["other"].toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@ -398,9 +398,9 @@ function f3(x: Boxified<Foo>) {
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 88, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
x["other"].x.toFixed();
>x["other"].x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@ -419,9 +419,9 @@ function f4(x: { [P in keyof Foo]: Foo[P] }) {
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 93, 18))
x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 93, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
x["other"].toFixed();
>x["other"].toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))

View File

@ -313,16 +313,16 @@ function f5(shape: Shape) {
let name = p.name.get();
>name : Symbol(name, Decl(mappedTypes2.ts, 84, 7))
>p.name.get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))
>p.name : Symbol(name)
>p.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
>name : Symbol(name)
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))
p.width.set(42);
>p.width.set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
>p.width : Symbol(width)
>p.width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
>width : Symbol(width)
>width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
>set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
}
@ -334,19 +334,19 @@ function f6(shape: DeepReadonly<Shape>) {
let name = shape.name; // string
>name : Symbol(name, Decl(mappedTypes2.ts, 89, 7))
>shape.name : Symbol(name)
>shape.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
>name : Symbol(name)
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
let location = shape.location; // DeepReadonly<Point>
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
>shape.location : Symbol(location)
>shape.location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
>location : Symbol(location)
>location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))
let x = location.x; // number
>x : Symbol(x, Decl(mappedTypes2.ts, 91, 7))
>location.x : Symbol(x)
>location.x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
>x : Symbol(x)
>x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
}

View File

@ -71,17 +71,17 @@ function f1(b: Bacon) {
let isPerfect = bb.isPerfect.value;
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 23, 7))
>bb.isPerfect.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
>bb.isPerfect : Symbol(isPerfect)
>bb.isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
>isPerfect : Symbol(isPerfect)
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
let weight = bb.weight.value;
>weight : Symbol(weight, Decl(mappedTypes3.ts, 24, 7))
>bb.weight.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
>bb.weight : Symbol(weight)
>bb.weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
>weight : Symbol(weight)
>weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
}

View File

@ -23,16 +23,16 @@ class A<P extends Partial<Foo>> {
>doSomething : Symbol(A.doSomething, Decl(typeVariableTypeGuards.ts, 7, 22))
this.props.foo && this.props.foo()
>this.props.foo : Symbol(foo)
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>foo : Symbol(foo)
>this.props.foo : Symbol(foo)
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>foo : Symbol(foo)
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
}
}

View File

@ -0,0 +1,30 @@
/// <reference path="../fourslash.ts"/>
////interface Foo {
//// /** Doc */
//// bar: number;
////}
////
////const f: Foo = { bar: 0 };
////f./*f*/bar;
////
////const f2: { [TKey in keyof Foo]: string } = { bar: "0" };
////f2./*f2*/bar;
////
////const f3 = { ...f };
////f3./*f3*/bar;
////
////const f4 = { ...f2 };
////f4./*f4*/bar;
goTo.marker("f");
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
goTo.marker("f2");
verify.quickInfoIs("(property) bar: string", "Doc ");
goTo.marker("f3");
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
goTo.marker("f4");
verify.quickInfoIs("(property) bar: string", "Doc ");