[parser] Fix import in arrow function parameters.

BUG=chromium:852765

Change-Id: Iaba84f6e52b08b3aee4c1529701239c049dceb9a
Reviewed-on: https://chromium-review.googlesource.com/1128875
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54450}
This commit is contained in:
Marja Hölttä 2018-07-12 17:01:02 +02:00 committed by Commit Bot
parent 19d9ca2d59
commit f128acee3b
3 changed files with 57 additions and 4 deletions

View File

@ -3599,13 +3599,14 @@ template <typename Impl>
typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseImportExpressions(
bool* ok) {
DCHECK(allow_harmony_dynamic_import());
classifier()->RecordPatternError(scanner()->peek_location(),
MessageTemplate::kUnexpectedToken,
Token::String(Token::IMPORT));
Consume(Token::IMPORT);
int pos = position();
if (allow_harmony_import_meta() && peek() == Token::PERIOD) {
classifier()->RecordPatternError(
Scanner::Location(pos, scanner()->location().end_pos),
MessageTemplate::kInvalidDestructuringTarget);
ArrowFormalParametersUnexpectedToken();
ExpectMetaProperty(Token::META, "import.meta", pos, CHECK_OK);
if (!parsing_module_) {
impl()->ReportMessageAt(scanner()->location(),

View File

@ -4227,6 +4227,39 @@ TEST(ImportExpressionErrors) {
RunModuleParserSyncTest(context_data, data, kError, nullptr, 0, flags,
arraysize(flags));
}
// Import statements as arrow function params and destructuring targets.
{
// clang-format off
const char* context_data[][2] = {
{"(", ") => {}"},
{"(a, ", ") => {}"},
{"(1, ", ") => {}"},
{"let f = ", " => {}"},
{"[", "] = [1];"},
{"{", "} = {'a': 1};"},
{nullptr, nullptr}
};
const char* data[] = {
"import(foo)",
"import(1)",
"import(y=x)",
"import(import(x))",
"import(x).then()",
nullptr
};
// clang-format on
RunParserSyncTest(context_data, data, kError);
RunModuleParserSyncTest(context_data, data, kError);
static const ParserFlag flags[] = {kAllowHarmonyDynamicImport};
RunParserSyncTest(context_data, data, kError, nullptr, 0, flags,
arraysize(flags));
RunModuleParserSyncTest(context_data, data, kError, nullptr, 0, flags,
arraysize(flags));
}
}
TEST(SuperCall) {
@ -8133,6 +8166,8 @@ TEST(ImportMetaFailure) {
{"({", "} = {1})"},
{"var {", " = 1} = 1"},
{"for (var ", " of [1]) {}"},
{"(", ") => {}"},
{"let f = ", " => {}"},
{nullptr}
};

View File

@ -0,0 +1,17 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The actual regression test
assertThrows("(import(foo)) =>", undefined, "Unexpected token import");
// Other related tests
assertThrows("import(foo) =>", undefined, "Unexpected token import");
assertThrows("(a, import(foo)) =>", undefined, "Unexpected token import");
assertThrows("(1, import(foo)) =>", undefined, "Unexpected number");
assertThrows("(super(foo)) =>", undefined, "'super' keyword unexpected here");
assertThrows("(bar(foo)) =>", undefined, "Unexpected token (");
// No syntax errors
assertThrows("[import(foo).then] = [1];", undefined, "foo is not defined");
assertThrows("[[import(foo).then]] = [[1]];", undefined, "foo is not defined");