Index: lib/src/codegen/js_printer.dart |
diff --git a/lib/src/codegen/js_printer.dart b/lib/src/codegen/js_printer.dart |
index e83548776dd33ac94b85b0dfb91f735230b2fdd1..6f8502fcfff23a172b2a3d57ffe1343aaa41d7e6 100644 |
--- a/lib/src/codegen/js_printer.dart |
+++ b/lib/src/codegen/js_printer.dart |
@@ -70,15 +70,25 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext { |
printer.add(string); |
} |
+ final _topLevelDeclarations = new Set<AstNode>(); |
+ |
void enterNode(JS.Node jsNode) { |
AstNode node = jsNode.sourceInformation; |
- if (node is CompilationUnit) { |
- unit = node; |
+ if (node == null || node.offset == -1) return; |
+ if (unit == null) { |
+ // This is a top-level declaration. Note: consecutive top-level |
+ // declarations may come from different compilation units due to |
+ // parts. |
+ _topLevelDeclarations.add(node); |
+ var containingUnit = node; |
+ 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!
|
+ containingUnit = containingUnit.parent; |
+ } |
+ unit = containingUnit; |
uri = _makeRelativeUri(unit.element.source.uri); |
- return; |
} |
- if (unit == null || node == null || node.offset == -1) return; |
+ assert(unit != null); |
var loc = _location(node.offset); |
var name = _getIdentifier(node); |
if (name != null) { |
@@ -100,15 +110,16 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext { |
void exitNode(JS.Node jsNode) { |
AstNode node = jsNode.sourceInformation; |
- if (node is CompilationUnit) { |
- unit = null; |
- uri = null; |
- return; |
- } |
if (unit == null || node == null || node.offset == -1) return; |
// TODO(jmesserly): in many cases marking the end will be unnecessary. |
printer.mark(_location(node.end)); |
+ |
+ 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
|
+ unit = null; |
+ uri = null; |
+ return; |
+ } |
} |
String _getIdentifier(AstNode node) { |