Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: src/parsing/pattern-rewriter.cc

Issue 2656753003: [ast/parsing] Pessimistically assume all top-level variables will be assigned. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parsing/pattern-rewriter.cc
diff --git a/src/parsing/pattern-rewriter.cc b/src/parsing/pattern-rewriter.cc
index 78830297f4d979015b14a1f37c69a4c3577c0481..0713b805f3e93fe309c2152970f2aca29f6c90d5 100644
--- a/src/parsing/pattern-rewriter.cc
+++ b/src/parsing/pattern-rewriter.cc
@@ -162,6 +162,9 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
names_->Add(name, zone());
}
+ Scope* var_init_scope = descriptor_->scope;
+ MarkTopLevelVariableAsAssigned(var_init_scope, proxy);
marja 2017/01/25 12:44:10 This CL is a bit weird in that we need to remember
+
// If there's no initializer, we're done.
if (value == nullptr) return;
@@ -177,7 +180,6 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// '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.
- Scope* var_init_scope = descriptor_->scope;
if (descriptor_->mode == VAR && var_init_scope->is_script_scope()) {
// Global variable declarations must be compiled in a specific
@@ -220,19 +222,9 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// But for var declarations we need to do a new lookup.
if (descriptor_->mode == VAR) {
proxy = var_init_scope->NewUnresolved(factory(), name);
- // TODO(neis): Set is_assigned on proxy.
} else {
DCHECK_NOT_NULL(proxy);
DCHECK_NOT_NULL(proxy->var());
- if (var_init_scope->is_script_scope() ||
- var_init_scope->is_module_scope()) {
- // We have to pessimistically assume that top-level variables will be
- // assigned. This is because they might be accessed by a lazily parsed
- // top-level function, which, for efficiency, we preparse without
- // variable tracking. In the case of a script (not a module), they
- // might also get accessed by another script.
- proxy->set_is_assigned();
- }
}
// Add break location for destructured sub-pattern.
int pos = IsSubPattern() ? pattern->position() : value->position();
« src/parsing/parser.h ('K') | « src/parsing/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698