@@ -6,8 +6,10 @@ import { describe, it } from "@std/testing/bdd";
66import { ScopeInfoBuilder } from "../builder/builder.ts" ;
77import { encode } from "../encode/encode.ts" ;
88import {
9+ assert ,
910 assertEquals ,
1011 assertExists ,
12+ assertFalse ,
1113 assertStrictEquals ,
1214 assertThrows ,
1315} from "@std/assert" ;
@@ -75,7 +77,7 @@ describe("decode", () => {
7577 encodeUnsigned ( 256 ) ,
7678 ] ;
7779 map . scopes = items . join ( "," ) ;
78- assertEquals ( decode ( map ) , info ) ;
80+ assertEquals ( decode ( map ) , { ... info , hasVariableAndBindingInfo : false } ) ;
7981 } ) ;
8082
8183 it ( "handles trailing VLQs in ORIGINAL_SCOPE_START items" , ( ) => {
@@ -90,7 +92,7 @@ describe("decode", () => {
9092 parts [ 0 ] += encodeSigned ( - 16 ) ;
9193 map . scopes = parts . join ( "," ) ;
9294
93- assertEquals ( decode ( map ) , info ) ;
95+ assertEquals ( decode ( map ) , { ... info , hasVariableAndBindingInfo : false } ) ;
9496 } ) ;
9597
9698 it ( "handles trailing VLQs in ORIGINAL_SCOPE_END items" , ( ) => {
@@ -105,7 +107,7 @@ describe("decode", () => {
105107 parts [ 1 ] += encodeSigned ( - 16 ) ;
106108 map . scopes = parts . join ( "," ) ;
107109
108- assertEquals ( decode ( map ) , info ) ;
110+ assertEquals ( decode ( map ) , { ... info , hasVariableAndBindingInfo : false } ) ;
109111 } ) ;
110112
111113 it ( "ignores wrong 'name' indices in lax mode" , ( ) => {
@@ -567,6 +569,7 @@ describe("decode", () => {
567569 assertEquals ( decode ( map , { mode : DecodeMode . STRICT } ) , {
568570 scopes : [ ] ,
569571 ranges : [ ] ,
572+ hasVariableAndBindingInfo : false ,
570573 } ) ;
571574 } ) ;
572575
@@ -589,6 +592,63 @@ describe("decode", () => {
589592 encoder . finishItem ( ) ;
590593 const map = createMap ( encoder . encode ( ) , [ ] ) ;
591594
592- assertEquals ( decode ( map ) , { scopes : [ ] , ranges : [ ] } ) ;
595+ assertEquals ( decode ( map ) , {
596+ scopes : [ ] ,
597+ ranges : [ ] ,
598+ hasVariableAndBindingInfo : false ,
599+ } ) ;
600+ } ) ;
601+
602+ describe ( "hasVariableAndBindingInfo" , ( ) => {
603+ it ( "is 'false' when no variables/bindings are present" , ( ) => {
604+ const map = encode (
605+ new ScopeInfoBuilder ( ) . startScope ( 0 , 0 , {
606+ isStackFrame : true ,
607+ key : "fn" ,
608+ } ) . endScope ( 10 , 0 ) . startRange ( 0 , 0 , {
609+ scopeKey : "fn" ,
610+ isStackFrame : true ,
611+ } ) . endRange ( 0 , 10 ) . build ( ) ,
612+ ) ;
613+
614+ const { hasVariableAndBindingInfo } = decode ( map ) ;
615+
616+ assertFalse ( hasVariableAndBindingInfo ) ;
617+ } ) ;
618+
619+ it ( "is 'false' when only variables are present" , ( ) => {
620+ const map = encode (
621+ new ScopeInfoBuilder ( ) . startScope ( 0 , 0 , {
622+ isStackFrame : true ,
623+ key : "fn" ,
624+ variables : [ "foo" , "bar" ] ,
625+ } ) . endScope ( 10 , 0 ) . startRange ( 0 , 0 , {
626+ scopeKey : "fn" ,
627+ isStackFrame : true ,
628+ } ) . endRange ( 0 , 10 ) . build ( ) ,
629+ ) ;
630+
631+ const { hasVariableAndBindingInfo } = decode ( map ) ;
632+
633+ assertFalse ( hasVariableAndBindingInfo ) ;
634+ } ) ;
635+
636+ it ( "is 'true' when variables/bindings are present" , ( ) => {
637+ const map = encode (
638+ new ScopeInfoBuilder ( ) . startScope ( 0 , 0 , {
639+ isStackFrame : true ,
640+ key : "fn" ,
641+ variables : [ "foo" , "bar" ] ,
642+ } ) . endScope ( 10 , 0 ) . startRange ( 0 , 0 , {
643+ scopeKey : "fn" ,
644+ isStackFrame : true ,
645+ values : [ "n" , "m" ] ,
646+ } ) . endRange ( 0 , 10 ) . build ( ) ,
647+ ) ;
648+
649+ const { hasVariableAndBindingInfo } = decode ( map ) ;
650+
651+ assert ( hasVariableAndBindingInfo ) ;
652+ } ) ;
593653 } ) ;
594654} ) ;
0 commit comments