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(cjs): analyze exports for chained assignments in module.exports #150

Merged

Conversation

await-ovo
Copy link
Contributor

related denoland/deno#19865

For the following cjs code:

exports = module.exports = {
  a,
  b,
  c,
}

Currently exports is an empty array after analyze_cjs(), it should be ["a", "b", "c"].

@CLAassistant
Copy link

CLAassistant commented Jul 20, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

I think we can do this without having the extra in_module_exports state. Looks great otherwise and thanks for fixing this!

src/cjs_parse.rs Outdated
Comment on lines 166 to 168
self.in_module_exports = true;
self.visit_assign_expr(right_assign_expr);
self.in_module_exports = false;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we can remove this extra state and just do?

Suggested change
self.in_module_exports = true;
self.visit_assign_expr(right_assign_expr);
self.in_module_exports = false;
self.visit_exports_right_expr(&right_assign_expr.right);

That seems to pass all the current tests, but is there a scenario where self.in_module_exports is necessary? It would be best to not introduce more state if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion, indeed in_module_exports is redundant ~

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @await-ovo!

@dsherret dsherret merged commit 7c3c40d into denoland:main Jul 20, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants