mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 04:01:11 +08:00
style: 自动格式化
This commit is contained in:
@@ -423,15 +423,13 @@ fn stmt_has_top_level_await(stmt: &Statement) -> bool {
|
|||||||
Statement::FunctionDeclaration(_) | Statement::ClassDeclaration(_) => false,
|
Statement::FunctionDeclaration(_) | Statement::ClassDeclaration(_) => false,
|
||||||
// `export const/let/var x = await ...` 是顶层 await;
|
// `export const/let/var x = await ...` 是顶层 await;
|
||||||
// 函数/类声明形态不进入(体是独立异步语义边界,与裸声明臂同口径)。
|
// 函数/类声明形态不进入(体是独立异步语义边界,与裸声明臂同口径)。
|
||||||
Statement::ExportNamedDeclaration(exp) => {
|
Statement::ExportNamedDeclaration(exp) => exp.declaration.as_ref().is_some_and(|decl| match decl {
|
||||||
exp.declaration.as_ref().is_some_and(|decl| match decl {
|
|
||||||
Declaration::VariableDeclaration(vd) => vd
|
Declaration::VariableDeclaration(vd) => vd
|
||||||
.declarations
|
.declarations
|
||||||
.iter()
|
.iter()
|
||||||
.any(|d| d.init.as_ref().is_some_and(|i| expr_has_top_level_await(i))),
|
.any(|d| d.init.as_ref().is_some_and(|i| expr_has_top_level_await(i))),
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
}),
|
||||||
}
|
|
||||||
// `export default await ...` 是顶层 await;函数/类声明形态不进入(同口径)。
|
// `export default await ...` 是顶层 await;函数/类声明形态不进入(同口径)。
|
||||||
Statement::ExportDefaultDeclaration(exp) => {
|
Statement::ExportDefaultDeclaration(exp) => {
|
||||||
exp.declaration.as_expression().is_some_and(expr_has_top_level_await)
|
exp.declaration.as_expression().is_some_and(expr_has_top_level_await)
|
||||||
|
|||||||
@@ -579,8 +579,7 @@ fn export_default_await_makes_module_async() {
|
|||||||
/// 不使模块异步——函数体是独立异步语义边界,不进入游走。
|
/// 不使模块异步——函数体是独立异步语义边界,不进入游走。
|
||||||
#[test]
|
#[test]
|
||||||
fn export_named_async_fn_expr_not_tla() {
|
fn export_named_async_fn_expr_not_tla() {
|
||||||
let (ir, _) =
|
let (ir, _) = emit_module("export const f = async () => { await Promise.resolve(1); };", "./entry.js", &[])
|
||||||
emit_module("export const f = async () => { await Promise.resolve(1); };", "./entry.js", &[])
|
|
||||||
.expect("导出异步函数表达式模块应编译成功");
|
.expect("导出异步函数表达式模块应编译成功");
|
||||||
assert!(!ir.is_async, "异步函数表达式体不得使模块标记异步");
|
assert!(!ir.is_async, "异步函数表达式体不得使模块标记异步");
|
||||||
assert_eq!(ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(), 0, "主身不得含 AWAIT");
|
assert_eq!(ir.insts.iter().filter(|i| i.op == OpCode::AWAIT).count(), 0, "主身不得含 AWAIT");
|
||||||
|
|||||||
Reference in New Issue
Block a user