mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
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:
parent
e0c9f58b0c
commit
72f8d90dc5
3 changed files with 9 additions and 21 deletions
|
@ -1310,13 +1310,6 @@ void FunctionNode::dump(int indent, String const& class_name) const
|
||||||
parameter.default_value->dump(indent + 3);
|
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);
|
print_indent(indent + 1);
|
||||||
outln("(Body)");
|
outln("(Body)");
|
||||||
body().dump(indent + 2);
|
body().dump(indent + 2);
|
||||||
|
|
|
@ -257,11 +257,10 @@ public:
|
||||||
FunctionKind kind() const { return m_kind; }
|
FunctionKind kind() const { return m_kind; }
|
||||||
|
|
||||||
protected:
|
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_name(move(name))
|
||||||
, m_body(move(body))
|
, m_body(move(body))
|
||||||
, m_parameters(move(parameters))
|
, m_parameters(move(parameters))
|
||||||
, m_variables(move(variables))
|
|
||||||
, m_function_length(function_length)
|
, m_function_length(function_length)
|
||||||
, m_kind(kind)
|
, m_kind(kind)
|
||||||
, m_is_strict_mode(is_strict_mode)
|
, m_is_strict_mode(is_strict_mode)
|
||||||
|
@ -271,8 +270,6 @@ protected:
|
||||||
|
|
||||||
void dump(int indent, String const& class_name) const;
|
void dump(int indent, String const& class_name) const;
|
||||||
|
|
||||||
NonnullRefPtrVector<VariableDeclaration> const& variables() const { return m_variables; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_name(FlyString name)
|
void set_name(FlyString name)
|
||||||
{
|
{
|
||||||
|
@ -284,7 +281,6 @@ private:
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
NonnullRefPtr<Statement> m_body;
|
NonnullRefPtr<Statement> m_body;
|
||||||
Vector<Parameter> const m_parameters;
|
Vector<Parameter> const m_parameters;
|
||||||
NonnullRefPtrVector<VariableDeclaration> m_variables;
|
|
||||||
const i32 m_function_length;
|
const i32 m_function_length;
|
||||||
FunctionKind m_kind;
|
FunctionKind m_kind;
|
||||||
bool m_is_strict_mode;
|
bool m_is_strict_mode;
|
||||||
|
@ -297,9 +293,9 @@ class FunctionDeclaration final
|
||||||
public:
|
public:
|
||||||
static bool must_have_name() { return true; }
|
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)
|
: 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:
|
public:
|
||||||
static bool must_have_name() { return false; }
|
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)
|
: 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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,6 @@ NonnullRefPtr<Statement> Parser::parse_statement()
|
||||||
RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expect_parens)
|
RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expect_parens)
|
||||||
{
|
{
|
||||||
save_state();
|
save_state();
|
||||||
m_state.var_scopes.append(NonnullRefPtrVector<VariableDeclaration>());
|
|
||||||
auto rule_start = push_start();
|
auto rule_start = push_start();
|
||||||
|
|
||||||
ArmedScopeGuard state_rollback_guard = [&] {
|
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();
|
auto body = function_body_result.release_nonnull();
|
||||||
return create_ast_node<FunctionExpression>(
|
return create_ast_node<FunctionExpression>(
|
||||||
{ m_state.current_token.filename(), rule_start.position(), position() }, "", move(body),
|
{ 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;
|
return nullptr;
|
||||||
|
@ -623,11 +622,11 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
|
||||||
|
|
||||||
constructor = create_ast_node<FunctionExpression>(
|
constructor = create_ast_node<FunctionExpression>(
|
||||||
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
|
{ 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 {
|
} else {
|
||||||
constructor = create_ast_node<FunctionExpression>(
|
constructor = create_ast_node<FunctionExpression>(
|
||||||
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
|
{ 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());
|
body->add_functions(m_state.function_scopes.last());
|
||||||
return create_ast_node<FunctionNodeType>(
|
return create_ast_node<FunctionNodeType>(
|
||||||
{ m_state.current_token.filename(), rule_start.position(), position() },
|
{ 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);
|
is_generator ? FunctionKind::Generator : FunctionKind::Regular, is_strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue