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

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

Issue 2815443003: Better DDC sourcemap generation for lambdas (Closed)
Patch Set: Added comments 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 | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | 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;
(...skipping 24 matching lines...) Expand all
35 _column = 0; 35 _column = 0;
36 } else { 36 } else {
37 _column++; 37 _column++;
38 } 38 }
39 } 39 }
40 super.emit(code); 40 super.emit(code);
41 } 41 }
42 42
43 void enterNode(JS.Node jsNode) { 43 void enterNode(JS.Node jsNode) {
44 AstNode node = jsNode.sourceInformation; 44 AstNode node = jsNode.sourceInformation;
45 if (node == null || node.offset == -1) return; 45 if (node == null || node.offset == -1 || node.isSynthetic) return;
46 if (unit == null) { 46 if (unit == null) {
47 // This is a top-level declaration. Note: consecutive top-level 47 // This is a top-level declaration. Note: consecutive top-level
48 // declarations may come from different compilation units due to 48 // declarations may come from different compilation units due to
49 // parts. 49 // parts.
50 _currentTopLevelDeclaration = node; 50 _currentTopLevelDeclaration = node;
51 unit = node.getAncestor((n) => n is CompilationUnit); 51 unit = node.getAncestor((n) => n is CompilationUnit);
52 sourcePath = 52 sourcePath =
53 resolutionMap.elementDeclaredByCompilationUnit(unit).source.fullName; 53 resolutionMap.elementDeclaredByCompilationUnit(unit).source.fullName;
54 } 54 }
55 55 // Skip MethodDeclarations - in the case of a one line function it finds the
56 // declaration rather than the body and confuses devtools.
57 if (node is MethodDeclaration) return;
56 _mark(node.offset, _getIdentifier(node)); 58 _mark(node.offset, _getIdentifier(node));
57 } 59 }
58 60
59 void exitNode(JS.Node jsNode) { 61 void exitNode(JS.Node jsNode) {
60 AstNode node = jsNode.sourceInformation; 62 AstNode node = jsNode.sourceInformation;
61 if (unit == null || node == null || node.offset == -1) return; 63 if (unit == null || node == null || node.offset == -1) return;
62 64
63 // TODO(jmesserly): in many cases marking the end will be unnecessary. 65 // TODO(jmesserly): in many cases marking the end will be unnecessary.
64 _mark(node.end); 66 // Skip MethodDeclarations - in the case of a one line function it finds the
67 // declaration rather than the body and confuses devtools.
68 if (node is! MethodDeclaration) {
69 _mark(node.end);
70 }
65 71
66 if (identical(node, _currentTopLevelDeclaration)) { 72 if (identical(node, _currentTopLevelDeclaration)) {
67 unit = null; 73 unit = null;
68 sourcePath = null; 74 sourcePath = null;
69 _currentTopLevelDeclaration == null; 75 _currentTopLevelDeclaration == null;
70 } 76 }
71 } 77 }
72 78
73 // TODO(jmesserly): prefix identifiers too, if they map to a named element. 79 // TODO(jmesserly): prefix identifiers too, if they map to a named element.
74 String _getIdentifier(AstNode node) => 80 String _getIdentifier(AstNode node) =>
75 node is SimpleIdentifier ? node.name : null; 81 node is SimpleIdentifier ? node.name : null;
76 82
77 void _mark(int offset, [String identifier]) { 83 void _mark(int offset, [String identifier]) {
78 var loc = unit.lineInfo.getLocation(offset); 84 var loc = unit.lineInfo.getLocation(offset);
85 // Chrome Devtools wants a mapping for the beginning of
86 // a line, so bump locations at the end of a line to the beginning of
87 // the next line.
88 var next = unit.lineInfo.getLocation(offset + 1);
89 if (next.lineNumber == loc.lineNumber + 1) {
90 loc = next;
91 }
79 sourceMap.addLocation( 92 sourceMap.addLocation(
80 new SourceLocation(offset, 93 new SourceLocation(offset,
81 sourceUrl: sourcePath, 94 sourceUrl: sourcePath,
82 line: loc.lineNumber - 1, 95 line: loc.lineNumber - 1,
83 column: loc.columnNumber - 1), 96 column: loc.columnNumber - 1),
84 new SourceLocation(buffer.length, line: _line, column: _column), 97 new SourceLocation(buffer.length, line: _line, column: _column),
85 identifier); 98 identifier);
86 } 99 }
87 } 100 }
88 101
89 const int _LF = 10; 102 const int _LF = 10;
90 const int _CR = 13; 103 const int _CR = 13;
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698