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

Unified Diff: src/parsing/parser.cc

Issue 2661933003: [ESnext] Parse dynamic import expression (Closed)
Patch Set: fix 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 36268493e971ae185e2f88b5254cc5a88a7dde70..ed4a8c06efa225889eeda6d0ced938053dc4cd35 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -553,6 +553,7 @@ Parser::Parser(ParseInfo* info)
set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas);
set_allow_harmony_class_fields(FLAG_harmony_class_fields);
set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread);
+ set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import);
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
++feature) {
use_counts_[feature] = 0;
@@ -962,15 +963,21 @@ Statement* Parser::ParseModuleItem(bool* ok) {
// ExportDeclaration
// StatementListItem
- switch (peek()) {
- case Token::IMPORT:
- ParseImportDeclaration(CHECK_OK);
- return factory()->NewEmptyStatement(kNoSourcePosition);
- case Token::EXPORT:
- return ParseExportDeclaration(ok);
- default:
- return ParseStatementListItem(ok);
+ Token::Value next = peek();
+
+ if (next == Token::EXPORT) {
+ return ParseExportDeclaration(ok);
}
+
+ // We must be careful not to parse a dynamic import expression as an import
+ // declaration.
+ if (next == Token::IMPORT &&
+ (!allow_harmony_dynamic_import() || PeekAhead() != Token::LPAREN)) {
+ ParseImportDeclaration(CHECK_OK);
+ return factory()->NewEmptyStatement(kNoSourcePosition);
+ }
+
+ return ParseStatementListItem(ok);
}
@@ -2792,6 +2799,7 @@ Parser::LazyParsingResult Parser::SkipFunction(
SET_ALLOW(harmony_trailing_commas);
SET_ALLOW(harmony_class_fields);
SET_ALLOW(harmony_object_rest_spread);
+ SET_ALLOW(harmony_dynamic_import);
#undef SET_ALLOW
}
// Aborting inner function preparsing would leave scopes in an inconsistent
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698