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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/source_map_printer.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/source_map_printer.dart b/pkg/dev_compiler/lib/src/compiler/source_map_printer.dart
index 3320e8d2af92ee2b899b0a2e1711a3a6074d69b3..a17005964d5a09eb2c0d6d316229a648bf2d91c7 100644
--- a/pkg/dev_compiler/lib/src/compiler/source_map_printer.dart
+++ b/pkg/dev_compiler/lib/src/compiler/source_map_printer.dart
@@ -42,7 +42,7 @@ class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext {
void enterNode(JS.Node jsNode) {
AstNode node = jsNode.sourceInformation;
- if (node == null || node.offset == -1) return;
+ if (node == null || node.offset == -1 || node.isSynthetic) return;
if (unit == null) {
// This is a top-level declaration. Note: consecutive top-level
// declarations may come from different compilation units due to
@@ -52,7 +52,9 @@ class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext {
sourcePath =
resolutionMap.elementDeclaredByCompilationUnit(unit).source.fullName;
}
-
+ // Skip MethodDeclarations - in the case of a one line function it finds the
+ // declaration rather than the body and confuses devtools.
+ if (node is MethodDeclaration) return;
_mark(node.offset, _getIdentifier(node));
}
@@ -61,7 +63,11 @@ class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext {
if (unit == null || node == null || node.offset == -1) return;
// TODO(jmesserly): in many cases marking the end will be unnecessary.
- _mark(node.end);
+ // Skip MethodDeclarations - in the case of a one line function it finds the
+ // declaration rather than the body and confuses devtools.
+ if (node is! MethodDeclaration) {
+ _mark(node.end);
+ }
if (identical(node, _currentTopLevelDeclaration)) {
unit = null;
@@ -76,6 +82,13 @@ class SourceMapPrintingContext extends JS.SimpleJavaScriptPrintingContext {
void _mark(int offset, [String identifier]) {
var loc = unit.lineInfo.getLocation(offset);
+ // Chrome Devtools wants a mapping for the beginning of
+ // a line, so bump locations at the end of a line to the beginning of
+ // the next line.
+ var next = unit.lineInfo.getLocation(offset + 1);
+ if (next.lineNumber == loc.lineNumber + 1) {
+ loc = next;
+ }
sourceMap.addLocation(
new SourceLocation(offset,
sourceUrl: sourcePath,
« 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