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

Side by Side Diff: lib/src/codegen/html_codegen.dart

Issue 1587693002: Avoid parsing and then generating HTML for documents without Dart scripts. This is a fragile workar… (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 dev_compiler.src.codegen.html_codegen; 5 library dev_compiler.src.codegen.html_codegen;
6 6
7 import 'package:html/dom.dart'; 7 import 'package:html/dom.dart';
8 import 'package:html/parser.dart' show parseFragment; 8 import 'package:html/parser.dart' show parseFragment;
9 import 'package:logging/logging.dart' show Logger; 9 import 'package:logging/logging.dart' show Logger;
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 10 matching lines...) Expand all
21 /// runtime and the compiled code, and to execute the main method of the 21 /// runtime and the compiled code, and to execute the main method of the
22 /// application. When compiling to Dart, we ensure that the document contains a 22 /// application. When compiling to Dart, we ensure that the document contains a
23 /// single Dart script tag, but otherwise emit the original document 23 /// single Dart script tag, but otherwise emit the original document
24 /// unmodified. 24 /// unmodified.
25 String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) { 25 String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) {
26 var options = compiler.options; 26 var options = compiler.options;
27 var document = root.document.clone(true); 27 var document = root.document.clone(true);
28 var scripts = document.querySelectorAll('script[type="application/dart"]'); 28 var scripts = document.querySelectorAll('script[type="application/dart"]');
29 if (scripts.isEmpty) { 29 if (scripts.isEmpty) {
30 _log.warning('No <script type="application/dart"> found in ${root.uri}'); 30 _log.warning('No <script type="application/dart"> found in ${root.uri}');
31 return '${document.outerHtml}\n'; 31 return root.contents;
Jennifer Messerly 2016/01/13 18:05:02 This could use a comment.
32 } 32 }
33 scripts.skip(1).forEach((s) { 33 scripts.skip(1).forEach((s) {
34 // TODO(sigmund): allow more than one Dart script tags? 34 // TODO(sigmund): allow more than one Dart script tags?
35 _log.warning(s.sourceSpan.message( 35 _log.warning(s.sourceSpan.message(
36 'unexpected script. Only one Dart script tag allowed ' 36 'unexpected script. Only one Dart script tag allowed '
37 '(see https://github.com/dart-lang/dart-dev-compiler/issues/53).', 37 '(see https://github.com/dart-lang/dart-dev-compiler/issues/53).',
38 color: options.useColors ? colorOf('warning') : false)); 38 color: options.useColors ? colorOf('warning') : false));
39 s.remove(); 39 s.remove();
40 }); 40 });
41 41
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 /// Convert the outputPath to include the hash in it. This function is the 120 /// Convert the outputPath to include the hash in it. This function is the
121 /// reverse of what the server does to determine whether a request needs to have 121 /// reverse of what the server does to determine whether a request needs to have
122 /// cache headers added to it. 122 /// cache headers added to it.
123 _addHash(String outPath, String hash) { 123 _addHash(String outPath, String hash) {
124 // (the ____ prefix makes it look better in the web inspector) 124 // (the ____ prefix makes it look better in the web inspector)
125 return '$outPath?____cached=$hash'; 125 return '$outPath?____cached=$hash';
126 } 126 }
127 127
128 final _log = new Logger('dev_compiler.src.codegen.html_codegen'); 128 final _log = new Logger('dev_compiler.src.codegen.html_codegen');
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698