Commit f128acee authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser] Fix import in arrow function parameters.

BUG=chromium:852765

Change-Id: Iaba84f6e52b08b3aee4c1529701239c049dceb9a
Reviewed-on: https://chromium-review.googlesource.com/1128875Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54450}
parent 19d9ca2d
......@@ -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(),
......
......@@ -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}
};
......
// 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");
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