Chromium Code Reviews| 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/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; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 source.isInSystemLibrary ? source.uri.toString() : source.fullName; | 59 source.isInSystemLibrary ? source.uri.toString() : source.fullName; |
| 60 } | 60 } |
| 61 // Skip MethodDeclarations - in the case of a one line function it finds the | 61 // Skip MethodDeclarations - in the case of a one line function it finds the |
| 62 // declaration rather than the body and confuses devtools. | 62 // declaration rather than the body and confuses devtools. |
| 63 if (node is MethodDeclaration) return; | 63 if (node is MethodDeclaration) return; |
| 64 _mark(node.offset, _getIdentifier(node)); | 64 _mark(node.offset, _getIdentifier(node)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void exitNode(JS.Node jsNode) { | 67 void exitNode(JS.Node jsNode) { |
| 68 AstNode node = jsNode.sourceInformation; | 68 AstNode node = jsNode.sourceInformation; |
| 69 if (unit == null || node == null || node.offset == -1) return; | 69 if (unit == null || node == null || node.offset == -1 || node.isSynthetic) |
| 70 return; | |
|
Jennifer Messerly
2017/04/20 18:22:39
I think this needs to be { ... } per style guide
vsm
2017/04/20 18:29:05
Done
| |
| 70 | 71 |
| 71 // TODO(jmesserly): in many cases marking the end will be unnecessary. | 72 // TODO(jmesserly): in many cases marking the end will be unnecessary. |
| 72 // Skip MethodDeclarations - in the case of a one line function it finds the | 73 // Skip MethodDeclarations - in the case of a one line function it finds the |
| 73 // declaration rather than the body and confuses devtools. | 74 // declaration rather than the body and confuses devtools. |
| 74 if (node is! MethodDeclaration) { | 75 if (node is! MethodDeclaration) { |
| 75 _mark(node.end); | 76 _mark(node.end); |
| 76 } | 77 } |
| 77 | 78 |
| 78 if (identical(node, _currentTopLevelDeclaration)) { | 79 if (identical(node, _currentTopLevelDeclaration)) { |
| 79 unit = null; | 80 unit = null; |
| 80 sourcePath = null; | 81 sourcePath = null; |
| 81 _currentTopLevelDeclaration == null; | 82 _currentTopLevelDeclaration == null; |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 | 85 |
| 85 // TODO(jmesserly): prefix identifiers too, if they map to a named element. | 86 // TODO(jmesserly): prefix identifiers too, if they map to a named element. |
| 86 String _getIdentifier(AstNode node) => | 87 String _getIdentifier(AstNode node) => |
| 87 node is SimpleIdentifier ? node.name : null; | 88 node is SimpleIdentifier ? node.name : null; |
| 88 | 89 |
| 89 void _mark(int offset, [String identifier]) { | 90 void _mark(int offset, [String identifier]) { |
| 90 var loc = unit.lineInfo.getLocation(offset); | 91 var loc = unit.lineInfo.getLocation(offset); |
| 91 // Chrome Devtools wants a mapping for the beginning of | 92 // Chrome Devtools wants a mapping for the beginning of |
| 92 // a line, so bump locations at the end of a line to the beginning of | 93 // a line, so bump locations at the end of a line to the beginning of |
| 93 // the next line. | 94 // the next line. |
| 94 var next = unit.lineInfo.getLocation(offset + 1); | 95 var next = unit.lineInfo.getLocation(offset + 1); |
| 95 if (next.lineNumber == loc.lineNumber + 1) { | 96 if (next.lineNumber == loc.lineNumber + 1) { |
| 96 loc = next; | 97 loc = next; |
| 97 } | 98 } |
| 99 var sourceUrl = | |
| 100 sourcePath.startsWith('dart:') || sourcePath.startsWith('package:') | |
| 101 ? sourcePath | |
| 102 : new Uri.file(sourcePath); | |
| 98 sourceMap.addLocation( | 103 sourceMap.addLocation( |
| 99 new SourceLocation(offset, | 104 new SourceLocation(offset, |
| 100 sourceUrl: sourcePath, | 105 sourceUrl: sourceUrl, |
| 101 line: loc.lineNumber - 1, | 106 line: loc.lineNumber - 1, |
| 102 column: loc.columnNumber - 1), | 107 column: loc.columnNumber - 1), |
| 103 new SourceLocation(buffer.length, line: _line, column: _column), | 108 new SourceLocation(buffer.length, line: _line, column: _column), |
| 104 identifier); | 109 identifier); |
| 105 } | 110 } |
| 106 } | 111 } |
| 107 | 112 |
| 108 const int _LF = 10; | 113 const int _LF = 10; |
| 109 const int _CR = 13; | 114 const int _CR = 13; |
| OLD | NEW |