Skip to content

Instantly share code, notes, and snippets.

@asterland
Last active October 20, 2015 02:29
Show Gist options
  • Save asterland/edf028ed7947c8c258d1 to your computer and use it in GitHub Desktop.
Save asterland/edf028ed7947c8c258d1 to your computer and use it in GitHub Desktop.
This gist covers a new addition extension to the source map specfication that would allow the resolution of local variables that have been renamed.
{
"version": 3,
"file": "example.js",
"sourceRoot": "",
"sources": ["example.ts"],
"names": ["this", "_this"],
"mappings": ";AAAA,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAE,OAAO,EAAE;IACrC,KAAI,CAAC,WAAW,GAAG,aAAa;AACpC,CAAC,CAAC",
"x_ms_scopes": "AA>IA<",
"x_ms_locals": "AC,A"
}
Line 6: Additional symbols/expressions are added to the end of the list of names that are used in the "x_ms_locals" entry.
Line 8: A string with the encoded scope data
Line 9: A string with the encoded local mapping data
"names" Array
The "names" array now also includes additional symbols or expressions that are also used by the "x_ms_locals" extension.
"x_ms_scopes" Data
The "x_ms_scopes" data is broken down as follows:
• Each segment is made up of two fields
• Each segment ends either with a ">" symbol (indicating the start of a new scope), or a "<" symbol (indicating the end of an existing scope)
• The ">" and "<" symbols must be balanced
The fields in each segment are:
1. The zero-based starting line of the scope in the generated output. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented.
2. The zero-based starting column in the starting line of the scope in the generated output. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented.
The balanced segments in the "x_ms_scopes" data represent a hierarchy of nested scopes in the generated output. A scope only needs to be emitted if it defines a mapping of a local identifier within that scope from the source to the generated output. As each new scope is defined, it is assigned a zero-based index based on the order of its definition.
"x_ms_locals" Data
The "x_ms_locals" data is broken down as follows:
• Each group representing a set of local mappings in a single scope is separated by a ";"
• Each segment is separated by a ","
• Each segment is made up of 1 or 2 variable length fields.
The fields in each segment are:
1. The zero-based index into the "names" list which is an identifier for the scope. This field is a base 64 VLQ relative to the previous occurrence of either field in this segment, unless this is the first occurrence of this field, in which case the whole value is represented. This indicates a local identifier within the scope that will be renamed or hidden.
2. If present, the zero-based index into the "names" list which is an identifier or expression for the scope. This field is a base 64 VLQ relative to the first field in this segment. This indicates a local identifier or expression within the scope to which an identifier will be renamed (or restored if pointing to the same index). If not present, this indicates the local identifier will be hidden within the scope.
A local only needs to be emitted if one of the following conditions occurs:
• Hide - The identifier exists only in the generated output and should be hidden from locals and watches when the source map is in use. In this case the segment contains only a single field which is the offset to the name of the generated identifier.
• Rename - The identifier has been mutated from the source to a different identifier or expression in the generated output. In this case, the segment contains two fields where the first is the offset to the name of the source identifier and the second is the offset to the generated identifier or expression.
• Restore - The identifier has been previously hidden or renamed in a parent scope and needs to be restored to its original value. As with Rename, the segment contains two fields where the first is the offset to the name of the source identifier and the second is the offset to the generated identifier or expression.
document.body.addEventListener( 'click', () => {
this.textContent = 'hello world';
});
var _this = this;
document.body.addEventListener('click', function () {
_this.textContent = 'hello world';
});
//# sourceMappingURL=example.js.map
@Daniel007007
Copy link

W

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment