diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 4f2e761bab..45b6bab6c5 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -351,12 +351,24 @@ public: continue; if (!identifier_group.captured_by_nested_function && !identifier_group.used_inside_with_statement) { - auto function_scope = last_function_scope(); - if (!function_scope || m_screwed_by_eval_in_scope_chain) { + if (m_screwed_by_eval_in_scope_chain) continue; + + auto local_scope = last_function_scope(); + if (!local_scope) { + // NOTE: If there is no function scope, we are in a *descendant* of the global program scope. + // While we cannot make `let` and `const` into locals in the topmost program scope, + // as that would break expected web behavior where subsequent