11import { isArrowToken , isOpeningParenToken } from "./token-predicate.mjs"
2+ /** @typedef {import("eslint").Rule.Node } RuleNode */
3+ /** @typedef {import("eslint").SourceCode } SourceCode */
4+ /** @typedef {import("eslint").AST.Token } Token */
5+ /** @typedef {import("estree").Function } FunctionNode */
6+ /** @typedef {import("estree").FunctionDeclaration } FunctionDeclaration */
7+ /** @typedef {import("estree").FunctionExpression } FunctionExpression */
8+ /** @typedef {import("estree").SourceLocation } SourceLocation */
9+ /** @typedef {import("estree").Position } Position */
210
311/**
412 * Get the `(` token of the given function node.
5- * @param {Node } node - The function node to get.
13+ * @param {FunctionExpression | FunctionDeclaration } node - The function node to get.
614 * @param {SourceCode } sourceCode - The source code object to get tokens.
715 * @returns {Token } `(` token.
816 */
917function getOpeningParenOfParams ( node , sourceCode ) {
1018 return node . id
11- ? sourceCode . getTokenAfter ( node . id , isOpeningParenToken )
12- : sourceCode . getFirstToken ( node , isOpeningParenToken )
19+ ? /** @type {Token } */ (
20+ sourceCode . getTokenAfter ( node . id , isOpeningParenToken )
21+ )
22+ : /** @type {Token } */ (
23+ sourceCode . getFirstToken ( node , isOpeningParenToken )
24+ )
1325}
1426
1527/**
1628 * Get the location of the given function node for reporting.
17- * @param {Node } node - The function node to get.
29+ * @param {FunctionNode } node - The function node to get.
1830 * @param {SourceCode } sourceCode - The source code object to get tokens.
19- * @returns {string } The location of the function node for reporting.
31+ * @returns {SourceLocation|null } The location of the function node for reporting.
2032 */
2133export function getFunctionHeadLocation ( node , sourceCode ) {
22- const parent = node . parent
34+ const parent = /** @type {RuleNode } */ ( node ) . parent
35+
36+ /** @type {Position|null } */
2337 let start = null
38+ /** @type {Position|null } */
2439 let end = null
2540
2641 if ( node . type === "ArrowFunctionExpression" ) {
27- const arrowToken = sourceCode . getTokenBefore ( node . body , isArrowToken )
42+ const arrowToken = /** @type {Token } */ (
43+ sourceCode . getTokenBefore ( node . body , isArrowToken )
44+ )
2845
2946 start = arrowToken . loc . start
3047 end = arrowToken . loc . end
@@ -33,11 +50,11 @@ export function getFunctionHeadLocation(node, sourceCode) {
3350 parent . type === "MethodDefinition" ||
3451 parent . type === "PropertyDefinition"
3552 ) {
36- start = parent . loc . start
37- end = getOpeningParenOfParams ( node , sourceCode ) . loc . start
53+ start = /** @type { SourceLocation } */ ( parent . loc ) . start
54+ end = getOpeningParenOfParams ( node , sourceCode ) ? .loc . start
3855 } else {
39- start = node . loc . start
40- end = getOpeningParenOfParams ( node , sourceCode ) . loc . start
56+ start = /** @type { SourceLocation } */ ( node . loc ) . start
57+ end = getOpeningParenOfParams ( node , sourceCode ) ? .loc . start
4158 }
4259
4360 return {
0 commit comments