Skip to content

Commit

Permalink
enhance the transformComponentReferenceToJSX.js module to support com…
Browse files Browse the repository at this point in the history
…ponent reference inside a ()
  • Loading branch information
wpdas committed Apr 19, 2024
1 parent a391466 commit 27b4c04
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/parsers/transformComponentReferenceToJSX.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ function transformComponentReferenceToJSX(code, componentName) {
}

function isValidJSXContext(path) {
// Checks if the identifier is used in an array, or as an object property value, or directly assigned to a variable
return (
// Expand the check to include situations where the identifier is an argument in any function call
if (
path.parentPath.isObjectProperty({ value: path.node }) ||
path.parentPath.isArrayExpression() ||
path.parentPath.isVariableDeclarator({ init: path.node })
);
) {
return true;
}

if (path.parentPath.isCallExpression()) {
return path.parentPath.node.arguments.includes(path.node);
}

return false;
}

module.exports = transformComponentReferenceToJSX;

0 comments on commit 27b4c04

Please sign in to comment.