| 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 library dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
| 6 | 6 |
| 7 import 'dart:collection' show HashSet, HashMap; | 7 import 'dart:collection' show HashSet, HashMap; |
| 8 import 'dart:io' show Directory, File; | 8 import 'dart:io' show Directory, File; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 if (classElem.type.isObject) return body; | 366 if (classElem.type.isObject) return body; |
| 367 | 367 |
| 368 // If we're not lazy, we still need to ensure our dependencies are | 368 // If we're not lazy, we still need to ensure our dependencies are |
| 369 // generated first. | 369 // generated first. |
| 370 var classDefs = <JS.Statement>[]; | 370 var classDefs = <JS.Statement>[]; |
| 371 _emitClassIfNeeded(classDefs, classElem.supertype.element); | 371 _emitClassIfNeeded(classDefs, classElem.supertype.element); |
| 372 for (var m in classElem.mixins) { | 372 for (var m in classElem.mixins) { |
| 373 _emitClassIfNeeded(classDefs, m.element); | 373 _emitClassIfNeeded(classDefs, m.element); |
| 374 } | 374 } |
| 375 for (var i in classElem.interfaces) { |
| 376 _emitClassIfNeeded(classDefs, i.element); |
| 377 } |
| 375 classDefs.add(body); | 378 classDefs.add(body); |
| 376 return _statement(classDefs); | 379 return _statement(classDefs); |
| 377 } | 380 } |
| 378 | 381 |
| 379 void _emitClassIfNeeded(List<JS.Statement> defs, ClassElement base) { | 382 void _emitClassIfNeeded(List<JS.Statement> defs, ClassElement base) { |
| 380 // We can only emit classes from this library. | 383 // We can only emit classes from this library. |
| 381 if (base.library != currentLibrary) return; | 384 if (base.library != currentLibrary) return; |
| 382 | 385 |
| 383 var baseNode = _pendingClasses[base]; | 386 var baseNode = _pendingClasses[base]; |
| 384 if (baseNode != null) defs.add(visitClassDeclaration(baseNode)); | 387 if (baseNode != null) defs.add(visitClassDeclaration(baseNode)); |
| 385 } | 388 } |
| 386 | 389 |
| 387 /// Returns true if the supertype or mixins aren't loaded. | 390 /// Returns true if the supertype or mixins aren't loaded. |
| 388 /// If that is the case, we'll emit a lazy class definition. | 391 /// If that is the case, we'll emit a lazy class definition. |
| 389 bool _lazyClass(ClassElement cls) { | 392 bool _lazyClass(ClassElement cls) { |
| 390 if (cls.type.isObject) return false; | 393 if (cls.type.isObject) return false; |
| 391 | 394 |
| 392 assert(cls.library == currentLibrary); | 395 assert(cls.library == currentLibrary); |
| 393 var result = _lazyClassMemo[cls]; | 396 var result = _lazyClassMemo[cls]; |
| 394 if (result != null) return result; | 397 if (result != null) return result; |
| 395 | 398 |
| 396 result = _classMightNotBeLoaded(cls.supertype.element); | 399 result = _classMightNotBeLoaded(cls.supertype.element); |
| 397 for (var mixin in cls.mixins) { | 400 for (var mixin in cls.mixins) { |
| 398 if (result) break; | 401 if (result) break; |
| 399 result = _classMightNotBeLoaded(mixin.element); | 402 result = _classMightNotBeLoaded(mixin.element); |
| 400 } | 403 } |
| 404 for (var iface in cls.interfaces) { |
| 405 if (result) break; |
| 406 result = _classMightNotBeLoaded(iface.element); |
| 407 } |
| 401 return _lazyClassMemo[cls] = result; | 408 return _lazyClassMemo[cls] = result; |
| 402 } | 409 } |
| 403 | 410 |
| 404 /// Curated order to minimize lazy classes needed by dart:core and its | 411 /// Curated order to minimize lazy classes needed by dart:core and its |
| 405 /// transitive SDK imports. | 412 /// transitive SDK imports. |
| 406 static const CORELIB_ORDER = const [ | 413 static const CORELIB_ORDER = const [ |
| 407 'dart.core', | 414 'dart.core', |
| 408 'dart.collection', | 415 'dart.collection', |
| 409 'dart._internal' | 416 'dart._internal' |
| 410 ]; | 417 ]; |
| (...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 | 2385 |
| 2379 // TODO(jmesserly): in many cases marking the end will be unncessary. | 2386 // TODO(jmesserly): in many cases marking the end will be unncessary. |
| 2380 printer.mark(_location(node.end)); | 2387 printer.mark(_location(node.end)); |
| 2381 } | 2388 } |
| 2382 | 2389 |
| 2383 String _getIdentifier(AstNode node) { | 2390 String _getIdentifier(AstNode node) { |
| 2384 if (node is SimpleIdentifier) return node.name; | 2391 if (node is SimpleIdentifier) return node.name; |
| 2385 return null; | 2392 return null; |
| 2386 } | 2393 } |
| 2387 } | 2394 } |
| OLD | NEW |