LibJS: Remove variables from FunctionNode

They weren't consumed anywhere outside the AST and went
against the usual concept of having declaration in ScopeNode.
This commit is contained in:
Hendi 2021-07-04 03:12:27 +02:00 committed by Linus Groh
parent e0c9f58b0c
commit 72f8d90dc5
Notes: sideshowbarker 2024-07-18 10:20:19 +09:00
3 changed files with 9 additions and 21 deletions

View File

@ -1310,13 +1310,6 @@ void FunctionNode::dump(int indent, String const& class_name) const
parameter.default_value->dump(indent + 3);
}
}
if (!m_variables.is_empty()) {
print_indent(indent + 1);
outln("(Variables)");
for (auto& variable : m_variables)
variable.dump(indent + 2);
}
print_indent(indent + 1);
outln("(Body)");
body().dump(indent + 2);

View File

@ -257,11 +257,10 @@ public:
FunctionKind kind() const { return m_kind; }
protected:
FunctionNode(FlyString name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode, bool is_arrow_function)
FunctionNode(FlyString name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool is_arrow_function)
: m_name(move(name))
, m_body(move(body))
, m_parameters(move(parameters))
, m_variables(move(variables))
, m_function_length(function_length)
, m_kind(kind)
, m_is_strict_mode(is_strict_mode)
@ -271,8 +270,6 @@ protected:
void dump(int indent, String const& class_name) const;
NonnullRefPtrVector<VariableDeclaration> const& variables() const { return m_variables; }
protected:
void set_name(FlyString name)
{
@ -284,7 +281,6 @@ private:
FlyString m_name;
NonnullRefPtr<Statement> m_body;
Vector<Parameter> const m_parameters;
NonnullRefPtrVector<VariableDeclaration> m_variables;
const i32 m_function_length;
FunctionKind m_kind;
bool m_is_strict_mode;
@ -297,9 +293,9 @@ class FunctionDeclaration final
public:
static bool must_have_name() { return true; }
FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode = false)
FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode = false)
: Declaration(source_range)
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), kind, is_strict_mode, false)
, FunctionNode(name, move(body), move(parameters), function_length, kind, is_strict_mode, false)
{
}
@ -314,9 +310,9 @@ class FunctionExpression final
public:
static bool must_have_name() { return false; }
FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode, bool is_arrow_function = false)
FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool is_arrow_function = false)
: Expression(source_range)
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), kind, is_strict_mode, is_arrow_function)
, FunctionNode(name, move(body), move(parameters), function_length, kind, is_strict_mode, is_arrow_function)
{
}

View File

@ -348,7 +348,6 @@ NonnullRefPtr<Statement> Parser::parse_statement()
RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expect_parens)
{
save_state();
m_state.var_scopes.append(NonnullRefPtrVector<VariableDeclaration>());
auto rule_start = push_start();
ArmedScopeGuard state_rollback_guard = [&] {
@ -426,7 +425,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
auto body = function_body_result.release_nonnull();
return create_ast_node<FunctionExpression>(
{ m_state.current_token.filename(), rule_start.position(), position() }, "", move(body),
move(parameters), function_length, m_state.var_scopes.take_last(), FunctionKind::Regular, is_strict, true);
move(parameters), function_length, FunctionKind::Regular, is_strict, true);
}
return nullptr;
@ -623,11 +622,11 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
constructor = create_ast_node<FunctionExpression>(
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
Vector { FunctionNode::Parameter { FlyString { "args" }, nullptr, true } }, 0, NonnullRefPtrVector<VariableDeclaration>(), FunctionKind::Regular, true);
Vector { FunctionNode::Parameter { FlyString { "args" }, nullptr, true } }, 0, FunctionKind::Regular, true);
} else {
constructor = create_ast_node<FunctionExpression>(
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
Vector<FunctionNode::Parameter> {}, 0, NonnullRefPtrVector<VariableDeclaration>(), FunctionKind::Regular, true);
Vector<FunctionNode::Parameter> {}, 0, FunctionKind::Regular, true);
}
}
@ -1465,7 +1464,7 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
body->add_functions(m_state.function_scopes.last());
return create_ast_node<FunctionNodeType>(
{ m_state.current_token.filename(), rule_start.position(), position() },
name, move(body), move(parameters), function_length, NonnullRefPtrVector<VariableDeclaration>(),
name, move(body), move(parameters), function_length,
is_generator ? FunctionKind::Generator : FunctionKind::Regular, is_strict);
}