mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 11:41:13 +08:00
fix: TLA 游走器补 export 声明顶层 await 判定
This commit is contained in:
@@ -546,3 +546,42 @@ fn sync_dep_no_gate() {
|
||||
assert_eq!(native_calls_to(&ir, "__moduleWaitAll"), 0, "同步依赖不得发聚合 gate");
|
||||
assert_eq!(ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(), 0, "主身不得含 AWAIT");
|
||||
}
|
||||
|
||||
/// 面 25:`export const x = await ...`(ExportNamedDeclaration 带变量声明)是
|
||||
/// 顶层 await,模块标记异步、体 await 编译为 AWAIT。
|
||||
#[test]
|
||||
fn export_named_var_decl_await_makes_module_async() {
|
||||
let (ir, _) = emit_module("export const x = await Promise.resolve(1);", "./entry.js", &[])
|
||||
.expect("export const x = await 模块应编译成功");
|
||||
assert!(ir.is_async, "export const x = await ... 应标记模块异步求值");
|
||||
assert_eq!(
|
||||
ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(),
|
||||
1,
|
||||
"顶层 await 应编译为一条 AWAIT"
|
||||
);
|
||||
}
|
||||
|
||||
/// 面 26:`export default await ...`(ExportDefaultDeclaration 表达式形态)是
|
||||
/// 顶层 await,模块标记异步、体 await 编译为 AWAIT。
|
||||
#[test]
|
||||
fn export_default_await_makes_module_async() {
|
||||
let (ir, _) = emit_module("export default await Promise.resolve(1);", "./entry.js", &[])
|
||||
.expect("export default await 模块应编译成功");
|
||||
assert!(ir.is_async, "export default await ... 应标记模块异步求值");
|
||||
assert_eq!(
|
||||
ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(),
|
||||
1,
|
||||
"顶层 await 应编译为一条 AWAIT"
|
||||
);
|
||||
}
|
||||
|
||||
/// 面 27:`export const f = async () => {}`(导出声明初始化器为异步函数表达式)
|
||||
/// 不使模块异步——函数体是独立异步语义边界,不进入游走。
|
||||
#[test]
|
||||
fn export_named_async_fn_expr_not_tla() {
|
||||
let (ir, _) =
|
||||
emit_module("export const f = async () => { await Promise.resolve(1); };", "./entry.js", &[])
|
||||
.expect("导出异步函数表达式模块应编译成功");
|
||||
assert!(!ir.is_async, "异步函数表达式体不得使模块标记异步");
|
||||
assert_eq!(ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(), 0, "主身不得含 AWAIT");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user