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

feat: don't consider ns import as dynamic #284

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions packages/babel-plugin-jsx-dom-expressions/src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,50 @@ export function isDynamic(path, { checkMember, checkTags, checkCallExpressions =
expr.leadingComments.shift();
return false;
}

if (
(checkCallExpressions && (t.isCallExpression(expr) || t.isOptionalCallExpression(expr))) ||
(checkMember &&
(t.isMemberExpression(expr) ||
t.isOptionalMemberExpression(expr) ||
t.isSpreadElement(expr) ||
(t.isBinaryExpression(expr) && expr.operator === "in"))) ||
(checkTags && (t.isJSXElement(expr) || t.isJSXFragment(expr)))
)
checkCallExpressions &&
(t.isCallExpression(expr) || t.isOptionalCallExpression(expr))
) {
return true;
}

if (checkMember && t.isMemberExpression(expr)) {
// Do not assume property access on namespaced imports as dynamic.
const object = path.get("object").node;

if (
t.isIdentifier(object) &&
(!expr.computed ||
!isDynamic(path.get("property"), {
checkMember,
checkTags,
checkCallExpressions,
native,
}))
Comment on lines +109 to +115
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if this code specifically needs any adjustments

) {
const binding = path.scope.getBinding(object.name);

if (binding && binding.path.isImportNamespaceSpecifier()) {
return false;
}
}

return true;
}

if (
checkMember &&
(t.isOptionalMemberExpression(expr) ||
t.isSpreadElement(expr) ||
(t.isBinaryExpression(expr) && expr.operator === "in"))
) {
return true;
}

if (checkTags && (t.isJSXElement(expr) || t.isJSXFragment(expr))) {
return true;
}

let dynamic;
path.traverse({
Expand Down
Loading
Loading