diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7f61986a80fb8..02fa618742201 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -734,7 +734,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { break; case SyntaxKind.JSDocFunctionType: return (isJSDocConstructSignature(node) ? InternalSymbolName.New : InternalSymbolName.Call); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // Parameters with names are handled at the top of this function. Parameters // without names can only come from JSDocFunctionTypes. Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType, "Impossible parameter parent kind", () => `parent is: ${Debug.formatSyntaxKind(node.parent.kind)}, expected JSDocFunctionType`); @@ -1206,7 +1206,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { case SyntaxKind.BindingElement: bindBindingElementFlow(node as BindingElement); break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: bindParameterFlow(node as ParameterDeclaration); break; case SyntaxKind.ObjectLiteralExpression: @@ -2940,7 +2940,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { break; // Binding the children will handle everything case SyntaxKind.TypeParameter: return bindTypeParameter(node as TypeParameterDeclaration); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return bindParameter(node as ParameterDeclaration); case SyntaxKind.VariableDeclaration: return bindVariableDeclarationOrBindingElement(node as VariableDeclaration); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 438e46eca11b6..47e3edb617f9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -686,7 +686,7 @@ import { isOptionalJSDocPropertyLikeTag, isOptionalTypeNode, isOutermostOptionalChain, - isParameter, + isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, isParenthesizedTypeNode, @@ -1613,7 +1613,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { }, getTypeOfSymbol, getSymbolsOfParameterPropertyDeclaration: (parameterIn, parameterName) => { - const parameter = getParseTreeNode(parameterIn, isParameter); + const parameter = getParseTreeNode(parameterIn, isParameterDeclaration); if (parameter === undefined) return Debug.fail("Cannot get symbols of a synthetic parameter that cannot be resolved to a parse-tree node."); Debug.assert(isParameterPropertyDeclaration(parameter, parameter.parent)); return getSymbolsOfParameterPropertyDeclaration(parameter, escapeLeadingUnderscores(parameterName)); @@ -1802,7 +1802,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { getAmbientModules, getJsxIntrinsicTagNamesAt, isOptionalParameter: nodeIn => { - const node = getParseTreeNode(nodeIn, isParameter); + const node = getParseTreeNode(nodeIn, isParameterDeclaration); return node ? isOptionalParameter(node) : false; }, tryGetMemberInModuleExports: (name, symbol) => tryGetMemberInModuleExports(escapeLeadingUnderscores(name), symbol), @@ -2980,7 +2980,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { isMethodDeclaration(n.parent) && n.parent.parent === declaration || isGetOrSetAccessorDeclaration(n.parent) && n.parent.parent === declaration || isPropertyDeclaration(n.parent) && n.parent.parent === declaration || - isParameter(n.parent) && n.parent.parent.parent === declaration)); + isParameterDeclaration(n.parent) && n.parent.parent.parent === declaration)); if (!container) { return true; } @@ -6141,7 +6141,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ) { const originalType = type; if (addUndefined) { - type = getOptionalType(type, !isParameter(host)); + type = getOptionalType(type, !isParameterDeclaration(host)); } const clone = tryReuseExistingNonParameterTypeNode(context, typeNode, type, host); if (clone) { @@ -7519,7 +7519,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else if ( !forEach(param.declarations, d => { - if (isParameter(d) && isBindingPattern(d.name)) { + if (isParameterDeclaration(d) && isBindingPattern(d.name)) { bindPattern(d.name); return true; } @@ -7671,7 +7671,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getEffectiveParameterDeclaration(parameterSymbol: Symbol): ParameterDeclaration | JSDocParameterTag | undefined { - const parameterDeclaration: ParameterDeclaration | JSDocParameterTag | undefined = getDeclarationOfKind(parameterSymbol, SyntaxKind.Parameter); + const parameterDeclaration: ParameterDeclaration | JSDocParameterTag | undefined = getDeclarationOfKind(parameterSymbol, SyntaxKind.ParameterDeclaration); if (parameterDeclaration) { return parameterDeclaration; } @@ -8365,7 +8365,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { * @param symbol - The symbol is used both to find an existing annotation if declaration is not provided, and to determine if `unique symbol` should be printed */ function serializeTypeForDeclaration(context: NodeBuilderContext, declaration: Declaration | undefined, type: Type, symbol: Symbol) { - const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration); + const addUndefinedForParameter = declaration && (isParameterDeclaration(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration); const enclosingDeclaration = context.enclosingDeclaration; const restoreFlags = saveRestoreFlags(context); if (declaration && hasInferredType(declaration) && !(context.internalFlags & InternalNodeBuilderFlags.NoSyntacticPrinter)) { @@ -8407,7 +8407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (typeFromTypeNode === type) { return true; } - if (annotatedDeclaration && (isParameter(annotatedDeclaration) || isPropertySignature(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) { + if (annotatedDeclaration && (isParameterDeclaration(annotatedDeclaration) || isPropertySignature(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) { return getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode; } return false; @@ -8963,14 +8963,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { (isFunctionLike(node) && !node.type) || (isPropertyDeclaration(node) && !node.type && !node.initializer) || (isPropertySignature(node) && !node.type && !node.initializer) - || (isParameter(node) && !node.type && !node.initializer) + || (isParameterDeclaration(node) && !node.type && !node.initializer) ) { let visited = visitEachChild(node, visitExistingNodeTreeSymbols); if (visited === node) { visited = setTextRange(context, factory.cloneNode(node), node); } (visited as Mutable).type = factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); - if (isParameter(node)) { + if (isParameterDeclaration(node)) { (visited as Mutable).modifiers = undefined; } return visited; @@ -10962,7 +10962,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: case SyntaxKind.IndexSignature: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.ModuleBlock: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -11474,7 +11474,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - if (isParameter(declaration)) { + if (isParameterDeclaration(declaration)) { if (!declaration.symbol) { // parameters of function types defined in JSDoc in TS files don't have symbols return; @@ -11506,7 +11506,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Use the type of the initializer expression if one is present and the declaration is // not a parameter of a contextually typed function if (hasOnlyExpressionInitializer(declaration) && !!declaration.initializer) { - if (isInJSFile(declaration) && !isParameter(declaration)) { + if (isInJSFile(declaration) && !isParameterDeclaration(declaration)) { const containerObjectType = getJSContainerObjectType(declaration, getSymbolOfDeclaration(declaration), getDeclaredExpandoInitializer(declaration)); if (containerObjectType) { return containerObjectType; @@ -12069,7 +12069,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } // Rest parameters default to type any[], other parameters default to type any - type = isParameter(declaration) && declaration.dotDotDotToken ? anyArrayType : anyType; + type = isParameterDeclaration(declaration) && declaration.dotDotDotToken ? anyArrayType : anyType; // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors) { @@ -12082,7 +12082,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function declarationBelongsToPrivateAmbientMember(declaration: VariableLikeDeclaration) { const root = getRootDeclaration(declaration); - const memberDeclaration = root.kind === SyntaxKind.Parameter ? root.parent : root; + const memberDeclaration = root.kind === SyntaxKind.ParameterDeclaration ? root.parent : root; return isPrivateWithinAmbient(memberDeclaration); } @@ -12101,7 +12101,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isBindingElement(decl)) { decl = walkUpBindingElementsAndPatterns(decl); } - if (isParameter(decl)) { + if (isParameterDeclaration(decl)) { return isContextSensitiveFunctionOrObjectLiteralMethod(decl.parent); } return false; @@ -12213,7 +12213,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { type = tryGetTypeFromEffectiveTypeNode(declaration) || checkObjectLiteralMethod(declaration, CheckMode.Normal); } else if ( - isParameter(declaration) + isParameterDeclaration(declaration) || isPropertyDeclaration(declaration) || isPropertySignature(declaration) || isVariableDeclaration(declaration) @@ -12462,7 +12462,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return errorType; } // Check if variable has initializer that circularly references the variable itself - if (noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || (declaration as HasInitializer).initializer)) { + if (noImplicitAny && (declaration.kind !== SyntaxKind.ParameterDeclaration || (declaration as HasInitializer).initializer)) { error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } @@ -15589,14 +15589,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function hasEffectiveQuestionToken(node: ParameterDeclaration | JSDocParameterTag | JSDocPropertyTag) { - return hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag(node) || isParameter(node) && isJSDocOptionalParameter(node); + return hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag(node) || isParameterDeclaration(node) && isJSDocOptionalParameter(node); } function isOptionalParameter(node: ParameterDeclaration | JSDocParameterTag | JSDocPropertyTag) { if (hasEffectiveQuestionToken(node)) { return true; } - if (!isParameter(node)) { + if (!isParameterDeclaration(node)) { return false; } if (node.initializer) { @@ -15729,7 +15729,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Record a new minimum argument count if this is not an optional parameter const isOptionalParameter = hasEffectiveQuestionToken(param) || - isParameter(param) && param.initializer || isRestParameter(param) || + isParameterDeclaration(param) && param.initializer || isRestParameter(param) || iife && parameters.length > iife.arguments.length && !type; if (!isOptionalParameter) { minArgumentCount = parameters.length; @@ -16278,7 +16278,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // When an 'infer T' declaration is immediately contained in a rest parameter declaration, a rest type // or a named rest tuple element, we infer an 'unknown[]' constraint. else if ( - grandParent.kind === SyntaxKind.Parameter && (grandParent as ParameterDeclaration).dotDotDotToken || + grandParent.kind === SyntaxKind.ParameterDeclaration && (grandParent as ParameterDeclaration).dotDotDotToken || grandParent.kind === SyntaxKind.RestType || grandParent.kind === SyntaxKind.NamedTupleMember && (grandParent as NamedTupleMember).dotDotDotToken ) { @@ -16747,7 +16747,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const parent = node.parent; // only consider variance flipped by parameter locations - `keyof` types would usually be considered variance inverting, but // often get used in indexed accesses where they behave sortof invariantly, but our checking is lax - if (parent.kind === SyntaxKind.Parameter) { + if (parent.kind === SyntaxKind.ParameterDeclaration) { covariant = !covariant; } // Always substitute on type parameters, regardless of variance, since even @@ -17226,7 +17226,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function memberIfLabeledElementDeclaration(member: Node): NamedTupleMember | ParameterDeclaration | undefined { - return isNamedTupleMember(member) || isParameter(member) ? member : undefined; + return isNamedTupleMember(member) || isParameterDeclaration(member) ? member : undefined; } // Return true if the given type reference node is directly aliased or if it needs to be deferred @@ -25520,7 +25520,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.PropertySignature: diagnostic = noImplicitAny ? Diagnostics.Member_0_implicitly_has_an_1_type : Diagnostics.Member_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage; break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: const param = declaration as ParameterDeclaration; if (isIdentifier(param.name)) { const originalKeywordKind = identifierToKeywordKind(param.name); @@ -27264,7 +27264,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const name = getDestructuringPropertyName(access); return name ? escapeLeadingUnderscores(name) : undefined; } - if (isParameter(access)) { + if (isParameterDeclaration(access)) { return ("" + access.parent.parameters.indexOf(access)) as __String; } return undefined; @@ -28079,7 +28079,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function isDeclarationWithExplicitTypeAnnotation(node: Declaration) { - return (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isParameter(node)) && + return (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isParameterDeclaration(node)) && !!(getEffectiveTypeAnnotationNode(node) || isInJSFile(node) && hasInitializer(node) && node.initializer && isFunctionExpressionOrArrowFunction(node.initializer) && getEffectiveReturnTypeNode(node.initializer)); } @@ -28359,7 +28359,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: const rootDeclaration = getRootDeclaration(node.parent); - return isParameter(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration) + return isParameterDeclaration(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration) ? !isSomeSymbolAssigned(rootDeclaration) : isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration); } @@ -28840,7 +28840,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isIdentifier(expr)) { const symbol = getResolvedSymbol(expr); const declaration = symbol.valueDeclaration; - if (declaration && (isBindingElement(declaration) || isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) { + if (declaration && (isBindingElement(declaration) || isParameterDeclaration(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) { return declaration; } } @@ -29657,7 +29657,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Check if a parameter or catch variable (or their bindings elements) is assigned anywhere function isSomeSymbolAssigned(rootDeclaration: Node) { - Debug.assert(isVariableDeclaration(rootDeclaration) || isParameter(rootDeclaration)); + Debug.assert(isVariableDeclaration(rootDeclaration) || isParameterDeclaration(rootDeclaration)); return isSomeSymbolAssignedWorker(rootDeclaration.name); } @@ -29758,7 +29758,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Return true if symbol is a parameter, a catch clause variable, or a mutable local variable const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration); return !!declaration && ( - isParameter(declaration) || + isParameterDeclaration(declaration) || isVariableDeclaration(declaration) && (isCatchClause(declaration.parent) || isMutableLocalVariableDeclaration(declaration)) ); } @@ -29796,7 +29796,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { /** remove undefined from the annotated type of a parameter when there is an initializer (that doesn't include undefined) */ function removeOptionalityFromDeclaredType(declaredType: Type, declaration: VariableLikeDeclaration): Type { const removeUndefined = strictNullChecks && - declaration.kind === SyntaxKind.Parameter && + declaration.kind === SyntaxKind.ParameterDeclaration && declaration.initializer && hasTypeFacts(declaredType, TypeFacts.IsUndefined) && !parameterInitializerContainsUndefined(declaration); @@ -30148,7 +30148,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveTypeAnnotationNode(node)); break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); const containingSignature = node.parent; for (const parameter of containingSignature.parameters) { @@ -30300,14 +30300,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) { const parent = declaration.parent.parent; const rootDeclaration = getRootDeclaration(parent); - if (rootDeclaration.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlagsCached(rootDeclaration) & NodeFlags.Constant || rootDeclaration.kind === SyntaxKind.Parameter) { + if (rootDeclaration.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlagsCached(rootDeclaration) & NodeFlags.Constant || rootDeclaration.kind === SyntaxKind.ParameterDeclaration) { const links = getNodeLinks(parent); if (!(links.flags & NodeCheckFlags.InCheckIdentifier)) { links.flags |= NodeCheckFlags.InCheckIdentifier; const parentType = getTypeForBindingElementParent(parent, CheckMode.Normal); const parentTypeConstraint = parentType && mapType(parentType, getBaseConstraintOrType); links.flags &= ~NodeCheckFlags.InCheckIdentifier; - if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.Parameter && isSomeSymbolAssigned(rootDeclaration))) { + if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.ParameterDeclaration && isSomeSymbolAssigned(rootDeclaration))) { const pattern = declaration.parent; const narrowedType = getFlowTypeOfReference(pattern, parentTypeConstraint, parentTypeConstraint, /*flowContainer*/ undefined, location.flowNode); if (narrowedType.flags & TypeFlags.Never) { @@ -30341,7 +30341,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as // if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the // narrowed tuple type. - if (isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) { + if (isParameterDeclaration(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) { const func = declaration.parent; if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) { const contextualSignature = getContextualSignature(func); @@ -30516,7 +30516,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // The declaration container is the innermost function that encloses the declaration of the variable // or parameter. The flow container is the innermost function starting with which we analyze the control // flow graph to determine the control flow based type. - const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter; + const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.ParameterDeclaration; const declarationContainer = getControlFlowContainer(declaration); let flowContainer = getControlFlowContainer(node); const isOuterVariable = flowContainer !== declarationContainer; @@ -30974,7 +30974,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean { - return !!findAncestor(node, n => isFunctionLikeDeclaration(n) ? "quit" : n.kind === SyntaxKind.Parameter && n.parent === constructorDecl); + return !!findAncestor(node, n => isFunctionLikeDeclaration(n) ? "quit" : n.kind === SyntaxKind.ParameterDeclaration && n.parent === constructorDecl); } function checkSuperExpression(node: Node): Type { @@ -31320,7 +31320,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return getTypeFromTypeNode(typeNode); } switch (declaration.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return getContextuallyTypedParameterType(declaration); case SyntaxKind.BindingElement: return getContextualTypeForBindingElement(declaration, contextFlags); @@ -31450,7 +31450,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isInParameterInitializerBeforeContainingFunction(node: Node) { let inBindingInitializer = false; while (node.parent && !isFunctionLike(node.parent)) { - if (isParameter(node.parent) && (inBindingInitializer || node.parent.initializer === node)) { + if (isParameterDeclaration(node.parent) && (inBindingInitializer || node.parent.initializer === node)) { return true; } if (isBindingElement(node.parent) && node.parent.initializer === node) { @@ -32137,7 +32137,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const { parent } = node; switch (parent.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.BindingElement: @@ -35629,7 +35629,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.SetAccessor: // For decorators with only two parameters we supply only two arguments return signature.parameters.length <= 2 ? 2 : 3; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return 3; default: return Debug.fail(); @@ -35676,7 +35676,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const symbol = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*isUse*/ false); const decl = symbol?.valueDeclaration; - if (!decl || !isParameter(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !isNewExpression(decl.parent.parent) || !isIdentifier(decl.parent.parent.expression)) { + if (!decl || !isParameterDeclaration(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !isNewExpression(decl.parent.parent) || !isIdentifier(decl.parent.parent.expression)) { return false; } @@ -36694,7 +36694,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ClassExpression: return Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; case SyntaxKind.PropertyDeclaration: @@ -37607,7 +37607,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getTupleElementLabel(d: ParameterDeclaration | NamedTupleMember | undefined, index: number, elementFlags: ElementFlags, restSymbol?: Symbol): __String; function getTupleElementLabel(d: ParameterDeclaration | NamedTupleMember | undefined, index = 0, elementFlags = ElementFlags.Fixed, restSymbol?: Symbol) { if (!d) { - const restParameter = tryCast(restSymbol?.valueDeclaration, isParameter); + const restParameter = tryCast(restSymbol?.valueDeclaration, isParameterDeclaration); return restParameter ? getTupleElementLabelFromBindingElement(restParameter, index, elementFlags) : `${restSymbol?.escapedName ?? "arg"}_${index}` as __String; } @@ -37675,10 +37675,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getParameterDeclarationIdentifier(symbol: Symbol) { - return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name) && symbol.valueDeclaration.name; + return symbol.valueDeclaration && isParameterDeclaration(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name) && symbol.valueDeclaration.name; } function isValidDeclarationForTupleLabel(d: Declaration): d is NamedTupleMember | (ParameterDeclaration & { name: Identifier; }) { - return d.kind === SyntaxKind.NamedTupleMember || (isParameter(d) && d.name && isIdentifier(d.name)); + return d.kind === SyntaxKind.NamedTupleMember || (isParameterDeclaration(d) && d.name && isIdentifier(d.name)); } function getNameableDeclarationAtPosition(signature: Signature, pos: number) { @@ -38234,7 +38234,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ); break; } - case SyntaxKind.Parameter: { + case SyntaxKind.ParameterDeclaration: { const node = parent as ParameterDeclaration; if ( !isConstructorDeclaration(node.parent) && @@ -40552,7 +40552,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const type = getQuickTypeOfExpression(initializer) || (contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, checkMode || CheckMode.Normal) : checkExpressionCached(initializer, checkMode)); - if (isParameter(isBindingElement(declaration) ? walkUpBindingElementsAndPatterns(declaration) : declaration)) { + if (isParameterDeclaration(isBindingElement(declaration) ? walkUpBindingElementsAndPatterns(declaration) : declaration)) { if (declaration.name.kind === SyntaxKind.ObjectBindingPattern && isObjectLiteralType(type)) { return padObjectLiteralType(type as ObjectType, declaration.name); } @@ -43116,7 +43116,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } // falls through - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: headMessage = Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any; break; @@ -43254,7 +43254,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (legacyDecorators) { checkExternalEmitHelpers(firstDecorator, ExternalEmitHelpers.Decorate); - if (node.kind === SyntaxKind.Parameter) { + if (node.kind === SyntaxKind.ParameterDeclaration) { checkExternalEmitHelpers(firstDecorator, ExternalEmitHelpers.Param); } } @@ -43670,7 +43670,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function tryGetRootParameterDeclaration(node: Node): ParameterDeclaration | undefined { - return tryCast(getRootDeclaration(node), isParameter); + return tryCast(getRootDeclaration(node), isParameterDeclaration); } function isValidUnusedLocalDeclaration(declaration: Declaration): boolean { @@ -43907,7 +43907,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const root = getRootDeclaration(node); - if (isParameter(root) && nodeIsMissing((root.parent as FunctionLikeDeclaration).body)) { + if (isParameterDeclaration(root) && nodeIsMissing((root.parent as FunctionLikeDeclaration).body)) { // just an overload - no codegen impact return false; } @@ -44338,8 +44338,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) { if ( - (left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) || - (left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter) + (left.kind === SyntaxKind.ParameterDeclaration && right.kind === SyntaxKind.VariableDeclaration) || + (left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.ParameterDeclaration) ) { // Differences in optionality between parameters and variables are allowed. return true; @@ -48087,7 +48087,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { switch (kind) { case SyntaxKind.TypeParameter: return checkTypeParameter(node as TypeParameterDeclaration); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return checkParameter(node as ParameterDeclaration); case SyntaxKind.PropertyDeclaration: return checkPropertyDeclaration(node as PropertyDeclaration); @@ -48300,7 +48300,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Only legal location is in the *last* parameter tag or last parameter of a JSDoc function. const { parent } = node; - if (isParameter(parent) && isJSDocFunctionType(parent.parent)) { + if (isParameterDeclaration(parent) && isJSDocFunctionType(parent.parent)) { if (last(parent.parent.parameters) !== parent) { error(node, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); } @@ -48357,7 +48357,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } - if (isParameter(parent) && isJSDocFunctionType(parent.parent)) { + if (isParameterDeclaration(parent) && isJSDocFunctionType(parent.parent)) { return createArrayType(type); } return addOptionality(type); @@ -50123,7 +50123,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ? declaration.expression : !!(declaration as HasInitializer).initializer ? (declaration as HasInitializer & typeof declaration).initializer - : isParameter(declaration) && isSetAccessor(declaration.parent) + : isParameterDeclaration(declaration) && isSetAccessor(declaration.parent) ? getSingleReturnExpression(getAllAccessorDeclarationsForDeclaration(declaration.parent).getAccessor) : undefined; } @@ -50237,7 +50237,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return filter(getExportSymbolOfValueSymbolIfExported(symbol).declarations, declaration => { switch (declaration.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertyAssignment: @@ -50318,7 +50318,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (direct) { return direct; } - if (node.kind === SyntaxKind.Parameter && node.parent.kind === SyntaxKind.SetAccessor) { + if (node.kind === SyntaxKind.ParameterDeclaration && node.parent.kind === SyntaxKind.SetAccessor) { const other = getAllAccessorDeclarationsForDeclaration(node.parent as SetAccessorDeclaration).getAccessor; if (other) { return getEffectiveReturnTypeNode(other); @@ -50705,7 +50705,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return quickResult; } - if (isParameter(node) && parameterIsThisKeyword(node)) { + if (isParameterDeclaration(node) && parameterIsThisKeyword(node)) { return grammarErrorOnFirstToken(node, Diagnostics.Neither_decorators_nor_modifiers_may_be_applied_to_this_parameters); } @@ -50870,7 +50870,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, "static"); } - else if (node.kind === SyntaxKind.Parameter) { + else if (node.kind === SyntaxKind.ParameterDeclaration) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & ModifierFlags.Abstract) { @@ -50904,7 +50904,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (flags & ModifierFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly"); } - else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature && node.kind !== SyntaxKind.Parameter) { + else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature && node.kind !== SyntaxKind.ParameterDeclaration) { // If node.kind === SyntaxKind.Parameter, checkParameter reports an error if it's not a parameter property. return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature); } @@ -50942,7 +50942,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (isClassLike(node.parent)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_class_elements_of_this_kind, "export"); } - else if (node.kind === SyntaxKind.Parameter) { + else if (node.kind === SyntaxKind.ParameterDeclaration) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } else if (blockScopeKind === NodeFlags.Using) { @@ -50986,7 +50986,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (isClassLike(node.parent) && !isPropertyDeclaration(node)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_class_elements_of_this_kind, "declare"); } - else if (node.kind === SyntaxKind.Parameter) { + else if (node.kind === SyntaxKind.ParameterDeclaration) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } else if (blockScopeKind === NodeFlags.Using) { @@ -51060,7 +51060,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (flags & ModifierFlags.Ambient || node.parent.flags & NodeFlags.Ambient) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.kind === SyntaxKind.Parameter) { + else if (node.kind === SyntaxKind.ParameterDeclaration) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } if (flags & ModifierFlags.Abstract) { @@ -51106,10 +51106,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & ModifierFlags.Ambient) { return grammarErrorOnNode(lastDeclare!, Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === SyntaxKind.Parameter && (flags & ModifierFlags.ParameterPropertyModifier) && isBindingPattern(node.name)) { + else if (node.kind === SyntaxKind.ParameterDeclaration && (flags & ModifierFlags.ParameterPropertyModifier) && isBindingPattern(node.name)) { return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern); } - else if (node.kind === SyntaxKind.Parameter && (flags & ModifierFlags.ParameterPropertyModifier) && node.dotDotDotToken) { + else if (node.kind === SyntaxKind.ParameterDeclaration && (flags & ModifierFlags.ParameterPropertyModifier) && node.dotDotDotToken) { return grammarErrorOnNode(node, Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter); } if (flags & ModifierFlags.Async) { @@ -51151,7 +51151,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ExportAssignment: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.TypeParameter: return undefined; case SyntaxKind.ClassStaticBlockDeclaration: diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 42e8637ac178a..81c1ed7c2f4eb 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -42,7 +42,7 @@ import { isNamedTupleMember, isNumericLiteral, isOptionalTypeNode, - isParameter, + isParameterDeclaration, isParenthesizedTypeNode, isParseTreeNode, isPrivateIdentifier, @@ -722,7 +722,7 @@ export namespace Debug { isNumericLiteral(this) ? `NumericLiteral ${this.text}` : isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : - isParameter(this) ? "ParameterDeclaration" : + isParameterDeclaration(this) ? "ParameterDeclaration" : isConstructorDeclaration(this) ? "ConstructorDeclaration" : isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e63bfd783ced2..1771dc7ca691c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1577,7 +1577,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri // Signature elements case SyntaxKind.TypeParameter: return emitTypeParameter(node as TypeParameterDeclaration); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return emitParameter(node as ParameterDeclaration); case SyntaxKind.Decorator: return emitDecorator(node as Decorator); @@ -5298,7 +5298,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri forEach((node as VariableDeclarationList).declarations, generateNames); break; case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.ClassDeclaration: generateNameIfNeeded((node as NamedDeclaration).name); diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 1c6e045f0f0bd..e5dd7af13fb2a 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -89,7 +89,7 @@ export function createSyntacticTypeNodeBuilder( switch (node.kind) { case SyntaxKind.PropertySignature: return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return typeFromParameter(node, context); case SyntaxKind.VariableDeclaration: return typeFromVariable(node, context); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index fbc97d9aa4d9c..1288a6b2e475e 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -192,7 +192,7 @@ import { isObjectLiteralExpression, isOmittedExpression, isOuterExpression, - isParameter, + isParameterDeclaration, isParenthesizedExpression, isParseTreeNode, isPrivateIdentifier, @@ -1649,7 +1649,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type?: TypeNode, initializer?: Expression, ) { - const node = createBaseDeclaration(SyntaxKind.Parameter); + const node = createBaseDeclaration(SyntaxKind.ParameterDeclaration); node.modifiers = asNodeArray(modifiers); node.dotDotDotToken = dotDotDotToken; node.name = asName(name); @@ -7065,7 +7065,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifierArray = modifiers; } return isTypeParameterDeclaration(node) ? updateTypeParameterDeclaration(node, modifierArray, node.name, node.constraint, node.default) : - isParameter(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : + isParameterDeclaration(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : isConstructorTypeNode(node) ? updateConstructorTypeNode1(node, modifierArray, node.typeParameters, node.parameters, node.type) : isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) : isPropertyDeclaration(node) ? updatePropertyDeclaration(node, modifierArray, node.name, node.questionToken ?? node.exclamationToken, node.type, node.initializer) : @@ -7094,7 +7094,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function replaceDecoratorsAndModifiers(node: T, modifiers: readonly ModifierLike[]): T; function replaceDecoratorsAndModifiers(node: HasModifiers & HasDecorators, modifierArray: readonly ModifierLike[]) { - return isParameter(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : + return isParameterDeclaration(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : isPropertyDeclaration(node) ? updatePropertyDeclaration(node, modifierArray, node.name, node.questionToken ?? node.exclamationToken, node.type, node.initializer) : isMethodDeclaration(node) ? updateMethodDeclaration(node, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) : isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, modifierArray, node.name, node.parameters, node.type, node.body) : @@ -7321,7 +7321,7 @@ function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { return TransformFlags.ArrayLiteralOrCallOrNewExcludes; case SyntaxKind.ModuleDeclaration: return TransformFlags.ModuleExcludes; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return TransformFlags.ParameterExcludes; case SyntaxKind.ArrowFunction: return TransformFlags.ArrowFunctionExcludes; diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index 8aa4bb02e83d2..0f7eb73ef506b 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -404,9 +404,8 @@ export function isTypeParameterDeclaration(node: Node): node is TypeParameterDec return node.kind === SyntaxKind.TypeParameter; } -// TODO(rbuckton): Rename to 'isParameterDeclaration' -export function isParameter(node: Node): node is ParameterDeclaration { - return node.kind === SyntaxKind.Parameter; +export function isParameterDeclaration(node: Node): node is ParameterDeclaration { + return node.kind === SyntaxKind.ParameterDeclaration; } export function isDecorator(node: Node): node is Decorator { diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 9f7cc54ef7508..186ab6b4b337d 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -984,7 +984,7 @@ export function getTargetOfBindingOrAssignmentElement(bindingElement: BindingOrA */ export function getRestIndicatorOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): BindingOrAssignmentElementRestIndicator | undefined { switch (bindingElement.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: // `...` in `let [...a] = ...` return bindingElement.dotDotDotToken; diff --git a/src/compiler/factory/utilitiesPublic.ts b/src/compiler/factory/utilitiesPublic.ts index be395a64523a4..38984f54f5d86 100644 --- a/src/compiler/factory/utilitiesPublic.ts +++ b/src/compiler/factory/utilitiesPublic.ts @@ -14,7 +14,7 @@ export function setTextRange(range: T, location: TextRange export function canHaveModifiers(node: Node): node is HasModifiers { const kind = node.kind; return kind === SyntaxKind.TypeParameter - || kind === SyntaxKind.Parameter + || kind === SyntaxKind.ParameterDeclaration || kind === SyntaxKind.PropertySignature || kind === SyntaxKind.PropertyDeclaration || kind === SyntaxKind.MethodSignature @@ -42,7 +42,7 @@ export function canHaveModifiers(node: Node): node is HasModifiers { export function canHaveDecorators(node: Node): node is HasDecorators { const kind = node.kind; - return kind === SyntaxKind.Parameter + return kind === SyntaxKind.ParameterDeclaration || kind === SyntaxKind.PropertyDeclaration || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.GetAccessor diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1f007410f11c5..53bf16a46d238 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -524,7 +524,7 @@ const forEachChildTable: ForEachChildTable = { [SyntaxKind.SpreadAssignment]: function forEachChildInSpreadAssignment(node: SpreadAssignment, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.expression); }, - [SyntaxKind.Parameter]: function forEachChildInParameter(node: ParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + [SyntaxKind.ParameterDeclaration]: function forEachChildInParameter(node: ParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { return visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, node.dotDotDotToken) || visitNode(cbNode, node.name) || @@ -3389,7 +3389,7 @@ namespace Parser { } function isReusableParameter(node: Node) { - if (node.kind !== SyntaxKind.Parameter) { + if (node.kind !== SyntaxKind.ParameterDeclaration) { return false; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ad18f43b29e35..350deb1929a15 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -205,7 +205,7 @@ import { isModifier, isModuleDeclaration, isObjectLiteralExpression, - isParameter, + isParameterDeclaration, isPlainJsFile, isRequireCall, isRootedDiskPath, @@ -3147,7 +3147,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg // Otherwise break to visit each child switch (parent.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: if ((parent as ParameterDeclaration | PropertyDeclaration | MethodDeclaration).questionToken === node) { @@ -3256,7 +3256,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg else if (canHaveDecorators(parent) && parent.modifiers) { const decoratorIndex = findIndex(parent.modifiers, isDecorator); if (decoratorIndex >= 0) { - if (isParameter(parent) && !options.experimentalDecorators) { + if (isParameterDeclaration(parent) && !options.experimentalDecorators) { // report illegall decorator on parameter diagnostics.push(createDiagnosticForNode(parent.modifiers[decoratorIndex], Diagnostics.Decorators_are_not_valid_here)); } @@ -3321,7 +3321,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg return "skip"; } break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // Check modifiers of parameter declaration if (nodes === (parent as ParameterDeclaration).modifiers && some(nodes, isModifier)) { diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.Parameter_modifiers_can_only_be_used_in_TypeScript_files)); diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 7d8bc6f8eab22..95f881be4da9e 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -120,7 +120,7 @@ import { isObjectLiteralElementLike, isObjectLiteralExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, isPrefixUnaryExpression, @@ -478,7 +478,7 @@ export function transformClassFields(context: TransformationContext): (x: Source return visitVariableStatement(node as VariableStatement); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node as VariableDeclaration); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return visitParameterDeclaration(node as ParameterDeclaration); case SyntaxKind.BindingElement: return visitBindingElement(node as BindingElement); @@ -2460,7 +2460,7 @@ export function transformClassFields(context: TransformationContext): (x: Source setCommentRange(statement, property); const propertyOriginalNode = getOriginalNode(property); - if (isParameter(propertyOriginalNode)) { + if (isParameterDeclaration(propertyOriginalNode)) { // replicate comment and source map behavior from the ts transform for parameter properties. setSourceMapRange(statement, propertyOriginalNode); removeAllComments(statement); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index ba19f34fe0af9..586c6b41bd1ce 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -678,7 +678,7 @@ export function transformDeclarations(context: TransformationContext): Transform // Literal const declarations will have an initializer ensured rather than a type return; } - const shouldAddImplicitUndefined = node.kind === SyntaxKind.Parameter && resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration); + const shouldAddImplicitUndefined = node.kind === SyntaxKind.ParameterDeclaration && resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration); if (type && !shouldAddImplicitUndefined) { return visitNode(type, visitDeclarationSubtree, isTypeNode); } @@ -691,7 +691,7 @@ export function transformDeclarations(context: TransformationContext): Transform } let typeNode; switch (node.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.PropertyDeclaration: case SyntaxKind.BindingElement: @@ -1914,7 +1914,7 @@ function canHaveLiteralInitializer(node: Node): node is CanHaveLiteralInitialize case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: return !hasEffectiveModifier(node, ModifierFlags.Private); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.VariableDeclaration: return true; } diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 7e2978d9c59b8..88eb209672867 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -55,7 +55,7 @@ import { isJSDocTypeAlias, isMethodDeclaration, isMethodSignature, - isParameter, + isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, isPartOfTypeNode, @@ -147,7 +147,7 @@ export function canProduceDiagnostics(node: Node): node is DeclarationDiagnostic isMethodDeclaration(node) || isMethodSignature(node) || isFunctionDeclaration(node) || - isParameter(node) || + isParameterDeclaration(node) || isTypeParameterDeclaration(node) || isExpressionWithTypeArguments(node) || isImportEqualsDeclaration(node) || @@ -245,7 +245,7 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD else if (isConstructSignatureDeclaration(node) || isCallSignatureDeclaration(node) || isMethodDeclaration(node) || isMethodSignature(node) || isFunctionDeclaration(node) || isIndexSignatureDeclaration(node)) { return getReturnTypeVisibilityError; } - else if (isParameter(node)) { + else if (isParameterDeclaration(node)) { if (isParameterPropertyDeclaration(node, node.parent) && hasSyntacticModifier(node.parent, ModifierFlags.Private)) { return getVariableDeclarationTypeVisibilityError; } @@ -279,7 +279,7 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD // The only exception here is if the constructor was marked as private. we are not emitting the constructor parameters at all. else if ( node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression || node.kind === SyntaxKind.BinaryExpression || node.kind === SyntaxKind.PropertySignature || - (node.kind === SyntaxKind.Parameter && hasSyntacticModifier(node.parent, ModifierFlags.Private)) + (node.kind === SyntaxKind.ParameterDeclaration && hasSyntacticModifier(node.parent, ModifierFlags.Private)) ) { // TODO(jfreeman): Deal with computed properties in error reporting. if (isStatic(node)) { @@ -289,7 +289,7 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.Parameter) { + else if (node.parent.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ParameterDeclaration) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -612,7 +612,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod [SyntaxKind.SetAccessor]: Diagnostics.Add_a_type_to_parameter_of_the_set_accessor_declaration, [SyntaxKind.FunctionDeclaration]: Diagnostics.Add_a_return_type_to_the_function_declaration, [SyntaxKind.ConstructSignature]: Diagnostics.Add_a_return_type_to_the_function_declaration, - [SyntaxKind.Parameter]: Diagnostics.Add_a_type_annotation_to_the_parameter_0, + [SyntaxKind.ParameterDeclaration]: Diagnostics.Add_a_type_annotation_to_the_parameter_0, [SyntaxKind.VariableDeclaration]: Diagnostics.Add_a_type_annotation_to_the_variable_0, [SyntaxKind.PropertyDeclaration]: Diagnostics.Add_a_type_annotation_to_the_property_0, [SyntaxKind.PropertySignature]: Diagnostics.Add_a_type_annotation_to_the_property_0, @@ -627,7 +627,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod [SyntaxKind.ConstructSignature]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, [SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, [SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.Parameter]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ParameterDeclaration]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations, [SyntaxKind.VariableDeclaration]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations, [SyntaxKind.PropertyDeclaration]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, [SyntaxKind.PropertySignature]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, @@ -692,7 +692,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod case SyntaxKind.PropertyDeclaration: case SyntaxKind.VariableDeclaration: return createVariableOrPropertyError(node); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return createParameterError(node); case SyntaxKind.PropertyAssignment: return createExpressionError(node.initializer); @@ -705,7 +705,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod } function findNearestDeclaration(node: Node) { - const result = findAncestor(node, n => isExportAssignment(n) || isStatement(n) || isVariableDeclaration(n) || isPropertyDeclaration(n) || isParameter(n)); + const result = findAncestor(node, n => isExportAssignment(n) || isStatement(n) || isVariableDeclaration(n) || isPropertyDeclaration(n) || isParameterDeclaration(n)); if (!result) return undefined; if (isExportAssignment(result)) return result; diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 5b29d34da9387..74d1806e32abc 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -641,7 +641,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile case SyntaxKind.ClassExpression: return visitClassExpression(node as ClassExpression); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return visitParameter(node as ParameterDeclaration); case SyntaxKind.FunctionDeclaration: diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index 3a80a84334eef..edeb0bd0532a1 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -217,7 +217,7 @@ export function transformES2017(context: TransformationContext): (x: SourceFile case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: return node; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.VariableDeclaration: break; diff --git a/src/compiler/transformers/es2018.ts b/src/compiler/transformers/es2018.ts index c8894d336af1c..dea2ec78a20f3 100644 --- a/src/compiler/transformers/es2018.ts +++ b/src/compiler/transformers/es2018.ts @@ -59,7 +59,7 @@ import { isModifier, isModifierLike, isObjectLiteralElementLike, - isParameter, + isParameterDeclaration, isPropertyAccessExpression, isPropertyName, isQuestionToken, @@ -361,7 +361,7 @@ export function transformES2018(context: TransformationContext): (x: SourceFile HierarchyFacts.ArrowFunctionExcludes, HierarchyFacts.ArrowFunctionIncludes, ); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return visitParameter(node as ParameterDeclaration); case SyntaxKind.ExpressionStatement: return visitExpressionStatement(node as ExpressionStatement); @@ -939,7 +939,7 @@ export function transformES2018(context: TransformationContext): (x: SourceFile } function parameterVisitor(node: Node) { - Debug.assertNode(node, isParameter); + Debug.assertNode(node, isParameterDeclaration); return visitParameter(node); } diff --git a/src/compiler/transformers/esDecorators.ts b/src/compiler/transformers/esDecorators.ts index 7609ab957a0c5..56815d3fe5742 100644 --- a/src/compiler/transformers/esDecorators.ts +++ b/src/compiler/transformers/esDecorators.ts @@ -104,7 +104,7 @@ import { isObjectLiteralElementLike, isObjectLiteralExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isParenthesizedExpression, isPrivateIdentifier, isPrivateIdentifierClassElementDeclaration, @@ -436,7 +436,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc case SyntaxKind.PropertyDeclaration: case SyntaxKind.ClassStaticBlockDeclaration: return Debug.fail("Not supported outside of a class. Use 'classElementVisitor' instead."); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return visitParameterDeclaration(node as ParameterDeclaration); // Support NamedEvaluation to ensure the correct class name for class expressions. @@ -1195,7 +1195,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc function visitConstructorDeclaration(node: ConstructorDeclaration) { enterClassElement(node); const modifiers = visitNodes(node.modifiers, modifierVisitor, isModifier); - const parameters = visitNodes(node.parameters, visitor, isParameter); + const parameters = visitNodes(node.parameters, visitor, isParameterDeclaration); let body: Block | undefined; if (node.body && classInfo) { // If there are instance extra initializers we need to add them to the body along with any @@ -1415,7 +1415,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc return finishClassElement(createMethodDescriptorForwarder(modifiers, name, descriptorName), node); } else { - const parameters = visitNodes(node.parameters, visitor, isParameter); + const parameters = visitNodes(node.parameters, visitor, isParameterDeclaration); const body = visitNode(node.body, visitor, isBlock); exitClassElement(); return finishClassElement(factory.updateMethodDeclaration(node, modifiers, node.asteriskToken, name, /*questionToken*/ undefined, /*typeParameters*/ undefined, parameters, /*type*/ undefined, body), node); @@ -1430,7 +1430,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc return finishClassElement(createGetAccessorDescriptorForwarder(modifiers, name, descriptorName), node); } else { - const parameters = visitNodes(node.parameters, visitor, isParameter); + const parameters = visitNodes(node.parameters, visitor, isParameterDeclaration); const body = visitNode(node.body, visitor, isBlock); exitClassElement(); return finishClassElement(factory.updateGetAccessorDeclaration(node, modifiers, name, parameters, /*type*/ undefined, body), node); @@ -1445,7 +1445,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc return finishClassElement(createSetAccessorDescriptorForwarder(modifiers, name, descriptorName), node); } else { - const parameters = visitNodes(node.parameters, visitor, isParameter); + const parameters = visitNodes(node.parameters, visitor, isParameterDeclaration); const body = visitNode(node.body, visitor, isBlock); exitClassElement(); return finishClassElement(factory.updateSetAccessorDeclaration(node, modifiers, name, parameters, body), node); @@ -2308,7 +2308,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc modifiers, node.asteriskToken, "value", - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), visitNode(node.body, visitor, isBlock), ), ]); @@ -2342,7 +2342,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc modifiers, /*asteriskToken*/ undefined, "set", - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), visitNode(node.body, visitor, isBlock), ), ]); diff --git a/src/compiler/transformers/legacyDecorators.ts b/src/compiler/transformers/legacyDecorators.ts index 6ef7745dfd301..91a1e5f7fbf96 100644 --- a/src/compiler/transformers/legacyDecorators.ts +++ b/src/compiler/transformers/legacyDecorators.ts @@ -47,7 +47,7 @@ import { isIdentifier, isModifier, isModifierLike, - isParameter, + isParameterDeclaration, isPrivateIdentifier, isPropertyDeclaration, isPropertyName, @@ -143,7 +143,7 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S return visitGetAccessorDeclaration(node as GetAccessorDeclaration); case SyntaxKind.PropertyDeclaration: return visitPropertyDeclaration(node as PropertyDeclaration); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return visitParameterDeclaration(node as ParameterDeclaration); default: return visitEachChild(node, visitor, context); @@ -422,7 +422,7 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S return factory.updateConstructorDeclaration( node, visitNodes(node.modifiers, modifierVisitor, isModifier), - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), visitNode(node.body, visitor, isBlock), ); } @@ -446,7 +446,7 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S Debug.checkDefined(visitNode(node.name, visitor, isPropertyName)), /*questionToken*/ undefined, /*typeParameters*/ undefined, - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), /*type*/ undefined, visitNode(node.body, visitor, isBlock), ), @@ -460,7 +460,7 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S node, visitNodes(node.modifiers, modifierVisitor, isModifier), Debug.checkDefined(visitNode(node.name, visitor, isPropertyName)), - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), /*type*/ undefined, visitNode(node.body, visitor, isBlock), ), @@ -474,7 +474,7 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S node, visitNodes(node.modifiers, modifierVisitor, isModifier), Debug.checkDefined(visitNode(node.name, visitor, isPropertyName)), - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), visitNode(node.body, visitor, isBlock), ), node, diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index be0cf4bdf85c2..75c78f9804d53 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -106,7 +106,7 @@ import { isNamedExports, isObjectLiteralExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isPrefixUnaryExpression, isShorthandPropertyAssignment, isSimpleCopiableExpression, @@ -1719,7 +1719,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile node.asteriskToken, factory.getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), /*type*/ undefined, visitEachChild(node.body, visitor, context), ), diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index c9fd1645345ca..acc35aa6b8d4d 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -78,7 +78,7 @@ import { isNamedExports, isObjectLiteralExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isPrefixUnaryExpression, isPropertyAssignment, isShorthandPropertyAssignment, @@ -806,7 +806,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc node.asteriskToken, factory.getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, visitor, isParameter), + visitNodes(node.parameters, visitor, isParameterDeclaration), /*type*/ undefined, visitNode(node.body, visitor, isBlock), ), diff --git a/src/compiler/transformers/namedEvaluation.ts b/src/compiler/transformers/namedEvaluation.ts index ab10bc1510c96..38e9f25b2bea5 100644 --- a/src/compiler/transformers/namedEvaluation.ts +++ b/src/compiler/transformers/namedEvaluation.ts @@ -475,7 +475,7 @@ export function transformNamedEvaluation(context: TransformationContext, node: N return transformNamedEvaluationOfShorthandAssignmentProperty(context, node, ignoreEmptyStringLiteral, assignedName); case SyntaxKind.VariableDeclaration: return transformNamedEvaluationOfVariableDeclaration(context, node, ignoreEmptyStringLiteral, assignedName); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return transformNamedEvaluationOfParameterDeclaration(context, node, ignoreEmptyStringLiteral, assignedName); case SyntaxKind.BindingElement: return transformNamedEvaluationOfBindingElement(context, node, ignoreEmptyStringLiteral, assignedName); diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 75a6a34a55b1c..a467d29ae1cef 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -767,7 +767,7 @@ export function transformTypeScript(context: TransformationContext): Transformer // TypeScript arrow functions can have modifiers and type annotations. return visitArrowFunction(node as ArrowFunction); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // This may be a parameter declaration with TypeScript syntax extensions. // // TypeScript parameter declaration syntax extensions include: diff --git a/src/compiler/transformers/typeSerializer.ts b/src/compiler/transformers/typeSerializer.ts index 4c9d397b74385..7fa4559456a7a 100644 --- a/src/compiler/transformers/typeSerializer.ts +++ b/src/compiler/transformers/typeSerializer.ts @@ -179,7 +179,7 @@ export function createRuntimeTypeSerializer(context: TransformationContext): Run function serializeTypeOfNode(node: PropertyDeclaration | ParameterDeclaration | AccessorDeclaration | ClassLikeDeclaration | MethodDeclaration, container: ClassLikeDeclaration): SerializedTypeNode { switch (node.kind) { case SyntaxKind.PropertyDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return serializeTypeNode(node.type); case SyntaxKind.SetAccessor: case SyntaxKind.GetAccessor: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6414327a2be5..8f8649cdf5b95 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -230,7 +230,9 @@ export const enum SyntaxKind { ComputedPropertyName, // Signature elements TypeParameter, - Parameter, + ParameterDeclaration, + /** @deprecated Use SyntaxKind.ParameterDeclaration */ + Parameter = ParameterDeclaration, Decorator, // TypeMember PropertySignature, @@ -1888,7 +1890,7 @@ export interface VariableDeclarationList extends Node { // dprint-ignore export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.Parameter; + readonly kind: SyntaxKind.ParameterDeclaration; readonly parent: SignatureDeclaration; readonly modifiers?: NodeArray; readonly dotDotDotToken?: DotDotDotToken; // Present on rest parameter diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c7ade289737ca..44922274cc24a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -340,7 +340,7 @@ import { isObjectLiteralExpression, isOmittedExpression, isOptionalChain, - isParameter, + isParameterDeclaration, isParameterPropertyDeclaration, isParenthesizedExpression, isParenthesizedTypeNode, @@ -2608,7 +2608,7 @@ export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: Sour /** @internal */ export function getJSDocCommentRanges(node: Node, text: string): CommentRange[] | undefined { - const commentRanges = (node.kind === SyntaxKind.Parameter || + const commentRanges = (node.kind === SyntaxKind.ParameterDeclaration || node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction || @@ -2699,7 +2699,7 @@ export function isPartOfTypeNode(node: Node): boolean { return node === (parent as JSDocTemplateTag).constraint; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.VariableDeclaration: return node === (parent as HasType).type; case SyntaxKind.FunctionDeclaration: @@ -2841,7 +2841,7 @@ export function isVariableLike(node: Node): node is VariableLikeDeclaration { switch (node.kind) { case SyntaxKind.BindingElement: case SyntaxKind.EnumMember: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -3067,7 +3067,7 @@ export function getThisContainer(node: Node, includeArrowFunctions: boolean, inc break; case SyntaxKind.Decorator: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) { + if (node.parent.kind === SyntaxKind.ParameterDeclaration && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -3220,7 +3220,7 @@ export function getSuperContainer(node: Node, stopOnFunctions: boolean) { return node as SuperContainerOrFunctions; case SyntaxKind.Decorator: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) { + if (node.parent.kind === SyntaxKind.ParameterDeclaration && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -3358,7 +3358,7 @@ export function nodeCanBeDecorated(useLegacyDecorators: boolean, node: Node, par && parent !== undefined && (useLegacyDecorators ? isClassDeclaration(parent) : isClassLike(parent)); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // TODO(rbuckton): Parameter decorator support for ES decorators must wait until it is standardized if (!useLegacyDecorators) return false; // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target. @@ -3557,7 +3557,7 @@ export function isInExpressionContext(node: Node): boolean { const { parent } = node; switch (parent.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.EnumMember: @@ -4290,7 +4290,7 @@ export function forEachImportClauseDeclaration(node: ImportClause, action: (d /** @internal */ export function hasQuestionToken(node: Node): boolean { switch (node.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.ShorthandPropertyAssignment: @@ -4437,7 +4437,7 @@ export function canHaveJSDoc(node: Node): node is HasJSDoc { case SyntaxKind.NamedTupleMember: case SyntaxKind.NamespaceExportDeclaration: case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.PropertyAssignment: @@ -4499,7 +4499,7 @@ export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): read result = addRange(result, filterOwnedJSDocTags(hostNode, node.jsDoc!)); } - if (node.kind === SyntaxKind.Parameter) { + if (node.kind === SyntaxKind.ParameterDeclaration) { result = addRange(result, (noCache ? getJSDocParameterTagsNoCache : getJSDocParameterTags)(node as ParameterDeclaration)); break; } @@ -5358,7 +5358,7 @@ export function isNamedEvaluationSource(node: Node): node is NamedEvaluationSour return !!(node as ShorthandPropertyAssignment).objectAssignmentInitializer; case SyntaxKind.VariableDeclaration: return isIdentifier((node as VariableDeclaration).name) && !!(node as VariableDeclaration).initializer; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return isIdentifier((node as ParameterDeclaration).name) && !!(node as VariableDeclaration).initializer && !(node as BindingElement).dotDotDotToken; case SyntaxKind.BindingElement: return isIdentifier((node as BindingElement).name) && !!(node as VariableDeclaration).initializer && !(node as BindingElement).dotDotDotToken; @@ -5400,7 +5400,7 @@ export function isNamedEvaluation(node: Node, cb?: (node: AnonymousFunctionDefin case SyntaxKind.ShorthandPropertyAssignment: return isAnonymousFunctionDefinition(node.objectAssignmentInitializer, cb); case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.PropertyDeclaration: return isAnonymousFunctionDefinition(node.initializer, cb); @@ -5427,7 +5427,7 @@ export function isPushOrUnshiftIdentifier(node: Identifier): boolean { */ export function isPartOfParameterDeclaration(node: Declaration): boolean { const root = getRootDeclaration(node); - return root.kind === SyntaxKind.Parameter; + return root.kind === SyntaxKind.ParameterDeclaration; } /** @internal */ @@ -7111,7 +7111,7 @@ export function getSyntacticModifierFlags(node: Node): ModifierFlags { function getRawJSDocModifierFlagsNoCache(node: Node): ModifierFlags { let flags = ModifierFlags.None; - if (!!node.parent && !isParameter(node)) { + if (!!node.parent && !isParameterDeclaration(node)) { if (isInJSFile(node)) { if (getJSDocPublicTagNoCache(node)) flags |= ModifierFlags.JSDocPublic; if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.JSDocPrivate; @@ -10583,7 +10583,7 @@ export function getContainingNodeArray(node: Node): NodeArray | undefined case SyntaxKind.TypeParameter: const { parent } = node as TypeParameterDeclaration; return parent.kind === SyntaxKind.InferType ? undefined : parent.typeParameters; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return (node as ParameterDeclaration).parent.parameters; case SyntaxKind.TemplateLiteralTypeSpan: return (node as TemplateLiteralTypeSpan).parent.templateSpans; @@ -10860,7 +10860,7 @@ export function isOptionalDeclaration(declaration: Declaration): boolean { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: return !!(declaration as PropertyDeclaration | PropertySignature).questionToken; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return !!(declaration as ParameterDeclaration).questionToken || isJSDocOptionalParameter(declaration as ParameterDeclaration); case SyntaxKind.JSDocPropertyTag: case SyntaxKind.JSDocParameterTag: @@ -10980,7 +10980,7 @@ export function getNameFromImportAttribute(node: ImportAttribute): __String { export function isSourceElement(node: Node): boolean { switch (node.kind) { case SyntaxKind.TypeParameter: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.ConstructorType: @@ -11324,7 +11324,7 @@ export function createNameResolver({ // type parameters are visible in parameter list, return type and type parameter list ? !!(lastLocation.flags & NodeFlags.Synthesized) || // Synthetic fake scopes are added for signatures so type parameters are accessible from them lastLocation === (location as FunctionLikeDeclaration).type || - lastLocation.kind === SyntaxKind.Parameter || + lastLocation.kind === SyntaxKind.ParameterDeclaration || lastLocation.kind === SyntaxKind.JSDocParameterTag || lastLocation.kind === SyntaxKind.JSDocReturnTag || lastLocation.kind === SyntaxKind.TypeParameter @@ -11341,11 +11341,11 @@ export function createNameResolver({ // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. - useResult = lastLocation.kind === SyntaxKind.Parameter || + useResult = lastLocation.kind === SyntaxKind.ParameterDeclaration || !!(lastLocation.flags & NodeFlags.Synthesized) || // Synthetic fake scopes are added for signatures so parameters are accessible from them ( lastLocation === (location as FunctionLikeDeclaration).type && - !!findAncestor(result.valueDeclaration, isParameter) + !!findAncestor(result.valueDeclaration, isParameterDeclaration) ); } } @@ -11548,7 +11548,7 @@ export function createNameResolver({ // method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. // } // - if (location.parent && location.parent.kind === SyntaxKind.Parameter) { + if (location.parent && location.parent.kind === SyntaxKind.ParameterDeclaration) { location = location.parent; } // @@ -11578,7 +11578,7 @@ export function createNameResolver({ location = root.parent; } break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: if ( lastLocation && ( lastLocation === (location as ParameterDeclaration).initializer || @@ -11677,7 +11677,7 @@ export function createNameResolver({ const target = getEmitScriptTarget(compilerOptions); const functionLocation = location as FunctionLikeDeclaration; if ( - isParameter(lastLocation) + isParameterDeclaration(lastLocation) && functionLocation.body && result.valueDeclaration && result.valueDeclaration.pos >= functionLocation.body.pos @@ -11766,7 +11766,7 @@ export function createNameResolver({ function isSelfReferenceLocation(node: Node, lastLocation: Node | undefined): node is SelfReferenceLocation { switch (node.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return !!lastLocation && lastLocation === (node as ParameterDeclaration).name; case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: @@ -11834,7 +11834,7 @@ export function unwrapParenthesizedExpression(o: Expression): Expression { export function hasInferredType(node: Node): node is HasInferredType { Debug.type(node); switch (node.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.PropertyDeclaration: case SyntaxKind.BindingElement: diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 462ebc6da06d4..4f2fc556745f5 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -160,7 +160,7 @@ import { isModuleBlock, isNonNullExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isPrivateIdentifier, isPropertyAccessExpression, isPropertyAssignment, @@ -604,7 +604,7 @@ export function getTypeParameterOwner(d: Declaration): Declaration | undefined { export type ParameterPropertyDeclaration = ParameterDeclaration & { parent: ConstructorDeclaration; name: Identifier; }; export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ParameterPropertyDeclaration { - return isParameter(node) && hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) && parent.kind === SyntaxKind.Constructor; + return isParameterDeclaration(node) && hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) && parent.kind === SyntaxKind.Constructor; } export function isEmptyBindingPattern(node: BindingName): node is BindingPattern { @@ -1214,7 +1214,7 @@ export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined { */ export function getJSDocType(node: Node): TypeNode | undefined { let tag: JSDocTypeTag | JSDocParameterTag | undefined = getFirstJSDocTag(node, isJSDocTypeTag); - if (!tag && isParameter(node)) { + if (!tag && isParameterDeclaration(node)) { tag = find(getJSDocParameterTags(node), tag => !!tag.typeExpression); } @@ -1846,7 +1846,7 @@ export function isArrayBindingElement(node: Node): node is ArrayBindingElement { export function isDeclarationBindingElement(bindingElement: BindingOrAssignmentElement): bindingElement is VariableDeclaration | ParameterDeclaration | BindingElement { switch (bindingElement.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: return true; } @@ -1857,7 +1857,7 @@ export function isDeclarationBindingElement(bindingElement: BindingOrAssignmentE /** @internal */ export function isBindingOrAssignmentElement(node: Node): node is BindingOrAssignmentElement { return isVariableDeclaration(node) - || isParameter(node) + || isParameterDeclaration(node) || isObjectBindingOrAssignmentElement(node) || isArrayBindingOrAssignmentElement(node); } @@ -2242,7 +2242,7 @@ export function canHaveSymbol(node: Node): node is Declaration { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.NumericLiteral: case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyDeclaration: @@ -2325,7 +2325,7 @@ function isDeclarationKind(kind: SyntaxKind) { || kind === SyntaxKind.NamespaceExportDeclaration || kind === SyntaxKind.NamespaceImport || kind === SyntaxKind.NamespaceExport - || kind === SyntaxKind.Parameter + || kind === SyntaxKind.ParameterDeclaration || kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.PropertyDeclaration || kind === SyntaxKind.PropertySignature @@ -2554,7 +2554,7 @@ export function hasInitializer(node: Node): node is HasInitializer { export function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer { switch (node.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertyAssignment: @@ -2624,7 +2624,7 @@ function hasInternalAnnotation(range: CommentRange, sourceFile: SourceFile) { export function isInternalDeclaration(node: Node, sourceFile?: SourceFile): boolean { sourceFile ??= getSourceFileOfNode(node); const parseTreeNode = getParseTreeNode(node); - if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) { + if (parseTreeNode && parseTreeNode.kind === SyntaxKind.ParameterDeclaration) { const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration); const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).parameters[paramIdx - 1] : undefined; const text = sourceFile.text; diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index dbd49379e5750..d38abb1f0b387 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -66,7 +66,7 @@ import { isNamedImportBindings, isObjectLiteralElementLike, isOptionalChain, - isParameter, + isParameterDeclaration, isPropertyAccessChain, isPropertyName, isQuestionDotToken, @@ -397,7 +397,7 @@ export function visitParameterList(nodes: NodeArray | unde context.startLexicalEnvironment(); if (nodes) { context.setLexicalEnvironmentFlags(LexicalEnvironmentFlags.InParameters, true); - updated = nodesVisitor(nodes, visitor, isParameter); + updated = nodesVisitor(nodes, visitor, isParameterDeclaration); // As of ES2015, any runtime execution of that occurs in for a parameter (such as evaluating an // initializer or a binding pattern), occurs in its own lexical scope. As a result, any expression @@ -647,7 +647,7 @@ const visitEachChildTable: VisitEachChildTable = { ); }, - [SyntaxKind.Parameter]: function visitEachChildOfParameterDeclaration(node, visitor, context, nodesVisitor, nodeVisitor, tokenVisitor) { + [SyntaxKind.ParameterDeclaration]: function visitEachChildOfParameterDeclaration(node, visitor, context, nodesVisitor, nodeVisitor, tokenVisitor) { return context.factory.updateParameterDeclaration( node, nodesVisitor(node.modifiers, visitor, isModifierLike), @@ -696,7 +696,7 @@ const visitEachChildTable: VisitEachChildTable = { Debug.checkDefined(nodeVisitor(node.name, visitor, isPropertyName)), tokenVisitor ? nodeVisitor(node.questionToken, tokenVisitor, isQuestionToken) : node.questionToken, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), nodeVisitor(node.type, visitor, isTypeNode), ); }, @@ -758,7 +758,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateCallSignature( node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), nodeVisitor(node.type, visitor, isTypeNode), ); }, @@ -767,7 +767,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateConstructSignature( node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), nodeVisitor(node.type, visitor, isTypeNode), ); }, @@ -776,7 +776,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateIndexSignature( node, nodesVisitor(node.modifiers, visitor, isModifierLike), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), Debug.checkDefined(nodeVisitor(node.type, visitor, isTypeNode)), ); }, @@ -803,7 +803,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateFunctionTypeNode( node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), Debug.checkDefined(nodeVisitor(node.type, visitor, isTypeNode)), ); }, @@ -813,7 +813,7 @@ const visitEachChildTable: VisitEachChildTable = { node, nodesVisitor(node.modifiers, visitor, isModifier), nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), - nodesVisitor(node.parameters, visitor, isParameter), + nodesVisitor(node.parameters, visitor, isParameterDeclaration), Debug.checkDefined(nodeVisitor(node.type, visitor, isTypeNode)), ); }, diff --git a/src/deprecatedCompat/5.5/isParameter.ts b/src/deprecatedCompat/5.5/isParameter.ts new file mode 100644 index 0000000000000..54304c4dec21b --- /dev/null +++ b/src/deprecatedCompat/5.5/isParameter.ts @@ -0,0 +1,20 @@ +import { + Node, + ParameterDeclaration, + SyntaxKind, +} from "../_namespaces/ts.js"; +import { deprecate } from "../deprecate.js"; + +// DEPRECATION: Renamed node tests +// DEPRECATION PLAN: +// - soft: 5.6 +// - warn: 5.7 +// - error: TBD +/** @deprecated Use `isParameterDeclaration` instead. */ +export const isParameter: (node: Node) => node is ParameterDeclaration = deprecate(function isParameter(node: Node): node is ParameterDeclaration { + return node.kind === SyntaxKind.ParameterDeclaration; +}, { + since: "5.6", + warnAfter: "5.7", + message: "Use `isParameterDeclaration` instead.", +}); diff --git a/src/deprecatedCompat/_namespaces/ts.ts b/src/deprecatedCompat/_namespaces/ts.ts index 0d062e9bc024d..51812e3f178f6 100644 --- a/src/deprecatedCompat/_namespaces/ts.ts +++ b/src/deprecatedCompat/_namespaces/ts.ts @@ -2,3 +2,4 @@ export * from "../../compiler/_namespaces/ts.js"; export * from "../deprecations.js"; +export * from "../5.5/isParameter.js"; diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index b3e53fed929b5..a34750cf6de7f 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -162,7 +162,7 @@ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: num case SyntaxKind.PropertySignature: return spanInVariableDeclaration(node as VariableDeclaration | PropertyDeclaration | PropertySignature); - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return spanInParameterDeclaration(node as ParameterDeclaration); case SyntaxKind.FunctionDeclaration: @@ -428,7 +428,7 @@ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: num } break; case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: { + case SyntaxKind.ParameterDeclaration: { // initializer of variable/parameter declaration go to previous node const { initializer, type } = node.parent as VariableDeclaration | ParameterDeclaration; if (initializer === node || type === node || isAssignmentOperator(node.kind)) { @@ -779,7 +779,7 @@ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: num if ( isFunctionLike(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment || - node.parent.kind === SyntaxKind.Parameter + node.parent.kind === SyntaxKind.ParameterDeclaration ) { return spanInPreviousNode(node); } diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index 77a3b4698e2c0..041b2557c3843 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -541,7 +541,7 @@ function createCallSiteCollector(program: Program, callSites: CallSite[]): (node collect((node as TypeAssertion | AsExpression).expression); return; case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // do not descend into the type of a variable or parameter declaration collect((node as VariableDeclaration | ParameterDeclaration).name); collect((node as VariableDeclaration | ParameterDeclaration).initializer); diff --git a/src/services/classifier.ts b/src/services/classifier.ts index cf2b087aeb85f..9695fbcc240f0 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -1128,7 +1128,7 @@ export function getEncodedSyntacticClassifications(cancellationToken: Cancellati if ( parent.kind === SyntaxKind.VariableDeclaration || parent.kind === SyntaxKind.PropertyDeclaration || - parent.kind === SyntaxKind.Parameter || + parent.kind === SyntaxKind.ParameterDeclaration || parent.kind === SyntaxKind.JsxAttribute ) { return ClassificationType.operator; @@ -1195,7 +1195,7 @@ export function getEncodedSyntacticClassifications(cancellationToken: Cancellati return ClassificationType.moduleName; } return; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: if ((token.parent as ParameterDeclaration).name === token) { return isThisIdentifier(token) ? ClassificationType.keyword : ClassificationType.parameterName; } diff --git a/src/services/classifier2020.ts b/src/services/classifier2020.ts index 529b0adc03563..1727026a1f67f 100644 --- a/src/services/classifier2020.ts +++ b/src/services/classifier2020.ts @@ -294,7 +294,7 @@ function isRightSideOfQualifiedNameOrPropertyAccess(node: Node): boolean { const tokenFromDeclarationMapping = new Map([ [SyntaxKind.VariableDeclaration, TokenType.variable], - [SyntaxKind.Parameter, TokenType.parameter], + [SyntaxKind.ParameterDeclaration, TokenType.parameter], [SyntaxKind.PropertyDeclaration, TokenType.property], [SyntaxKind.ModuleDeclaration, TokenType.namespace], [SyntaxKind.EnumDeclaration, TokenType.enum], diff --git a/src/services/codefixes/addNameToNamelessParameter.ts b/src/services/codefixes/addNameToNamelessParameter.ts index d8e5e24e1cdd6..7b61e427aba7f 100644 --- a/src/services/codefixes/addNameToNamelessParameter.ts +++ b/src/services/codefixes/addNameToNamelessParameter.ts @@ -13,7 +13,7 @@ import { Identifier, isArrayBindingPattern, isArrayTypeNode, - isParameter, + isParameterDeclaration, ParameterDeclaration, SourceFile, SyntaxKind, @@ -36,7 +36,7 @@ registerCodeFix({ function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, start: number) { const token = getTokenAtPosition(sourceFile, start); const param = token.parent; - if (!isParameter(param)) { + if (!isParameterDeclaration(param)) { return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind)); } @@ -68,7 +68,7 @@ function tryGetNextParam(sourceFile: SourceFile, param: ParameterDeclaration) { const nextToken = findNextToken(param.name, param.parent, sourceFile); if ( nextToken && nextToken.kind === SyntaxKind.OpenBracketToken - && isArrayBindingPattern(nextToken.parent) && isParameter(nextToken.parent.parent) + && isArrayBindingPattern(nextToken.parent) && isParameterDeclaration(nextToken.parent.parent) ) { return nextToken.parent.parent; } diff --git a/src/services/codefixes/annotateWithTypeFromJSDoc.ts b/src/services/codefixes/annotateWithTypeFromJSDoc.ts index 72a9cd7d19297..bac1b9639f37f 100644 --- a/src/services/codefixes/annotateWithTypeFromJSDoc.ts +++ b/src/services/codefixes/annotateWithTypeFromJSDoc.ts @@ -21,7 +21,7 @@ import { isIdentifier, isJSDocIndexSignature, isOptionalJSDocPropertyLikeTag, - isParameter, + isParameterDeclaration, isTypeNode, JSDocFunctionType, JSDocNonNullableType, @@ -68,7 +68,7 @@ registerCodeFix({ function getDeclaration(file: SourceFile, pos: number): DeclarationWithType | undefined { const name = getTokenAtPosition(file, pos); // For an arrow function with no name, 'name' lands on the first parameter. - return tryCast(isParameter(name.parent) ? name.parent.parent : name.parent, parameterShouldGetTypeFromJSDoc); + return tryCast(isParameterDeclaration(name.parent) ? name.parent.parent : name.parent, parameterShouldGetTypeFromJSDoc); } /** @internal */ diff --git a/src/services/codefixes/convertToAsyncFunction.ts b/src/services/codefixes/convertToAsyncFunction.ts index 07ac83e40ea19..3e11a439bf098 100644 --- a/src/services/codefixes/convertToAsyncFunction.ts +++ b/src/services/codefixes/convertToAsyncFunction.ts @@ -53,7 +53,7 @@ import { isInJSFile, isObjectBindingPattern, isOmittedExpression, - isParameter, + isParameterDeclaration, isPropertyAccessExpression, isReturnStatement, isReturnStatementWithFixablePromiseHandler, @@ -309,10 +309,10 @@ function renameCollidingVarNames(nodeToRename: FunctionLikeDeclaration, checker: // will eventually become // const response = await fetch('...') // so we push an entry for 'response'. - if (lastCallSignature && !isParameter(node.parent) && !isFunctionLikeDeclaration(node.parent) && !synthNamesMap.has(symbolIdString)) { + if (lastCallSignature && !isParameterDeclaration(node.parent) && !isFunctionLikeDeclaration(node.parent) && !synthNamesMap.has(symbolIdString)) { const firstParameter = firstOrUndefined(lastCallSignature.parameters); const ident = firstParameter?.valueDeclaration - && isParameter(firstParameter.valueDeclaration) + && isParameterDeclaration(firstParameter.valueDeclaration) && tryCast(firstParameter.valueDeclaration.name, isIdentifier) || factory.createUniqueName("result", GeneratedIdentifierFlags.Optimistic); const synthName = getNewNameIfConflict(ident, collidingSymbolMap); @@ -320,7 +320,7 @@ function renameCollidingVarNames(nodeToRename: FunctionLikeDeclaration, checker: collidingSymbolMap.add(ident.text, symbol); } // We only care about identifiers that are parameters, variable declarations, or binding elements - else if (node.parent && (isParameter(node.parent) || isVariableDeclaration(node.parent) || isBindingElement(node.parent))) { + else if (node.parent && (isParameterDeclaration(node.parent) || isVariableDeclaration(node.parent) || isBindingElement(node.parent))) { const originalName = node.text; const collidingSymbols = collidingSymbolMap.get(originalName); diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 77bec1ed7f173..6b30c0297a861 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -74,7 +74,7 @@ import { isMethodSignature, isModuleDeclaration, isObjectLiteralExpression, - isParameter, + isParameterDeclaration, isPrivateIdentifier, isPropertyAccessExpression, isPropertyDeclaration, @@ -313,7 +313,7 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch if (!(signature && signature.declaration && signature.parameters[argIndex])) return undefined; const param = signature.parameters[argIndex].valueDeclaration; - if (!(param && isParameter(param) && isIdentifier(param.name))) return undefined; + if (!(param && isParameterDeclaration(param) && isIdentifier(param.name))) return undefined; const properties = arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getParameterType(signature, argIndex), /*requireOptionalProperties*/ false, /*matchDiscriminantProperties*/ false)); if (!length(properties)) return undefined; diff --git a/src/services/codefixes/fixAddMissingParam.ts b/src/services/codefixes/fixAddMissingParam.ts index 65c9cf861586e..a33b7256ad75f 100644 --- a/src/services/codefixes/fixAddMissingParam.ts +++ b/src/services/codefixes/fixAddMissingParam.ts @@ -30,7 +30,7 @@ import { isAccessExpression, isCallExpression, isIdentifier, - isParameter, + isParameterDeclaration, isPropertyDeclaration, isSourceFileFromLibrary, isVariableDeclaration, @@ -215,7 +215,7 @@ function tryGetName(node: FunctionLikeDeclaration) { if ( isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) || isPropertyDeclaration(node.parent) || - isParameter(node.parent) + isParameterDeclaration(node.parent) ) { return node.parent.name; } diff --git a/src/services/codefixes/fixAddVoidToPromise.ts b/src/services/codefixes/fixAddVoidToPromise.ts index a9061b9d24ca7..53b475fe08043 100644 --- a/src/services/codefixes/fixAddVoidToPromise.ts +++ b/src/services/codefixes/fixAddVoidToPromise.ts @@ -14,7 +14,7 @@ import { isIdentifier, isInJSFile, isNewExpression, - isParameter, + isParameterDeclaration, isParenthesizedExpression, isParenthesizedTypeNode, isTypeReferenceNode, @@ -60,7 +60,7 @@ function makeChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, // decl should be `new Promise(() => {})` const decl = symbol?.valueDeclaration; - if (!decl || !isParameter(decl) || !isNewExpression(decl.parent.parent)) return; + if (!decl || !isParameterDeclaration(decl) || !isNewExpression(decl.parent.parent)) return; // no need to make this change if we have already seen this parameter. if (seen?.has(decl)) return; diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 7d3983db3d48d..80a8a758b84b5 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -106,7 +106,7 @@ function isTypeContainer(node: Node): node is TypeContainer { case SyntaxKind.MappedType: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.SetAccessor: diff --git a/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts b/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts index bc0a14dbfac51..bff4632a59033 100644 --- a/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts +++ b/src/services/codefixes/fixMissingTypeAnnotationOnExports.ts @@ -69,7 +69,7 @@ import { isObjectBindingPattern, isObjectLiteralExpression, isOmittedExpression, - isParameter, + isParameterDeclaration, isPropertyAssignment, isPropertyDeclaration, isShorthandPropertyAssignment, @@ -148,7 +148,7 @@ const canHaveTypeAnnotation = new Set([ SyntaxKind.FunctionExpression, SyntaxKind.ArrowFunction, SyntaxKind.VariableDeclaration, - SyntaxKind.Parameter, + SyntaxKind.ParameterDeclaration, SyntaxKind.ExportAssignment, SyntaxKind.ClassDeclaration, SyntaxKind.ObjectBindingPattern, @@ -527,7 +527,7 @@ function withContext( fixedNodes?.add(node); switch (node.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.VariableDeclaration: return addTypeToVariableLike(node as ParameterDeclaration | PropertyDeclaration | VariableDeclaration); @@ -916,7 +916,7 @@ function withContext( } const enclosingDeclaration = findAncestor(node, isDeclaration) ?? sourceFile; - if (isParameter(node) && typeChecker.requiresAddingImplicitUndefined(node, enclosingDeclaration)) { + if (isParameterDeclaration(node) && typeChecker.requiresAddingImplicitUndefined(node, enclosingDeclaration)) { type = typeChecker.getUnionType([typeChecker.getUndefinedType(), type], UnionReduction.None); } return { @@ -1052,7 +1052,7 @@ function withContext( } function relativeType(node: Node): InferenceResult { - if (isParameter(node)) { + if (isParameterDeclaration(node)) { return emptyInferenceResult; } if (isShorthandPropertyAssignment(node)) { diff --git a/src/services/codefixes/fixOverrideModifier.ts b/src/services/codefixes/fixOverrideModifier.ts index 360c7eda51c61..45eb739913049 100644 --- a/src/services/codefixes/fixOverrideModifier.ts +++ b/src/services/codefixes/fixOverrideModifier.ts @@ -211,7 +211,7 @@ function isClassElementLikeHasJSDoc(node: Node): node is ClassElementLikeHasJSDo case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return true; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return isParameterPropertyDeclaration(node, node.parent); default: return false; diff --git a/src/services/codefixes/fixUnusedIdentifier.ts b/src/services/codefixes/fixUnusedIdentifier.ts index 1974e8067a45f..9c32e529a1ba0 100644 --- a/src/services/codefixes/fixUnusedIdentifier.ts +++ b/src/services/codefixes/fixUnusedIdentifier.ts @@ -42,7 +42,7 @@ import { isMethodSignature, isModifier, isObjectBindingPattern, - isParameter, + isParameterDeclaration, isPostfixUnaryExpression, isPrefixUnaryExpression, isPropertyAccessExpression, @@ -109,7 +109,7 @@ registerCodeFix({ } if (isObjectBindingPattern(token.parent) || isArrayBindingPattern(token.parent)) { - if (isParameter(token.parent.parent)) { + if (isParameterDeclaration(token.parent.parent)) { const elements = token.parent.elements; const diagnostic: [DiagnosticMessage, string] = [ elements.length > 1 ? Diagnostics.Remove_unused_declarations_for_Colon_0 : Diagnostics.Remove_unused_declaration_for_Colon_0, @@ -190,7 +190,7 @@ registerCodeFix({ if (token.parent.parent.initializer) { break; } - else if (!isParameter(token.parent.parent) || isNotProvidedArguments(token.parent.parent, checker, sourceFiles)) { + else if (!isParameterDeclaration(token.parent.parent) || isNotProvidedArguments(token.parent.parent, checker, sourceFiles)) { changes.delete(sourceFile, token.parent.parent); } } @@ -280,7 +280,7 @@ function tryPrefixDeclaration(changes: textChanges.ChangeTracker, errorCode: num } if (isIdentifier(token) && canPrefix(token)) { changes.replaceNode(sourceFile, token, factory.createIdentifier(`_${token.text}`)); - if (isParameter(token.parent)) { + if (isParameterDeclaration(token.parent)) { getJSDocParameterTags(token.parent).forEach(tag => { if (isIdentifier(tag.name)) { changes.replaceNode(sourceFile, tag.name, factory.createIdentifier(`_${tag.name.text}`)); @@ -292,7 +292,7 @@ function tryPrefixDeclaration(changes: textChanges.ChangeTracker, errorCode: num function canPrefix(token: Identifier): boolean { switch (token.parent.kind) { - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.TypeParameter: return true; case SyntaxKind.VariableDeclaration: { @@ -321,7 +321,7 @@ function tryDeleteDeclaration(sourceFile: SourceFile, token: Node, changes: text function tryDeleteDeclarationWorker(token: Node, changes: textChanges.ChangeTracker, sourceFile: SourceFile, checker: TypeChecker, sourceFiles: readonly SourceFile[], program: Program, cancellationToken: CancellationToken, isFixAll: boolean): void { const { parent } = token; - if (isParameter(parent)) { + if (isParameterDeclaration(parent)) { tryDeleteParameter(changes, sourceFile, parent, checker, sourceFiles, program, cancellationToken, isFixAll); } else if (!(isFixAll && isIdentifier(token) && FindAllReferences.Core.isSymbolReferencedInFile(token, checker, sourceFile))) { diff --git a/src/services/codefixes/generateAccessors.ts b/src/services/codefixes/generateAccessors.ts index 75837f080749f..a02d25f7a0696 100644 --- a/src/services/codefixes/generateAccessors.ts +++ b/src/services/codefixes/generateAccessors.ts @@ -201,7 +201,7 @@ export function getAccessorConvertiblePropertyAtPosition(file: SourceFile, progr isStatic: hasStaticModifier(declaration), isReadonly: hasEffectiveReadonlyModifier(declaration), type: getDeclarationType(declaration, program), - container: declaration.kind === SyntaxKind.Parameter ? declaration.parent.parent : declaration.parent, + container: declaration.kind === SyntaxKind.ParameterDeclaration ? declaration.parent.parent : declaration.parent, originalName: (declaration.name as AcceptedNameType).text, declaration, fieldName, diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 620542686acab..2352d414616b9 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -53,7 +53,7 @@ import { isGetAccessorDeclaration, isIdentifier, isInJSFile, - isParameter, + isParameterDeclaration, isParameterPropertyModifier, isPropertyAccessExpression, isPropertyDeclaration, @@ -277,7 +277,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, to // falls through case Diagnostics.Rest_parameter_0_implicitly_has_an_any_type.code: if (markSeen(containingFunction)) { - const param = cast(parent, isParameter); + const param = cast(parent, isParameterDeclaration); annotateParameters(changes, importAdder, sourceFile, param, containingFunction, program, host, cancellationToken); declaration = param; } diff --git a/src/services/codefixes/returnValueCorrect.ts b/src/services/codefixes/returnValueCorrect.ts index b021eb9f8105c..6f6a5ffcd23a5 100644 --- a/src/services/codefixes/returnValueCorrect.ts +++ b/src/services/codefixes/returnValueCorrect.ts @@ -239,7 +239,7 @@ function getInfo(checker: TypeChecker, sourceFile: SourceFile, position: number, function getVariableLikeInitializer(declaration: VariableLikeDeclaration): Expression | undefined { switch (declaration.kind) { case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertyAssignment: diff --git a/src/services/completions.ts b/src/services/completions.ts index 3291902986fa0..b0b3fc107be8b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -222,7 +222,7 @@ import { isObjectBindingPattern, isObjectLiteralExpression, isObjectTypeDeclaration, - isParameter, + isParameterDeclaration, isParameterPropertyModifier, isPartOfTypeNode, isPossiblyTypeArgumentPosition, @@ -2754,7 +2754,7 @@ export function getCompletionEntriesFromSymbols( // `function f(a: T, b: T2) { }` const symbolDeclaration = symbol.valueDeclaration ?? symbol.declarations?.[0]; if (closestSymbolDeclaration && symbolDeclaration) { - if (isParameter(closestSymbolDeclaration) && isParameter(symbolDeclaration)) { + if (isParameterDeclaration(closestSymbolDeclaration) && isParameterDeclaration(symbolDeclaration)) { const parameters = closestSymbolDeclaration.parent.parameters; if (symbolDeclaration.pos >= closestSymbolDeclaration.pos && symbolDeclaration.pos < parameters.end) { return false; @@ -4105,7 +4105,7 @@ function getCompletionData( case SyntaxKind.ColonToken: return parentKind === SyntaxKind.PropertyDeclaration || parentKind === SyntaxKind.PropertySignature || - parentKind === SyntaxKind.Parameter || + parentKind === SyntaxKind.ParameterDeclaration || parentKind === SyntaxKind.VariableDeclaration || isFunctionLikeKind(parentKind); @@ -4582,7 +4582,7 @@ function getCompletionData( // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed - // type of parameter will flow in from the contextual type of the function let canGetType = hasInitializer(rootDeclaration) || !!getEffectiveTypeAnnotationNode(rootDeclaration) || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement; - if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) { + if (!canGetType && rootDeclaration.kind === SyntaxKind.ParameterDeclaration) { if (isExpression(rootDeclaration.parent)) { canGetType = !!typeChecker.getContextualType(rootDeclaration.parent as Expression); } @@ -4779,7 +4779,7 @@ function getCompletionData( } function isConstructorParameterCompletion(node: Node): boolean { - return !!node.parent && isParameter(node.parent) && isConstructorDeclaration(node.parent.parent) + return !!node.parent && isParameterDeclaration(node.parent) && isConstructorDeclaration(node.parent.parent) && (isParameterPropertyModifier(node.kind) || isDeclarationName(node)); } @@ -4945,13 +4945,13 @@ function getCompletionData( return containingNodeKind === SyntaxKind.PropertyDeclaration && !isClassLike(parent.parent); case SyntaxKind.DotDotDotToken: - return containingNodeKind === SyntaxKind.Parameter || + return containingNodeKind === SyntaxKind.ParameterDeclaration || (!!parent.parent && parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z| case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: - return containingNodeKind === SyntaxKind.Parameter && !isConstructorDeclaration(parent.parent); + return containingNodeKind === SyntaxKind.ParameterDeclaration && !isConstructorDeclaration(parent.parent); case SyntaxKind.AsKeyword: return containingNodeKind === SyntaxKind.ImportSpecifier || @@ -6014,7 +6014,7 @@ function getClosestSymbolDeclaration(contextToken: Node | undefined, location: N let closestDeclaration = findAncestor(contextToken, node => isFunctionBlock(node) || isArrowFunctionBody(node) || isBindingPattern(node) ? "quit" - : ((isParameter(node) || isTypeParameterDeclaration(node)) && !isIndexSignatureDeclaration(node.parent))); + : ((isParameterDeclaration(node) || isTypeParameterDeclaration(node)) && !isIndexSignatureDeclaration(node.parent))); if (!closestDeclaration) { closestDeclaration = findAncestor(location, node => diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 74aeb9c5be05c..57fde0f2972cc 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -170,7 +170,7 @@ import { isObjectBindingElementWithoutPropertyName, isObjectLiteralExpression, isObjectLiteralMethod, - isParameter, + isParameterDeclaration, isParameterPropertyDeclaration, isPrivateIdentifierClassElementDeclaration, isPropertyAccessExpression, @@ -942,7 +942,7 @@ function declarationIsWriteAccess(decl: Declaration): boolean { case SyntaxKind.NamespaceExportDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.NamespaceExport: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.TypeParameter: @@ -2400,7 +2400,7 @@ export namespace Core { } function isParameterName(node: Node) { - return node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.Parameter && (node.parent as ParameterDeclaration).name === node; + return node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.ParameterDeclaration && (node.parent as ParameterDeclaration).name === node; } function getReferencesForThisKeyword(thisOrSuperKeyword: Node, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken): SymbolAndEntries[] | undefined { @@ -2467,7 +2467,7 @@ export namespace Core { }); }).map(n => nodeEntry(n)); - const thisParameter = firstDefined(references, r => isParameter(r.node.parent) ? r.node : undefined); + const thisParameter = firstDefined(references, r => isParameterDeclaration(r.node.parent) ? r.node : undefined); return [{ definition: { type: DefinitionKind.This, node: thisParameter || thisOrSuperKeyword }, references, @@ -2597,7 +2597,7 @@ export namespace Core { if (symbol.valueDeclaration && isParameterPropertyDeclaration(symbol.valueDeclaration, symbol.valueDeclaration.parent)) { // For a parameter property, now try on the other symbol (property if this was a parameter, parameter if this was a property). - const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(cast(symbol.valueDeclaration, isParameter), symbol.name); + const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(cast(symbol.valueDeclaration, isParameterDeclaration), symbol.name); Debug.assert(paramProps.length === 2 && !!(paramProps[0].flags & SymbolFlags.FunctionScopedVariable) && !!(paramProps[1].flags & SymbolFlags.Property)); // is [parameter, property] return fromRoot(symbol.flags & SymbolFlags.FunctionScopedVariable ? paramProps[1] : paramProps[0]); } diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index e641b0f2b0434..5f934c99c0b4a 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -680,7 +680,7 @@ function formatSpanWorker( // falls through case SyntaxKind.PropertyDeclaration: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: const name = getNameOfDeclaration(node as Declaration); if (name) { return name.kind; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 806dc6003f510..fec6e0f104e79 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -529,7 +529,7 @@ function isBinaryOpContext(context: FormattingContext): boolean { case SyntaxKind.VariableDeclaration: // equal in p = 0 // falls through - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.EnumMember: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -559,7 +559,7 @@ function isTypeAnnotationContext(context: FormattingContext): boolean { const contextKind = context.contextNode.kind; return contextKind === SyntaxKind.PropertyDeclaration || contextKind === SyntaxKind.PropertySignature || - contextKind === SyntaxKind.Parameter || + contextKind === SyntaxKind.ParameterDeclaration || contextKind === SyntaxKind.VariableDeclaration || isFunctionLikeKind(contextKind); } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index c6ed975a1a516..a8192c6cbd719 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -664,7 +664,7 @@ export namespace SmartIndenter { case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.ParenthesizedType: diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index a3e54cf237896..98a678e3ac5ac 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -69,7 +69,7 @@ import { isObjectBindingPattern, isObjectLiteralExpression, isOptionalTypeNode, - isParameter, + isParameterDeclaration, isParenthesizedTypeNode, isPartOfParameterDeclaration, isPrefixUnaryExpression, @@ -463,7 +463,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] { function getParameterDeclarationTypeHints(symbol: Symbol) { const valueDeclaration = symbol.valueDeclaration; - if (!valueDeclaration || !isParameter(valueDeclaration)) { + if (!valueDeclaration || !isParameterDeclaration(valueDeclaration)) { return undefined; } @@ -592,8 +592,8 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] { visitForDisplayParts(node.default); } break; - case SyntaxKind.Parameter: - Debug.assertNode(node, isParameter); + case SyntaxKind.ParameterDeclaration: + Debug.assertNode(node, isParameterDeclaration); if (node.modifiers) { visitDisplayPartList(node.modifiers, " "); } diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 2d59e42c433d6..13fcb9a392594 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -590,7 +590,7 @@ export function getRangeToExtract(sourceFile: SourceFile, span: TextSpan, invoke } break; } - else if (current.kind === SyntaxKind.Parameter) { + else if (current.kind === SyntaxKind.ParameterDeclaration) { const ctorOrMethod = getContainingFunction(current)!; if (ctorOrMethod.kind === SyntaxKind.Constructor) { rangeFacts |= RangeFacts.InStaticRegion; @@ -866,7 +866,7 @@ function collectEnclosingScopes(range: TargetRange): Scope[] { while (true) { current = current.parent; // A function parameter's initializer is actually in the outer scope, not the function declaration - if (current.kind === SyntaxKind.Parameter) { + if (current.kind === SyntaxKind.ParameterDeclaration) { // Skip all the way to the outer scope of the function that declared this parameter current = findAncestor(current, parent => isFunctionLikeDeclaration(parent))!.parent; } diff --git a/src/services/refactors/generateGetAccessorAndSetAccessor.ts b/src/services/refactors/generateGetAccessorAndSetAccessor.ts index 7e0820c3e2224..579d9ccf6fb6d 100644 --- a/src/services/refactors/generateGetAccessorAndSetAccessor.ts +++ b/src/services/refactors/generateGetAccessorAndSetAccessor.ts @@ -7,7 +7,7 @@ import { getLocaleSpecificMessage, getRenameLocation, isIdentifier, - isParameter, + isParameterDeclaration, RefactorContext, } from "../_namespaces/ts.js"; import { @@ -35,7 +35,7 @@ registerRefactor(actionName, { const renameFilename = context.file.fileName; const nameNeedRename = info.renameAccessor ? info.accessorName : info.fieldName; const renameLocationOffset = isIdentifier(nameNeedRename) ? 0 : -1; - const renameLocation = renameLocationOffset + getRenameLocation(edits, renameFilename, nameNeedRename.text, /*preferLastLocation*/ isParameter(info.declaration)); + const renameLocation = renameLocationOffset + getRenameLocation(edits, renameFilename, nameNeedRename.text, /*preferLastLocation*/ isParameterDeclaration(info.declaration)); return { renameFilename, renameLocation, edits }; }, diff --git a/src/services/services.ts b/src/services/services.ts index c51089dfe25de..2ad88b80588d3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1220,7 +1220,7 @@ class SourceFileObject extends NodeObject implements Sour forEachChild(node, visit); break; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: // Only consider parameter properties if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { break; @@ -2339,7 +2339,7 @@ export function createLanguageService( if ( node.flags & NodeFlags.JSDoc && !isInJSFile(node) && ((node.parent.kind === SyntaxKind.PropertySignature && (node.parent as PropertySignature).name === node) || - findAncestor(node, n => n.kind === SyntaxKind.Parameter)) + findAncestor(node, n => n.kind === SyntaxKind.ParameterDeclaration)) ) { // if we'd request type at those locations we'd get `errorType` that displays confusingly as `any` return false; diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 70e9174e64a60..6f931b9799456 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -45,7 +45,7 @@ import { isMethodDeclaration, isNoSubstitutionTemplateLiteral, isObjectBindingPattern, - isParameter, + isParameterDeclaration, isPropertyAccessExpression, isSourceFile, isSourceFileJS, @@ -435,7 +435,7 @@ function getAdjustedNode(node: Node) { case SyntaxKind.CommaToken: return node; default: - return findAncestor(node.parent, n => isParameter(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit"); + return findAncestor(node.parent, n => isParameterDeclaration(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit"); } } diff --git a/src/services/smartSelection.ts b/src/services/smartSelection.ts index f58862d76ab68..53440ad2759f2 100644 --- a/src/services/smartSelection.ts +++ b/src/services/smartSelection.ts @@ -20,7 +20,7 @@ import { isJSDocTypeExpression, isJSDocTypeLiteral, isMappedTypeNode, - isParameter, + isParameterDeclaration, isPropertySignature, isSourceFile, isStringLiteral, @@ -261,7 +261,7 @@ function getSelectionChildren(node: Node): readonly Node[] { } // Group the parameter name with its `...`, then that group with its `?`, then pivot on `=`. - if (isParameter(node)) { + if (isParameterDeclaration(node)) { const groupedDotDotDotAndName = groupChildren(node.getChildren(), child => child === node.dotDotDotToken || child === node.name); const groupedWithQuestionToken = groupChildren(groupedDotDotDotAndName, child => child === groupedDotDotDotAndName[0] || child === node.questionToken); return splitChildren(groupedWithQuestionToken, ({ kind }) => kind === SyntaxKind.EqualsToken); diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index e73da8490b683..11bd02edf08d9 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -94,7 +94,7 @@ import { isLineBreak, isNamedImports, isObjectLiteralExpression, - isParameter, + isParameterDeclaration, isPinnedComment, isPrologueDirective, isPropertyDeclaration, @@ -791,8 +791,8 @@ export class ChangeTracker { else if (isVariableDeclaration(before)) { // insert `x = 1, ` into `const x = 1, y = 2; return { suffix: ", " }; } - else if (isParameter(before)) { - return isParameter(inserted) ? { suffix: ", " } : {}; + else if (isParameterDeclaration(before)) { + return isParameterDeclaration(inserted) ? { suffix: ", " } : {}; } else if (isStringLiteral(before) && isImportDeclaration(before.parent) || isNamedImports(before)) { return { suffix: ", " }; @@ -969,7 +969,7 @@ export class ChangeTracker { case SyntaxKind.ExportKeyword: return { prefix: " " }; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return {}; default: @@ -1671,7 +1671,7 @@ function needSemicolonBetween(a: Node, b: Node): boolean { namespace deleteDeclaration { export function deleteDeclaration(changes: ChangeTracker, deletedNodesInLists: Set, sourceFile: SourceFile, node: Node): void { switch (node.kind) { - case SyntaxKind.Parameter: { + case SyntaxKind.ParameterDeclaration: { const oldFunction = node.parent; if ( isArrowFunction(oldFunction) && diff --git a/src/services/utilities.ts b/src/services/utilities.ts index fe06adeb8b217..06446ed2775d3 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -227,7 +227,7 @@ import { isObjectLiteralExpression, isOptionalChain, isOptionalChainRoot, - isParameter, + isParameterDeclaration, isPartOfTypeNode, isPrivateIdentifier, isPropertyAccessExpression, @@ -411,7 +411,7 @@ export function getMeaningFromDeclaration(node: Node): SemanticMeaning { case SyntaxKind.VariableDeclaration: return isInJSFile(node) && getJSDocEnumTag(node) ? SemanticMeaning.All : SemanticMeaning.Value; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -833,7 +833,7 @@ export function getNodeKind(node: Node): ScriptElementKind { return ScriptElementKind.typeParameterElement; case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement; - case SyntaxKind.Parameter: + case SyntaxKind.ParameterDeclaration: return hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ImportSpecifier: @@ -895,7 +895,7 @@ export function isThis(node: Node): boolean { return true; case SyntaxKind.Identifier: // 'this' as a parameter - return identifierIsThisKeyword(node as Identifier) && node.parent.kind === SyntaxKind.Parameter; + return identifierIsThisKeyword(node as Identifier) && node.parent.kind === SyntaxKind.ParameterDeclaration; default: return false; } @@ -2774,7 +2774,7 @@ export function getMappedContextSpan(documentSpan: DocumentSpan, sourceMapper: S /** @internal */ export function isFirstDeclarationOfSymbolParameter(symbol: Symbol): boolean { const declaration = symbol.declarations ? firstOrUndefined(symbol.declarations) : undefined; - return !!findAncestor(declaration, n => isParameter(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit"); + return !!findAncestor(declaration, n => isParameterDeclaration(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit"); } const displayPartWriter = getDisplayPartWriter(); diff --git a/src/testRunner/unittests/services/utilities.ts b/src/testRunner/unittests/services/utilities.ts index 2d0fc8876f23d..8fe21c8acead5 100644 --- a/src/testRunner/unittests/services/utilities.ts +++ b/src/testRunner/unittests/services/utilities.ts @@ -15,7 +15,7 @@ describe("unittests:: services:: utilities", () => { /*setParentNodes*/ true, ); // can't use ts.getTokenAtPosition because it returns back the wrong token - const param = ts.forEachChildRecursively(sourceFile, node => node.kind === ts.SyntaxKind.Parameter ? node : undefined)!; + const param = ts.forEachChildRecursively(sourceFile, node => node.kind === ts.SyntaxKind.ParameterDeclaration ? node : undefined)!; const jsDoc = param.getChildren()[0]; const token = jsDoc.getLastToken()!; const result = ts.findPrecedingMatchingToken(token, ts.SyntaxKind.OpenBraceToken, sourceFile); diff --git a/tests/baselines/reference/APISample_jsdoc.js b/tests/baselines/reference/APISample_jsdoc.js index 1e087006d4044..0cc6cb1a987b5 100644 --- a/tests/baselines/reference/APISample_jsdoc.js +++ b/tests/baselines/reference/APISample_jsdoc.js @@ -78,7 +78,7 @@ function getAnnotations(this: any, node: ts.Node): Annotations | undefined { // these examples are artificial and mostly nonsensical function parseSpecificTags(node: ts.Node) { - if (node.kind === ts.SyntaxKind.Parameter) { + if (node.kind === ts.SyntaxKind.ParameterDeclaration) { return ts.getJSDocParameterTags(node as ts.ParameterDeclaration); } if (node.kind === ts.SyntaxKind.FunctionDeclaration) { @@ -178,7 +178,7 @@ function getAnnotations(node) { } // these examples are artificial and mostly nonsensical function parseSpecificTags(node) { - if (node.kind === ts.SyntaxKind.Parameter) { + if (node.kind === ts.SyntaxKind.ParameterDeclaration) { return ts.getJSDocParameterTags(node); } if (node.kind === ts.SyntaxKind.FunctionDeclaration) { diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json index 3ec8a590dcdeb..4b95202cd7d66 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json @@ -7,7 +7,7 @@ "transformFlags": 1, "parameters": { "0": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 10, "end": 16, "flags": "JSDoc", @@ -22,7 +22,7 @@ } }, "1": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 17, "end": 25, "flags": "JSDoc", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json index 3ec8a590dcdeb..4b95202cd7d66 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json @@ -7,7 +7,7 @@ "transformFlags": 1, "parameters": { "0": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 10, "end": 16, "flags": "JSDoc", @@ -22,7 +22,7 @@ } }, "1": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 17, "end": 25, "flags": "JSDoc", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json index 9ee95f4db14bc..50213483e4b64 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json @@ -7,7 +7,7 @@ "transformFlags": 1, "parameters": { "0": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 10, "end": 11, "flags": "JSDoc", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json index a2f84428ced0e..9f7e21ca80da0 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json @@ -7,7 +7,7 @@ "transformFlags": 1, "parameters": { "0": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 10, "end": 17, "flags": "JSDoc", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json index ddb591f737c63..462ce8aa1814f 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json @@ -7,7 +7,7 @@ "transformFlags": 1, "parameters": { "0": { - "kind": "Parameter", + "kind": "ParameterDeclaration", "pos": 10, "end": 18, "flags": "JSDoc", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 304462086e8a8..404791cf291ad 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3792,6 +3792,8 @@ declare namespace ts { QualifiedName = 166, ComputedPropertyName = 167, TypeParameter = 168, + ParameterDeclaration = 169, + /** @deprecated Use SyntaxKind.ParameterDeclaration */ Parameter = 169, Decorator = 170, PropertySignature = 171, @@ -4492,7 +4494,7 @@ declare namespace ts { readonly declarations: NodeArray; } interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.Parameter; + readonly kind: SyntaxKind.ParameterDeclaration; readonly parent: SignatureDeclaration; readonly modifiers?: NodeArray; readonly dotDotDotToken?: DotDotDotToken; @@ -8883,7 +8885,7 @@ declare namespace ts { function isQualifiedName(node: Node): node is QualifiedName; function isComputedPropertyName(node: Node): node is ComputedPropertyName; function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration; - function isParameter(node: Node): node is ParameterDeclaration; + function isParameterDeclaration(node: Node): node is ParameterDeclaration; function isDecorator(node: Node): node is Decorator; function isPropertySignature(node: Node): node is PropertySignature; function isPropertyDeclaration(node: Node): node is PropertyDeclaration; @@ -11337,5 +11339,7 @@ declare namespace ts { * @param compilerOptions Optional compiler options. */ function transform(source: T | T[], transformers: TransformerFactory[], compilerOptions?: CompilerOptions): TransformationResult; + /** @deprecated Use `isParameterDeclaration` instead. */ + const isParameter: (node: Node) => node is ParameterDeclaration; } export = ts; diff --git a/tests/cases/compiler/APISample_jsdoc.ts b/tests/cases/compiler/APISample_jsdoc.ts index b2f39259cb32e..91219005d6bf1 100644 --- a/tests/cases/compiler/APISample_jsdoc.ts +++ b/tests/cases/compiler/APISample_jsdoc.ts @@ -82,7 +82,7 @@ function getAnnotations(this: any, node: ts.Node): Annotations | undefined { // these examples are artificial and mostly nonsensical function parseSpecificTags(node: ts.Node) { - if (node.kind === ts.SyntaxKind.Parameter) { + if (node.kind === ts.SyntaxKind.ParameterDeclaration) { return ts.getJSDocParameterTags(node as ts.ParameterDeclaration); } if (node.kind === ts.SyntaxKind.FunctionDeclaration) {