File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,9 @@ SourceMapConsumer.prototype.eachMapping =
151
151
for ( var i = 0 , n = mappings . length ; i < n ; i ++ ) {
152
152
var mapping = mappings [ i ] ;
153
153
var source = mapping . source === null ? null : sources . at ( mapping . source ) ;
154
- source = util . computeSourceURL ( sourceRoot , source , sourceMapURL ) ;
154
+ if ( source !== null ) {
155
+ source = util . computeSourceURL ( sourceRoot , source , sourceMapURL ) ;
156
+ }
155
157
boundCallback ( {
156
158
source : source ,
157
159
generatedLine : mapping . generatedLine ,
@@ -1142,7 +1144,9 @@ IndexedSourceMapConsumer.prototype._parseMappings =
1142
1144
var mapping = sectionMappings [ j ] ;
1143
1145
1144
1146
var source = section . consumer . _sources . at ( mapping . source ) ;
1145
- source = util . computeSourceURL ( section . consumer . sourceRoot , source , this . _sourceMapURL ) ;
1147
+ if ( source !== null ) {
1148
+ source = util . computeSourceURL ( section . consumer . sourceRoot , source , this . _sourceMapURL ) ;
1149
+ }
1146
1150
this . _sources . add ( source ) ;
1147
1151
source = this . _sources . indexOf ( source ) ;
1148
1152
Original file line number Diff line number Diff line change @@ -768,3 +768,18 @@ exports['test numeric names #231'] = function (assert) {
768
768
assert . equal ( map . names . length , 1 , "Should have one name" ) ;
769
769
assert . equal ( map . names [ 0 ] , "8" , "Should have the right name" ) ;
770
770
} ;
771
+
772
+ exports [ 'test that we can create a generator from a source map with empty mappings' ] = function ( assert ) {
773
+ var generator = new SourceMapGenerator ( ) ;
774
+ generator . addMapping ( {
775
+ generated : { line : 1 , column : 1 } ,
776
+ original : null ,
777
+ source : null ,
778
+ } ) ;
779
+ const originalMap = generator . toJSON ( ) ;
780
+ const consumer = new SourceMapConsumer ( originalMap ) ;
781
+ const fromConsumer = SourceMapGenerator . fromSourceMap ( consumer ) ;
782
+ const fromSourceMap = fromConsumer . toJSON ( ) ;
783
+ assert . ok ( fromSourceMap , "Creating a generator from a map with only generated position did not throw" ) ;
784
+ assert . equal ( fromSourceMap . mappings , originalMap . mappings ) ;
785
+ }
You can’t perform that action at this time.
0 commit comments