mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 05:00:05 +08:00
fix(script): support runtime console methods during validation
This commit is contained in:
@@ -26,7 +26,7 @@ pub enum MainDeclaration {
|
||||
pub fn validate(source: &str) -> Result<MainDeclaration, std::string::String> {
|
||||
let mut context = Context::default();
|
||||
let _ = context.eval(Source::from_bytes(
|
||||
"var console = Object.freeze({log(...data){},info(...data){},error(...data){},debug(...data){}});",
|
||||
"var console = Object.freeze({log(...data){},info(...data){},error(...data){},debug(...data){},warn(...data){},table(...data){}});",
|
||||
));
|
||||
context
|
||||
.eval(Source::from_bytes(source))
|
||||
@@ -256,6 +256,14 @@ mod tests {
|
||||
assert_eq!(validate("const main = 42;"), Ok(MainDeclaration::Missing));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validation_supports_console_methods_at_top_level() {
|
||||
assert_eq!(
|
||||
validate("console.warn('setup'); console.table([1]); function main(config) { return config; }"),
|
||||
Ok(MainDeclaration::Present)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validation_distinguishes_missing_main_from_evaluation_failure() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user