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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/source_map_printer.dart

Issue 2839733003: Cache path -> URI mapping in SourceMapPrintingContext. (Closed)
Patch Set: 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
« 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 6 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
7 import 'package:source_maps/source_maps.dart' hide Printer; 7 import 'package:source_maps/source_maps.dart' hide Printer;
8 import 'package:source_span/source_span.dart' show SourceLocation; 8 import 'package:source_span/source_span.dart' show SourceLocation;
9 9
10 import '../js_ast/js_ast.dart' as JS; 10 import '../js_ast/js_ast.dart' as JS;
11 11
12 class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext { 12 class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext {
13 /// Current line in the buffer; 13 /// Current line in the buffer;
14 int _line = 0; 14 int _line = 0;
15 15
16 /// Current column in the buffer. 16 /// Current column in the buffer.
17 int _column = 0; 17 int _column = 0;
18 18
19 /// The source_maps builder we write JavaScript code to. 19 /// The source_maps builder we write JavaScript code to.
20 final sourceMap = new SourceMapBuilder(); 20 final sourceMap = new SourceMapBuilder();
21 21
22 /// The cache of URIs for paths.
23 final _sourceUrlCache = <String, Object>{};
24
22 CompilationUnit unit; 25 CompilationUnit unit;
23 String sourcePath; 26 String sourcePath;
24 AstNode _currentTopLevelDeclaration; 27 AstNode _currentTopLevelDeclaration;
25 28
26 @override 29 @override
27 void emit(String code) { 30 void emit(String code) {
28 var chars = code.runes.toList(); 31 var chars = code.runes.toList();
29 var length = chars.length; 32 var length = chars.length;
30 for (int i = 0; i < length; i++) { 33 for (int i = 0; i < length; i++) {
31 var c = chars[i]; 34 var c = chars[i];
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 93
91 void _mark(int offset, [String identifier]) { 94 void _mark(int offset, [String identifier]) {
92 var loc = unit.lineInfo.getLocation(offset); 95 var loc = unit.lineInfo.getLocation(offset);
93 // Chrome Devtools wants a mapping for the beginning of 96 // Chrome Devtools wants a mapping for the beginning of
94 // a line, so bump locations at the end of a line to the beginning of 97 // a line, so bump locations at the end of a line to the beginning of
95 // the next line. 98 // the next line.
96 var next = unit.lineInfo.getLocation(offset + 1); 99 var next = unit.lineInfo.getLocation(offset + 1);
97 if (next.lineNumber == loc.lineNumber + 1) { 100 if (next.lineNumber == loc.lineNumber + 1) {
98 loc = next; 101 loc = next;
99 } 102 }
100 var sourceUrl = 103 var sourceUrl = _sourceUrlCache.putIfAbsent(
101 sourcePath.startsWith('dart:') || sourcePath.startsWith('package:') 104 sourcePath,
102 ? sourcePath 105 () =>
103 : new Uri.file(sourcePath); 106 sourcePath.startsWith('dart:') || sourcePath.startsWith('package:')
107 ? sourcePath
108 : new Uri.file(sourcePath));
104 sourceMap.addLocation( 109 sourceMap.addLocation(
105 new SourceLocation(offset, 110 new SourceLocation(offset,
106 sourceUrl: sourceUrl, 111 sourceUrl: sourceUrl,
107 line: loc.lineNumber - 1, 112 line: loc.lineNumber - 1,
108 column: loc.columnNumber - 1), 113 column: loc.columnNumber - 1),
109 new SourceLocation(buffer.length, line: _line, column: _column), 114 new SourceLocation(buffer.length, line: _line, column: _column),
110 identifier); 115 identifier);
111 } 116 }
112 } 117 }
113 118
114 const int _LF = 10; 119 const int _LF = 10;
115 const int _CR = 13; 120 const int _CR = 13;
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