Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 7452259

Browse files
concavelenzfitzgenPavel Podivilovcramforce
authored andcommitted
Source Map Revision 3 Proposal as of 2012-05-02
Co-authored-by: John Lenz <[email protected]> Co-authored-by: Nick Fitzgerald <[email protected]> Co-authored-by: Pavel Podivilov <[email protected]> Co-authored-by: Malte Ubl <[email protected]>
1 parent cc27c96 commit 7452259

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

source-map-rev3.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ April 12, 2011 | John Lenz | Initial Revision
1616
April 15, 2011 | John Lenz | Updates to reflect prototype
1717
July 20, 2011 | John Lenz | Removed “lineCount” field, remove “Combined Map” section
1818
August 18, 2011 | John Lenz | Draft
19+
May 2, 2012 | John Lenz | HTTP header and CC-BY-SA license
20+
21+
## License
22+
23+
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-sa/3.0/).
1924

2025
## Background
2126

22-
Even with the changes made with the v2 version of the format, the source map file size was limiting it usefulness. The v3 format is based on suggestions made by podivilov
27+
The original source map format (v1) was created by Joseph Schorr for use by Closure Inspector to enable source level debugging of optimized JavaScript code (although the format itself is language agnostic). However, as the size of the projects using the source maps expanded the verbosity of the format started to be become a problem. The v2 was created trading some simplicity and flexibility to reduce to overall size of the source map. Even with the changes made with the v2 version of the format, the source map file size was limiting its usefulness. The v3 format is based on suggestions made by podivilov.
2328

2429
Related documents:
2530

@@ -85,11 +90,11 @@ The fields in each segment are:
8590

8691

8792

88-
1. The starting column of the line in the generated code that the segment represents. If this is the first field of the first segment, or the first segment following a new generated line (“;”), then this field holds the whole base 64 VLQ. Otherwise, this field contains a base 64 VLQ that is relative to the previous occurrence of this field. _Note that this is different than the fields below because the previous value is reset after every generated line._
89-
2. If present, an index into the “sources” list. 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.
90-
3. If present, the starting line in the original source represented. 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. Always present if there is a source field.
91-
4. If present, the starting column of the line in the source represented. 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. Always present if there is a source field.
92-
5. If present, the index into the “names” list associated with this segment. 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.
93+
1. The zero-based starting column of the line in the generated code that the segment represents. If this is the first field of the first segment, or the first segment following a new generated line (“;”), then this field holds the whole base 64 VLQ. Otherwise, this field contains a base 64 VLQ that is relative to the previous occurrence of this field. _Note that this is different than the fields below because the previous value is reset after every generated line._
94+
2. If present, an zero-based index into the “sources” list. 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.
95+
3. If present, the zero-based starting line in the original source represented. 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. Always present if there is a source field.
96+
4. If present, the zero-based starting column of the line in the source represented. 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. Always present if there is a source field.
97+
5. If present, the zero-based index into the “names” list associated with this segment. 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.
9398

9499
Note: This encoding reduces the source map size 50% relative to the V2 format in tests performed using Google Calendar.
95100

@@ -169,17 +174,28 @@ Optionally, a source map will have the same name as the generated file but with
169174

170175
#### Linking generated code to source maps
171176

172-
While the source map format is intended to be language agnostic, it is useful to have a few language specific notes.
177+
While the source map format is intended to be language and platform agnostic, it is useful to have a some conventions for the expected use-case of web server hosted javascript.
178+
179+
There are two suggested ways to link source maps to the output. The first requires server support to add a HTTP header and the second requires an annotation in the source.
180+
181+
The HTTP header should supply the source map URL reference as:
182+
183+
184+
185+
186+
X-SourceMap
173187

174188
The generated code may include a line at the end of the source, with the following form:
175189

176190

177191
```
178-
//@sourceMappingURL=<url>
192+
//@ sourceMappingURL=<url>
179193
```
180194

181195

182-
When the source mapping URL is not absolute, then it is relative to the generated code’s “source origin”. The source origin is determined by one of the following cases:
196+
Regardless of the method used to retrieve the source mapping URL the same process is used to resolve it, which is as follows:
197+
198+
When the source mapping URL is not absolute, then it is relative to the generated code’s “source origin”. The source origin is determined by one of the following cases:
183199

184200

185201

@@ -189,15 +205,9 @@ When the source mapping URL is not absolute, then it is relative to the generate
189205
* If the generated code is being evaluated as a string with the `eval()` function or via `new Function()`, then the source origin will be the page’s origin.
190206

191207

192-
```
193-
TODO: Using a HTTP header?
194-
```
195-
196-
197-
198208
#### Linking eval’d code to named generate code
199209

200-
There is an existing convention that should be support to all the use of source maps with eval’d code, it has the following form:
210+
There is an existing convention that should be supported for the use of source maps with eval’d code, it has the following form:
201211

202212

203213
```
@@ -219,4 +229,11 @@ Stack tracing mapping without knowledge of the source language is not covered by
219229

220230
It is getting more common to have tools generate source from some [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) (templates) or to compile CoffeeScript -> JavaScript -> minified JavaScript, resulting in multiple translations before the final source map is created. This problem can be handled in one of two ways. The easy but lossy way is to ignore the intermediate steps in the process for the purposes of debugging, the source location information from the translation is either ignored (the intermediate translation is considered the “Original Source”) or the source location information is carried through (the intermediate translation hidden). The more complete way is to support multiple levels of mapping: if the Original Source also has a source map reference, the user is given the choice of using the that as well.
221231

222-
However, It is unclear what a “source map reference” looks like in anything other than JavaScript. More specifically, what a source map reference looks like in a language that doesn’t support JavaScript style single line comments. An HTTP header would address this, but is not yet aggreed upon.
232+
However, It is unclear what a “source map reference” looks like in anything other than JavaScript. More specifically, what a source map reference looks like in a language that doesn’t support JavaScript style single line comments. An HTTP header would address this, but is not yet agreed upon.
233+
234+
235+
### JSON over HTTP Transport
236+
237+
[XSSI](http://googleonlinesecurity.blogspot.com/2011/05/website-security-for-webmasters.html) attacks <span style="text-decoration:underline;">(https://wiki.corp.google.com/twiki/bin/view/Main/ISETeamScriptInclusion)</span> could potentially make source maps available to attackers by doing a direct script src to a source map after overriding the Array constructor. This can be effectively prevented by preprending a JavaScript syntax error to the start of the response.
238+
239+
Thus when delivering source maps over HTTP, servers may prepend a line starting with the string “)]}'” to the sourcemap. If the response starts with this string clients must ignore the first line.

0 commit comments

Comments
 (0)