mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibJS: Preserve information about local variables declaration kind
This is required for upcoming change where we want to emit ThrowIfTDZ for assignment expressions only for lexical declarations.
This commit is contained in:
parent
2774068ca0
commit
db480b1f0c
Notes:
github-actions[bot]
2025-05-06 10:07:32 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: db480b1f0c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4616
Reviewed-by: https://github.com/awesomekling
11 changed files with 83 additions and 40 deletions
|
@ -298,17 +298,22 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool scope_has_declaration = false;
|
||||
if (is_top_level() && m_var_names.contains(identifier_group_name))
|
||||
scope_has_declaration = true;
|
||||
else if (m_lexical_names.contains(identifier_group_name) || m_function_names.contains(identifier_group_name))
|
||||
scope_has_declaration = true;
|
||||
Optional<LocalVariable::DeclarationKind> local_variable_declaration_kind;
|
||||
if (is_top_level() && m_var_names.contains(identifier_group_name)) {
|
||||
local_variable_declaration_kind = LocalVariable::DeclarationKind::Var;
|
||||
} else if (m_lexical_names.contains(identifier_group_name)) {
|
||||
local_variable_declaration_kind = LocalVariable::DeclarationKind::LetOrConst;
|
||||
} else if (m_function_names.contains(identifier_group_name)) {
|
||||
local_variable_declaration_kind = LocalVariable::DeclarationKind::Function;
|
||||
}
|
||||
|
||||
if (m_type == ScopeType::Function && !m_is_arrow_function && identifier_group_name == "arguments"sv)
|
||||
scope_has_declaration = true;
|
||||
if (m_type == ScopeType::Function && !m_is_arrow_function && identifier_group_name == "arguments"sv) {
|
||||
local_variable_declaration_kind = LocalVariable::DeclarationKind::ArgumentsObject;
|
||||
}
|
||||
|
||||
if (m_type == ScopeType::Catch && m_catch_parameter_names.contains(identifier_group_name))
|
||||
scope_has_declaration = true;
|
||||
if (m_type == ScopeType::Catch && m_catch_parameter_names.contains(identifier_group_name)) {
|
||||
local_variable_declaration_kind = LocalVariable::DeclarationKind::CatchClauseParameter;
|
||||
}
|
||||
|
||||
bool hoistable_function_declaration = false;
|
||||
for (auto const& function_declaration : m_functions_to_hoist) {
|
||||
|
@ -329,7 +334,7 @@ public:
|
|||
|
||||
if (m_type == ScopeType::ClassDeclaration) {
|
||||
// NOTE: Class declaration doesn't not have own ScopeNode hence can't contain declaration of any variable
|
||||
scope_has_declaration = false;
|
||||
local_variable_declaration_kind.clear();
|
||||
}
|
||||
|
||||
bool is_function_parameter = false;
|
||||
|
@ -353,7 +358,7 @@ public:
|
|||
for (auto& identifier : identifier_group.identifiers)
|
||||
identifier->set_is_global();
|
||||
}
|
||||
} else if (scope_has_declaration || is_function_parameter) {
|
||||
} else if (local_variable_declaration_kind.has_value() || is_function_parameter) {
|
||||
if (hoistable_function_declaration)
|
||||
continue;
|
||||
|
||||
|
@ -380,7 +385,7 @@ public:
|
|||
for (auto& identifier : identifier_group.identifiers)
|
||||
identifier->set_argument_index(argument_index.value());
|
||||
} else {
|
||||
auto local_variable_index = local_scope->m_node->add_local_variable(identifier_group_name);
|
||||
auto local_variable_index = local_scope->m_node->add_local_variable(identifier_group_name, *local_variable_declaration_kind);
|
||||
for (auto& identifier : identifier_group.identifiers)
|
||||
identifier->set_local_variable_index(local_variable_index);
|
||||
}
|
||||
|
@ -1656,7 +1661,7 @@ NonnullRefPtr<ClassExpression const> Parser::parse_class_expression(bool expect_
|
|||
constructor = create_ast_node<FunctionExpression>(
|
||||
{ m_source_code, rule_start.position(), position() }, class_name, "",
|
||||
move(constructor_body), FunctionParameters::create(Vector { FunctionParameter { move(argument_name), nullptr, true } }), 0, FunctionKind::Normal,
|
||||
/* is_strict_mode */ true, parsing_insights, /* local_variables_names */ Vector<FlyString> {});
|
||||
/* is_strict_mode */ true, parsing_insights, /* local_variables_names */ Vector<LocalVariable> {});
|
||||
} else {
|
||||
FunctionParsingInsights parsing_insights;
|
||||
parsing_insights.uses_this_from_environment = true;
|
||||
|
@ -1664,7 +1669,7 @@ NonnullRefPtr<ClassExpression const> Parser::parse_class_expression(bool expect_
|
|||
constructor = create_ast_node<FunctionExpression>(
|
||||
{ m_source_code, rule_start.position(), position() }, class_name, "",
|
||||
move(constructor_body), FunctionParameters::empty(), 0, FunctionKind::Normal,
|
||||
/* is_strict_mode */ true, parsing_insights, /* local_variables_names */ Vector<FlyString> {});
|
||||
/* is_strict_mode */ true, parsing_insights, /* local_variables_names */ Vector<LocalVariable> {});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue