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

Side by Side Diff: tests/compiler/dart2js/sourcemaps/sourcemap_helper.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: dartfmt Created 3 years, 8 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
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 sourcemap.helper; 5 library sourcemap.helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:compiler/compiler_new.dart'; 9 import 'package:compiler/compiler_new.dart';
10 import 'package:compiler/src/apiimpl.dart' as api; 10 import 'package:compiler/src/apiimpl.dart' as api;
11 import 'package:compiler/src/commandline_options.dart'; 11 import 'package:compiler/src/commandline_options.dart';
12 import 'package:compiler/src/null_compiler_output.dart' show NullSink; 12 import 'package:compiler/src/null_compiler_output.dart' show NullSink;
13 import 'package:compiler/src/elements/elements.dart'; 13 import 'package:compiler/src/elements/elements.dart';
14 import 'package:compiler/src/helpers/helpers.dart'; 14 import 'package:compiler/src/helpers/helpers.dart';
15 import 'package:compiler/src/filenames.dart'; 15 import 'package:compiler/src/filenames.dart';
16 import 'package:compiler/src/io/code_output.dart'; 16 import 'package:compiler/src/io/code_output.dart';
17 import 'package:compiler/src/io/source_file.dart'; 17 import 'package:compiler/src/io/source_file.dart';
18 import 'package:compiler/src/io/source_information.dart'; 18 import 'package:compiler/src/io/source_information.dart';
19 import 'package:compiler/src/io/position_information.dart'; 19 import 'package:compiler/src/io/position_information.dart';
20 import 'package:compiler/src/js/js.dart' as js; 20 import 'package:compiler/src/js/js.dart' as js;
21 import 'package:compiler/src/js/js_debug.dart'; 21 import 'package:compiler/src/js/js_debug.dart';
22 import 'package:compiler/src/js/js_source_mapping.dart'; 22 import 'package:compiler/src/js/js_source_mapping.dart';
23 import 'package:compiler/src/js_backend/js_backend.dart'; 23 import 'package:compiler/src/js_backend/js_backend.dart';
24 import 'package:compiler/src/source_file_provider.dart'; 24 import 'package:compiler/src/source_file_provider.dart';
25 import 'package:kernel/ast.dart' show Location;
25 import '../memory_compiler.dart'; 26 import '../memory_compiler.dart';
26 import '../output_collector.dart'; 27 import '../output_collector.dart';
27 28
28 class SourceFileSink implements OutputSink { 29 class SourceFileSink implements OutputSink {
29 final String filename; 30 final String filename;
30 StringBuffer sb = new StringBuffer(); 31 StringBuffer sb = new StringBuffer();
31 SourceFile sourceFile; 32 SourceFile sourceFile;
32 33
33 SourceFileSink(this.filename); 34 SourceFileSink(this.filename);
34 35
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 register(kind, node); 494 register(kind, node);
494 } 495 }
495 496
496 void register(StepKind kind, js.Node node, {bool expectInfo: true}) { 497 void register(StepKind kind, js.Node node, {bool expectInfo: true}) {
497 String dartCodeFromSourceLocation(SourceLocation sourceLocation) { 498 String dartCodeFromSourceLocation(SourceLocation sourceLocation) {
498 SourceFile sourceFile = 499 SourceFile sourceFile =
499 sourceFileManager.getSourceFile(sourceLocation.sourceUri); 500 sourceFileManager.getSourceFile(sourceLocation.sourceUri);
500 if (sourceFile == null) { 501 if (sourceFile == null) {
501 return sourceLocation.shortText; 502 return sourceLocation.shortText;
502 } 503 }
503 return sourceFile 504 return sourceFile.kernelSource
504 .getLineText(sourceLocation.line) 505 .getTextLine(sourceLocation.line + 1)
505 .substring(sourceLocation.column) 506 .substring(sourceLocation.column)
506 .trim(); 507 .trim();
507 } 508 }
508 509
509 void addLocation(SourceLocation sourceLocation, String jsCode) { 510 void addLocation(SourceLocation sourceLocation, String jsCode) {
510 if (sourceLocation == null) { 511 if (sourceLocation == null) {
511 if (expectInfo) { 512 if (expectInfo) {
512 SourceInformation sourceInformation = node.sourceInformation; 513 SourceInformation sourceInformation = node.sourceInformation;
513 SourceLocation sourceLocation; 514 SourceLocation sourceLocation;
514 String dartCode; 515 String dartCode;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 absoluteUri = base.resolveUri(uri); 570 absoluteUri = base.resolveUri(uri);
570 } else { 571 } else {
571 absoluteUri = base.resolve(uri); 572 absoluteUri = base.resolve(uri);
572 } 573 }
573 return sourceFiles.putIfAbsent(absoluteUri, () { 574 return sourceFiles.putIfAbsent(absoluteUri, () {
574 String text = new File.fromUri(absoluteUri).readAsStringSync(); 575 String text = new File.fromUri(absoluteUri).readAsStringSync();
575 return new StringSourceFile.fromUri(absoluteUri, text); 576 return new StringSourceFile.fromUri(absoluteUri, text);
576 }); 577 });
577 } 578 }
578 } 579 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698