Commit 24fb7b47 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Avoid superfluous var decl proxy creation

var declarations that walk through with scopes are special in that the variable
will always end up in the outer declaration scope, but the initializer for the
var will possibly target the with scope. Hence we can't simply use the resolved
variable proxy from the declaration for the initialization. However, if we know
that the var declaration lives in the scope where it will be declared (the
common case), there can't be a with scope in between. Hence we are free to
reuse the proxy.

Change-Id: I434abcd5df1a44313a8b8da3303cf5748299de4b
Reviewed-on: https://chromium-review.googlesource.com/c/1261450Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56403}
parent 8caaeb37
......@@ -256,15 +256,15 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
//
// var v; v = x;
//
// In particular, we need to re-lookup 'v' as it may be a different
// 'v' than the 'v' in the declaration (e.g., if we are inside a
// 'with' statement or 'catch' block). Global var declarations
// also need special treatment.
// For 'let' and 'const' declared variables the initialization always
// assigns to the declared variable.
// But for var declarations we need to do a new lookup.
if (descriptor_->mode == VariableMode::kVar) {
// In particular, we need to re-lookup 'v' if it may be a different 'v' than
// the 'v' in the declaration (e.g., if we are inside a 'with' statement or
// 'catch' block).
// For 'let' and 'const' declared variables the initialization always assigns
// to the declared variable. But for var declarations that target a different
// scope we need to do a new lookup.
if (descriptor_->mode == VariableMode::kVar &&
var_init_scope != declaration_scope) {
proxy = var_init_scope->NewUnresolved(factory(), name);
} else {
DCHECK_NOT_NULL(proxy);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment