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/export star in dependence loop #1277

Merged
merged 5 commits into from
Jun 17, 2024
Merged

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Jun 14, 2024

close #1272

  1. 原先通过逆拓扑序逐层计算所有的模块的导出符号,然后计算出 export * 对应的导出符号是没有必要的;因为如果一个模块没有 export * 语法 ,那么其导出了什么仅语法分析就能直接完成,不需要计算依赖的导出
  2. 如果模块在 export * 在环上,并不表示 export * 的结果不能计算,因为仅通过 export * from 连接起来的模块不一定成为一个环。
  3. 即使 export * from 成为了环,只有要收集完所有在环上模块的 export 语法也能确定 export * 语句导出了多少符号,就能知道export * 的导出。

所以不再计算所有模块的导出符号,仅从 export * 语句出发,递归的计算这条语句的导出符号即可。

另外因为存在 export * 成环,那么一个符号可能来自两条语句,所以匹配到所有的导出后对这些语句都做 used 处理。
见新增用例。
image

Summary by CodeRabbit

  • 新功能
    • shake.rs中添加了HashMapHashSet的导入。
    • 通过将逻辑提取到新函数fill_all_export_start_export_info来修改函数optimize_farm
    • 调整导出和依赖处理逻辑。
    • 添加AllExports结构及相关导出处理功能。
    • 添加collect_all_exports_of函数用于递归收集导出。

Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

整体变更包括增加了对Farm Tree Shake插件的功能改进,包括导出处理和优化逻辑的调整,以及针对不同模块的功能性新增和修改。

Changes

文件 摘要
crates/mako/src/plugins/farm_tree_shake/module.rs AllExports枚举实现增加Default trait,引入新方法如extendsas_ambiguous,调整TreeShakeModule结构体中的方法
crates/mako/src/plugins/farm_tree_shake/statement_graph.rs 新增ExportSource枚举和相关转换实现,修改ExportInfoMatch枚举
e2e/fixtures/tree-shaking.export_start_loop/expect.js 新增injectSimpleJestparseBuildResult函数声明
e2e/fixtures/tree-shaking.export_start_loop/index.js 引入对l1.jsa的导入
e2e/fixtures/tree-shaking.export_start_loop/l1.js 导出所有l2.js的实体和常量a
e2e/fixtures/tree-shaking.export_start_loop/l2.js 导出所有l1.js的实体和常量b
e2e/fixtures/tree-shaking.export_start_loop/mako.config.json 配置入口点为index.js和模块合并选项
文件 摘要
crates/mako/src/plugins/farm_tree_shake/shake.rs 导入HashMapHashSet,重构optimize_farm函数,新增fill_all_export_start_export_info函数和相关调整,添加AllExports结构体和collect_all_exports_of函数

Poem

公告变更,林中振兮,草木含翠;情感加深,编程思路开拓,历经变革之风。 🌿🐇


Note

Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://coderabbit.ai

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@stormslowly stormslowly changed the title fix/export star in dependence loop wip fix/export star in dependence loop Jun 14, 2024
@stormslowly stormslowly changed the title wip fix/export star in dependence loop fix/export star in dependence loop Jun 15, 2024
@sorrycc sorrycc merged commit e892555 into master Jun 17, 2024
8 checks passed
@sorrycc sorrycc deleted the fix/export_start_in_dependence_loop branch June 17, 2024 00:55
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.

[bug] tree-shaking cant handle export * in a dependence loop
2 participants