Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1387)

Unified Diff: lib/src/codegen/html_codegen.dart

Issue 973433003: Initial cut for a development server (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/codegen/dart_codegen.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/html_codegen.dart
diff --git a/lib/src/codegen/html_codegen.dart b/lib/src/codegen/html_codegen.dart
index f080611a96b823012e2e9793a5b1c069e4004276..44c137601e67312cf788f924ecd0fbaffe652f11 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,40 +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);
- var root = new Uri.file(path.absolute(inputFile));
- for (var lib in results.libraries) {
- if (lib.isEntry) mainLibraryName = jsLibraryName(lib.library);
- fragment.nodes.add(_libraryInclude(jsOutputPath(lib, root)));
+ 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, root.uri)));
}
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.
@@ -78,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');
« no previous file with comments | « lib/src/codegen/dart_codegen.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698