fix(turbopack): support parse ~ prefix for less & sass#73
Conversation
Summary of ChangesHello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求解决了 Turbopack 在解析 Less 和 Sass 中使用的 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| // Handle webpack-style tilde prefix (~) for node_modules resolution | ||
| // This is commonly used in CSS preprocessors like less-loader and sass-loader | ||
| // Only strip ~ if it's followed by a module path (not a relative path like ~/home) | ||
| // for utoopack issue: https://github.com/utooland/utoo/issues/2309 |
| let r = if let Some(remainder) = r | ||
| .strip_prefix('~') | ||
| .filter(|s| !s.is_empty() && !s.starts_with('/') && !s.starts_with('\\')) | ||
| .filter(|s| MODULE_PATH.is_match(s)) | ||
| { | ||
| remainder.into() | ||
| } else { | ||
| r | ||
| }; |
There was a problem hiding this comment.
这个 if let ... else 语句块可以重构为一个更简洁、更符合 Rust 语言习惯的函数式风格链式调用。使用 map 和 unwrap_or 可以将转换逻辑表达为单个表达式,从而提高可读性。
| let r = if let Some(remainder) = r | |
| .strip_prefix('~') | |
| .filter(|s| !s.is_empty() && !s.starts_with('/') && !s.starts_with('\\')) | |
| .filter(|s| MODULE_PATH.is_match(s)) | |
| { | |
| remainder.into() | |
| } else { | |
| r | |
| }; | |
| let r = r | |
| .strip_prefix('~') | |
| .filter(|s| { | |
| !s.is_empty() | |
| && !s.starts_with('/') | |
| && !s.starts_with('\') | |
| && MODULE_PATH.is_match(s) | |
| }) | |
| .map(RcStr::from) | |
| .unwrap_or(r); |
让 resolve 去把
~${moduleName}/xx.css先直接处理成${moduleName}/xx.css。for issue: utooland/utoo#2309