mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibJS: Update parser to detect if identifier refer a "local" variable
This modification enables the parser to determine whether an identifier used within a function refers to a local variable or not. In this context, a local identifier means that it is not captured by any nested function declaration which means it modified only from inside a function. The information about whether identifier is local is stored inside Identifier AST node and also contains information about the index of local variable inside a function and information about total number of local variables used by a function is stored in function nodes.
This commit is contained in:
parent
c734f2b5e6
commit
380abddf3c
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 380abddf3c
Pull-request: https://github.com/SerenityOS/serenity/pull/19719
Reviewed-by: https://github.com/awesomekling
4 changed files with 270 additions and 99 deletions
|
@ -2679,7 +2679,11 @@ Completion Identifier::execute(Interpreter& interpreter) const
|
|||
void Identifier::dump(int indent) const
|
||||
{
|
||||
print_indent(indent);
|
||||
outln("Identifier \"{}\"", m_string);
|
||||
if (is_local()) {
|
||||
outln("Identifier \"{}\" is_local=(true) index=({})", m_string, m_local_variable_index);
|
||||
} else {
|
||||
outln("Identifier \"{}\"", m_string);
|
||||
}
|
||||
}
|
||||
|
||||
Completion PrivateIdentifier::execute(Interpreter&) const
|
||||
|
@ -4435,6 +4439,16 @@ ThrowCompletionOr<void> ScopeNode::for_each_var_function_declaration_in_reverse_
|
|||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> ScopeNode::for_each_lexical_function_declaration_in_reverse_order(ThrowCompletionOrVoidCallback<FunctionDeclaration const&>&& callback) const
|
||||
{
|
||||
for (ssize_t i = m_lexical_declarations.size() - 1; i >= 0; i--) {
|
||||
auto& declaration = m_lexical_declarations[i];
|
||||
if (is<FunctionDeclaration>(declaration))
|
||||
TRY(callback(static_cast<FunctionDeclaration const&>(*declaration)));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> ScopeNode::for_each_var_scoped_variable_declaration(ThrowCompletionOrVoidCallback<VariableDeclaration const&>&& callback) const
|
||||
{
|
||||
for (auto& declaration : m_var_declarations) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue