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

Side by Side Diff: src/parsing/parser.cc

Issue 2368613002: [modules] Simplify treatment of empty imports. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698