Skip to content

Commit

Permalink
Skip environment creation when possible for arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Sep 22, 2024
1 parent 4c16b20 commit 27ab91a
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 93 deletions.
7 changes: 7 additions & 0 deletions core/ast/src/expression/literal/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ impl ObjectMethodDefinition {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the object method definition contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for ObjectMethodDefinition {
Expand Down
7 changes: 7 additions & 0 deletions core/ast/src/function/arrow_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ impl ArrowFunction {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the arrow function contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for ArrowFunction {
Expand Down
7 changes: 7 additions & 0 deletions core/ast/src/function/async_arrow_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ impl AsyncArrowFunction {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the function declaration contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for AsyncArrowFunction {
Expand Down
14 changes: 14 additions & 0 deletions core/ast/src/function/async_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ impl AsyncFunctionDeclaration {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the async function declaration contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for AsyncFunctionDeclaration {
Expand Down Expand Up @@ -207,6 +214,13 @@ impl AsyncFunctionExpression {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the async function expression contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for AsyncFunctionExpression {
Expand Down
14 changes: 14 additions & 0 deletions core/ast/src/function/async_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ impl AsyncGeneratorDeclaration {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the async generator declaration contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for AsyncGeneratorDeclaration {
Expand Down Expand Up @@ -206,6 +213,13 @@ impl AsyncGeneratorExpression {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the async generator expression contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for AsyncGeneratorExpression {
Expand Down
7 changes: 7 additions & 0 deletions core/ast/src/function/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,13 @@ impl ClassMethodDefinition {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the class method definition contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for ClassMethodDefinition {
Expand Down
14 changes: 14 additions & 0 deletions core/ast/src/function/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ impl GeneratorDeclaration {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the generator declaration contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for GeneratorDeclaration {
Expand Down Expand Up @@ -205,6 +212,13 @@ impl GeneratorExpression {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the generator expression contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for GeneratorExpression {
Expand Down
14 changes: 14 additions & 0 deletions core/ast/src/function/ordinary_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ impl FunctionDeclaration {
pub const fn scopes(&self) -> &FunctionScopes {
&self.scopes
}

/// Returns `true` if the function declaration contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}
}

impl ToIndentedString for FunctionDeclaration {
Expand Down Expand Up @@ -207,6 +214,13 @@ impl FunctionExpression {
&self.scopes
}

/// Returns `true` if the function expression contains a direct call to `eval`.
#[inline]
#[must_use]
pub const fn contains_direct_eval(&self) -> bool {
self.contains_direct_eval
}

/// Analyze the scope of the function expression.
pub fn analyze_scope(&mut self, strict: bool, scope: &Scope, interner: &Interner) -> bool {
if !collect_bindings(self, strict, false, scope, interner) {
Expand Down
Loading

0 comments on commit 27ab91a

Please sign in to comment.