-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getCallExpressionIdentifier): add resolveCallExpression option
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
workspaces/estree-ast-utils/src/getCallExpressionIdentifier.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
// Import Internal Dependencies | ||
import { getMemberExpressionIdentifier } from "./getMemberExpressionIdentifier.js"; | ||
import { VariableTracer } from "./utils/VariableTracer.js"; | ||
|
||
/** | ||
* @param {any} node | ||
* @param {object} options | ||
* @param {VariableTracer} [options.tracer=null] | ||
* @param {boolean} [options.resolveCallExpression=true] | ||
* @returns {string | null} | ||
*/ | ||
export function getCallExpressionIdentifier(node) { | ||
export function getCallExpressionIdentifier(node, options = {}) { | ||
if (node.type !== "CallExpression") { | ||
return null; | ||
} | ||
const { tracer = null, resolveCallExpression = true } = options; | ||
|
||
if (node.callee.type === "Identifier") { | ||
return node.callee.name; | ||
} | ||
if (node.callee.type === "MemberExpression") { | ||
return [...getMemberExpressionIdentifier(node.callee)].join("."); | ||
return [ | ||
...getMemberExpressionIdentifier(node.callee, { tracer }) | ||
].join("."); | ||
} | ||
|
||
return getCallExpressionIdentifier(node.callee); | ||
return resolveCallExpression ? | ||
getCallExpressionIdentifier(node.callee, { tracer }) : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters