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(tree-shaking): object spread transform should go before deconstructing #1598

Merged
merged 2 commits into from
Sep 14, 2024

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Sep 14, 2024

import * as ns from "./ns"

let {x, ..rest} = ns

console.log(x,rest)

will panic with

internal error: entered unreachable code: Object rest pattern should be removed by es2018::object_rest_spread pass

Summary by CodeRabbit

  • 新功能

    • 引入了对象 rest/spread 语法的支持,增强了模块的树摇能力。
    • 添加了与数组和对象操作相关的新变量声明和控制台日志,展示了 JavaScript 的数组和对象处理特性。
  • 无变化

    • 未对导出或公共实体的声明进行更改。

Copy link
Contributor

coderabbitai bot commented Sep 14, 2024

Walkthrough

此次更改增强了 remove_useless_stmts.rs 文件中 optimize_import_namespace 函数的功能,主要通过引入 es2018 兼容层中的 object_rest_spread 转换。该转换在进行解构转换之前应用于 shadow 模块,允许更全面地处理对象属性。此外,在 index.tsx 文件中添加了新的变量声明和控制台日志语句,展示了数组和对象操作的用法。

Changes

文件路径 更改摘要
crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs 引入 object_rest_spread 转换,调整操作顺序以优化模块处理,增强对现代 JavaScript 特性的支持。
e2e/fixtures/tree-shaking.import_namespace/src/index.tsx 添加数组和对象操作的新变量声明和日志,展示了扩展语法和解构赋值的用法。

Possibly related PRs

🐇 在代码的草地上,
变化如春风轻轻吹,
新增语法如花绽放,
对象与数组共舞飞。
优化导入如兔跳跃,
未来代码更精彩! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0aef8b8 and 0ae9e80.

Files selected for processing (1)
  • e2e/fixtures/tree-shaking.import_namespace/src/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/fixtures/tree-shaking.import_namespace/src/index.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
e2e/fixtures/tree-shaking.import_namespace/src/index.tsx (3)

8-10: 代码看起来不错!

数组声明和打印到控制台的逻辑是正确的。

建议删除第 8 行的注释,因为它可能只是一个占位符,对代码的理解没有帮助。


13-14: 使用扩展运算符复制数组的逻辑是正确的

使用扩展运算符 ... 创建数组副本的逻辑是正确的,打印到控制台的语句也没有问题。

建议将变量 copieArray 重命名为 copiedArray,因为当前的名称有拼写错误。

Tools
GitHub Check: Spell Check

[warning] 13-13:
"copie" should be "copied" or "copier" or "copies" or "copy".


[warning] 14-14:
"copie" should be "copied" or "copier" or "copies" or "copy".


20-21: 使用扩展运算符复制对象的逻辑是正确的

使用扩展运算符 ... 创建对象副本的逻辑是正确的,打印到控制台的语句也没有问题。

建议将变量 copieObject 重命名为 copiedObject,因为当前的名称有拼写错误。

Tools
GitHub Check: Spell Check

[warning] 20-20:
"copie" should be "copied" or "copier" or "copies" or "copy".


[warning] 21-21:
"copie" should be "copied" or "copier" or "copies" or "copy".

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75118d5 and 0aef8b8.

Files selected for processing (2)
  • crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs (2 hunks)
  • e2e/fixtures/tree-shaking.import_namespace/src/index.tsx (1 hunks)
Additional context used
GitHub Check: Spell Check
e2e/fixtures/tree-shaking.import_namespace/src/index.tsx

[warning] 13-13:
"copie" should be "copied" or "copier" or "copies" or "copy".


[warning] 14-14:
"copie" should be "copied" or "copier" or "copies" or "copy".


[warning] 20-20:
"copie" should be "copied" or "copier" or "copies" or "copy".


[warning] 21-21:
"copie" should be "copied" or "copier" or "copies" or "copy".

Additional comments not posted (9)
e2e/fixtures/tree-shaking.import_namespace/src/index.tsx (3)

11-12: 解构赋值逻辑正确

将数组解构为第一个元素和其余元素的逻辑是正确的,打印到控制台的语句也没有问题。


16-17: 对象声明和打印逻辑正确

使用对象字面量语法声明具有 3 个属性的对象,并将其打印到控制台的逻辑是正确的。


18-19: 对象解构赋值逻辑正确

将对象解构为第一个属性和其余属性的逻辑是正确的,打印到控制台的语句也没有问题。

crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs (6)

10-10: LGTM!

引入 object_rest_spread 转换以支持对象 rest/spread 语法是正确的。


272-272: LGTM!

创建 IdExplicitPropAccessCollector 的新实例以收集显式属性访问是正确的。


273-273: LGTM!

克隆 module 变量以避免修改原始模块是正确的。


274-274: LGTM!

destructuring 转换之前应用 object_rest_spread 转换是正确的。


275-275: LGTM!

object_rest_spread 转换之后应用 destructuring 转换是正确的。


276-276: LGTM!

使用 IdExplicitPropAccessCollector 实例 v 访问转换后的模块以收集显式属性访问是正确的。

@stormslowly stormslowly force-pushed the fix/import_namespace_optimize_edge_case branch from 0aef8b8 to 0ae9e80 Compare September 14, 2024 07:01
Copy link

codecov bot commented Sep 14, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 62.11%. Comparing base (75118d5) to head (0ae9e80).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...o/src/plugins/tree_shaking/remove_useless_stmts.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1598      +/-   ##
==========================================
- Coverage   62.11%   62.11%   -0.01%     
==========================================
  Files         129      129              
  Lines       15559    15561       +2     
==========================================
  Hits         9665     9665              
- Misses       5894     5896       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xusd320 xusd320 merged commit 9434d99 into master Sep 14, 2024
19 of 21 checks passed
@xusd320 xusd320 deleted the fix/import_namespace_optimize_edge_case branch September 14, 2024 07:35
stormslowly added a commit that referenced this pull request Sep 22, 2024
stormslowly added a commit that referenced this pull request Sep 23, 2024
* Revert "fix(tree-shaking): object spread transform should go before deconstructing (#1598)"

This reverts commit 9434d99.

* Revert "feat(tree-shaking): optimize import namespace used all exports to partial used of source modules (#1584)"

This reverts commit 81a52f8.
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.

2 participants