OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 | 1201 |
1202 int pos = peek_position(); | 1202 int pos = peek_position(); |
1203 Expect(Token::IMPORT, CHECK_OK_VOID); | 1203 Expect(Token::IMPORT, CHECK_OK_VOID); |
1204 | 1204 |
1205 Token::Value tok = peek(); | 1205 Token::Value tok = peek(); |
1206 | 1206 |
1207 // 'import' ModuleSpecifier ';' | 1207 // 'import' ModuleSpecifier ';' |
1208 if (tok == Token::STRING) { | 1208 if (tok == Token::STRING) { |
1209 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); | 1209 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1210 ExpectSemicolon(CHECK_OK_VOID); | 1210 ExpectSemicolon(CHECK_OK_VOID); |
1211 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1211 module()->AddEmptyImport(module_specifier); |
1212 return; | 1212 return; |
1213 } | 1213 } |
1214 | 1214 |
1215 // Parse ImportedDefaultBinding if present. | 1215 // Parse ImportedDefaultBinding if present. |
1216 const AstRawString* import_default_binding = nullptr; | 1216 const AstRawString* import_default_binding = nullptr; |
1217 Scanner::Location import_default_binding_loc; | 1217 Scanner::Location import_default_binding_loc; |
1218 if (tok != Token::MUL && tok != Token::LBRACE) { | 1218 if (tok != Token::MUL && tok != Token::LBRACE) { |
1219 import_default_binding = | 1219 import_default_binding = |
1220 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1220 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1221 import_default_binding_loc = scanner()->location(); | 1221 import_default_binding_loc = scanner()->location(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 } | 1269 } |
1270 | 1270 |
1271 if (import_default_binding != nullptr) { | 1271 if (import_default_binding != nullptr) { |
1272 module()->AddImport(ast_value_factory()->default_string(), | 1272 module()->AddImport(ast_value_factory()->default_string(), |
1273 import_default_binding, module_specifier, | 1273 import_default_binding, module_specifier, |
1274 import_default_binding_loc, zone()); | 1274 import_default_binding_loc, zone()); |
1275 } | 1275 } |
1276 | 1276 |
1277 if (named_imports != nullptr) { | 1277 if (named_imports != nullptr) { |
1278 if (named_imports->length() == 0) { | 1278 if (named_imports->length() == 0) { |
1279 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1279 module()->AddEmptyImport(module_specifier); |
1280 } else { | 1280 } else { |
1281 for (int i = 0; i < named_imports->length(); ++i) { | 1281 for (int i = 0; i < named_imports->length(); ++i) { |
1282 const NamedImport* import = named_imports->at(i); | 1282 const NamedImport* import = named_imports->at(i); |
1283 module()->AddImport(import->import_name, import->local_name, | 1283 module()->AddImport(import->import_name, import->local_name, |
1284 module_specifier, import->location, zone()); | 1284 module_specifier, import->location, zone()); |
1285 } | 1285 } |
1286 } | 1286 } |
1287 } | 1287 } |
1288 } | 1288 } |
1289 | 1289 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 ExpectSemicolon(CHECK_OK); | 1408 ExpectSemicolon(CHECK_OK); |
1409 const int length = export_names.length(); | 1409 const int length = export_names.length(); |
1410 DCHECK_EQ(length, original_names.length()); | 1410 DCHECK_EQ(length, original_names.length()); |
1411 DCHECK_EQ(length, export_locations.length()); | 1411 DCHECK_EQ(length, export_locations.length()); |
1412 if (module_specifier == nullptr) { | 1412 if (module_specifier == nullptr) { |
1413 for (int i = 0; i < length; ++i) { | 1413 for (int i = 0; i < length; ++i) { |
1414 module()->AddExport(original_names[i], export_names[i], | 1414 module()->AddExport(original_names[i], export_names[i], |
1415 export_locations[i], zone()); | 1415 export_locations[i], zone()); |
1416 } | 1416 } |
1417 } else if (length == 0) { | 1417 } else if (length == 0) { |
1418 module()->AddEmptyImport(module_specifier, scanner()->location(), | 1418 module()->AddEmptyImport(module_specifier); |
1419 zone()); | |
1420 } else { | 1419 } else { |
1421 for (int i = 0; i < length; ++i) { | 1420 for (int i = 0; i < length; ++i) { |
1422 module()->AddExport(original_names[i], export_names[i], | 1421 module()->AddExport(original_names[i], export_names[i], |
1423 module_specifier, export_locations[i], zone()); | 1422 module_specifier, export_locations[i], zone()); |
1424 } | 1423 } |
1425 } | 1424 } |
1426 return factory()->NewEmptyStatement(pos); | 1425 return factory()->NewEmptyStatement(pos); |
1427 } | 1426 } |
1428 | 1427 |
1429 case Token::FUNCTION: | 1428 case Token::FUNCTION: |
(...skipping 4176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5606 | 5605 |
5607 return final_loop; | 5606 return final_loop; |
5608 } | 5607 } |
5609 | 5608 |
5610 #undef CHECK_OK | 5609 #undef CHECK_OK |
5611 #undef CHECK_OK_VOID | 5610 #undef CHECK_OK_VOID |
5612 #undef CHECK_FAILED | 5611 #undef CHECK_FAILED |
5613 | 5612 |
5614 } // namespace internal | 5613 } // namespace internal |
5615 } // namespace v8 | 5614 } // namespace v8 |
OLD | NEW |