| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashMap; | 5 import 'dart:collection' show HashMap; |
| 6 import 'package:analyzer/src/generated/ast.dart'; | 6 import 'package:analyzer/src/generated/ast.dart'; |
| 7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:dev_compiler/src/compiler.dart' show corelibOrder; | 8 import 'package:dev_compiler/src/compiler.dart' show corelibOrder; |
| 9 | 9 |
| 10 typedef void ModuleItemEmitter(AstNode item); | 10 typedef void ModuleItemEmitter(AstNode item); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 for (var current in _topLevelElements) { | 173 for (var current in _topLevelElements) { |
| 174 // TODO(jmesserly): if we want to log what triggered laziness, this is | 174 // TODO(jmesserly): if we want to log what triggered laziness, this is |
| 175 // the place to do so. | 175 // the place to do so. |
| 176 _loaded[current] = false; | 176 _loaded[current] = false; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool libraryIsLoaded(LibraryElement library) { | 180 bool libraryIsLoaded(LibraryElement library) { |
| 181 assert(library != _currentLibrary); | 181 assert(library != _currentLibrary); |
| 182 | 182 |
| 183 // DynamicElementImpl has no library. |
| 184 if (library == null) return true; |
| 185 |
| 183 // The SDK is a special case: we optimize the order to prevent laziness. | 186 // The SDK is a special case: we optimize the order to prevent laziness. |
| 184 if (_isDartUri(library)) { | 187 if (_isDartUri(library)) { |
| 185 // SDK is loaded before non-SDK libraries | 188 // SDK is loaded before non-SDK libraries |
| 186 if (!_isDartUri(_currentLibrary)) return true; | 189 if (!_isDartUri(_currentLibrary)) return true; |
| 187 | 190 |
| 188 // Compute the order of both SDK libraries. If unknown, assume it's after. | 191 // Compute the order of both SDK libraries. If unknown, assume it's after. |
| 189 var order = corelibOrder.indexOf(library.name); | 192 var order = corelibOrder.indexOf(library.name); |
| 190 if (order == -1) order = corelibOrder.length; | 193 if (order == -1) order = corelibOrder.length; |
| 191 | 194 |
| 192 var currentOrder = corelibOrder.indexOf(_currentLibrary.name); | 195 var currentOrder = corelibOrder.indexOf(_currentLibrary.name); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 228 } |
| 226 return _libraryCycleMemo[library] = result; | 229 return _libraryCycleMemo[library] = result; |
| 227 } | 230 } |
| 228 | 231 |
| 229 /// Returns whether this is a library imported with 'dart:' URI. | 232 /// Returns whether this is a library imported with 'dart:' URI. |
| 230 /// | 233 /// |
| 231 /// This is similar to [LibraryElement.isInSdk], but checking the URI instead | 234 /// This is similar to [LibraryElement.isInSdk], but checking the URI instead |
| 232 /// of the library naming convention, because the URI is reliable. | 235 /// of the library naming convention, because the URI is reliable. |
| 233 static bool _isDartUri(LibraryElement e) => e.source.uri.scheme == 'dart'; | 236 static bool _isDartUri(LibraryElement e) => e.source.uri.scheme == 'dart'; |
| 234 } | 237 } |
| OLD | NEW |