fix(plugin:emotion): panic when target to chrome 40#1527
Conversation
Walkthrough此次更改主要涉及 Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this comment.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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: 配置更新已批准。添加的
targets和progress属性增强了配置的灵活性,符合 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/ast/js_ast.rs
Outdated
| 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; |
There was a problem hiding this comment.
优化 AST 转换逻辑
通过直接使用 ast.take() 方法创建 module,简化了控制流,减少了对 AST 的操作步骤。这种简化有助于提高代码的可读性和性能。
crates/mako/src/build/transform.rs
Outdated
| // 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, | ||
| ) | ||
| }) | ||
| }) | ||
| })?; |
There was a problem hiding this comment.
集成插件转换
通过 try_with_handler 设置错误处理上下文,并调用 plugin_driver.transform_js 方法进行插件转换。这种集成增强了转换过程的灵活性和可扩展性。
crates/mako/src/build/transform.rs
Outdated
| // 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())?; |
There was a problem hiding this comment.
调整 preset_env 的顺序
将 preset_env 的调用移到最后,确保在所有插件转换之后应用。这种调整有助于保持转换逻辑的清晰性,并确保插件转换的优先级。
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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
close. #1484
Summary by CodeRabbit
新特性
优化