mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +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:
@@ -196,13 +196,29 @@ private:
|
||||
|
||||
[[nodiscard]] RulePosition push_start() { return { *this, position() }; }
|
||||
|
||||
struct Scope : public RefCounted<Scope> {
|
||||
enum Type {
|
||||
Function,
|
||||
Block,
|
||||
};
|
||||
|
||||
Type type;
|
||||
RefPtr<Scope> parent;
|
||||
|
||||
NonnullRefPtrVector<FunctionDeclaration> function_declarations;
|
||||
NonnullRefPtrVector<FunctionDeclaration> hoisted_function_declarations;
|
||||
|
||||
explicit Scope(Type, RefPtr<Scope>);
|
||||
RefPtr<Scope> get_current_function_scope();
|
||||
};
|
||||
|
||||
struct ParserState {
|
||||
Lexer lexer;
|
||||
Token current_token;
|
||||
Vector<Error> errors;
|
||||
Vector<NonnullRefPtrVector<VariableDeclaration>> var_scopes;
|
||||
Vector<NonnullRefPtrVector<VariableDeclaration>> let_scopes;
|
||||
Vector<NonnullRefPtrVector<FunctionDeclaration>> function_scopes;
|
||||
RefPtr<Scope> current_scope;
|
||||
|
||||
Vector<Vector<FunctionNode::Parameter>&> function_parameters;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user