@@ -16,13 +16,7 @@ const INTERNAL = Symbol("smcInternal");
16
16
17
17
class SourceMapConsumer {
18
18
constructor ( aSourceMap , aSourceMapURL ) {
19
- // If the constructor was called by super(), just return Promise<this>.
20
- // Yes, this is a hack to retain the pre-existing API of the base-class
21
- // constructor also being an async factory function.
22
- if ( aSourceMap == INTERNAL ) {
23
- return Promise . resolve ( this ) ;
24
- }
25
-
19
+ if ( aSourceMap === INTERNAL ) return this ;
26
20
return _factory ( aSourceMap , aSourceMapURL ) ;
27
21
}
28
22
@@ -198,74 +192,71 @@ exports.SourceMapConsumer = SourceMapConsumer;
198
192
*/
199
193
class BasicSourceMapConsumer extends SourceMapConsumer {
200
194
constructor ( aSourceMap , aSourceMapURL ) {
201
- return super ( INTERNAL ) . then ( that => {
202
- let sourceMap = aSourceMap ;
203
- if ( typeof aSourceMap === "string" ) {
204
- sourceMap = util . parseSourceMapInput ( aSourceMap ) ;
205
- }
195
+ super ( INTERNAL ) ;
196
+ let sourceMap = aSourceMap ;
197
+ if ( typeof aSourceMap === "string" ) {
198
+ sourceMap = util . parseSourceMapInput ( aSourceMap ) ;
199
+ }
206
200
207
- const version = util . getArg ( sourceMap , "version" ) ;
208
- let sources = util . getArg ( sourceMap , "sources" ) ;
209
- // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
210
- // requires the array) to play nice here.
211
- const names = util . getArg ( sourceMap , "names" , [ ] ) ;
212
- let sourceRoot = util . getArg ( sourceMap , "sourceRoot" , null ) ;
213
- const sourcesContent = util . getArg ( sourceMap , "sourcesContent" , null ) ;
214
- const mappings = util . getArg ( sourceMap , "mappings" ) ;
215
- const file = util . getArg ( sourceMap , "file" , null ) ;
216
-
217
- // Once again, Sass deviates from the spec and supplies the version as a
218
- // string rather than a number, so we use loose equality checking here.
219
- if ( version != that . _version ) {
220
- throw new Error ( "Unsupported version: " + version ) ;
221
- }
201
+ const version = util . getArg ( sourceMap , "version" ) ;
202
+ let sources = util . getArg ( sourceMap , "sources" ) ;
203
+ // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
204
+ // requires the array) to play nice here.
205
+ const names = util . getArg ( sourceMap , "names" , [ ] ) ;
206
+ let sourceRoot = util . getArg ( sourceMap , "sourceRoot" , null ) ;
207
+ const sourcesContent = util . getArg ( sourceMap , "sourcesContent" , null ) ;
208
+ const mappings = util . getArg ( sourceMap , "mappings" ) ;
209
+ const file = util . getArg ( sourceMap , "file" , null ) ;
210
+
211
+ // Once again, Sass deviates from the spec and supplies the version as a
212
+ // string rather than a number, so we use loose equality checking here.
213
+ if ( version != this . _version ) {
214
+ throw new Error ( "Unsupported version: " + version ) ;
215
+ }
222
216
223
- if ( sourceRoot ) {
224
- sourceRoot = util . normalize ( sourceRoot ) ;
225
- }
217
+ if ( sourceRoot ) {
218
+ sourceRoot = util . normalize ( sourceRoot ) ;
219
+ }
226
220
227
- sources = sources
228
- . map ( String )
229
- // Some source maps produce relative source paths like "./foo.js" instead of
230
- // "foo.js". Normalize these first so that future comparisons will succeed.
231
- // See bugzil.la/1090768.
232
- . map ( util . normalize )
233
- // Always ensure that absolute sources are internally stored relative to
234
- // the source root, if the source root is absolute. Not doing this would
235
- // be particularly problematic when the source root is a prefix of the
236
- // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
237
- . map ( function ( source ) {
238
- return sourceRoot && util . isAbsolute ( sourceRoot ) && util . isAbsolute ( source )
239
- ? util . relative ( sourceRoot , source )
240
- : source ;
241
- } ) ;
221
+ sources = sources
222
+ . map ( String )
223
+ // Some source maps produce relative source paths like "./foo.js" instead of
224
+ // "foo.js". Normalize these first so that future comparisons will succeed.
225
+ // See bugzil.la/1090768.
226
+ . map ( util . normalize )
227
+ // Always ensure that absolute sources are internally stored relative to
228
+ // the source root, if the source root is absolute. Not doing this would
229
+ // be particularly problematic when the source root is a prefix of the
230
+ // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
231
+ . map ( function ( source ) {
232
+ return sourceRoot && util . isAbsolute ( sourceRoot ) && util . isAbsolute ( source )
233
+ ? util . relative ( sourceRoot , source )
234
+ : source ;
235
+ } ) ;
242
236
243
- // Pass `true` below to allow duplicate names and sources. While source maps
244
- // are intended to be compressed and deduplicated, the TypeScript compiler
245
- // sometimes generates source maps with duplicates in them. See Github issue
246
- // #72 and bugzil.la/889492.
247
- that . _names = ArraySet . fromArray ( names . map ( String ) , true ) ;
248
- that . _sources = ArraySet . fromArray ( sources , true ) ;
237
+ // Pass `true` below to allow duplicate names and sources. While source maps
238
+ // are intended to be compressed and deduplicated, the TypeScript compiler
239
+ // sometimes generates source maps with duplicates in them. See Github issue
240
+ // #72 and bugzil.la/889492.
241
+ this . _names = ArraySet . fromArray ( names . map ( String ) , true ) ;
242
+ this . _sources = ArraySet . fromArray ( sources , true ) ;
249
243
250
- that . _absoluteSources = that . _sources . toArray ( ) . map ( function ( s ) {
251
- return util . computeSourceURL ( sourceRoot , s , aSourceMapURL ) ;
252
- } ) ;
244
+ this . _absoluteSources = this . _sources . toArray ( ) . map ( function ( s ) {
245
+ return util . computeSourceURL ( sourceRoot , s , aSourceMapURL ) ;
246
+ } ) ;
253
247
254
- that . sourceRoot = sourceRoot ;
255
- that . sourcesContent = sourcesContent ;
256
- that . _mappings = mappings ;
257
- that . _sourceMapURL = aSourceMapURL ;
258
- that . file = file ;
248
+ this . sourceRoot = sourceRoot ;
249
+ this . sourcesContent = sourcesContent ;
250
+ this . _mappings = mappings ;
251
+ this . _sourceMapURL = aSourceMapURL ;
252
+ this . file = file ;
259
253
260
- that . _computedColumnSpans = false ;
261
- that . _mappingsPtr = 0 ;
262
- that . _wasm = null ;
254
+ this . _computedColumnSpans = false ;
255
+ this . _mappingsPtr = 0 ;
256
+ this . _wasm = null ;
263
257
264
- return wasm ( ) . then ( w => {
265
- that . _wasm = w ;
266
- return that ;
267
- } ) ;
268
- } ) ;
258
+ const w = wasm . sync ( ) ;
259
+ this . _wasm = w ;
269
260
}
270
261
271
262
/**
@@ -383,14 +374,14 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
383
374
} ,
384
375
( ) => {
385
376
switch ( order ) {
386
- case SourceMapConsumer . GENERATED_ORDER :
387
- this . _wasm . exports . by_generated_location ( this . _getMappingsPtr ( ) ) ;
388
- break ;
389
- case SourceMapConsumer . ORIGINAL_ORDER :
390
- this . _wasm . exports . by_original_location ( this . _getMappingsPtr ( ) ) ;
391
- break ;
392
- default :
393
- throw new Error ( "Unknown order of iteration." ) ;
377
+ case SourceMapConsumer . GENERATED_ORDER :
378
+ this . _wasm . exports . by_generated_location ( this . _getMappingsPtr ( ) ) ;
379
+ break ;
380
+ case SourceMapConsumer . ORIGINAL_ORDER :
381
+ this . _wasm . exports . by_original_location ( this . _getMappingsPtr ( ) ) ;
382
+ break ;
383
+ default :
384
+ throw new Error ( "Unknown order of iteration." ) ;
394
385
}
395
386
}
396
387
) ;
@@ -746,62 +737,56 @@ exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
746
737
*/
747
738
class IndexedSourceMapConsumer extends SourceMapConsumer {
748
739
constructor ( aSourceMap , aSourceMapURL ) {
749
- return super ( INTERNAL ) . then ( that => {
750
- let sourceMap = aSourceMap ;
751
- if ( typeof aSourceMap === "string" ) {
752
- sourceMap = util . parseSourceMapInput ( aSourceMap ) ;
753
- }
740
+ super ( INTERNAL ) ;
741
+ let sourceMap = aSourceMap ;
742
+ if ( typeof aSourceMap === "string" ) {
743
+ sourceMap = util . parseSourceMapInput ( aSourceMap ) ;
744
+ }
754
745
755
- const version = util . getArg ( sourceMap , "version" ) ;
756
- const sections = util . getArg ( sourceMap , "sections" ) ;
746
+ const version = util . getArg ( sourceMap , "version" ) ;
747
+ const sections = util . getArg ( sourceMap , "sections" ) ;
757
748
758
- if ( version != that . _version ) {
759
- throw new Error ( "Unsupported version: " + version ) ;
749
+ if ( version != this . _version ) {
750
+ throw new Error ( "Unsupported version: " + version ) ;
751
+ }
752
+
753
+ this . _sources = new ArraySet ( ) ;
754
+ this . _names = new ArraySet ( ) ;
755
+ this . __generatedMappings = null ;
756
+ this . __originalMappings = null ;
757
+ this . __generatedMappingsUnsorted = null ;
758
+ this . __originalMappingsUnsorted = null ;
759
+
760
+ let lastOffset = {
761
+ line : - 1 ,
762
+ column : 0
763
+ } ;
764
+ this . _sections = sections . map ( s => {
765
+ if ( s . url ) {
766
+ // The url field will require support for asynchronicity.
767
+ // See https://github.com/mozilla/source-map/issues/16
768
+ throw new Error ( "Support for url field in sections not implemented." ) ;
760
769
}
770
+ const offset = util . getArg ( s , "offset" ) ;
771
+ const offsetLine = util . getArg ( offset , "line" ) ;
772
+ const offsetColumn = util . getArg ( offset , "column" ) ;
761
773
762
- that . _sources = new ArraySet ( ) ;
763
- that . _names = new ArraySet ( ) ;
764
- that . __generatedMappings = null ;
765
- that . __originalMappings = null ;
766
- that . __generatedMappingsUnsorted = null ;
767
- that . __originalMappingsUnsorted = null ;
774
+ if ( offsetLine < lastOffset . line ||
775
+ ( offsetLine === lastOffset . line && offsetColumn < lastOffset . column ) ) {
776
+ throw new Error ( "Section offsets must be ordered and non-overlapping." ) ;
777
+ }
778
+ lastOffset = offset ;
768
779
769
- let lastOffset = {
770
- line : - 1 ,
771
- column : 0
780
+ const consumer = new SourceMapConsumer ( util . getArg ( s , "map" ) , aSourceMapURL ) ;
781
+ return {
782
+ generatedOffset : {
783
+ // The offset fields are 0-based, but we use 1-based indices when
784
+ // encoding/decoding from VLQ.
785
+ generatedLine : offsetLine + 1 ,
786
+ generatedColumn : offsetColumn + 1
787
+ } ,
788
+ consumer
772
789
} ;
773
- return Promise . all ( sections . map ( s => {
774
- if ( s . url ) {
775
- // The url field will require support for asynchronicity.
776
- // See https://github.com/mozilla/source-map/issues/16
777
- throw new Error ( "Support for url field in sections not implemented." ) ;
778
- }
779
- const offset = util . getArg ( s , "offset" ) ;
780
- const offsetLine = util . getArg ( offset , "line" ) ;
781
- const offsetColumn = util . getArg ( offset , "column" ) ;
782
-
783
- if ( offsetLine < lastOffset . line ||
784
- ( offsetLine === lastOffset . line && offsetColumn < lastOffset . column ) ) {
785
- throw new Error ( "Section offsets must be ordered and non-overlapping." ) ;
786
- }
787
- lastOffset = offset ;
788
-
789
- const cons = new SourceMapConsumer ( util . getArg ( s , "map" ) , aSourceMapURL ) ;
790
- return cons . then ( consumer => {
791
- return {
792
- generatedOffset : {
793
- // The offset fields are 0-based, but we use 1-based indices when
794
- // encoding/decoding from VLQ.
795
- generatedLine : offsetLine + 1 ,
796
- generatedColumn : offsetColumn + 1
797
- } ,
798
- consumer
799
- } ;
800
- } ) ;
801
- } ) ) . then ( s => {
802
- that . _sections = s ;
803
- return that ;
804
- } ) ;
805
790
} ) ;
806
791
}
807
792
@@ -926,7 +911,7 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
926
911
}
927
912
928
913
return ( aNeedle . generatedColumn -
929
- section . generatedOffset . generatedColumn ) ;
914
+ section . generatedOffset . generatedColumn ) ;
930
915
} ) ;
931
916
const section = this . _sections [ sectionIndex ] ;
932
917
@@ -944,8 +929,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
944
929
( section . generatedOffset . generatedLine - 1 ) ,
945
930
column : needle . generatedColumn -
946
931
( section . generatedOffset . generatedLine === needle . generatedLine
947
- ? section . generatedOffset . generatedColumn - 1
948
- : 0 ) ,
932
+ ? section . generatedOffset . generatedColumn - 1
933
+ : 0 ) ,
949
934
bias : aArgs . bias
950
935
} ) ;
951
936
}
@@ -1014,8 +999,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
1014
999
( section . generatedOffset . generatedLine - 1 ) ,
1015
1000
column : generatedPosition . column +
1016
1001
( section . generatedOffset . generatedLine === generatedPosition . line
1017
- ? section . generatedOffset . generatedColumn - 1
1018
- : 0 )
1002
+ ? section . generatedOffset . generatedColumn - 1
1003
+ : 0 )
1019
1004
} ;
1020
1005
return ret ;
1021
1006
}
@@ -1068,8 +1053,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
1068
1053
( section . generatedOffset . generatedLine - 1 ) ,
1069
1054
generatedColumn : mapping . generatedColumn +
1070
1055
( section . generatedOffset . generatedLine === mapping . generatedLine
1071
- ? section . generatedOffset . generatedColumn - 1
1072
- : 0 ) ,
1056
+ ? section . generatedOffset . generatedColumn - 1
1057
+ : 0 ) ,
1073
1058
originalLine : mapping . originalLine ,
1074
1059
originalColumn : mapping . originalColumn ,
1075
1060
name
@@ -1122,19 +1107,19 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
1122
1107
* we are searching for in the given "haystack" of mappings.
1123
1108
*/
1124
1109
_findMapping ( aNeedle , aMappings , aLineName ,
1125
- aColumnName , aComparator , aBias ) {
1110
+ aColumnName , aComparator , aBias ) {
1126
1111
// To return the position we are searching for, we must first find the
1127
1112
// mapping for the given position and then return the opposite position it
1128
1113
// points to. Because the mappings are sorted, we can use binary search to
1129
1114
// find the best mapping.
1130
1115
1131
1116
if ( aNeedle [ aLineName ] <= 0 ) {
1132
1117
throw new TypeError ( "Line must be greater than or equal to 1, got "
1133
- + aNeedle [ aLineName ] ) ;
1118
+ + aNeedle [ aLineName ] ) ;
1134
1119
}
1135
1120
if ( aNeedle [ aColumnName ] < 0 ) {
1136
1121
throw new TypeError ( "Column must be greater than or equal to 0, got "
1137
- + aNeedle [ aColumnName ] ) ;
1122
+ + aNeedle [ aColumnName ] ) ;
1138
1123
}
1139
1124
1140
1125
return binarySearch . search ( aNeedle , aMappings , aComparator , aBias ) ;
@@ -1169,11 +1154,11 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
1169
1154
const mappings = [ ] ;
1170
1155
1171
1156
let index = this . _findMapping ( needle ,
1172
- this . _originalMappings ,
1173
- "originalLine" ,
1174
- "originalColumn" ,
1175
- util . compareByOriginalPositions ,
1176
- binarySearch . LEAST_UPPER_BOUND ) ;
1157
+ this . _originalMappings ,
1158
+ "originalLine" ,
1159
+ "originalColumn" ,
1160
+ util . compareByOriginalPositions ,
1161
+ binarySearch . LEAST_UPPER_BOUND ) ;
1177
1162
if ( index >= 0 ) {
1178
1163
let mapping = this . _originalMappings [ index ] ;
1179
1164
@@ -1205,8 +1190,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
1205
1190
// Since mappings are sorted, this is guaranteed to find all mappings for
1206
1191
// the line we are searching for.
1207
1192
while ( mapping &&
1208
- mapping . originalLine === line &&
1209
- mapping . originalColumn == originalColumn ) {
1193
+ mapping . originalLine === line &&
1194
+ mapping . originalColumn == originalColumn ) {
1210
1195
let lastColumn = mapping . lastGeneratedColumn ;
1211
1196
if ( this . _computedColumnSpans && lastColumn === null ) {
1212
1197
lastColumn = Infinity ;
@@ -1244,9 +1229,9 @@ function _factory(aSourceMap, aSourceMapURL) {
1244
1229
}
1245
1230
1246
1231
const consumer = sourceMap . sections != null
1247
- ? new IndexedSourceMapConsumer ( sourceMap , aSourceMapURL )
1248
- : new BasicSourceMapConsumer ( sourceMap , aSourceMapURL ) ;
1249
- return Promise . resolve ( consumer ) ;
1232
+ ? new IndexedSourceMapConsumer ( sourceMap , aSourceMapURL )
1233
+ : new BasicSourceMapConsumer ( sourceMap , aSourceMapURL ) ;
1234
+ return consumer ;
1250
1235
}
1251
1236
1252
1237
function _factoryBSM ( aSourceMap , aSourceMapURL ) {
0 commit comments