Commit 53667c89 authored by marja's avatar marja Committed by Commit bot

[parser] Skipping inner funcs: produce correct data for var redeclarations.

This unifies the behavior of Scope::DeclareVariableName with
Scope::DeclareVariable.

BUG=v8:5516

Review-Url: https://codereview.chromium.org/2658063005
Cr-Commit-Position: refs/heads/master@{#42744}
parent aaaffd37
......@@ -1083,8 +1083,14 @@ void Scope::DeclareVariableName(const AstRawString* name, VariableMode mode) {
// Declare the variable in the declaration scope.
if (FLAG_preparser_scope_analysis) {
Variable* var = LookupLocal(name);
DCHECK_NE(var, kDummyPreParserLexicalVariable);
DCHECK_NE(var, kDummyPreParserVariable);
if (var == nullptr) {
var = DeclareLocal(name, mode);
} else if (!IsLexicalVariableMode(var->mode()) &&
!IsLexicalVariableMode(mode)) {
DCHECK_EQ(mode, VAR);
var->set_maybe_assigned();
}
var->set_is_used();
} else {
......
......@@ -9066,6 +9066,15 @@ TEST(PreParserScopeAnalysis) {
{"", "const var1 = 5;"},
{"", "if (true) { const var1 = 5; }"},
{"", "const var1 = 5; function f() { var1; }"},
{"", "var var1; var var1;"},
{"", "var var1; var var1; var1 = 5;"},
{"", "var var1; if (true) { var var1; }"},
{"", "if (true) { var var1; var var1; }"},
{"", "var var1; if (true) { var var1; var1 = 5; }"},
{"", "if (true) { var var1; var var1; var1 = 5; }"},
{"", "var var1; var var1; function f() { var1; }"},
{"", "var var1; var var1; function f() { var1 = 5; }"},
};
for (unsigned i = 0; i < arraysize(inners); ++i) {
......
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