Skip to content
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

Rename isParameterDeclaration to isPartOfParameterDeclaration #58251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ import {
isOptionalChain,
isOptionalChainRoot,
isOutermostOptionalChain,
isParameterDeclaration,
isParameterPropertyDeclaration,
isParenthesizedExpression,
isPartOfParameterDeclaration,
isPartOfTypeQuery,
isPrefixUnaryExpression,
isPrivateIdentifier,
Expand Down Expand Up @@ -3647,7 +3647,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
else if (isBlockOrCatchScoped(node)) {
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
}
else if (isParameterDeclaration(node)) {
else if (isPartOfParameterDeclaration(node)) {
// It is safe to walk up parent chain to find whether the node is a destructuring parameter declaration
// because its parent chain has already been set up, since parents are set before descending into children.
//
Expand Down
16 changes: 8 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,10 @@ import {
isOptionalTypeNode,
isOutermostOptionalChain,
isParameter,
isParameterDeclaration,
isParameterPropertyDeclaration,
isParenthesizedExpression,
isParenthesizedTypeNode,
isPartOfParameterDeclaration,
isPartOfTypeNode,
isPartOfTypeQuery,
isPlainJsFile,
Expand Down Expand Up @@ -8233,7 +8233,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
sym.flags & SymbolFlags.FunctionScopedVariable
&& sym.valueDeclaration
) {
if (isParameterDeclaration(sym.valueDeclaration)) {
if (isPartOfParameterDeclaration(sym.valueDeclaration)) {
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
}
}
Expand Down Expand Up @@ -8994,7 +8994,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function includePrivateSymbol(symbol: Symbol) {
if (some(symbol.declarations, isParameterDeclaration)) return;
if (some(symbol.declarations, isPartOfParameterDeclaration)) return;
Debug.assertIsDefined(deferredPrivatesStack[deferredPrivatesStack.length - 1]);
getUnusedName(unescapeLeadingUnderscores(symbol.escapedName), symbol); // Call to cache unique name for symbol
// Blanket moving (import) aliases into the root private context should work, since imports are not valid within namespaces
Expand Down Expand Up @@ -10686,7 +10686,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
const pattern = declaration.parent;
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isPartOfParameterDeclaration(declaration)) {
parentType = getNonNullableType(parentType);
}
// Filter `undefined` from the type we check against if the parent has an initializer and that initializer is not possibly `undefined`
Expand Down Expand Up @@ -42464,7 +42464,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
for (const node of potentialUnusedRenamedBindingElementsInTypes) {
if (!getSymbolOfDeclaration(node)?.isReferenced) {
const wrappingDeclaration = walkUpBindingElementsAndPatterns(node);
Debug.assert(isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
Debug.assert(isPartOfParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
const diagnostic = createDiagnosticForNode(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName));
if (!wrappingDeclaration.type) {
// entire parameter does not have type annotation, suggest adding an annotation
Expand Down Expand Up @@ -42746,7 +42746,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// }

// skip block-scoped variables and parameters
if ((getCombinedNodeFlagsCached(node) & NodeFlags.BlockScoped) !== 0 || isParameterDeclaration(node)) {
if ((getCombinedNodeFlagsCached(node) & NodeFlags.BlockScoped) !== 0 || isPartOfParameterDeclaration(node)) {
return;
}

Expand Down Expand Up @@ -42818,7 +42818,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (
node.propertyName &&
isIdentifier(node.name) &&
isParameterDeclaration(node) &&
isPartOfParameterDeclaration(node) &&
nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)
) {
// type F = ({a: string}) => void;
Expand Down Expand Up @@ -42864,7 +42864,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
forEach(node.name.elements, checkSourceElement);
}
// For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body
if (node.initializer && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) {
if (node.initializer && isPartOfParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) {
error(node, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
return;
}
Expand Down
8 changes: 2 additions & 6 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5340,10 +5340,6 @@ export function isPushOrUnshiftIdentifier(node: Identifier) {
return node.escapedText === "push" || node.escapedText === "unshift";
}

// TODO(jakebailey): this function should not be named this. While it does technically
// return true if the argument is a ParameterDeclaration, it also returns true for nodes
// that are children of ParameterDeclarations inside binding elements.
// Probably, this should be called `rootDeclarationIsParameter`.
/**
* This function returns true if the this node's root declaration is a parameter.
* For example, passing a `ParameterDeclaration` will return true, as will passing a
Expand All @@ -5353,7 +5349,7 @@ export function isPushOrUnshiftIdentifier(node: Identifier) {
*
* @internal
*/
export function isParameterDeclaration(node: Declaration): boolean {
export function isPartOfParameterDeclaration(node: Declaration): boolean {
const root = getRootDeclaration(node);
return root.kind === SyntaxKind.Parameter;
}
Expand Down Expand Up @@ -11239,7 +11235,7 @@ export function createNameResolver({
lastLocation === (location as BindingElement).name && isBindingPattern(lastLocation)
)
) {
if (isParameterDeclaration(location as BindingElement) && !associatedDeclarationForContainingInitializerOrBindingName) {
if (isPartOfParameterDeclaration(location as BindingElement) && !associatedDeclarationForContainingInitializerOrBindingName) {
associatedDeclarationForContainingInitializerOrBindingName = location as BindingElement;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ import {
isObjectLiteralExpression,
isOptionalTypeNode,
isParameter,
isParameterDeclaration,
isParenthesizedTypeNode,
isPartOfParameterDeclaration,
isPrefixUnaryExpression,
isPropertyAccessExpression,
isPropertyDeclaration,
Expand Down Expand Up @@ -899,7 +899,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
}

function isHintableDeclaration(node: VariableDeclaration | ParameterDeclaration) {
if ((isParameterDeclaration(node) || isVariableDeclaration(node) && isVarConst(node)) && node.initializer) {
if ((isPartOfParameterDeclaration(node) || isVariableDeclaration(node) && isVarConst(node)) && node.initializer) {
const initializer = skipParentheses(node.initializer);
return !(isHintableLiteral(initializer) || isNewExpression(initializer) || isObjectLiteralExpression(initializer) || isAssertionExpression(initializer));
}
Expand Down