From f7900ab2463658fdc2f2075b9aa466a4938b3bcb Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:57:41 +0000 Subject: [PATCH] feat(ast): add `ArrowFunctionExpression::has_use_strict_directive` method (#7784) Add `ArrowFunctionExpression::has_use_strict_directive` method to go with `Function::has_use_strict_directive` etc. --- crates/oxc_ast/src/ast/js.rs | 2 +- crates/oxc_ast/src/ast_impl/js.rs | 5 +++++ crates/oxc_ast/src/generated/visit.rs | 2 +- crates/oxc_ast/src/generated/visit_mut.rs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index efb72a22e..a6174ece6 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1701,7 +1701,7 @@ pub struct FunctionBody<'a> { #[ast(visit)] #[scope( flags(ScopeFlags::Function | ScopeFlags::Arrow), - strict_if(self.body.has_use_strict_directive()), + strict_if(self.has_use_strict_directive()), )] #[derive(Debug)] #[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)] diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index dacdec4f3..8db452837 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -1094,6 +1094,11 @@ impl<'a> ArrowFunctionExpression<'a> { } None } + + /// Returns `true` if this arrow function's body has a `"use strict"` directive. + pub fn has_use_strict_directive(&self) -> bool { + self.body.has_use_strict_directive() + } } impl Class<'_> { diff --git a/crates/oxc_ast/src/generated/visit.rs b/crates/oxc_ast/src/generated/visit.rs index 24457baff..70da037f4 100644 --- a/crates/oxc_ast/src/generated/visit.rs +++ b/crates/oxc_ast/src/generated/visit.rs @@ -1684,7 +1684,7 @@ pub mod walk { visitor.enter_scope( { let mut flags = ScopeFlags::Function | ScopeFlags::Arrow; - if it.body.has_use_strict_directive() { + if it.has_use_strict_directive() { flags |= ScopeFlags::StrictMode; } flags diff --git a/crates/oxc_ast/src/generated/visit_mut.rs b/crates/oxc_ast/src/generated/visit_mut.rs index e23a8a672..43615f863 100644 --- a/crates/oxc_ast/src/generated/visit_mut.rs +++ b/crates/oxc_ast/src/generated/visit_mut.rs @@ -1703,7 +1703,7 @@ pub mod walk_mut { visitor.enter_scope( { let mut flags = ScopeFlags::Function | ScopeFlags::Arrow; - if it.body.has_use_strict_directive() { + if it.has_use_strict_directive() { flags |= ScopeFlags::StrictMode; } flags