| 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 ddc.src.codegen.html_codegen; | 5 library ddc.src.codegen.html_codegen; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:html5lib/dom.dart'; | 9 import 'package:html5lib/dom.dart'; |
| 10 import 'package:html5lib/parser.dart' show parseFragment; | 10 import 'package:html5lib/parser.dart' show parseFragment; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 if (options.outputDart) { | 36 if (options.outputDart) { |
| 37 new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); | 37 new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 String mainLibraryName; | 41 String mainLibraryName; |
| 42 var pathToDdc = path.dirname(path | 42 var pathToDdc = path.dirname(path |
| 43 .dirname(path.relative(Platform.script.path, from: options.outputDir))); | 43 .dirname(path.relative(Platform.script.path, from: options.outputDir))); |
| 44 var fragment = _loadRuntimeScripts(path.join(pathToDdc, 'lib')); | 44 var fragment = _loadRuntimeScripts(path.join(pathToDdc, 'lib')); |
| 45 if (!options.checkSdk) fragment.nodes.add(_miniMockSdk); | 45 if (!options.checkSdk) fragment.nodes.add(_miniMockSdk); |
| 46 var root = new Uri.file(path.absolute(inputFile)); |
| 46 for (var lib in results.libraries) { | 47 for (var lib in results.libraries) { |
| 47 if (lib.isEntry) mainLibraryName = jsLibraryName(lib.library); | 48 if (lib.isEntry) mainLibraryName = jsLibraryName(lib.library); |
| 48 fragment.nodes.add(_libraryInclude(jsOutputPath(lib))); | 49 fragment.nodes.add(_libraryInclude(jsOutputPath(lib, root))); |
| 49 } | 50 } |
| 50 fragment.nodes.add(_invokeMain(mainLibraryName)); | 51 fragment.nodes.add(_invokeMain(mainLibraryName)); |
| 51 mainScript.replaceWith(fragment); | 52 mainScript.replaceWith(fragment); |
| 52 new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); | 53 new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); |
| 53 } | 54 } |
| 54 | 55 |
| 55 /// A document fragment with scripts that check for harmony features and that | 56 /// A document fragment with scripts that check for harmony features and that |
| 56 /// inject our runtime. | 57 /// inject our runtime. |
| 57 Node _loadRuntimeScripts(String ddcLibDir) => parseFragment(''' | 58 Node _loadRuntimeScripts(String ddcLibDir) => parseFragment(''' |
| 58 <script src="$ddcLibDir/runtime/harmony_feature_check.js"></script> | 59 <script src="$ddcLibDir/runtime/harmony_feature_check.js"></script> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 /// A script tag with a tiny mock of the core SDK. This is just used for testing | 71 /// A script tag with a tiny mock of the core SDK. This is just used for testing |
| 71 /// some small samples. | 72 /// some small samples. |
| 72 // TODO(sigmund,jmesserly): remove. | 73 // TODO(sigmund,jmesserly): remove. |
| 73 Node get _miniMockSdk => parseFragment(''' | 74 Node get _miniMockSdk => parseFragment(''' |
| 74 <script> | 75 <script> |
| 75 /* placehorder for unimplemented code libraries */ | 76 /* placehorder for unimplemented code libraries */ |
| 76 var math = Math; | 77 var math = Math; |
| 77 var core = { int: { parse: Number }, print: e => console.log(e) }; | 78 var core = { int: { parse: Number }, print: e => console.log(e) }; |
| 78 var dom = { document: document }; | 79 var dom = { document: document }; |
| 79 </script>'''); | 80 </script>'''); |
| OLD | NEW |