mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 14:34:35 -06:00
Remove unnecessary getFirstChildOfKind helper function (#20647)
This commit is contained in:
parent
e58d80ad83
commit
21ff2cd501
@ -170,7 +170,7 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
const type = inferTypeForVariableFromUsage(getAccessorDeclaration.name, sourceFile, program, cancellationToken);
|
||||
const closeParenToken = getFirstChildOfKind(getAccessorDeclaration, sourceFile, SyntaxKind.CloseParenToken);
|
||||
const closeParenToken = findChildOfKind(getAccessorDeclaration, SyntaxKind.CloseParenToken, sourceFile);
|
||||
return makeFix(getAccessorDeclaration, closeParenToken.getEnd(), type, program);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ namespace ts.codefix {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
const isConstructor = containingFunction.kind === SyntaxKind.Constructor;
|
||||
const searchToken = isConstructor ?
|
||||
<Token<SyntaxKind.ConstructorKeyword>>getFirstChildOfKind(containingFunction, sourceFile, SyntaxKind.ConstructorKeyword) :
|
||||
findChildOfKind<Token<SyntaxKind.ConstructorKeyword>>(containingFunction, SyntaxKind.ConstructorKeyword, sourceFile) :
|
||||
containingFunction.name;
|
||||
if (searchToken) {
|
||||
return InferFromReference.inferTypeForParametersFromReferences(getReferences(searchToken, sourceFile, program, cancellationToken), containingFunction, program.getTypeChecker(), cancellationToken);
|
||||
|
||||
@ -992,7 +992,7 @@ namespace ts.FindAllReferences.Core {
|
||||
*/
|
||||
function findOwnConstructorReferences(classSymbol: Symbol, sourceFile: SourceFile, addNode: (node: Node) => void): void {
|
||||
for (const decl of classSymbol.members.get(InternalSymbolName.Constructor).declarations) {
|
||||
const ctrKeyword = ts.findChildOfKind(decl, ts.SyntaxKind.ConstructorKeyword, sourceFile)!;
|
||||
const ctrKeyword = findChildOfKind(decl, ts.SyntaxKind.ConstructorKeyword, sourceFile)!;
|
||||
Debug.assert(decl.kind === SyntaxKind.Constructor && !!ctrKeyword);
|
||||
addNode(ctrKeyword);
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ namespace ts {
|
||||
return position < candidate.end || !isCompletedNode(candidate, sourceFile);
|
||||
}
|
||||
|
||||
export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean {
|
||||
function isCompletedNode(n: Node, sourceFile: SourceFile): boolean {
|
||||
if (nodeIsMissing(n)) {
|
||||
return false;
|
||||
}
|
||||
@ -512,7 +512,7 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return isCompletedNode((<ExpressionStatement>n).expression, sourceFile) ||
|
||||
hasChildOfKind(n, SyntaxKind.SemicolonToken);
|
||||
hasChildOfKind(n, SyntaxKind.SemicolonToken, sourceFile);
|
||||
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
@ -540,11 +540,9 @@ namespace ts {
|
||||
return isCompletedNode((<IterationStatement>n).statement, sourceFile);
|
||||
case SyntaxKind.DoStatement:
|
||||
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
|
||||
const hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile);
|
||||
if (hasWhileKeyword) {
|
||||
return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile);
|
||||
}
|
||||
return isCompletedNode((<DoStatement>n).statement, sourceFile);
|
||||
return hasChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile)
|
||||
? nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile)
|
||||
: isCompletedNode((<DoStatement>n).statement, sourceFile);
|
||||
|
||||
case SyntaxKind.TypeQuery:
|
||||
return isCompletedNode((<TypeQueryNode>n).exprName, sourceFile);
|
||||
@ -619,12 +617,12 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function hasChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): boolean {
|
||||
export function hasChildOfKind(n: Node, kind: SyntaxKind, sourceFile: SourceFile): boolean {
|
||||
return !!findChildOfKind(n, kind, sourceFile);
|
||||
}
|
||||
|
||||
export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFileLike): Node | undefined {
|
||||
return forEach(n.getChildren(sourceFile), c => c.kind === kind && c);
|
||||
export function findChildOfKind<T extends Node>(n: Node, kind: T["kind"], sourceFile: SourceFileLike): T | undefined {
|
||||
return find(n.getChildren(sourceFile), (c): c is T => c.kind === kind);
|
||||
}
|
||||
|
||||
export function findContainingList(node: Node): SyntaxList | undefined {
|
||||
@ -1113,10 +1111,6 @@ namespace ts {
|
||||
export function singleElementArray<T>(t: T | undefined): T[] {
|
||||
return t === undefined ? undefined : [t];
|
||||
}
|
||||
|
||||
export function getFirstChildOfKind(node: Node, sourceFile: SourceFile, kind: SyntaxKind): Node | undefined {
|
||||
return find(node.getChildren(sourceFile), c => c.kind === kind);
|
||||
}
|
||||
}
|
||||
|
||||
// Display-part writer helpers
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user