Skip to content

Commit

Permalink
feat(ast): add ArrowFunctionExpression::has_use_strict_directive me…
Browse files Browse the repository at this point in the history
…thod (#7784)

Add `ArrowFunctionExpression::has_use_strict_directive` method to go with `Function::has_use_strict_directive` etc.
  • Loading branch information
overlookmotel committed Dec 10, 2024
1 parent 96a26d3 commit f7900ab
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7900ab

Please sign in to comment.