-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(esbuildHelperChecker): catch js parse error #12285
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
WalkthroughThe recent update to the Changes
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
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 Configration File (
|
Size Change: +69 B (0%) Total Size: 9.9 MB
ℹ️ View Unchanged
|
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.
Actionable comments posted: 1
export async function getGlobalVars(opts: { | ||
content: string; | ||
fileName: string; | ||
}) { | ||
const vars: string[] = []; | ||
ast.program.body.forEach((node) => { | ||
if (t.isVariableDeclaration(node)) { | ||
node.declarations.forEach((declaration) => { | ||
if (t.isVariableDeclarator(declaration)) { | ||
if (t.isIdentifier(declaration.id)) { | ||
vars.push(declaration.id.name); | ||
/** | ||
* 产物目录可能会有用户自定义的非标准 js 文件,会导致 parse 异常,这里转为 error 提示,不中断程序 | ||
* eg. git lfs 会生成不符合 js 规范的 js 文件 | ||
*/ | ||
try { | ||
const ast = parser.parse(opts.content, { | ||
sourceType: 'module', | ||
sourceFilename: 'foo.js', | ||
plugins: [], | ||
}); | ||
ast.program.body.forEach((node) => { | ||
if (t.isVariableDeclaration(node)) { | ||
node.declarations.forEach((declaration) => { | ||
if (t.isVariableDeclarator(declaration)) { | ||
if (t.isIdentifier(declaration.id)) { | ||
vars.push(declaration.id.name); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} catch (error: any) { | ||
logger.error( | ||
`[esbuildHelperChecker] Failed to parse ${opts.fileName}, ${error.message}`, | ||
); | ||
} |
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.
Refine the hardcoded filename in parser options.
The sourceFilename
property in the parser options is currently hardcoded to 'foo.js'. It would be more appropriate to use the actual fileName
from the function's parameters to enhance the error context and debugging process.
- sourceFilename: 'foo.js',
+ sourceFilename: opts.fileName,
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
export async function getGlobalVars(opts: { | |
content: string; | |
fileName: string; | |
}) { | |
const vars: string[] = []; | |
ast.program.body.forEach((node) => { | |
if (t.isVariableDeclaration(node)) { | |
node.declarations.forEach((declaration) => { | |
if (t.isVariableDeclarator(declaration)) { | |
if (t.isIdentifier(declaration.id)) { | |
vars.push(declaration.id.name); | |
/** | |
* 产物目录可能会有用户自定义的非标准 js 文件,会导致 parse 异常,这里转为 error 提示,不中断程序 | |
* eg. git lfs 会生成不符合 js 规范的 js 文件 | |
*/ | |
try { | |
const ast = parser.parse(opts.content, { | |
sourceType: 'module', | |
sourceFilename: 'foo.js', | |
plugins: [], | |
}); | |
ast.program.body.forEach((node) => { | |
if (t.isVariableDeclaration(node)) { | |
node.declarations.forEach((declaration) => { | |
if (t.isVariableDeclarator(declaration)) { | |
if (t.isIdentifier(declaration.id)) { | |
vars.push(declaration.id.name); | |
} | |
} | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
}); | |
} catch (error: any) { | |
logger.error( | |
`[esbuildHelperChecker] Failed to parse ${opts.fileName}, ${error.message}`, | |
); | |
} | |
export async function getGlobalVars(opts: { | |
content: string; | |
fileName: string; | |
}) { | |
const vars: string[] = []; | |
/** | |
* 产物目录可能会有用户自定义的非标准 js 文件,会导致 parse 异常,这里转为 error 提示,不中断程序 | |
* eg. git lfs 会生成不符合 js 规范的 js 文件 | |
*/ | |
try { | |
const ast = parser.parse(opts.content, { | |
sourceType: 'module', | |
sourceFilename: opts.fileName, | |
plugins: [], | |
}); | |
ast.program.body.forEach((node) => { | |
if (t.isVariableDeclaration(node)) { | |
node.declarations.forEach((declaration) => { | |
if (t.isVariableDeclarator(declaration)) { | |
if (t.isIdentifier(declaration.id)) { | |
vars.push(declaration.id.name); | |
} | |
} | |
}); | |
} | |
}); | |
} catch (error: any) { | |
logger.error( | |
`[esbuildHelperChecker] Failed to parse ${opts.fileName}, ${error.message}`, | |
); | |
} |
产物目录可能会有用户自定义的非标准 js 文件,会导致 parse 异常,这里转为 error 提示,不中断 esbuildHelperChecker 检查
Summary by CodeRabbit