Skip to content

Commit e4dba00

Browse files
authored
Scopes: Use unsigned VLQ (1-based) for binding expressions (tc39#205)
1 parent 8cc45d2 commit e4dba00

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

proposals/scopes.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ If a "generated range" contains a callsite, then the range describes an inlined
363363
```
364364
generated_range_bindings :=
365365
'G' // Tag: 0x6 unsigned
366-
sBINDING+
366+
uBINDING+
367367
```
368368

369-
`generated_range_bindings` are only valid for generated ranges that have a `sDEFINITION`. The bindings list must be equal in length as the variable list of the original scope the `sDEFINITION` references. `sBINDING+` is a list of indices into the `"names"` field of the source map JSON. Each binding is a JavaScript expression that, when evaluated, produces the **value** of the corresponding variable.
369+
`generated_range_bindings` are only valid for generated ranges that have a `sDEFINITION`. The bindings list must be equal in length as the variable list of the original scope the `sDEFINITION` references. `uBINDING+` is a list of 1-based indices into the `"names"` field of the source map JSON. Each binding is a JavaScript expression that, when evaluated, produces the **value** of the corresponding variable.
370370

371-
`sBINDING+` indices are encoded absolute. To signify that a variable is unavailable, use the index `-1`.
371+
`uBINDING+` indices are encoded absolute. To signify that a variable is unavailable, use the index `0`.
372372

373373
```
374374
generated_range_subrange_binding :=
@@ -377,19 +377,21 @@ generated_range_subrange_binding :=
377377
binding_from+
378378
379379
binding_from :=
380-
sBINDING
380+
uBINDING
381381
uLINE
382382
uCOLUMN
383383
```
384384

385385
A variable might not be available through the full generated range, or a different expression is required for parts of the generated range to retrieve a variables value. In this case a generator can use `generated_range_subrange_binding` to encode this.
386386

387387
* `uVARIABLE_INDEX` is an index into the corresponding original scopes' variables list. It is encoded relative inside a generated range.
388-
* `binding_from` are the sub-ranges. The initial value expression for a variable is provided by the `generated_range_bindings` item. The generated position in `binding_from` is the start from which the expression `sBINDING` from `binding_from` needs to be used to retrieve the variables value instead.
389-
* `sBINDING` is an index into the `"names"` field in the source map JSON. It is relative to previous occurrences (also relative to the last `sBINDING+` in `generated_range_bindings`)
388+
* `binding_from` are the sub-ranges. The initial value expression for a variable is provided by the `generated_range_bindings` item. The generated position in `binding_from` is the start from which the expression `uBINDING` from `binding_from` needs to be used to retrieve the variables value instead.
389+
* `uBINDING` is a 1-based absolute index into the `"names"` field in the source map JSON. To indicate that a variable is unavailable, use the index `0`.
390390
* `uLINE` is relative to the generated range's start line for the first `generated_range_subrange_binding` for a specific variable. Or relative to the previous subrange `uLINE` of the same variable.
391391
* `uCOLUMN` is relative to the `binding_from`/`generated_range_start` `uCOLUMN` if the line of this subrange is the same as the line of the preceding `binding_from`/`generated_range_start` or absolute otherwise.
392392

393+
Note: `uBINDING` in `binding_from` and `uBINDING+` in `generated_range_bindings` are both absolute 1-based indices. This means the index `1` (encoded as the unsigned VLQ `B`) refers to the first entry in the `names` array.
394+
393395
### Example
394396

395397
Original Code (file.js):

0 commit comments

Comments
 (0)