-
Notifications
You must be signed in to change notification settings - Fork 108
Fix/context module source with first empty quasis #1719
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ | |
| "alias": [ | ||
| ["@", "./src"] | ||
| ] | ||
| } | ||
| }, | ||
| "progress":false | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||||||||||||||||||||||||||||||||||||||
| export function loadUrl(url) { | ||||||||||||||||||||||||||||||||||||||||||
| return import(`${url}`) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议增加错误处理和输入验证 当前实现过于简单,建议添加以下改进:
建议按照以下方式重构: +/**
+ * 动态加载URL指定的模块
+ * @param {string} url - 要加载的模块URL
+ * @returns {Promise<any>} 返回加载的模块
+ * @throws {Error} 当URL无效或模块加载失败时抛出错误
+ */
export function loadUrl(url) {
+ if (typeof url !== 'string' || !url.trim()) {
+ throw new Error('URL must be a non-empty string');
+ }
+
+ try {
return import(`${url}`)
+ } catch (error) {
+ throw new Error(`Failed to load module at ${url}: ${error.message}`);
+ }
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const other = "other" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议改进模板字符串处理逻辑
当前的模板字符串处理逻辑可能存在边缘情况未处理:
Expr::Tpl(tpl) => { if !tpl.exprs.is_empty() { - let first_quasis_str = tpl.quasis.first().unwrap().raw.to_string(); + let first_quasis_str = tpl.quasis.first() + .ok_or_else(|| anyhow::anyhow!("Template literal must have at least one quasi"))? + .raw.to_string(); let pre_quasis = if first_quasis_str.is_empty() { "./".to_string() } else { first_quasis_str };📝 Committable suggestion