diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d1c9c196f252e..59b1eb19d7323 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -200,9 +200,9 @@ import { isOptionalChain, isOptionalChainRoot, isOutermostOptionalChain, - isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, + isPartOfParameterDeclaration, isPartOfTypeQuery, isPrefixUnaryExpression, isPrivateIdentifier, @@ -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. // diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc5d7b0cdd664..d4565607249fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -674,10 +674,10 @@ import { isOptionalTypeNode, isOutermostOptionalChain, isParameter, - isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, isParenthesizedTypeNode, + isPartOfParameterDeclaration, isPartOfTypeNode, isPartOfTypeQuery, isPlainJsFile, @@ -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 }; } } @@ -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 @@ -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` @@ -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 @@ -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; } @@ -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; @@ -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; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3759d3fd21325..85d06e1fe2a3a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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 @@ -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; } @@ -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; } } diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 5fdc91e2dab3c..ed084912c6863 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -70,8 +70,8 @@ import { isObjectLiteralExpression, isOptionalTypeNode, isParameter, - isParameterDeclaration, isParenthesizedTypeNode, + isPartOfParameterDeclaration, isPrefixUnaryExpression, isPropertyAccessExpression, isPropertyDeclaration, @@ -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)); }