@@ -58,12 +58,12 @@ runInEachFileSystem(() => {
58
58
} ) ;
59
59
60
60
describe ( 'extractOriginalSegments()' , ( ) => {
61
- it ( 'should return an empty array for source files with no source map' ,
62
- ( ) => { expect ( extractOriginalSegments ( parseMappings ( null , [ ] ) ) ) . toEqual ( [ ] ) ; } ) ;
61
+ it ( 'should return an empty Map for source files with no source map' ,
62
+ ( ) => { expect ( extractOriginalSegments ( parseMappings ( null , [ ] ) ) ) . toEqual ( new Map ( ) ) ; } ) ;
63
63
64
- it ( 'should be empty array for source files with no source map mappings' , ( ) => {
64
+ it ( 'should be empty Map for source files with no source map mappings' , ( ) => {
65
65
const rawSourceMap : RawSourceMap = { mappings : '' , names : [ ] , sources : [ ] , version : 3 } ;
66
- expect ( extractOriginalSegments ( parseMappings ( rawSourceMap , [ ] ) ) ) . toEqual ( [ ] ) ;
66
+ expect ( extractOriginalSegments ( parseMappings ( rawSourceMap , [ ] ) ) ) . toEqual ( new Map ( ) ) ;
67
67
} ) ;
68
68
69
69
it ( 'should parse the segments in ascending order of original position from the raw source map' ,
@@ -75,12 +75,37 @@ runInEachFileSystem(() => {
75
75
sources : [ 'a.js' ] ,
76
76
version : 3
77
77
} ;
78
- expect ( extractOriginalSegments ( parseMappings ( rawSourceMap , [ originalSource ] ) ) ) . toEqual ( [
78
+ const originalSegments =
79
+ extractOriginalSegments ( parseMappings ( rawSourceMap , [ originalSource ] ) ) ;
80
+ expect ( originalSegments . get ( originalSource ) ) . toEqual ( [
79
81
{ line : 0 , column : 0 } ,
80
82
{ line : 0 , column : 2 } ,
81
83
{ line : 0 , column : 3 } ,
82
84
] ) ;
83
85
} ) ;
86
+
87
+ it ( 'should create separate arrays for each original source file' , ( ) => {
88
+ const sourceA = new SourceFile ( _ ( '/foo/src/a.js' ) , 'abcdefg' , null , false , [ ] ) ;
89
+ const sourceB = new SourceFile ( _ ( '/foo/src/b.js' ) , '1234567' , null , false , [ ] ) ;
90
+ const rawSourceMap : RawSourceMap = {
91
+ mappings :
92
+ encode ( [ [ [ 0 , 0 , 0 , 0 ] , [ 2 , 1 , 0 , 3 ] , [ 4 , 0 , 0 , 2 ] , [ 5 , 1 , 0 , 5 ] , [ 6 , 1 , 0 , 2 ] ] ] ) ,
93
+ names : [ ] ,
94
+ sources : [ 'a.js' , 'b.js' ] ,
95
+ version : 3
96
+ } ;
97
+ const originalSegments =
98
+ extractOriginalSegments ( parseMappings ( rawSourceMap , [ sourceA , sourceB ] ) ) ;
99
+ expect ( originalSegments . get ( sourceA ) ) . toEqual ( [
100
+ { line : 0 , column : 0 } ,
101
+ { line : 0 , column : 2 } ,
102
+ ] ) ;
103
+ expect ( originalSegments . get ( sourceB ) ) . toEqual ( [
104
+ { line : 0 , column : 2 } ,
105
+ { line : 0 , column : 3 } ,
106
+ { line : 0 , column : 5 } ,
107
+ ] ) ;
108
+ } ) ;
84
109
} ) ;
85
110
86
111
describe ( 'findLastMappingIndexBefore' , ( ) => {
@@ -313,15 +338,18 @@ runInEachFileSystem(() => {
313
338
} ) ;
314
339
315
340
it ( 'should merge mappings from flattened original source files' , ( ) => {
316
- const cSource = new SourceFile ( _ ( '/foo/src/c.js' ) , 'bcd123e' , null , false , [ ] ) ;
341
+ const cSource = new SourceFile ( _ ( '/foo/src/c.js' ) , 'bcd123' , null , false , [ ] ) ;
342
+ const dSource = new SourceFile ( _ ( '/foo/src/d.js' ) , 'aef' , null , false , [ ] ) ;
343
+
317
344
const bSourceMap : RawSourceMap = {
318
- mappings : encode ( [ [ [ 1 , 0 , 0 , 0 ] , [ 4 , 0 , 0 , 3 ] , [ 4 , 0 , 0 , 6 ] , [ 5 , 0 , 0 , 7 ] ] ] ) ,
345
+ mappings : encode ( [ [ [ 0 , 1 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] , [ 4 , 1 , 0 , 1 ] ] ] ) ,
319
346
names : [ ] ,
320
- sources : [ 'c.js' ] ,
347
+ sources : [ 'c.js' , 'd.js' ] ,
321
348
version : 3
322
349
} ;
323
350
const bSource =
324
- new SourceFile ( _ ( '/foo/src/b.js' ) , 'abcdef' , bSourceMap , false , [ cSource ] ) ;
351
+ new SourceFile ( _ ( '/foo/src/b.js' ) , 'abcdef' , bSourceMap , false , [ cSource , dSource ] ) ;
352
+
325
353
const aSourceMap : RawSourceMap = {
326
354
mappings : encode ( [ [ [ 0 , 0 , 0 , 0 ] , [ 2 , 0 , 0 , 3 ] , [ 4 , 0 , 0 , 2 ] , [ 5 , 0 , 0 , 5 ] ] ] ) ,
327
355
names : [ ] ,
@@ -333,27 +361,27 @@ runInEachFileSystem(() => {
333
361
334
362
expect ( aSource . flattenedMappings ) . toEqual ( [
335
363
{
336
- generatedSegment : { line : 0 , column : 1 } ,
337
- originalSource : cSource ,
364
+ generatedSegment : { line : 0 , column : 0 } ,
365
+ originalSource : dSource ,
338
366
originalSegment : { line : 0 , column : 0 } ,
339
367
name : undefined
340
368
} ,
341
369
{
342
- generatedSegment : { line : 0 , column : 2 } ,
370
+ generatedSegment : { line : 0 , column : 1 } ,
343
371
originalSource : cSource ,
344
- originalSegment : { line : 0 , column : 2 } ,
372
+ originalSegment : { line : 0 , column : 0 } ,
345
373
name : undefined
346
374
} ,
347
375
{
348
- generatedSegment : { line : 0 , column : 3 } ,
376
+ generatedSegment : { line : 0 , column : 2 } ,
349
377
originalSource : cSource ,
350
- originalSegment : { line : 0 , column : 3 } ,
378
+ originalSegment : { line : 0 , column : 2 } ,
351
379
name : undefined
352
380
} ,
353
381
{
354
382
generatedSegment : { line : 0 , column : 3 } ,
355
- originalSource : cSource ,
356
- originalSegment : { line : 0 , column : 6 } ,
383
+ originalSource : dSource ,
384
+ originalSegment : { line : 0 , column : 1 } ,
357
385
name : undefined
358
386
} ,
359
387
{
@@ -364,8 +392,8 @@ runInEachFileSystem(() => {
364
392
} ,
365
393
{
366
394
generatedSegment : { line : 0 , column : 5 } ,
367
- originalSource : cSource ,
368
- originalSegment : { line : 0 , column : 7 } ,
395
+ originalSource : dSource ,
396
+ originalSegment : { line : 0 , column : 2 } ,
369
397
name : undefined
370
398
} ,
371
399
] ) ;
0 commit comments