@@ -70,15 +70,21 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
70
70
printer.add (string);
71
71
}
72
72
73
+ AstNode _currentTopLevelDeclaration;
74
+
73
75
void enterNode (JS .Node jsNode) {
74
76
AstNode node = jsNode.sourceInformation;
75
- if (node is CompilationUnit ) {
76
- unit = node;
77
+ if (node == null || node.offset == - 1 ) return ;
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
+ _currentTopLevelDeclaration = node;
83
+ unit = node.getAncestor ((n) => n is CompilationUnit );
77
84
uri = _makeRelativeUri (unit.element.source.uri);
78
- return ;
79
85
}
80
- if (unit == null || node == null || node.offset == - 1 ) return ;
81
86
87
+ assert (unit != null );
82
88
var loc = _location (node.offset);
83
89
var name = _getIdentifier (node);
84
90
if (name != null ) {
@@ -100,15 +106,17 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
100
106
101
107
void exitNode (JS .Node jsNode) {
102
108
AstNode node = jsNode.sourceInformation;
103
- if (node is CompilationUnit ) {
104
- unit = null ;
105
- uri = null ;
106
- return ;
107
- }
108
109
if (unit == null || node == null || node.offset == - 1 ) return ;
109
110
110
111
// TODO(jmesserly): in many cases marking the end will be unnecessary.
111
112
printer.mark (_location (node.end));
113
+
114
+ if (_currentTopLevelDeclaration == node) {
115
+ unit = null ;
116
+ uri = null ;
117
+ _currentTopLevelDeclaration == null ;
118
+ return ;
119
+ }
112
120
}
113
121
114
122
String _getIdentifier (AstNode node) {
0 commit comments