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

workaround: fix empty chunk #1147

Merged
merged 3 commits into from
May 11, 2024
Merged

workaround: fix empty chunk #1147

merged 3 commits into from
May 11, 2024

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented May 10, 2024

swc_core 升级之前的 workaround
swc 升级完成之后可以 revert。

REF:swc-project/swc#8172

close #899

Summary by CodeRabbit

  • 新功能
    • Cargo.toml文件中的[dependencies]部分添加了delegate依赖项版本0.12.0
    • 重命名并重构了Comments结构以使用MakoComments,更新了方法签名,并为MakoComments实现了CommentsTrait。此外,在虚拟位置的纯注释上添加了新的警告消息。
    • e2e/fixtures/issue.empty_chunk目录中的新文件expect.js包含了使用Jest的断言,用于检查在某些操作后文件的内容长度是否大于0。
    • mako.config.json文件引入了Mako项目的配置设置,启用了缩小、将模式设置为生产模式、为IE指定目标浏览器版本并禁用devtool。
    • index.tsx文件引入了一个接受参数a的异步函数。

Copy link
Contributor

coderabbitai bot commented May 10, 2024

更改摘要


crates/mako/Cargo.toml: ## 简要说明
在`Cargo.toml`文件的`[dependencies]`部分中添加了`delegate`依赖项,版本为`0.12.0`。

## 导出或公共实体声明的更改
- 在`Cargo.toml`中的`[dependencies]`部分添加了`delegate = "0.12.0"`

---

crates/mako/src/ast/comments.rs: ## 简要说明
在`mako`包的`comments.rs`文件中,对`Comments`结构进行了重命名和重构,使用`MakoComments`,更新了方法签名,并为`MakoComments`实现了`CommentsTrait`。此外,在虚拟位置添加了纯注释的新警告消息。

## 导出或公共实体声明的更改
- `use mako_core::swc_common::comments::Comment;` → `use mako_core::swc_common::comments::{Comment, Comments as CommentsTrait};`
- `pub struct Comments(SwcComments);` → `pub struct Comments(MakoComments);`
- `pub fn get_swc_comments(&self) -> &SwcComments {` → `pub fn get_swc_comments(&self) -> &MakoComments {`
- `pub fn add_leading_comment_at(&mut self, pos: BytePos, comment: Comment) {` 更新了实现
- 添加了`pub struct MakoComments(SwcComments);`
- 为`MakoComments`实现了`CommentsTrait`,包括委托方法

---

e2e/fixtures/issue.empty_chunk/expect.js: ## 摘要
在`e2e/fixtures/issue.empty_chunk`目录中的新文件`expect.js`包含使用Jest的断言,检查在某些操作后文件的内容长度是否大于0。

## 导出或公共实体声明的更改
此文件中未对导出或公共实体的声明进行更改。

---

e2e/fixtures/issue.empty_chunk/mako.config.json: ## 摘要
新文件`mako.config.json`为Mako项目引入配置设置,启用了最小化,将模式设置为生产模式,为IE指定了目标浏览器版本,并禁用了devtool。

## 导出或公共实体声明的更改
此文件中未对导出或公共实体的声明进行更改。

---

e2e/fixtures/issue.empty_chunk/src/index.tsx: ## 摘要
新文件`index.tsx`引入了一个接受参数`a`的异步函数。

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


## 漫游

整体变更的高层摘要:包括了添加依赖、重构结构、实现新功能和配置设置等。

## 变更

| 文件                                    | 变更摘要                                                                                   |
|-----------------------------------------|--------------------------------------------------------------------------------------------|
| crates/mako/Cargo.toml                  | 添加`delegate`依赖版本`0.12.0`                                                             |
| crates/mako/src/ast/comments.rs         | 重命名和重构`Comments`结构为`MakoComments`,更新方法签名,实现`CommentsTrait`,添加警告消息        |
| e2e/fixtures/issue.empty_chunk/expect.js | 新文件,包含Jest断言以检查文件内容长度是否大于0                                          |
| e2e/fixtures/issue.empty_chunk/mako.config.json | 新文件,引入Mako项目配置设置,包括启用最小化、设置生产模式、指定目标浏览器版本、禁用devtool |
| e2e/fixtures/issue.empty_chunk/src/index.tsx | 新文件,引入一个接受参数`a`的异步函数                                                 |

兔子编码忙改变,结构重构显新颜。
Jest断言文件内容测,配置设置启新篇。

Note

Pull Request 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copy link
Member

@sorrycc sorrycc left a comment

Choose a reason for hiding this comment

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

1、展开点说下原因?为啥注释会导致产物不生成?
2、这么改有啥副作用吗?所有注释相关操作会不生效?

@stormslowly
Copy link
Member Author

1、展开点说下原因?为啥注释会导致产物不生成? 2、这么改有啥副作用吗?所有注释相关操作会不生效?

  1. pure comment 其实就是 #__PURE__ 这样标记无副作用的注释,compress 会依据这个注释决定删不删代码。原先使用 ast 工具方法生成的代码都被打上了 pure,因为 dummy span。
  2. 无;只影响 pure comment 在 pos(0)的插入,swc 的实现也是将 0 位置的 pure comment 转移到一个代码不可能触达的 pos 上。

@sorrycc sorrycc merged commit 0c0f19c into master May 11, 2024
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the fix/empty_chunk branch May 11, 2024 08:50
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.

JS 产物内容消失的潜在 Bug
2 participants