3
3
*--------------------------------------------------------*/
4
4
5
5
import { inject , injectable } from 'inversify' ;
6
- import { BasicSourceMapConsumer , RawSourceMap , SourceMapConsumer } from 'source-map' ;
6
+ import { RawIndexMap , RawSourceMap , SourceMapConsumer } from 'source-map' ;
7
7
import { IResourceProvider } from '../../adapter/resourceProvider' ;
8
8
import Dap from '../../dap/api' ;
9
9
import { IRootDapApi } from '../../dap/connection' ;
@@ -57,7 +57,7 @@ export class SourceMapFactory implements ISourceMapFactory {
57
57
* @inheritdoc
58
58
*/
59
59
public async load ( metadata : ISourceMapMetadata ) : Promise < SourceMap > {
60
- let basic : RawSourceMap | undefined ;
60
+ let basic : RawSourceMap | RawIndexMap | undefined ;
61
61
try {
62
62
basic = await this . parseSourceMap ( metadata . sourceMapUrl ) ;
63
63
} catch ( e ) {
@@ -75,18 +75,32 @@ export class SourceMapFactory implements ISourceMapFactory {
75
75
const actualRoot = basic . sourceRoot ;
76
76
basic . sourceRoot = undefined ;
77
77
78
+ let hasNames = false ;
79
+
78
80
// The source map library (also) "helpfully" normalizes source URLs, so
79
81
// preserve them in the same way. Then, rename the sources to prevent any
80
82
// of their names colliding (e.g. "webpack://./index.js" and "webpack://../index.js")
81
- const actualSources = basic . sources ;
82
- basic . sources = basic . sources . map ( ( _ , i ) => `source${ i } .js` ) ;
83
+ let actualSources : string [ ] = [ ] ;
84
+ if ( 'sections' in basic && Array . isArray ( basic . sections ) ) {
85
+ actualSources = [ ] ;
86
+ let i = 0 ;
87
+ for ( const section of basic . sections ) {
88
+ actualSources . push ( ...section . map . sources ) ;
89
+ section . map . sources = section . map . sources . map ( ( ) => `source${ i ++ } .js` ) ;
90
+ hasNames ||= ! ! section . map . names ?. length ;
91
+ }
92
+ } else if ( 'sources' in basic && Array . isArray ( basic . sources ) ) {
93
+ actualSources = basic . sources ;
94
+ basic . sources = basic . sources . map ( ( _ , i ) => `source${ i } .js` ) ;
95
+ hasNames = ! ! basic . names ?. length ;
96
+ }
83
97
84
98
return new SourceMap (
85
- ( await new SourceMapConsumer ( basic ) ) as BasicSourceMapConsumer ,
99
+ await new SourceMapConsumer ( basic ) ,
86
100
metadata ,
87
101
actualRoot ?? '' ,
88
102
actualSources ,
89
- ! ! basic . names ?. length ,
103
+ hasNames ,
90
104
) ;
91
105
}
92
106
@@ -136,7 +150,7 @@ export class SourceMapFactory implements ISourceMapFactory {
136
150
// no-op
137
151
}
138
152
139
- private async parseSourceMap ( sourceMapUrl : string ) : Promise < RawSourceMap > {
153
+ private async parseSourceMap ( sourceMapUrl : string ) : Promise < RawSourceMap | RawIndexMap > {
140
154
let absolutePath = fileUrlToAbsolutePath ( sourceMapUrl ) ;
141
155
if ( absolutePath ) {
142
156
absolutePath = this . pathResolve . rebaseRemoteToLocal ( absolutePath ) ;
0 commit comments