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

Side by Side Diff: pkg/analyzer/lib/src/task/html.dart

Issue 1211993003: Get more tests passing using the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('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) 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 analyzer.src.task.html; 5 library analyzer.src.task.html;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
11 import 'package:analyzer/src/generated/source.dart'; 11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/task/dart.dart'; 12 import 'package:analyzer/src/task/dart.dart';
13 import 'package:analyzer/src/task/general.dart'; 13 import 'package:analyzer/src/task/general.dart';
14 import 'package:analyzer/task/dart.dart'; 14 import 'package:analyzer/task/dart.dart';
15 import 'package:analyzer/task/general.dart'; 15 import 'package:analyzer/task/general.dart';
16 import 'package:analyzer/task/html.dart'; 16 import 'package:analyzer/task/html.dart';
17 import 'package:analyzer/task/model.dart'; 17 import 'package:analyzer/task/model.dart';
18 import 'package:html/dom.dart'; 18 import 'package:html/dom.dart';
19 import 'package:html/parser.dart'; 19 import 'package:html/parser.dart';
20 import 'package:source_span/source_span.dart'; 20 import 'package:source_span/source_span.dart';
21 import 'package:analyzer/src/context/cache.dart';
22 import 'package:analyzer/src/generated/java_engine.dart';
23 import 'package:analyzer/src/generated/scanner.dart';
21 24
22 /** 25 /**
23 * The Dart scripts that are embedded in an HTML file. 26 * The Dart scripts that are embedded in an HTML file.
24 */ 27 */
25 final ListResultDescriptor<DartScript> DART_SCRIPTS = 28 final ListResultDescriptor<DartScript> DART_SCRIPTS =
26 new ListResultDescriptor<DartScript>('DART_SCRIPTS', DartScript.EMPTY_LIST); 29 new ListResultDescriptor<DartScript>('DART_SCRIPTS', DartScript.EMPTY_LIST);
27 30
28 /** 31 /**
29 * The errors found while parsing an HTML file. 32 * The errors found while parsing an HTML file.
30 */ 33 */
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ParseHtmlTask(InternalAnalysisContext context, AnalysisTarget target) 281 ParseHtmlTask(InternalAnalysisContext context, AnalysisTarget target)
279 : super(context, target); 282 : super(context, target);
280 283
281 @override 284 @override
282 TaskDescriptor get descriptor => DESCRIPTOR; 285 TaskDescriptor get descriptor => DESCRIPTOR;
283 286
284 @override 287 @override
285 void internalPerform() { 288 void internalPerform() {
286 String content = getRequiredInput(CONTENT_INPUT_NAME); 289 String content = getRequiredInput(CONTENT_INPUT_NAME);
287 290
288 HtmlParser parser = new HtmlParser(content, generateSpans: true); 291 if (context.getModificationStamp(target.source) < 0) {
289 parser.compatMode = 'quirks'; 292 String message = 'Content could not be read';
290 Document document = parser.parse(); 293 if (context is InternalAnalysisContext) {
291 List<ParseError> parseErrors = parser.errors; 294 CacheEntry entry = (context as InternalAnalysisContext).getCacheEntry(ta rget);
292 List<AnalysisError> errors = <AnalysisError>[]; 295 CaughtException exception = entry.exception;
293 for (ParseError parseError in parseErrors) { 296 if (exception != null) {
294 SourceSpan span = parseError.span; 297 message = exception.toString();
295 errors.add(new AnalysisError(target.source, span.start.offset, 298 }
296 span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message])); 299 }
300
301 outputs[HTML_DOCUMENT] = new Document();
302 outputs[HTML_DOCUMENT_ERRORS] = <AnalysisError>[new AnalysisError(
303 target.source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])];
304 } else {
305 HtmlParser parser = new HtmlParser(content, generateSpans: true);
306 parser.compatMode = 'quirks';
307 Document document = parser.parse();
308 List<ParseError> parseErrors = parser.errors;
309 List<AnalysisError> errors = <AnalysisError>[];
310 for (ParseError parseError in parseErrors) {
311 SourceSpan span = parseError.span;
312 errors.add(new AnalysisError(target.source, span.start.offset,
313 span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message]));
314 }
315
316 outputs[HTML_DOCUMENT] = document;
317 outputs[HTML_DOCUMENT_ERRORS] = errors;
297 } 318 }
298
299 outputs[HTML_DOCUMENT] = document;
300 outputs[HTML_DOCUMENT_ERRORS] = errors;
301 } 319 }
302 320
303 /** 321 /**
304 * Return a map from the names of the inputs of this kind of task to the task 322 * Return a map from the names of the inputs of this kind of task to the task
305 * input descriptors describing those inputs for a task with the given 323 * input descriptors describing those inputs for a task with the given
306 * [source]. 324 * [source].
307 */ 325 */
308 static Map<String, TaskInput> buildInputs(Source source) { 326 static Map<String, TaskInput> buildInputs(Source source) {
309 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; 327 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
310 } 328 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 * The content of the fragment. 361 * The content of the fragment.
344 */ 362 */
345 final String content; 363 final String content;
346 364
347 /** 365 /**
348 * Initialize a newly created script fragment to have the given [offset] and 366 * Initialize a newly created script fragment to have the given [offset] and
349 * [content]. 367 * [content].
350 */ 368 */
351 ScriptFragment(this.offset, this.line, this.column, this.content); 369 ScriptFragment(this.offset, this.line, this.column, this.content);
352 } 370 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698