mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibJS: Improve function hoisting across blocks
The parser now keeps track of a scope chain so that it can hoist function declarations to the closest function scope.
This commit is contained in:
parent
72f8d90dc5
commit
38fd980b0c
Notes:
sideshowbarker
2024-07-18 10:20:15 +09:00
Author: https://github.com/Hendi48
Commit: 38fd980b0c
Pull-request: https://github.com/SerenityOS/serenity/pull/8439
Issue: https://github.com/SerenityOS/serenity/issues/8299
Reviewed-by: https://github.com/linusg ✅
6 changed files with 79 additions and 22 deletions
|
@ -145,8 +145,10 @@ public:
|
|||
|
||||
void add_variables(NonnullRefPtrVector<VariableDeclaration>);
|
||||
void add_functions(NonnullRefPtrVector<FunctionDeclaration>);
|
||||
void add_hoisted_functions(NonnullRefPtrVector<FunctionDeclaration>);
|
||||
NonnullRefPtrVector<VariableDeclaration> const& variables() const { return m_variables; }
|
||||
NonnullRefPtrVector<FunctionDeclaration> const& functions() const { return m_functions; }
|
||||
NonnullRefPtrVector<FunctionDeclaration> const& hoisted_functions() const { return m_hoisted_functions; }
|
||||
|
||||
protected:
|
||||
explicit ScopeNode(SourceRange source_range)
|
||||
|
@ -160,6 +162,7 @@ private:
|
|||
NonnullRefPtrVector<Statement> m_children;
|
||||
NonnullRefPtrVector<VariableDeclaration> m_variables;
|
||||
NonnullRefPtrVector<FunctionDeclaration> m_functions;
|
||||
NonnullRefPtrVector<FunctionDeclaration> m_hoisted_functions;
|
||||
};
|
||||
|
||||
class Program final : public ScopeNode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue