OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library deferred_load; | 5 library deferred_load; |
6 | 6 |
7 import 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
8 Compiler, | 8 Compiler, |
9 CompilerTask, | 9 CompilerTask, |
10 Constant, | 10 Constant, |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 } | 610 } |
611 | 611 |
612 _assignNamesToOutputUnits(allOutputUnits); | 612 _assignNamesToOutputUnits(allOutputUnits); |
613 }); | 613 }); |
614 } | 614 } |
615 | 615 |
616 void ensureMetadataResolved(Compiler compiler) { | 616 void ensureMetadataResolved(Compiler compiler) { |
617 _allDeferredImports[_fakeMainImport] = compiler.mainApp; | 617 _allDeferredImports[_fakeMainImport] = compiler.mainApp; |
618 bool deferredUsedFromMain = false; | 618 bool deferredUsedFromMain = false; |
619 var lastDeferred; | 619 var lastDeferred; |
620 // When detecting duplicate prefixes of deferred libraries there are 4 | |
621 // cases of duplicate prefixes: | |
622 // 1. | |
623 // @DeferredLibrary("a") import "lib.dart" as a; | |
624 // @DeferredLibrary("b") import "lib2.dart" as a; | |
625 // 2. | |
626 // @DeferredLibrary("a") import "lib.dart" as a; | |
627 // import "lib2.dart" as a; | |
628 // 3. | |
629 // import "lib.dart" as a; | |
630 // @DeferredLibrary("a") import "lib2.dart" as a; | |
631 // 4. | |
632 // import "lib.dart" as a; | |
633 // import "lib2.dart" as a; | |
634 // We must be able to signal error for case 1, 2, 3, but accept case 4. | |
635 | |
636 // The prefixes that have been used by any imports in this library. | |
637 Setlet<String> usedPrefixes = new Setlet<String>(); | |
638 // The last deferred import we saw with a given prefix (if any). | |
639 Map<String, Import> prefixDeferredImport = new Map<String, Import>(); | |
620 for (LibraryElement library in compiler.libraries.values) { | 640 for (LibraryElement library in compiler.libraries.values) { |
641 prefixDeferredImport.clear(); | |
642 usedPrefixes.clear(); | |
621 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List | 643 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List |
622 // instead of a Link. | 644 // instead of a Link. |
623 for (LibraryTag tag in library.tags) { | 645 for (LibraryTag tag in library.tags) { |
624 if (tag is! Import) continue; | 646 if (tag is! Import) continue; |
625 Import import = tag; | 647 Import import = tag; |
626 if (_isImportDeferred(import)) { | 648 String prefix = import.prefix != null ? import.prefix.toString() : null; |
floitsch
2014/02/18 12:19:25
parenthesis around the condition.
sigurdm
2014/02/18 13:31:47
Done.
| |
649 // The last import we saw with the same prefix. | |
650 Import previousDeferredImport = prefixDeferredImport[prefix]; | |
651 bool isDeferred = _isImportDeferred(import); | |
652 if (isDeferred) { | |
653 if (prefix == null) { | |
654 compiler.reportError(import, | |
655 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); | |
656 } else { | |
657 prefixDeferredImport[prefix] = import; | |
658 } | |
627 splitProgram = true; | 659 splitProgram = true; |
628 _allDeferredImports[tag] = library.getLibraryFromTag(tag); | 660 _allDeferredImports[tag] = library.getLibraryFromTag(tag); |
629 lastDeferred = import.metadata.first; | 661 lastDeferred = import.metadata.first; |
630 if (library == compiler.mainApp) { | 662 if (library == compiler.mainApp) { |
631 deferredUsedFromMain = true; | 663 deferredUsedFromMain = true; |
632 } | 664 } |
633 } | 665 } |
666 if (prefix != null) { | |
667 if (previousDeferredImport != null || | |
668 (isDeferred && usedPrefixes.contains(prefix))) { | |
669 Import failingImport = previousDeferredImport != null | |
floitsch
2014/02/18 12:19:25
parenthesis around condition.
sigurdm
2014/02/18 13:31:47
Done.
| |
670 ? previousDeferredImport | |
671 : import; | |
672 compiler.reportError(failingImport, | |
673 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX); | |
674 } | |
675 usedPrefixes.add(prefix); | |
676 } | |
634 } | 677 } |
635 } | 678 } |
636 if (splitProgram && !deferredUsedFromMain) { | 679 if (splitProgram && !deferredUsedFromMain) { |
637 compiler.reportInfo( | 680 compiler.reportInfo( |
638 lastDeferred, | 681 lastDeferred, |
639 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); | 682 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); |
640 splitProgram = false; | 683 splitProgram = false; |
641 } | 684 } |
642 } | 685 } |
643 } | 686 } |
OLD | NEW |