| 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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 typedef bool IsSafeToRemoveTypeDeclarations( | 7 typedef bool IsSafeToRemoveTypeDeclarations( |
| 8 Map<ClassElement, Iterable<Element>> classMembers); | 8 Map<ClassElement, Iterable<Element>> classMembers); |
| 9 typedef void ElementCallback<E>(E element); | 9 typedef void ElementCallback<E>(E element); |
| 10 typedef void ElementPostProcessFunction( | 10 typedef void ElementPostProcessFunction( |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 260 } |
| 261 }); | 261 }); |
| 262 } | 262 } |
| 263 // Even class names are added due to a delicate problem we have: | 263 // Even class names are added due to a delicate problem we have: |
| 264 // if one imports dart:core with a prefix, we cannot tell prefix.name | 264 // if one imports dart:core with a prefix, we cannot tell prefix.name |
| 265 // from dynamic invocation (alas!). So we'd better err on preserving | 265 // from dynamic invocation (alas!). So we'd better err on preserving |
| 266 // those names. | 266 // those names. |
| 267 fixedStaticNames.add(element.name); | 267 fixedStaticNames.add(element.name); |
| 268 }); | 268 }); |
| 269 | 269 |
| 270 for (Element export in library.exports) { | 270 library.forEachExport((Element export) { |
| 271 if (!library.isInternalLibrary && | 271 if (!library.isInternalLibrary && |
| 272 export.library.isInternalLibrary) { | 272 export.library.isInternalLibrary) { |
| 273 // If an element of an internal library is reexported by a platform | 273 // If an element of an internal library is reexported by a platform |
| 274 // library, we have to import the reexporting library instead of the | 274 // library, we have to import the reexporting library instead of the |
| 275 // internal library, because the internal library is an | 275 // internal library, because the internal library is an |
| 276 // implementation detail of dart2js. | 276 // implementation detail of dart2js. |
| 277 reexportingLibraries[export] = library; | 277 reexportingLibraries[export] = library; |
| 278 } | 278 } |
| 279 } | 279 }); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Map to keep track of names of enum classes. Since these cannot be renamed | 282 // Map to keep track of names of enum classes. Since these cannot be renamed |
| 283 // we ensure that they are unique. | 283 // we ensure that they are unique. |
| 284 Map<String, ClassElement> enumClassMap = <String, ClassElement>{}; | 284 Map<String, ClassElement> enumClassMap = <String, ClassElement>{}; |
| 285 | 285 |
| 286 // As of now names of named optionals are not renamed. Therefore add all | 286 // As of now names of named optionals are not renamed. Therefore add all |
| 287 // field names used as named optionals into [fixedMemberNames]. | 287 // field names used as named optionals into [fixedMemberNames]. |
| 288 for (final element in resolvedElements) { | 288 for (final element in resolvedElements) { |
| 289 if (!element.isConstructor) continue; | 289 if (!element.isConstructor) continue; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 | 521 |
| 522 /// Rewrites imports/exports to refer to the paths given in [outputPaths]. | 522 /// Rewrites imports/exports to refer to the paths given in [outputPaths]. |
| 523 for(LibraryElement outputLibrary in libraryInfo.userLibraries) { | 523 for(LibraryElement outputLibrary in libraryInfo.userLibraries) { |
| 524 EmitterUnparser unparser = new EmitterUnparser( | 524 EmitterUnparser unparser = new EmitterUnparser( |
| 525 placeholderRenamer.renames, | 525 placeholderRenamer.renames, |
| 526 stripTypes: forceStripTypes, | 526 stripTypes: forceStripTypes, |
| 527 minify: enableMinification); | 527 minify: enableMinification); |
| 528 unparsers[outputLibrary] = unparser; | 528 unparsers[outputLibrary] = unparser; |
| 529 LibraryName libraryName = outputLibrary.libraryTag; | 529 if (outputLibrary.hasLibraryName) { |
| 530 if (libraryName != null) { | 530 unparser.unparseLibraryName(outputLibrary.libraryName); |
| 531 unparser.visitLibraryName(libraryName); | |
| 532 } | 531 } |
| 533 for (LibraryTag tag in outputLibrary.tags) { | 532 for (ImportElement import in outputLibrary.imports) { |
| 534 if (tag is! LibraryDependency) continue; | 533 LibraryElement libraryElement = import.importedLibrary; |
| 535 LibraryDependency dependency = tag; | |
| 536 LibraryElement libraryElement = | |
| 537 outputLibrary.getLibraryFromTag(dependency); | |
| 538 String uri = outputPaths.containsKey(libraryElement) | 534 String uri = outputPaths.containsKey(libraryElement) |
| 539 ? "${outputPaths[libraryElement]}.dart" | 535 ? "${outputPaths[libraryElement]}.dart" |
| 540 : libraryElement.canonicalUri.toString(); | 536 : libraryElement.canonicalUri.toString(); |
| 541 if (dependency is Import) { | 537 unparser.unparseImportTag(uri); |
| 542 unparser.unparseImportTag(uri); | 538 } |
| 543 } else { | 539 for (ExportElement export in outputLibrary.exports) { |
| 544 unparser.unparseExportTag(uri); | 540 LibraryElement libraryElement = export.exportedLibrary; |
| 545 } | 541 String uri = outputPaths.containsKey(libraryElement) |
| 542 ? "${outputPaths[libraryElement]}.dart" |
| 543 : libraryElement.canonicalUri.toString(); |
| 544 unparser.unparseExportTag(uri); |
| 546 } | 545 } |
| 547 } | 546 } |
| 548 } else { | 547 } else { |
| 549 placeholderRenamer.platformImports.forEach( | 548 placeholderRenamer.platformImports.forEach( |
| 550 (LibraryElement library, String prefix) { | 549 (LibraryElement library, String prefix) { |
| 551 assert(library.isPlatformLibrary && !library.isInternalLibrary); | 550 assert(library.isPlatformLibrary && !library.isInternalLibrary); |
| 552 mainUnparser.unparseImportTag(library.canonicalUri.toString()); | 551 mainUnparser.unparseImportTag(library.canonicalUri.toString()); |
| 553 if (prefix != null) { | 552 if (prefix != null) { |
| 554 // Adding a prefixed import because (some) top-level access need | 553 // Adding a prefixed import because (some) top-level access need |
| 555 // it to avoid shadowing. | 554 // it to avoid shadowing. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 outputProvider("", "dart") | 588 outputProvider("", "dart") |
| 590 ..add(code) | 589 ..add(code) |
| 591 ..close(); | 590 ..close(); |
| 592 | 591 |
| 593 totalSize = code.length; | 592 totalSize = code.length; |
| 594 } | 593 } |
| 595 | 594 |
| 596 return totalSize; | 595 return totalSize; |
| 597 } | 596 } |
| 598 } | 597 } |
| OLD | NEW |