diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1cbd9e5b54a..477c0ce7e88 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5692,6 +5692,7 @@ namespace ts { prop.type = propType; if (propertySymbol) { prop.syntheticOrigin = propertySymbol; + prop.declarations = propertySymbol.declarations; } members.set(propName, prop); } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index efc6a6f6ed1..e12215abde0 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -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 && (symbol).checkFlags & CheckFlags.Synthetic)) { - return undefined; - } - let scope: Node | undefined; for (const declaration of declarations) { const container = getContainerNode(declaration); diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.symbols b/tests/baselines/reference/isomorphicMappedTypeInference.symbols index 6c638f442c8..48765d15260 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.symbols +++ b/tests/baselines/reference/isomorphicMappedTypeInference.symbols @@ -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)) } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 6d7e886d26c..65cc44fe84b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -820,19 +820,19 @@ function f71(func: (x: T, y: U) => Partial) { >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: (x: T, y: U, k: K) => (T & U)[K]) { @@ -1951,11 +1951,11 @@ class AnotherSampleClass extends SampleClass { 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, --, --)) } } diff --git a/tests/baselines/reference/mappedTypeModifiers.symbols b/tests/baselines/reference/mappedTypeModifiers.symbols index 2aa6492d99f..363345a2e55 100644 --- a/tests/baselines/reference/mappedTypeModifiers.symbols +++ b/tests/baselines/reference/mappedTypeModifiers.symbols @@ -364,9 +364,9 @@ function f1(x: Partial) { >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 : 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 : 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, --, --)) diff --git a/tests/baselines/reference/mappedTypes2.symbols b/tests/baselines/reference/mappedTypes2.symbols index 7d9727daedd..9100c408ee9 100644 --- a/tests/baselines/reference/mappedTypes2.symbols +++ b/tests/baselines/reference/mappedTypes2.symbols @@ -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) { 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 >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)) } diff --git a/tests/baselines/reference/mappedTypes3.symbols b/tests/baselines/reference/mappedTypes3.symbols index 683c764f0f4..74b3f3d783a 100644 --- a/tests/baselines/reference/mappedTypes3.symbols +++ b/tests/baselines/reference/mappedTypes3.symbols @@ -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)) } diff --git a/tests/baselines/reference/typeVariableTypeGuards.symbols b/tests/baselines/reference/typeVariableTypeGuards.symbols index fa94cfd9462..d201d0538a1 100644 --- a/tests/baselines/reference/typeVariableTypeGuards.symbols +++ b/tests/baselines/reference/typeVariableTypeGuards.symbols @@ -23,16 +23,16 @@ class A

> { >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)) } } diff --git a/tests/cases/fourslash/server/quickInfoMappedSpreadTypes.ts b/tests/cases/fourslash/server/quickInfoMappedSpreadTypes.ts new file mode 100644 index 00000000000..2a0c1668763 --- /dev/null +++ b/tests/cases/fourslash/server/quickInfoMappedSpreadTypes.ts @@ -0,0 +1,30 @@ +/// + +////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 ");