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(plugin:emotion): panic when target to chrome 40 #1527

Merged
merged 7 commits into from
Aug 29, 2024

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Aug 23, 2024

close. #1484

  1. move scoped value outside of ast transform method, because we need to use the same scoped value in different method calling
  2. make preset env to go last while transforming js
  3. extract plugin in transform to transform mod

Summary by CodeRabbit

  • 新特性

    • 改进了 JavaScript 转换过程,集成插件处理机制,增强了错误处理能力。
    • 添加了新配置属性,允许更细致的目标环境控制。
  • 优化

    • 精简了 AST 的处理逻辑,提高了性能和可读性。
    • 测试模块中移除了不必要的依赖,简化了函数签名。

Copy link
Contributor

coderabbitai bot commented Aug 23, 2024

Walkthrough

此次更改主要涉及JsAst和相关模块中对JavaScript抽象语法树(AST)转换的处理。通过简化方法签名、优化转换逻辑和重构代码,整体提高了代码的清晰度和效率。此外,还对配置文件进行了更新,以支持针对特定浏览器的目标设置。

Changes

文件 更改摘要
crates/mako/src/ast/js_ast.rs 移除transform_js方法中的file参数,简化AST处理,直接使用ast.take()创建模块。
crates/mako/src/build/transform.rs 增加try_with_handler调用以处理JavaScript插件转换,调整操作顺序,删除多余的注释代码。
crates/mako/src/visitors/fix_helper_inject_position.rs 移除测试模块中对File结构的导入,更新ast.transform方法调用以省略file参数。
e2e/fixtures/config.emotion/expect.js 添加条件块以自动执行test函数,增强模块的可用性。
e2e/fixtures/config.emotion/mako.config.json 新增targets对象和progress标志,以便更详细地管理配置目标。

Assessment against linked issues

Objective Addressed Explanation
修复情感转换JS时在Chrome 40目标下的panic问题 (#1484)
使转换过程不再依赖File实例 (#1484)

Poem

在代码的世界里,兔子欢跳,
精简的逻辑,让我们骄傲。
配置文件新添目标,
让转换更顺畅,问题少。
代码如花,愈加美妙! 🐇✨


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 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 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

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 83.23353% with 28 lines in your changes missing coverage. Please review.

Project coverage is 61.04%. Comparing base (e1e4c77) to head (16fd868).
Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/build/transform.rs 84.67% 19 Missing ⚠️
crates/mako/src/ast/js_ast.rs 57.89% 8 Missing ⚠️
crates/mako/src/plugins/emotion.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1527      +/-   ##
==========================================
+ Coverage   61.03%   61.04%   +0.01%     
==========================================
  Files         127      127              
  Lines       15120    15125       +5     
==========================================
+ Hits         9228     9233       +5     
  Misses       5892     5892              

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

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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 193b7dd and c6c403f.

Files selected for processing (6)
  • crates/mako/src/ast/js_ast.rs (3 hunks)
  • crates/mako/src/build/transform.rs (5 hunks)
  • crates/mako/src/plugins/emotion.rs (2 hunks)
  • crates/mako/src/visitors/fix_helper_inject_position.rs (2 hunks)
  • e2e/fixtures/config.emotion/expect.js (1 hunks)
  • e2e/fixtures/config.emotion/mako.config.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • crates/mako/src/visitors/fix_helper_inject_position.rs
Additional context used
GitHub Check: codecov/patch
crates/mako/src/plugins/emotion.rs

[warning] 82-82: crates/mako/src/plugins/emotion.rs#L82
Added line #L82 was not covered by tests

Additional comments not posted (3)
e2e/fixtures/config.emotion/mako.config.json (1)

2-6: 配置更新已批准。

添加的 targetsprogress 属性增强了配置的灵活性,符合 PR 的目标。

e2e/fixtures/config.emotion/expect.js (1)

59-61: 更改已批准。

添加的条件块允许直接运行测试脚本,提高了可用性。

crates/mako/src/build/transform.rs (1)

199-200: 调用 AST 转换

调用 ast.transform 方法进行 AST 转换,确保在插件转换之前应用所有访问者和文件夹。这一步是为了准备后续的插件转换。

crates/mako/src/plugins/emotion.rs Show resolved Hide resolved
Comment on lines 152 to 156
let mut module = ast.take();
for folder in folders {
module = folder.as_mut().fold_module(module);
}
ast.body = module.body;

// transform with plugin
context.plugin_driver.transform_js(
&PluginTransformJsParam {
handler,
path: file.path.to_str().unwrap(),
top_level_mark: self.top_level_mark,
unresolved_mark: self.unresolved_mark,
},
ast,
&context,
)?;
*ast = module;
Copy link
Contributor

Choose a reason for hiding this comment

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

优化 AST 转换逻辑

通过直接使用 ast.take() 方法创建 module,简化了控制流,减少了对 AST 的操作步骤。这种简化有助于提高代码的可读性和性能。

Comment on lines 201 to 218
// run transform js in plugins
try_with_handler(cm.clone(), Default::default(), |handler| {
HELPERS.set(&Helpers::new(true), || {
HANDLER.set(handler, || {
// transform with plugin
context.plugin_driver.transform_js(
&PluginTransformJsParam {
handler,
path: file.path.to_str().unwrap(),
top_level_mark,
unresolved_mark,
},
&mut ast.ast,
&context,
)
})
})
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

集成插件转换

通过 try_with_handler 设置错误处理上下文,并调用 plugin_driver.transform_js 方法进行插件转换。这种集成增强了转换过程的灵活性和可扩展性。

Comment on lines 220 to 234
// preset_env should go last
let preset_env = Box::new(swc_preset_env::preset_env(
unresolved_mark,
Some(comments),
swc_preset_env::Config {
mode: Some(swc_preset_env::Mode::Entry),
targets: Some(swc_preset_env_targets_from_map(
context.config.targets.clone(),
)),
..Default::default()
},
assumptions,
&mut FeatureFlag::default(),
));
ast.transform(&mut vec![], &mut vec![preset_env], true, context.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

调整 preset_env 的顺序

preset_env 的调用移到最后,确保在所有插件转换之后应用。这种调整有助于保持转换逻辑的清晰性,并确保插件转换的优先级。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c6c403f and d408550.

Files selected for processing (1)
  • crates/mako/src/build/transform.rs (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/mako/src/build/transform.rs

@stormslowly stormslowly changed the title fix(plugin:emotion): panic when target to chrome 40 wip: fix(plugin:emotion): panic when target to chrome 40 Aug 23, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d408550 and 16fd868.

Files selected for processing (3)
  • crates/mako/src/ast/js_ast.rs (4 hunks)
  • crates/mako/src/build/transform.rs (3 hunks)
  • crates/mako/src/visitors/fix_helper_inject_position.rs (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • crates/mako/src/ast/js_ast.rs
  • crates/mako/src/build/transform.rs
  • crates/mako/src/visitors/fix_helper_inject_position.rs

@stormslowly stormslowly changed the title wip: fix(plugin:emotion): panic when target to chrome 40 fix(plugin:emotion): panic when target to chrome 40 Aug 29, 2024
@stormslowly stormslowly merged commit b4563e2 into master Aug 29, 2024
18 checks passed
@stormslowly stormslowly deleted the fix/emotion_with_sourcemap branch August 29, 2024 06:48
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.

1 participant