Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(getQueryNodeFrom): move Identifier type checks to getInnerNodeFrom #255

Merged
20 changes: 10 additions & 10 deletions src/assignment-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import { queries } from "./queries";
* await someAsyncFunc() => someAsyncFunc()
* someElement as HTMLDivElement => someElement
*
* @param {Object} context - Context for a rule
* @param {Object} expression - An expression node
* @returns {Object} - A node
*/
export function getInnerNodeFrom(expression) {
export function getInnerNodeFrom(context, expression) {
switch (expression.type) {
case "Identifier":
return getAssignmentForIdentifier(context, expression.name);
case "TSAsExpression":
return getInnerNodeFrom(expression.expression);
return getInnerNodeFrom(context, expression.expression);
case "AwaitExpression":
return getInnerNodeFrom(expression.argument);
return getInnerNodeFrom(context, expression.argument);
case "MemberExpression":
return getInnerNodeFrom(expression.object);
return getInnerNodeFrom(context, expression.object);
default:
return expression;
}
Expand All @@ -37,7 +40,7 @@ export function getAssignmentForIdentifier(context, identifierName) {
let assignmentNode;
if (init) {
// let foo = bar;
assignmentNode = getInnerNodeFrom(init);
assignmentNode = getInnerNodeFrom(context, init);
} else {
// let foo;
// foo = bar;
Expand All @@ -47,7 +50,7 @@ export function getAssignmentForIdentifier(context, identifierName) {
if (!assignmentRef) {
return;
}
assignmentNode = getInnerNodeFrom(assignmentRef.writeExpr);
assignmentNode = getInnerNodeFrom(context, assignmentRef.writeExpr);
}
return assignmentNode;
}
Expand All @@ -61,10 +64,7 @@ export function getAssignmentForIdentifier(context, identifierName) {
* @returns {Object} - Object with query, queryArg & isDTLQuery
*/
export function getQueryNodeFrom(context, nodeWithValueProp) {
const queryNode =
nodeWithValueProp.type === "Identifier"
? getAssignmentForIdentifier(context, nodeWithValueProp.name)
: getInnerNodeFrom(nodeWithValueProp);
const queryNode = getInnerNodeFrom(context, nodeWithValueProp);

if (!queryNode || !queryNode.callee) {
return {
Expand Down