summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/AST.h
diff options
context:
space:
mode:
authorHendi <hendi48@users.noreply.github.com>2021-07-04 03:15:52 +0200
committerLinus Groh <mail@linusgroh.de>2021-07-06 00:15:37 +0100
commit38fd980b0ce98130f5f62ab8c87531a2b367da5c (patch)
treea6297d970ed05b5653beeb90c5ee739150009fee /Userland/Libraries/LibJS/AST.h
parent72f8d90dc5afb023eb2449511439fc2116783961 (diff)
downloadserenity-38fd980b0ce98130f5f62ab8c87531a2b367da5c.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/AST.h')
-rw-r--r--Userland/Libraries/LibJS/AST.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h
index e71a91b638..f6bc2639de 100644
--- a/Userland/Libraries/LibJS/AST.h
+++ b/Userland/Libraries/LibJS/AST.h
@@ -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 {