Chromium Code Reviews| Index: lib/src/codegen/html_codegen.dart |
| diff --git a/lib/src/codegen/html_codegen.dart b/lib/src/codegen/html_codegen.dart |
| index a148256ab5b4bf981993bd0084c8633aaf0fe4f1..bbbece9e26e7a3475718ba26b4c6ef60732465b9 100644 |
| --- a/lib/src/codegen/html_codegen.dart |
| +++ b/lib/src/codegen/html_codegen.dart |
| @@ -4,14 +4,13 @@ |
| library ddc.src.codegen.html_codegen; |
| -import 'dart:io'; |
| - |
| import 'package:html5lib/dom.dart'; |
| import 'package:html5lib/parser.dart' show parseFragment; |
| -import 'package:path/path.dart' as path; |
| +import 'package:logging/logging.dart' show Logger; |
| -import 'package:dev_compiler/src/info.dart'; |
| +import 'package:dev_compiler/src/dependency_graph.dart'; |
| import 'package:dev_compiler/src/options.dart'; |
| +import 'package:dev_compiler/src/utils.dart' show colorOf; |
| import 'js_codegen.dart' show jsLibraryName, jsOutputPath; |
| @@ -24,39 +23,48 @@ import 'js_codegen.dart' show jsLibraryName, jsOutputPath; |
| /// application. When compiling to Dart, we ensure that the document contains a |
| /// single Dart script tag, but otherwise emit the original document |
| /// unmodified. |
| -void generateEntryHtml(String inputFile, CompilerOptions options, |
| - CheckerResults results, Document document) { |
| - String outputFile = path.join(options.outputDir, path.basename(inputFile)); |
| - |
| +String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) { |
| + var document = root.document.clone(true); |
| var scripts = document.querySelectorAll('script[type="application/dart"]'); |
| - var mainScript = scripts[0]; |
| - // TODO(sigmund): allow more than one Dart script tags? |
| - scripts.skip(1).forEach((s) => s.remove()); |
| - |
| - if (options.outputDart) { |
| - new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); |
| - return; |
| + if (scripts.isEmpty) { |
| + _log.severe('No <script type="application/dart"> found in ${root.uri}'); |
| + return null; |
| } |
| + scripts.skip(1).forEach((s) { |
| + // TODO(sigmund): allow more than one Dart script tags? |
| + _log.warning(s.sourceSpan.message( |
| + 'unexpected script. Only one Dart script tag allowed ' |
| + '(see https://github.com/dart-lang/dart-dev-compiler/issues/53).', |
| + color: options.useColors ? colorOf('warning') : false)); |
| + s.remove(); |
| + }); |
| + |
| + if (options.outputDart) return '${document.outerHtml}\n'; |
| + |
| + var libraries = []; |
| + visitInPostOrder(root, (n) { |
| + if (n is LibrarySourceNode) libraries.add(n); |
| + }); |
| String mainLibraryName; |
| - var pathToDdc = path.dirname(path |
| - .dirname(path.relative(Platform.script.path, from: options.outputDir))); |
| - var fragment = _loadRuntimeScripts(path.join(pathToDdc, 'lib')); |
| + var fragment = _loadRuntimeScripts(); |
| if (!options.checkSdk) fragment.nodes.add(_miniMockSdk); |
| - for (var lib in results.libraries) { |
| - if (lib.isEntry) mainLibraryName = jsLibraryName(lib.library); |
| - fragment.nodes.add(_libraryInclude(jsOutputPath(lib))); |
| + for (var lib in libraries) { |
| + var info = lib.info; |
| + if (info == null) continue; |
| + if (info.isEntry) mainLibraryName = jsLibraryName(info.library); |
| + fragment.nodes.add(_libraryInclude(jsOutputPath(info))); |
| } |
| fragment.nodes.add(_invokeMain(mainLibraryName)); |
| - mainScript.replaceWith(fragment); |
| - new File(outputFile).writeAsStringSync('${document.outerHtml}\n'); |
| + scripts[0].replaceWith(fragment); |
| + return '${document.outerHtml}\n'; |
| } |
| /// A document fragment with scripts that check for harmony features and that |
| /// inject our runtime. |
| -Node _loadRuntimeScripts(String ddcLibDir) => parseFragment(''' |
| -<script src="$ddcLibDir/runtime/harmony_feature_check.js"></script> |
| -<script src="$ddcLibDir/runtime/dart_runtime.js"></script> |
| +Node _loadRuntimeScripts() => parseFragment(''' |
| +<script src="dev_compiler/runtime/harmony_feature_check.js"></script> |
| +<script src="dev_compiler/runtime/dart_runtime.js"></script> |
| '''); |
| /// A script tag that loads the .js code for a compiled library. |
| @@ -77,3 +85,4 @@ Node get _miniMockSdk => parseFragment(''' |
| var core = { int: { parse: Number }, print: e => console.log(e) }; |
| var dom = { document: document }; |
| </script>'''); |
| +final _log = new Logger('ddc.src.codegen.html_codegen'); |
|
Jennifer Messerly
2015/03/03 02:24:21
dev_compiler?
Siggi Cherem (dart-lang)
2015/03/04 04:44:23
Good point - I'll send out a follow up CL with thi
|