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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 } | 270 } |
271 | 271 |
272 void _compileHtml(Source source, CompilationNotifier notifier) { | 272 void _compileHtml(Source source, CompilationNotifier notifier) { |
273 // TODO(jmesserly): reuse DartScriptsTask instead of copy/paste. | 273 // TODO(jmesserly): reuse DartScriptsTask instead of copy/paste. |
274 var contents = context.getContents(source); | 274 var contents = context.getContents(source); |
275 var document = html.parse(contents.data, generateSpans: true); | 275 var document = html.parse(contents.data, generateSpans: true); |
276 var scripts = document.querySelectorAll('script[type="application/dart"]'); | 276 var scripts = document.querySelectorAll('script[type="application/dart"]'); |
277 | 277 |
278 var loadedLibs = new LinkedHashSet<Uri>(); | 278 var loadedLibs = new LinkedHashSet<Uri>(); |
279 | 279 |
280 var htmlOutDir = path.dirname(getOutputPath(source.uri)); | 280 // If we're generating code, convert the HTML file as well. |
ochafik
2016/03/04 23:27:57
+1 !
| |
281 // Otherwise, just search for Dart sources to analyze. | |
282 var htmlOutDir = | |
283 _jsGen != null ? path.dirname(getOutputPath(source.uri)) : null; | |
281 for (var script in scripts) { | 284 for (var script in scripts) { |
282 Source scriptSource = null; | 285 Source scriptSource = null; |
283 var srcAttr = script.attributes['src']; | 286 var srcAttr = script.attributes['src']; |
284 if (srcAttr == null) { | 287 if (srcAttr == null) { |
285 if (script.hasContent()) { | 288 if (script.hasContent()) { |
286 var fragments = <ScriptFragment>[]; | 289 var fragments = <ScriptFragment>[]; |
287 for (var node in script.nodes) { | 290 for (var node in script.nodes) { |
288 if (node is html.Text) { | 291 if (node is html.Text) { |
289 var start = node.sourceSpan.start; | 292 var start = node.sourceSpan.start; |
290 fragments.add(new ScriptFragment( | 293 fragments.add(new ScriptFragment( |
291 start.offset, start.line, start.column, node.data)); | 294 start.offset, start.line, start.column, node.data)); |
292 } | 295 } |
293 } | 296 } |
294 scriptSource = new DartScript(source, fragments); | 297 scriptSource = new DartScript(source, fragments); |
295 } | 298 } |
296 } else if (AnalysisEngine.isDartFileName(srcAttr)) { | 299 } else if (AnalysisEngine.isDartFileName(srcAttr)) { |
297 scriptSource = context.sourceFactory.resolveUri(source, srcAttr); | 300 scriptSource = context.sourceFactory.resolveUri(source, srcAttr); |
298 } | 301 } |
299 | 302 |
300 if (scriptSource != null) { | 303 if (scriptSource != null) { |
301 var lib = context.computeLibraryElement(scriptSource); | 304 var lib = context.computeLibraryElement(scriptSource); |
302 _compileLibrary(lib, notifier); | 305 _compileLibrary(lib, notifier); |
303 script.replaceWith(_linkLibraries(lib, loadedLibs, from: htmlOutDir)); | 306 if (htmlOutDir != null) { |
307 script.replaceWith(_linkLibraries(lib, loadedLibs, from: htmlOutDir)); | |
308 } | |
304 } | 309 } |
305 } | 310 } |
306 | 311 |
307 fileSystem.writeAsStringSync( | 312 if (htmlOutDir != null) { |
308 getOutputPath(source.uri), document.outerHtml + '\n'); | 313 fileSystem.writeAsStringSync( |
314 getOutputPath(source.uri), document.outerHtml + '\n'); | |
315 } | |
309 } | 316 } |
310 | 317 |
311 html.DocumentFragment _linkLibraries( | 318 html.DocumentFragment _linkLibraries( |
312 LibraryElement mainLib, LinkedHashSet<Uri> loaded, | 319 LibraryElement mainLib, LinkedHashSet<Uri> loaded, |
313 {String from}) { | 320 {String from}) { |
314 assert(from != null); | 321 assert(from != null); |
315 var alreadyLoaded = loaded.length; | 322 var alreadyLoaded = loaded.length; |
316 _collectLibraries(mainLib, loaded); | 323 _collectLibraries(mainLib, loaded); |
317 | 324 |
318 var newLibs = loaded.skip(alreadyLoaded); | 325 var newLibs = loaded.skip(alreadyLoaded); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 var files = [ | 540 var files = [ |
534 'harmony_feature_check.js', | 541 'harmony_feature_check.js', |
535 'dart_library.js', | 542 'dart_library.js', |
536 'dart/_runtime.js', | 543 'dart/_runtime.js', |
537 ]; | 544 ]; |
538 files.addAll(corelibOrder.map(coreToFile)); | 545 files.addAll(corelibOrder.map(coreToFile)); |
539 return files; | 546 return files; |
540 }(); | 547 }(); |
541 | 548 |
542 final _log = new Logger('dev_compiler.src.compiler'); | 549 final _log = new Logger('dev_compiler.src.compiler'); |
OLD | NEW |