| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * A script to assist in documenting the difference between the dart:html API | 6 * A script to assist in documenting the difference between the dart:html API |
| 7 * and the old DOM API. | 7 * and the old DOM API. |
| 8 */ | 8 */ |
| 9 library html_diff; | 9 library html_diff; |
| 10 | 10 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 import 'dart:io'; | 12 import 'dart:io'; |
| 13 import 'dart:uri'; |
| 13 | 14 |
| 14 import 'lib/metadata.dart'; | 15 import 'lib/metadata.dart'; |
| 15 | 16 |
| 16 // TODO(rnystrom): Use "package:" URL (#4968). | 17 // TODO(rnystrom): Use "package:" URL (#4968). |
| 17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.d
art'; | 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.d
art'; |
| 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; | 19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; |
| 19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar
t'; | 20 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar
t'; |
| 21 import '../../sdk/lib/_internal/compiler/implementation/source_file_provider.dar
t'; |
| 20 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; | 22 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; |
| 21 import '../../sdk/lib/html/html_common/metadata.dart'; | 23 import '../../sdk/lib/html/html_common/metadata.dart'; |
| 22 | 24 |
| 23 // TODO(amouravski): There is currently magic that looks at dart:* libraries | 25 // TODO(amouravski): There is currently magic that looks at dart:* libraries |
| 24 // rather than the declared library names. This changed due to recent syntax | 26 // rather than the declared library names. This changed due to recent syntax |
| 25 // changes. We should only need to look at the library 'html'. | 27 // changes. We should only need to look at the library 'html'. |
| 26 const List<String> HTML_LIBRARY_NAMES = const [ | 28 const List<Uri> HTML_LIBRARY_URIS = const [ |
| 27 'dart:html', | 29 const Uri.fromComponents(scheme: 'dart', path: 'html'), |
| 28 'dart:indexed_db', | 30 const Uri.fromComponents(scheme: 'dart', path: 'indexed_db'), |
| 29 'dart:svg', | 31 const Uri.fromComponents(scheme: 'dart', path: 'svg'), |
| 30 'dart:web_audio']; | 32 const Uri.fromComponents(scheme: 'dart', path: 'web_audio')]; |
| 31 const List<String> HTML_DECLARED_NAMES = const [ | |
| 32 'dart.dom.html', | |
| 33 'dart.dom.indexed_db', | |
| 34 'dart.dom.svg', | |
| 35 'dart.dom.web_audio']; | |
| 36 | 33 |
| 37 /** | 34 /** |
| 38 * A class for computing a many-to-many mapping between the types and | 35 * A class for computing a many-to-many mapping between the types and |
| 39 * members in `dart:html` and the MDN DOM types. This mapping is | 36 * members in `dart:html` and the MDN DOM types. This mapping is |
| 40 * based on two indicators: | 37 * based on two indicators: |
| 41 * | 38 * |
| 42 * 1. Auto-detected wrappers. Most `dart:html` types correspond | 39 * 1. Auto-detected wrappers. Most `dart:html` types correspond |
| 43 * straightforwardly to a single `@DomName` type, and | 40 * straightforwardly to a single `@DomName` type, and |
| 44 * have the same name. In addition, most `dart:html` methods | 41 * have the same name. In addition, most `dart:html` methods |
| 45 * just call a single `@DomName` method. This class | 42 * just call a single `@DomName` method. This class |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 print('Warning: $s'); | 82 print('Warning: $s'); |
| 86 } | 83 } |
| 87 } | 84 } |
| 88 | 85 |
| 89 /** | 86 /** |
| 90 * Computes the `@DomName` to `dart:html` mapping, and | 87 * Computes the `@DomName` to `dart:html` mapping, and |
| 91 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js | 88 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js |
| 92 * should be initialized (via [parseOptions] and [initializeWorld]) and | 89 * should be initialized (via [parseOptions] and [initializeWorld]) and |
| 93 * [HtmlDiff.initialize] should be called. | 90 * [HtmlDiff.initialize] should be called. |
| 94 */ | 91 */ |
| 95 Future run(Path libDir) { | 92 Future run(Uri libraryRoot) { |
| 96 var result = new Completer(); | 93 var result = new Completer(); |
| 97 var paths = <Path>[]; | 94 var provider = new SourceFileProvider(); |
| 98 for (var libraryName in HTML_LIBRARY_NAMES) { | 95 var handler = new FormattingDiagnosticHandler(provider); |
| 99 paths.add(new Path(libraryName)); | 96 Future<MirrorSystem> analysis = analyzeUri( |
| 100 } | 97 HTML_LIBRARY_URIS, libraryRoot, null, |
| 101 analyze(paths, libDir).then((MirrorSystem mirrors) { | 98 provider.readStringFromUri, |
| 102 for (var libraryName in HTML_DECLARED_NAMES) { | 99 handler.diagnosticHandler); |
| 103 var library = mirrors.libraries[libraryName]; | 100 analysis.then((MirrorSystem mirrors) { |
| 101 for (var libraryUri in HTML_LIBRARY_URIS) { |
| 102 var library = mirrors.libraries[libraryUri]; |
| 104 if (library == null) { | 103 if (library == null) { |
| 105 warn('Could not find $libraryName'); | 104 warn('Could not find $libraryUri'); |
| 106 result.complete(false); | 105 result.complete(false); |
| 107 } | 106 } |
| 108 for (ClassMirror type in library.classes.values) { | 107 for (ClassMirror type in library.classes.values) { |
| 109 final domTypes = htmlToDomTypes(type); | 108 final domTypes = htmlToDomTypes(type); |
| 110 if (domTypes.isEmpty) continue; | 109 if (domTypes.isEmpty) continue; |
| 111 | 110 |
| 112 htmlTypesToDom.putIfAbsent(type.qualifiedName, | 111 htmlTypesToDom.putIfAbsent(type.qualifiedName, |
| 113 () => new Set()).addAll(domTypes); | 112 () => new Set()).addAll(domTypes); |
| 114 | 113 |
| 115 type.members.forEach( | 114 type.members.forEach( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return members; | 225 return members; |
| 227 } | 226 } |
| 228 | 227 |
| 229 if (name.split('.').length != 2) { | 228 if (name.split('.').length != 2) { |
| 230 warn('invalid member name ${name}'); | 229 warn('invalid member name ${name}'); |
| 231 return new Set(); | 230 return new Set(); |
| 232 } | 231 } |
| 233 return new Set.from([name]); | 232 return new Set.from([name]); |
| 234 } | 233 } |
| 235 } | 234 } |
| OLD | NEW |