OLD | NEW |
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/resolution_accessors.dart'; |
6 import 'package:source_maps/source_maps.dart' hide Printer; | 7 import 'package:source_maps/source_maps.dart' hide Printer; |
7 import 'package:source_span/source_span.dart' show SourceLocation; | 8 import 'package:source_span/source_span.dart' show SourceLocation; |
8 | 9 |
9 import '../js_ast/js_ast.dart' as JS; | 10 import '../js_ast/js_ast.dart' as JS; |
10 | 11 |
11 class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext { | 12 class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext { |
12 /// Current line in the buffer; | 13 /// Current line in the buffer; |
13 int _line = 0; | 14 int _line = 0; |
14 | 15 |
15 /// Current column in the buffer. | 16 /// Current column in the buffer. |
(...skipping 25 matching lines...) Expand all Loading... |
41 | 42 |
42 void enterNode(JS.Node jsNode) { | 43 void enterNode(JS.Node jsNode) { |
43 AstNode node = jsNode.sourceInformation; | 44 AstNode node = jsNode.sourceInformation; |
44 if (node == null || node.offset == -1) return; | 45 if (node == null || node.offset == -1) return; |
45 if (unit == null) { | 46 if (unit == null) { |
46 // This is a top-level declaration. Note: consecutive top-level | 47 // This is a top-level declaration. Note: consecutive top-level |
47 // declarations may come from different compilation units due to | 48 // declarations may come from different compilation units due to |
48 // parts. | 49 // parts. |
49 _currentTopLevelDeclaration = node; | 50 _currentTopLevelDeclaration = node; |
50 unit = node.getAncestor((n) => n is CompilationUnit); | 51 unit = node.getAncestor((n) => n is CompilationUnit); |
51 sourcePath = unit.element.source.fullName; | 52 sourcePath = elementForCompilationUnit(unit).source.fullName; |
52 } | 53 } |
53 | 54 |
54 _mark(node.offset, _getIdentifier(node)); | 55 _mark(node.offset, _getIdentifier(node)); |
55 } | 56 } |
56 | 57 |
57 void exitNode(JS.Node jsNode) { | 58 void exitNode(JS.Node jsNode) { |
58 AstNode node = jsNode.sourceInformation; | 59 AstNode node = jsNode.sourceInformation; |
59 if (unit == null || node == null || node.offset == -1) return; | 60 if (unit == null || node == null || node.offset == -1) return; |
60 | 61 |
61 // TODO(jmesserly): in many cases marking the end will be unnecessary. | 62 // TODO(jmesserly): in many cases marking the end will be unnecessary. |
(...skipping 17 matching lines...) Expand all Loading... |
79 sourceUrl: sourcePath, | 80 sourceUrl: sourcePath, |
80 line: loc.lineNumber - 1, | 81 line: loc.lineNumber - 1, |
81 column: loc.columnNumber - 1), | 82 column: loc.columnNumber - 1), |
82 new SourceLocation(buffer.length, line: _line, column: _column), | 83 new SourceLocation(buffer.length, line: _line, column: _column), |
83 identifier); | 84 identifier); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 const int _LF = 10; | 88 const int _LF = 10; |
88 const int _CR = 13; | 89 const int _CR = 13; |
OLD | NEW |