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

Side by Side Diff: pkg/polymer/lib/src/compiler.dart

Issue 23735003: Get rid of doctype warning in analyzer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/example/scoped_style/my_test.html ('k') | samples/third_party/todomvc/web/app.html » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 compiler; 5 library compiler;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show SplayTreeMap; 8 import 'dart:collection' show SplayTreeMap;
9 9
10 import 'package:csslib/visitor.dart' show StyleSheet, treeToDebugString; 10 import 'package:csslib/visitor.dart' show StyleSheet, treeToDebugString;
(...skipping 12 matching lines...) Expand all
23 import 'compiler_options.dart'; 23 import 'compiler_options.dart';
24 import 'utils.dart'; 24 import 'utils.dart';
25 25
26 /** 26 /**
27 * Parses an HTML file [contents] and returns a DOM-like tree. 27 * Parses an HTML file [contents] and returns a DOM-like tree.
28 * Note that [contents] will be a [String] if coming from a browser-based 28 * Note that [contents] will be a [String] if coming from a browser-based
29 * [FileSystem], or it will be a [List<int>] if running on the command line. 29 * [FileSystem], or it will be a [List<int>] if running on the command line.
30 * 30 *
31 * Adds emitted error/warning to [messages], if [messages] is supplied. 31 * Adds emitted error/warning to [messages], if [messages] is supplied.
32 */ 32 */
33 Document parseHtml(contents, String sourcePath, Messages messages) { 33 Document parseHtml(contents, String sourcePath, Messages messages,
34 bool checkDocType) {
34 var parser = new HtmlParser(contents, generateSpans: true, 35 var parser = new HtmlParser(contents, generateSpans: true,
35 sourceUrl: sourcePath); 36 sourceUrl: sourcePath);
36 var document = parser.parse(); 37 var document = parser.parse();
37 38
38 // Note: errors aren't fatal in HTML (unless strict mode is on). 39 // Note: errors aren't fatal in HTML (unless strict mode is on).
39 // So just print them as warnings. 40 // So just print them as warnings.
40 for (var e in parser.errors) { 41 for (var e in parser.errors) {
41 messages.warning(e.message, e.span); 42 if (checkDocType || e.errorCode != 'expected-doctype-but-got-start-tag') {
43 messages.warning(e.message, e.span);
44 }
42 } 45 }
43 return document; 46 return document;
44 } 47 }
45 48
46 /** Compiles an application written with Dart web components. */ 49 /** Compiles an application written with Dart web components. */
47 class Compiler { 50 class Compiler {
48 final FileSystem fileSystem; 51 final FileSystem fileSystem;
49 final CompilerOptions options; 52 final CompilerOptions options;
50 final List<SourceFile> files = <SourceFile>[]; 53 final List<SourceFile> files = <SourceFile>[];
51 54
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 113
111 /** 114 /**
112 * Asynchronously parse [inputFile] and transitively discover web components 115 * Asynchronously parse [inputFile] and transitively discover web components
113 * to load and parse. Returns a future that completes when all files are 116 * to load and parse. Returns a future that completes when all files are
114 * processed. 117 * processed.
115 */ 118 */
116 Future _parseAndDiscover(String inputFile) { 119 Future _parseAndDiscover(String inputFile) {
117 _tasks = new FutureGroup(); 120 _tasks = new FutureGroup();
118 _processed = new Set(); 121 _processed = new Set();
119 _processed.add(inputFile); 122 _processed.add(inputFile);
120 _tasks.add(_parseHtmlFile(new UrlInfo(inputFile, inputFile, null))); 123 _tasks.add(_parseHtmlFile(new UrlInfo(inputFile, inputFile, null), true));
121 return _tasks.future; 124 return _tasks.future;
122 } 125 }
123 126
124 void _processHtmlFile(UrlInfo inputUrl, SourceFile file) { 127 void _processHtmlFile(UrlInfo inputUrl, SourceFile file) {
125 if (file == null) return; 128 if (file == null) return;
126 129
127 bool isEntryPoint = _processed.length == 1; 130 bool isEntryPoint = _processed.length == 1;
128 131
129 files.add(file); 132 files.add(file);
130 133
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void _loadFile(UrlInfo urlInfo, Future loadAndParse(UrlInfo inputUrl)) { 178 void _loadFile(UrlInfo urlInfo, Future loadAndParse(UrlInfo inputUrl)) {
176 if (urlInfo == null) return; 179 if (urlInfo == null) return;
177 var resolvedPath = urlInfo.resolvedPath; 180 var resolvedPath = urlInfo.resolvedPath;
178 if (!_processed.contains(resolvedPath)) { 181 if (!_processed.contains(resolvedPath)) {
179 _processed.add(resolvedPath); 182 _processed.add(resolvedPath);
180 _tasks.add(loadAndParse(urlInfo)); 183 _tasks.add(loadAndParse(urlInfo));
181 } 184 }
182 } 185 }
183 186
184 /** Parse an HTML file. */ 187 /** Parse an HTML file. */
185 Future _parseHtmlFile(UrlInfo inputUrl) { 188 Future _parseHtmlFile(UrlInfo inputUrl, [bool checkDocType = false]) {
186 var filePath = inputUrl.resolvedPath; 189 var filePath = inputUrl.resolvedPath;
187 return fileSystem.readTextOrBytes(filePath) 190 return fileSystem.readTextOrBytes(filePath)
188 .catchError((e) => _readError(e, inputUrl)) 191 .catchError((e) => _readError(e, inputUrl))
189 .then((source) { 192 .then((source) {
190 if (source == null) return; 193 if (source == null) return;
191 var file = new SourceFile(filePath); 194 var file = new SourceFile(filePath);
192 file.document = _time('Parsed', filePath, 195 file.document = _time('Parsed', filePath,
193 () => parseHtml(source, filePath, _messages)); 196 () => parseHtml(source, filePath, _messages, checkDocType));
194 _processHtmlFile(inputUrl, file); 197 _processHtmlFile(inputUrl, file);
195 }); 198 });
196 } 199 }
197 200
198 /** Parse a stylesheet file. */ 201 /** Parse a stylesheet file. */
199 Future _parseCssFile(UrlInfo inputUrl) { 202 Future _parseCssFile(UrlInfo inputUrl) {
200 if (!options.emulateScopedCss) { 203 if (!options.emulateScopedCss) {
201 return new Future<SourceFile>.value(null); 204 return new Future<SourceFile>.value(null);
202 } 205 }
203 var filePath = inputUrl.resolvedPath; 206 var filePath = inputUrl.resolvedPath;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 message.write(logMessage); 351 message.write(logMessage);
349 var filename = path.basename(filePath); 352 var filename = path.basename(filePath);
350 for (int i = (60 - logMessage.length - filename.length); i > 0 ; i--) { 353 for (int i = (60 - logMessage.length - filename.length); i > 0 ; i--) {
351 message.write(' '); 354 message.write(' ');
352 } 355 }
353 message.write(filename); 356 message.write(filename);
354 return time(message.toString(), callback, 357 return time(message.toString(), callback,
355 printTime: options.verbose || printTime); 358 printTime: options.verbose || printTime);
356 } 359 }
357 } 360 }
OLDNEW
« no previous file with comments | « pkg/polymer/example/scoped_style/my_test.html ('k') | samples/third_party/todomvc/web/app.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698