Commit 458bd3b9 authored by adamk's avatar adamk Committed by Commit bot

Slight cleanup of TryCatch parsing/variable declaration

Instead of unconditionally parsing the catch parameter as an expression
and then recovering if it turns out to be a simple variable proxy
(the overwhelmingly common case), this patch peeks one token ahead
before attempting to parse. This avoids doing the usual RemoveUnresolved
gymnastics in ParseTryStatement, and as a side-effect slightly improves
function name inference for an async arrow function test case.

Review-Url: https://codereview.chromium.org/2151433005
Cr-Commit-Position: refs/heads/master@{#37780}
parent 53be2530
......@@ -2995,17 +2995,14 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
BlockState block_state(&scope_, block_scope);
Target target(&this->target_stack_, catch_block);
ExpressionClassifier pattern_classifier(this);
Expression* pattern =
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
const AstRawString* name = ast_value_factory()->dot_catch_string();
bool is_simple = pattern->IsVariableProxy();
if (is_simple) {
auto proxy = pattern->AsVariableProxy();
scope_->RemoveUnresolved(proxy);
name = proxy->raw_name();
Expression* pattern = nullptr;
if (peek_any_identifier()) {
name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
} else {
ExpressionClassifier pattern_classifier(this);
pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
}
catch_variable = catch_scope->DeclareLocal(
name, VAR, kCreatedInitialized, Variable::NORMAL);
......@@ -3013,8 +3010,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Expect(Token::RPAREN, CHECK_OK);
ZoneList<const AstRawString*> bound_names(1, zone());
if (!is_simple) {
if (pattern != nullptr) {
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
descriptor.parser = this;
......
......@@ -97,7 +97,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["e"]); // TODO(caitp): FuncNameInferer is doing some weird stuff...
}, ["async"]);
await test(async() => {
await 1;
......@@ -106,7 +106,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["e"]);
}, ["async"]);
}
runTests().catch(e => {
......
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