-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Allow to find all references of the 'this 'keyword #9270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,8 +134,8 @@ namespace ts { | |
|
|
||
| const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); | ||
|
|
||
| const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); | ||
| const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); | ||
| const anySignature = createSignature(undefined, undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); | ||
| const unknownSignature = createSignature(undefined, undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); | ||
|
|
||
| const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); | ||
|
|
||
|
|
@@ -3198,6 +3198,11 @@ namespace ts { | |
| return undefined; | ||
| } | ||
|
|
||
| function getAnnotatedAccessorThisParameter(accessor: AccessorDeclaration): Symbol { | ||
| const parameter = getAccessorThisParameter(accessor); | ||
| return parameter && parameter.symbol; | ||
| } | ||
|
|
||
|
||
| function getAnnotatedAccessorThisType(accessor: AccessorDeclaration): Type { | ||
| if (accessor) { | ||
| const parameter = getAccessorThisParameter(accessor); | ||
|
|
@@ -3888,12 +3893,13 @@ namespace ts { | |
| resolveObjectTypeMembers(type, source, typeParameters, typeArguments); | ||
| } | ||
|
|
||
| function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisType: Type, parameters: Symbol[], | ||
| function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisParameter: Symbol | undefined, thisType: Type | undefined, parameters: Symbol[], | ||
| resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasStringLiterals: boolean): Signature { | ||
| const sig = new Signature(checker); | ||
| sig.declaration = declaration; | ||
| sig.typeParameters = typeParameters; | ||
| sig.parameters = parameters; | ||
| sig.thisParameter = thisParameter; | ||
| sig.thisType = thisType; | ||
| sig.resolvedReturnType = resolvedReturnType; | ||
| sig.typePredicate = typePredicate; | ||
|
|
@@ -3904,15 +3910,15 @@ namespace ts { | |
| } | ||
|
|
||
| function cloneSignature(sig: Signature): Signature { | ||
| return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, | ||
| return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.thisType, sig.parameters, sig.resolvedReturnType, | ||
| sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); | ||
| } | ||
|
|
||
| function getDefaultConstructSignatures(classType: InterfaceType): Signature[] { | ||
| const baseConstructorType = getBaseConstructorTypeOfClass(classType); | ||
| const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct); | ||
| if (baseSignatures.length === 0) { | ||
| return [createSignature(undefined, classType.localTypeParameters, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)]; | ||
| return [createSignature(undefined, classType.localTypeParameters, undefined, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)]; | ||
| } | ||
| const baseTypeNode = getBaseTypeNodeOfClass(classType); | ||
| const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode); | ||
|
|
@@ -4454,6 +4460,7 @@ namespace ts { | |
| const parameters: Symbol[] = []; | ||
| let hasStringLiterals = false; | ||
| let minArgumentCount = -1; | ||
| let thisParameter: Symbol = undefined; | ||
| let thisType: Type = undefined; | ||
| let hasThisParameter: boolean; | ||
| const isJSConstructSignature = isJSDocConstructSignature(declaration); | ||
|
|
@@ -4472,6 +4479,7 @@ namespace ts { | |
| } | ||
| if (i === 0 && paramSymbol.name === "this") { | ||
| hasThisParameter = true; | ||
| thisParameter = param.symbol; | ||
| thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; | ||
| } | ||
| else { | ||
|
|
@@ -4498,8 +4506,11 @@ namespace ts { | |
| !hasDynamicName(declaration) && | ||
| (!hasThisParameter || thisType === unknownType)) { | ||
| const otherKind = declaration.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; | ||
| const setter = <AccessorDeclaration>getDeclarationOfKind(declaration.symbol, otherKind); | ||
| thisType = getAnnotatedAccessorThisType(setter); | ||
| const other = <AccessorDeclaration>getDeclarationOfKind(declaration.symbol, otherKind); | ||
| if (other) { | ||
| thisParameter = getAnnotatedAccessorThisParameter(other); | ||
| thisType = getAnnotatedAccessorThisType(other); | ||
| } | ||
| } | ||
|
|
||
| if (minArgumentCount < 0) { | ||
|
|
@@ -4520,7 +4531,7 @@ namespace ts { | |
| createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) : | ||
| undefined; | ||
|
|
||
| links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasStringLiterals); | ||
| links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, thisType, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasStringLiterals); | ||
| } | ||
| return links.resolvedSignature; | ||
| } | ||
|
|
@@ -5453,6 +5464,7 @@ namespace ts { | |
| freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); | ||
| } | ||
| const result = createSignature(signature.declaration, freshTypeParameters, | ||
| signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), | ||
| signature.thisType && instantiateType(signature.thisType, mapper), | ||
| instantiateList(signature.parameters, mapper, instantiateSymbol), | ||
| instantiateType(signature.resolvedReturnType, mapper), | ||
|
|
@@ -17156,6 +17168,15 @@ namespace ts { | |
| return getSymbolOfEntityNameOrPropertyAccessExpression(<EntityName | PropertyAccessExpression>node); | ||
|
|
||
| case SyntaxKind.ThisKeyword: | ||
| const container = getThisContainer(node, /*includeArrowFunctions*/ false); | ||
| if (isFunctionLike(container)) { | ||
| const sig = getSignatureFromDeclaration(container); | ||
| if (sig.thisParameter) { | ||
| return sig.thisParameter; | ||
| } | ||
| } | ||
| // fallthrough | ||
|
|
||
| case SyntaxKind.SuperKeyword: | ||
| const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node); | ||
| return type.symbol; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2388,6 +2388,8 @@ namespace ts { | |
| parameters: Symbol[]; // Parameters | ||
| thisType?: Type; // type of this-type | ||
| /* @internal */ | ||
| thisParameter?: Symbol; // symbol of this-type parameter | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was never quite right to resolve |
||
| /* @internal */ | ||
| resolvedReturnType: Type; // Resolved return type | ||
| /* @internal */ | ||
| minArgumentCount: number; // Number of non-optional parameters | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, pushed WIP