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

Side by Side Diff: lib/src/codegen/js_printer.dart

Issue 1425313003: Re-enable source maps (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 5 years, 1 month 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 | « no previous file | test/codegen/expect/map_keys.js.map » ('j') | 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 library dev_compiler.src.codegen.js_printer; 5 library dev_compiler.src.codegen.js_printer;
6 6
7 import 'dart:io' show Directory, File, Platform, Process; 7 import 'dart:io' show Directory, File, Platform, Process;
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 CompilationUnit unit; 64 CompilationUnit unit;
65 Uri uri; 65 Uri uri;
66 66
67 SourceMapPrintingContext(this.printer, this.outputDir); 67 SourceMapPrintingContext(this.printer, this.outputDir);
68 68
69 void emit(String string) { 69 void emit(String string) {
70 printer.add(string); 70 printer.add(string);
71 } 71 }
72 72
73 final _topLevelDeclarations = new Set<AstNode>();
74
73 void enterNode(JS.Node jsNode) { 75 void enterNode(JS.Node jsNode) {
74 AstNode node = jsNode.sourceInformation; 76 AstNode node = jsNode.sourceInformation;
75 if (node is CompilationUnit) { 77 if (node == null || node.offset == -1) return;
76 unit = node; 78 if (unit == null) {
79 // This is a top-level declaration. Note: consecutive top-level
80 // declarations may come from different compilation units due to
81 // parts.
82 _topLevelDeclarations.add(node);
83 var containingUnit = node;
84 while (containingUnit is! CompilationUnit) {
Jennifer Messerly 2015/11/09 23:21:11 I think this could be node.getAncestor((n) => n is
vsm 2015/11/10 14:35:47 Done - thanks!
85 containingUnit = containingUnit.parent;
86 }
87 unit = containingUnit;
77 uri = _makeRelativeUri(unit.element.source.uri); 88 uri = _makeRelativeUri(unit.element.source.uri);
78 return;
79 } 89 }
80 if (unit == null || node == null || node.offset == -1) return;
81 90
91 assert(unit != null);
82 var loc = _location(node.offset); 92 var loc = _location(node.offset);
83 var name = _getIdentifier(node); 93 var name = _getIdentifier(node);
84 if (name != null) { 94 if (name != null) {
85 // TODO(jmesserly): mark only uses the beginning of the span, but 95 // TODO(jmesserly): mark only uses the beginning of the span, but
86 // we're required to pass this as a valid span. 96 // we're required to pass this as a valid span.
87 var end = _location(node.end); 97 var end = _location(node.end);
88 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true)); 98 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true));
89 } else { 99 } else {
90 printer.mark(loc); 100 printer.mark(loc);
91 } 101 }
92 } 102 }
93 103
94 SourceLocation _location(int offset) => 104 SourceLocation _location(int offset) =>
95 locationForOffset(unit.lineInfo, uri, offset); 105 locationForOffset(unit.lineInfo, uri, offset);
96 106
97 Uri _makeRelativeUri(Uri src) { 107 Uri _makeRelativeUri(Uri src) {
98 return new Uri(path: path.relative(src.path, from: outputDir)); 108 return new Uri(path: path.relative(src.path, from: outputDir));
99 } 109 }
100 110
101 void exitNode(JS.Node jsNode) { 111 void exitNode(JS.Node jsNode) {
102 AstNode node = jsNode.sourceInformation; 112 AstNode node = jsNode.sourceInformation;
103 if (node is CompilationUnit) { 113 if (unit == null || node == null || node.offset == -1) return;
114
115 // TODO(jmesserly): in many cases marking the end will be unnecessary.
116 printer.mark(_location(node.end));
117
118 if (_topLevelDeclarations.contains(node)) {
Jennifer Messerly 2015/11/09 23:21:11 Could we just have a boolean "_isTopLevel" so we k
vsm 2015/11/10 14:35:47 It does nest - I think it's proper nesting. Modif
104 unit = null; 119 unit = null;
105 uri = null; 120 uri = null;
106 return; 121 return;
107 } 122 }
108 if (unit == null || node == null || node.offset == -1) return;
109
110 // TODO(jmesserly): in many cases marking the end will be unnecessary.
111 printer.mark(_location(node.end));
112 } 123 }
113 124
114 String _getIdentifier(AstNode node) { 125 String _getIdentifier(AstNode node) {
115 if (node is SimpleIdentifier) return node.name; 126 if (node is SimpleIdentifier) return node.name;
116 return null; 127 return null;
117 } 128 }
118 } 129 }
OLDNEW
« no previous file with comments | « no previous file | test/codegen/expect/map_keys.js.map » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698