File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -217,4 +217,24 @@ describe("decode", () => {
217
217
218
218
assertEquals ( info . ranges , [ ] ) ;
219
219
} ) ;
220
+
221
+ it ( "throws for free ORIGINAL_SCOPE_VARIABLES items in strict mode" , ( ) => {
222
+ const encoder = new ItemEncoder ( ) ;
223
+ encoder . addUnsignedVLQs ( Tag . ORIGINAL_SCOPE_VARIABLES ) ;
224
+ encoder . addSignedVLQs ( 0 , 1 ) . finishItem ( ) ;
225
+ const map = createMap ( encoder . encode ( ) , [ "foo" , "bar" ] ) ;
226
+
227
+ assertThrows ( ( ) => decode ( map , { mode : DecodeMode . STRICT } ) ) ;
228
+ } ) ;
229
+
230
+ it ( "ignores free ORIGINAL_SCOPE_VARIABLES items in loose mode" , ( ) => {
231
+ const encoder = new ItemEncoder ( ) ;
232
+ encoder . addUnsignedVLQs ( Tag . ORIGINAL_SCOPE_VARIABLES ) ;
233
+ encoder . addSignedVLQs ( 0 , 1 ) . finishItem ( ) ;
234
+ const map = createMap ( encoder . encode ( ) , [ "foo" , "bar" ] ) ;
235
+
236
+ const info = decode ( map , { mode : DecodeMode . LOOSE } ) ;
237
+
238
+ assertEquals ( info . scopes , [ ] ) ;
239
+ } ) ;
220
240
} ) ;
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ import { TokenIterator } from "../vlq.ts";
27
27
* STRICT mode will throw in the following situations:
28
28
*
29
29
* - Encountering ORIGINAL_SCOPE_END, or GENERATED_RANGE_END items that don't have matching *_START items.
30
+ * - Encountering ORIGINAL_SCOPE_VARIABLES items outside a surrounding scope START/END.
31
+ * - Encountering GENERATED_RANGE_BINDINGS items outside a surrounding range START/END.
30
32
* - Miss-matches between the number of variables in a scope vs the number of value expressions in the ranges.
31
33
* - Out-of-bound indices into the "names" array.
32
34
*/
@@ -121,9 +123,10 @@ class Decoder {
121
123
case Tag . ORIGINAL_SCOPE_VARIABLES : {
122
124
const scope = this . #scopeStack. at ( - 1 ) ;
123
125
if ( ! scope ) {
124
- throw new Error (
126
+ this . #throwInStrictMode (
125
127
"Encountered ORIGINAL_SCOPE_VARIABLES without surrounding ORIGINAL_SCOPE_START" ,
126
128
) ;
129
+ continue ;
127
130
}
128
131
129
132
for ( const variableIdx of item . variableIdxs ) {
You can’t perform that action at this time.
0 commit comments