44
55import * as TextUtils from '../../models/text_utils/text_utils.js' ;
66import { describeWithEnvironment } from '../../testing/EnvironmentHelpers.js' ;
7- import { encodeSourceMap , GeneratedRangeBuilder , OriginalScopeBuilder } from '../../testing/SourceMapEncoder.js' ;
7+ import { encodeSourceMap } from '../../testing/SourceMapEncoder.js' ;
8+ import * as ScopesCodec from '../../third_party/source-map-scopes-codec/source-map-scopes-codec.js' ;
89import * as Platform from '../platform/platform.js' ;
910import * as Root from '../root/root.js' ;
1011
@@ -1239,33 +1240,29 @@ describeWithEnvironment('SourceMap', () => {
12391240 it ( 'can resolve generated positions with inlineFrameIndex' , ( ) => {
12401241 Root . Runtime . experiments . enableForTest ( Root . Runtime . ExperimentName . USE_SOURCE_MAP_SCOPES ) ;
12411242 // 'foo' calls 'bar', 'bar' calls 'baz'. 'bar' and 'baz' are inlined into 'foo'.
1242- const names : string [ ] = [ ] ;
1243- const originalScopes = [ new OriginalScopeBuilder ( names )
1244- . start ( 0 , 0 , { kind : 'global' } )
1245- . start ( 10 , 0 , { kind : 'function' , name : 'foo' } )
1246- . end ( 20 , 0 )
1247- . start ( 30 , 0 , { kind : 'function' , name : 'bar' } )
1248- . end ( 40 , 0 )
1249- . start ( 50 , 0 , { kind : 'function' , name : 'baz' } )
1250- . end ( 60 , 0 )
1251- . end ( 70 , 0 )
1252- . build ( ) ] ;
1253-
1254- const generatedRanges =
1255- new GeneratedRangeBuilder ( names )
1256- . start ( 0 , 0 , { definition : { sourceIdx : 0 , scopeIdx : 0 } } )
1257- . start ( 0 , 0 , { definition : { sourceIdx : 0 , scopeIdx : 1 } , isStackFrame : true } )
1258- . start ( 0 , 5 , { definition : { sourceIdx : 0 , scopeIdx : 3 } , callsite : { sourceIdx : 0 , line : 15 , column : 0 } } )
1259- . start ( 0 , 5 , { definition : { sourceIdx : 0 , scopeIdx : 5 } , callsite : { sourceIdx : 0 , line : 35 , column : 0 } } )
1260- . end ( 0 , 10 )
1261- . end ( 0 , 10 )
1262- . end ( 0 , 10 )
1263- . end ( 0 , 10 )
1264- . build ( ) ;
1243+ const builder = new ScopesCodec . ScopeInfoBuilder ( ) ;
1244+ builder . startScope ( 0 , 0 , { kind : 'global' , key : 'global' } )
1245+ . startScope ( 10 , 0 , { kind : 'function' , key : 'foo' , name : 'foo' } )
1246+ . endScope ( 20 , 0 )
1247+ . startScope ( 30 , 0 , { kind : 'function' , key : 'bar' , name : 'bar' } )
1248+ . endScope ( 40 , 0 )
1249+ . startScope ( 50 , 0 , { kind : 'function' , key : 'baz' , name : 'baz' } )
1250+ . endScope ( 60 , 0 )
1251+ . endScope ( 70 , 0 ) ;
1252+
1253+ builder . startRange ( 0 , 0 , { scopeKey : 'global' } )
1254+ . startRange ( 0 , 0 , { scopeKey : 'foo' , isStackFrame : true } )
1255+ . startRange ( 0 , 5 , { scopeKey : 'bar' , callSite : { sourceIndex : 0 , line : 15 , column : 0 } } )
1256+ . startRange ( 0 , 5 , { scopeKey : 'baz' , callSite : { sourceIndex : 0 , line : 35 , column : 0 } } )
1257+ . endRange ( 0 , 10 )
1258+ . endRange ( 0 , 10 )
1259+ . endRange ( 0 , 10 )
1260+ . endRange ( 0 , 10 ) ;
12651261
12661262 const sourceMap = new SDK . SourceMap . SourceMap (
12671263 compiledUrl , sourceMapJsonUrl ,
1268- { version : 3 , sources : [ 'foo.ts' ] , mappings : '' , names, originalScopes, generatedRanges} ) ;
1264+ ScopesCodec . encode ( builder . build ( ) , { version : 3 , sources : [ 'foo.ts' ] , mappings : '' } ) as
1265+ SDK . SourceMap . SourceMapV3Object ) ;
12691266
12701267 assert . isNull (
12711268 sourceMap . findEntry ( 0 , 7 , 0 ) ) ; // We don't have mappings, so inlineFrameIndex = 0 ('baz') has no entry.
@@ -1284,57 +1281,42 @@ describeWithEnvironment('SourceMap', () => {
12841281
12851282 it ( 'combines "scopes" proposal scopes appropriately for index maps' , ( ) => {
12861283 Root . Runtime . experiments . enableForTest ( Root . Runtime . ExperimentName . USE_SOURCE_MAP_SCOPES ) ;
1287- const names1 : string [ ] = [ ] ;
1288- const originalScopes1 = [ new OriginalScopeBuilder ( names1 )
1289- . start ( 0 , 0 , { kind : 'global' } )
1290- . start ( 10 , 0 , { name : 'foo' , kind : 'function' , isStackFrame : true } )
1291- . end ( 20 , 0 )
1292- . end ( 30 , 0 )
1293- . build ( ) ] ;
1294- const generatedRanges1 = new GeneratedRangeBuilder ( names1 )
1295- . start ( 0 , 0 , { definition : { sourceIdx : 0 , scopeIdx : 0 } } )
1296- . start ( 0 , 7 , { definition : { sourceIdx : 0 , scopeIdx : 1 } , isStackFrame : true } )
1297- . end ( 0 , 14 )
1298- . end ( 0 , 21 )
1299- . build ( ) ;
1300- const names2 : string [ ] = [ ] ;
1301- const originalScopes2 = [ new OriginalScopeBuilder ( names2 )
1302- . start ( 0 , 0 , { kind : 'global' } )
1303- . start ( 10 , 0 , { name : 'bar' , kind : 'function' , isStackFrame : true } )
1304- . end ( 20 , 0 )
1305- . end ( 30 , 0 )
1306- . build ( ) ] ;
1307- const generatedRanges2 = new GeneratedRangeBuilder ( names2 )
1308- . start ( 0 , 0 , { definition : { sourceIdx : 0 , scopeIdx : 0 } } )
1309- . start ( 0 , 7 , { definition : { sourceIdx : 0 , scopeIdx : 1 } , isStackFrame : true } )
1310- . end ( 0 , 14 )
1311- . end ( 0 , 21 )
1312- . build ( ) ;
1284+ const info1 = new ScopesCodec . ScopeInfoBuilder ( )
1285+ . startScope ( 0 , 0 , { kind : 'global' , key : 'global' } )
1286+ . startScope ( 10 , 0 , { name : 'foo' , key : 'foo' , kind : 'function' , isStackFrame : true } )
1287+ . endScope ( 20 , 0 )
1288+ . endScope ( 30 , 0 )
1289+ . startRange ( 0 , 0 , { scopeKey : 'global' } )
1290+ . startRange ( 0 , 7 , { scopeKey : 'foo' , isStackFrame : true } )
1291+ . endRange ( 0 , 14 )
1292+ . endRange ( 0 , 21 )
1293+ . build ( ) ;
1294+ const map1 = ScopesCodec . encode ( info1 , {
1295+ version : 3 ,
1296+ sources : [ 'foo.ts' ] ,
1297+ mappings : '' ,
1298+ } ) ;
1299+
1300+ const info2 = new ScopesCodec . ScopeInfoBuilder ( )
1301+ . startScope ( 0 , 0 , { kind : 'global' , key : 'global' } )
1302+ . startScope ( 10 , 0 , { name : 'bar' , key : 'bar' , kind : 'function' , isStackFrame : true } )
1303+ . endScope ( 20 , 0 )
1304+ . endScope ( 30 , 0 )
1305+ . startRange ( 0 , 0 , { scopeKey : 'global' } )
1306+ . startRange ( 0 , 7 , { scopeKey : 'bar' , isStackFrame : true } )
1307+ . endRange ( 0 , 14 )
1308+ . endRange ( 0 , 21 )
1309+ . build ( ) ;
1310+ const map2 = ScopesCodec . encode ( info2 , {
1311+ version : 3 ,
1312+ sources : [ 'bar.ts' ] ,
1313+ mappings : '' ,
1314+ } ) ;
13131315 const indexMap : SDK . SourceMap . SourceMapV3 = {
13141316 version : 3 ,
13151317 sections : [
1316- {
1317- offset : { line : 0 , column : 0 } ,
1318- map : {
1319- version : 3 ,
1320- sources : [ 'foo.ts' ] ,
1321- names : names1 ,
1322- originalScopes : originalScopes1 ,
1323- generatedRanges : generatedRanges1 ,
1324- mappings : '' ,
1325- } ,
1326- } ,
1327- {
1328- offset : { line : 1 , column : 100 } ,
1329- map : {
1330- version : 3 ,
1331- sources : [ 'bar.ts' ] ,
1332- names : names2 ,
1333- originalScopes : originalScopes2 ,
1334- generatedRanges : generatedRanges2 ,
1335- mappings : '' ,
1336- } ,
1337- }
1318+ { offset : { line : 0 , column : 0 } , map : map1 as SDK . SourceMap . SourceMapV3Object } ,
1319+ { offset : { line : 1 , column : 100 } , map : map2 as SDK . SourceMap . SourceMapV3Object } ,
13381320 ] ,
13391321 } ;
13401322
0 commit comments