Index: src/parsing/parser.cc |
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
index 36268493e971ae185e2f88b5254cc5a88a7dde70..07a2479bf12fb57cdef972d79bb62adc9d066c13 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,24 @@ 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: |
+ Token::Value next = peek(); |
+ |
+ if (next == Token::IMPORT) { |
+ // This makes sure we don't parse a dynamic import expression as |
+ // an import declaration. |
+ if (allow_harmony_dynamic_import() && PeekAhead() == Token::LPAREN) { |
return ParseStatementListItem(ok); |
+ } |
+ |
+ ParseImportDeclaration(CHECK_OK); |
+ return factory()->NewEmptyStatement(kNoSourcePosition); |
+ } |
+ |
+ if (next == Token::EXPORT) { |
+ return ParseExportDeclaration(ok); |
} |
+ |
+ return ParseStatementListItem(ok); |
} |
neis
2017/01/31 10:47:57
Nit: I find this version a little nicer as it does
gsathya
2017/01/31 18:26:07
I did this initially and found the if conditional
|
@@ -2792,6 +2802,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 |