Skip to content

Commit 31a1bc4

Browse files
autofix-ci[bot]Copilot
authored andcommitted
[autofix.ci] apply automated fixes
1 parent a187215 commit 31a1bc4

File tree

6 files changed

+70
-30
lines changed

6 files changed

+70
-30
lines changed

crates/oxc_compat/src/es_features.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ pub enum ESFeature {
5050
ES2022ClassProperties,
5151
ES2022PrivateMethods,
5252
ES2022MatchIndicesRegex,
53-
ES2022TopLevelAwait,
5453
ES2024UnicodeSetsRegex,
5554
ES2025DuplicateNamedCapturingGroupsRegex,
5655
ES2025RegexpModifiers,
5756
ES2026ExplicitResourceManagement,
5857
ES2020ExportNamespaceFrom,
58+
ES2022TopLevelAwait,
5959
}
6060
pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
6161
use ESFeature::*;
@@ -834,23 +834,6 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
834834
(Es, Version(2022u16, 0, 0)),
835835
])),
836836
),
837-
(
838-
ES2022TopLevelAwait,
839-
EngineTargets::new(FxHashMap::from_iter([
840-
(Samsung, Version(15u16, 0u16, 0u16)),
841-
(Node, Version(14u16, 8u16, 0u16)),
842-
(Firefox, Version(89u16, 0u16, 0u16)),
843-
(Chrome, Version(89u16, 0u16, 0u16)),
844-
(Safari, Version(15u16, 0u16, 0u16)),
845-
(Ios, Version(15u16, 0u16, 0u16)),
846-
(Edge, Version(89u16, 0u16, 0u16)),
847-
(OperaMobile, Version(63u16, 0u16, 0u16)),
848-
(Deno, Version(1u16, 0u16, 0u16)),
849-
(Electron, Version(12u16, 0u16, 0u16)),
850-
(Opera, Version(75u16, 0u16, 0u16)),
851-
(Es, Version(2022u16, 0, 0)),
852-
])),
853-
),
854837
(
855838
ES2024UnicodeSetsRegex,
856839
EngineTargets::new(FxHashMap::from_iter([
@@ -922,6 +905,23 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
922905
(Es, Version(2020u16, 0, 0)),
923906
])),
924907
),
908+
(
909+
ES2022TopLevelAwait,
910+
EngineTargets::new(FxHashMap::from_iter([
911+
(Samsung, Version(15u16, 0u16, 0u16)),
912+
(Node, Version(14u16, 8u16, 0u16)),
913+
(Firefox, Version(89u16, 0u16, 0u16)),
914+
(Chrome, Version(89u16, 0u16, 0u16)),
915+
(Safari, Version(15u16, 0u16, 0u16)),
916+
(Ios, Version(15u16, 0u16, 0u16)),
917+
(Edge, Version(89u16, 0u16, 0u16)),
918+
(OperaMobile, Version(63u16, 0u16, 0u16)),
919+
(Deno, Version(1u16, 0u16, 0u16)),
920+
(Electron, Version(12u16, 0u16, 0u16)),
921+
(Opera, Version(75u16, 0u16, 0u16)),
922+
(Es, Version(2022u16, 0, 0)),
923+
])),
924+
),
925925
])
926926
})
927927
}

crates/oxc_transformer/src/es2022/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ impl<'a> Traverse<'a, TransformState<'a>> for ES2022<'a, '_> {
132132
}
133133
}
134134

135-
fn enter_await_expression(&mut self, node: &mut AwaitExpression<'a>, ctx: &mut TraverseCtx<'a>) {
136-
if self.options.top_level_await && Self::is_top_level_await(ctx) {
135+
fn enter_await_expression(
136+
&mut self,
137+
node: &mut AwaitExpression<'a>,
138+
ctx: &mut TraverseCtx<'a>,
139+
) {
140+
if self.options.top_level_await && Self::is_top_level(ctx) {
137141
let warning = OxcDiagnostic::warn(
138142
"Top-level await is not available in the configured target environment.",
139143
)
@@ -144,9 +148,7 @@ impl<'a> Traverse<'a, TransformState<'a>> for ES2022<'a, '_> {
144148
}
145149

146150
impl ES2022<'_, '_> {
147-
fn is_top_level_await(ctx: &TraverseCtx) -> bool {
148-
// Check if the hoist scope is the root scope
149-
// Top-level await means await at the module top level
151+
fn is_top_level(ctx: &TraverseCtx) -> bool {
150152
ctx.current_hoist_scope_id() == ctx.scoping().root_scope_id()
151153
}
152154
}

crates/oxc_transformer/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ impl<'a> Traverse<'a, TransformState<'a>> for TransformerImpl<'a, '_> {
250250
self.x2_es2020.enter_big_int_literal(node, ctx);
251251
}
252252

253-
fn enter_await_expression(&mut self, node: &mut AwaitExpression<'a>, ctx: &mut TraverseCtx<'a>) {
253+
fn enter_await_expression(
254+
&mut self,
255+
node: &mut AwaitExpression<'a>,
256+
ctx: &mut TraverseCtx<'a>,
257+
) {
254258
self.x2_es2022.enter_await_expression(node, ctx);
255259
}
256260

tasks/compat_data/custom-compat-data.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ const customEs2020 = [
2727
},
2828
].map(f('ES2020'));
2929

30-
module.exports = [...customEs2020];
30+
const customEs2022 = [
31+
{
32+
name: 'TopLevelAwait',
33+
babel: null,
34+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility
35+
targets: {
36+
chrome: '89',
37+
opera: '75',
38+
edge: '89',
39+
firefox: '89',
40+
safari: '15.0',
41+
node: '14.8',
42+
deno: '1.0',
43+
ios: '15.0',
44+
samsung: '15.0',
45+
opera_mobile: '63',
46+
electron: '12.0',
47+
},
48+
},
49+
].map(f('ES2022'));
50+
51+
module.exports = [...customEs2020, ...customEs2022];

tasks/compat_data/data.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,5 +1066,23 @@
10661066
"electron": "5.0"
10671067
},
10681068
"es": "ES2020"
1069+
},
1070+
{
1071+
"name": "TopLevelAwait",
1072+
"babel": null,
1073+
"targets": {
1074+
"chrome": "89",
1075+
"opera": "75",
1076+
"edge": "89",
1077+
"firefox": "89",
1078+
"safari": "15.0",
1079+
"node": "14.8",
1080+
"deno": "1.0",
1081+
"ios": "15.0",
1082+
"samsung": "15.0",
1083+
"opera_mobile": "63",
1084+
"electron": "12.0"
1085+
},
1086+
"es": "ES2022"
10691087
}
10701088
]

tasks/compat_data/es-features.js

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

307302
const es2024 = [

0 commit comments

Comments
 (0)