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

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: Skip synthetic nodes and method declarations 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 if (node is MethodDeclaration) return;
56 _mark(node.offset, _getIdentifier(node)); 56 _mark(node.offset, _getIdentifier(node));
57 } 57 }
58 58
59 void exitNode(JS.Node jsNode) { 59 void exitNode(JS.Node jsNode) {
60 AstNode node = jsNode.sourceInformation; 60 AstNode node = jsNode.sourceInformation;
61 if (unit == null || node == null || node.offset == -1) return; 61 if (unit == null || node == null || node.offset == -1) return;
62 62
63 // TODO(jmesserly): in many cases marking the end will be unnecessary. 63 // TODO(jmesserly): in many cases marking the end will be unnecessary.
64 _mark(node.end); 64 if (node is! MethodDeclaration) {
Jennifer Messerly 2017/04/12 16:11:23 Add a comment on why we're skipping MethodDeclarat
65 _mark(node.end);
66 }
65 67
66 if (identical(node, _currentTopLevelDeclaration)) { 68 if (identical(node, _currentTopLevelDeclaration)) {
67 unit = null; 69 unit = null;
68 sourcePath = null; 70 sourcePath = null;
69 _currentTopLevelDeclaration == null; 71 _currentTopLevelDeclaration == null;
70 } 72 }
71 } 73 }
72 74
73 // TODO(jmesserly): prefix identifiers too, if they map to a named element. 75 // TODO(jmesserly): prefix identifiers too, if they map to a named element.
74 String _getIdentifier(AstNode node) => 76 String _getIdentifier(AstNode node) =>
75 node is SimpleIdentifier ? node.name : null; 77 node is SimpleIdentifier ? node.name : null;
76 78
77 void _mark(int offset, [String identifier]) { 79 void _mark(int offset, [String identifier]) {
78 var loc = unit.lineInfo.getLocation(offset); 80 var loc = unit.lineInfo.getLocation(offset);
81 // Chrome Devtools wants a mapping for the beginning of
82 // a line, so bump locations at the end of a line to the beginning of
83 // the next line.
84 var next = unit.lineInfo.getLocation(offset + 1);
85 if (next.lineNumber == loc.lineNumber + 1) {
86 loc = next;
87 }
79 sourceMap.addLocation( 88 sourceMap.addLocation(
80 new SourceLocation(offset, 89 new SourceLocation(offset,
81 sourceUrl: sourcePath, 90 sourceUrl: sourcePath,
82 line: loc.lineNumber - 1, 91 line: loc.lineNumber - 1,
83 column: loc.columnNumber - 1), 92 column: loc.columnNumber - 1),
84 new SourceLocation(buffer.length, line: _line, column: _column), 93 new SourceLocation(buffer.length, line: _line, column: _column),
85 identifier); 94 identifier);
86 } 95 }
87 } 96 }
88 97
89 const int _LF = 10; 98 const int _LF = 10;
90 const int _CR = 13; 99 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