Skip to content

Commit b7c7950

Browse files
Copilotsapphi-red
andcommitted
Address review feedback: use scoping() to check root scope and add TopLevelAwait to es-features.js
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent 4b25cc0 commit b7c7950

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

crates/oxc_transformer/src/es2022/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,8 @@ impl<'a> Traverse<'a, TransformState<'a>> for ES2022<'a, '_> {
145145

146146
impl ES2022<'_, '_> {
147147
fn is_top_level_await(ctx: &TraverseCtx) -> bool {
148-
use oxc_traverse::Ancestor;
149-
150-
// Check if we're inside any function
151-
// Top-level await means await at the module top level (not inside any function)
152-
for ancestor in ctx.ancestors() {
153-
match ancestor {
154-
Ancestor::FunctionBody(_) | Ancestor::ArrowFunctionExpressionBody(_) => {
155-
// If inside any function, it's not top-level await
156-
return false;
157-
}
158-
_ => {}
159-
}
160-
}
161-
162-
// If we didn't find any function ancestor, it's top-level await
163-
true
148+
// Check if the hoist scope is the root scope
149+
// Top-level await means await at the module top level
150+
ctx.current_hoist_scope_id() == ctx.scoping().root_scope_id()
164151
}
165152
}

tasks/compat_data/es-features.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ const es2022 = [
297297
// ignore "shows up in flags"
298298
],
299299
},
300+
{
301+
name: 'TopLevelAwait',
302+
babel: null,
303+
features: [],
304+
},
300305
].map(f('ES2022'));
301306

302307
const es2024 = [

0 commit comments

Comments
 (0)