-
Notifications
You must be signed in to change notification settings - Fork 16
/
mozilla_source_map.javascript.txt
193 lines (148 loc) · 11.2 KB
/
mozilla_source_map.javascript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
MOZILLA_SOURCE_MAP
ALTERNATIVES ==> # - mozilla source-map (prefered):
# - by far the most high-profile
# - handles full parsing|serializing
# - inline source maps, multi-mapping, reverse compilation
# - uses WASM for faster VLQ encoding|decoding
# - Node.js native MODULE.SourceMap (prefered when only Node >= 13.7.0)
# - only parsing source map comment + generated->original mapping
# - source-list-map (prefered if simple file-wise mapping is enough):
# - file-wise (instead of symbol-wise) source map generation:
# - each whole source file (each of its lines) is mapped to single position in compiled file
# - no "names"
# - source code is inlined in "sourceContent"
# - i.e. simpler but less powerful mapping
# - fast-source-map:
# - not maintained
VERSION ==> #0.8.0-beta.0
GOAL ==> #Serializes and parses source maps
#Based on source map format (see its doc)
#Node/browser
BROWSER ==> #Must first call SourceMapConsumer.initialize({ 'lib/mappings.wasm': URL|ARRBUFFER }) with URL pointing
#to 'mappings.wasm file'
#That file is available at ./lib/mappings.wasm with that library.
SOURCE_MAP #Source map as object
/=+===============================+=\
/ : : \
)==: GENERATOR :==(
\ :_______________________________: /
\=+===============================+=/
GENERATOR #Low-level API to generate|serialize a source map by specifying each mapping
new SourceMapGenerator #GENERATOR_OPTS:
([GENERATOR_OPTS]) # - file 'COMPILED_FILENAME' (SOURCE_MAP "file")
# - sourceRoot 'URI' (SOURCE_MAP "sourceRoot")
# - skipValidation BOOL (def: false): faster but less safe
GENERATOR.addMapping(OBJ) #Add to "mappings"
#OBJ:
# - source 'SOURCE_PATH' (SOURCE_MAP "sources")
# - generated|original:
# - line|column NUM
# - name 'SOURCE_CODE'|null (SOURCE_MAP "names")
GENERATOR.setSourceContent
('SOURCE_PATH', STR) #Add to "sourceContent"
GENERATOR.toJSON()
->SOURCE_MAP_OBJ #
GENERATOR.toString()
->SOURCE_MAP_STR #
/=+===============================+=\
/ : : \
)==: SOURCE_NODE :==(
\ :_______________________________: /
\=+===============================+=/
SOURCE_NODE #Higher-level API over GENERATOR
new SourceNode #Single "mapping":
([LINE_NUM, COLUMN_NUM] # - LINE|COLUMN_NUM are source file's
[, 'SOURCE_FILENAME'] # - line|column of compiled file are automatically calculated from 'COMPILED_CODE'
[,'COMPILED_CODE'|SOURCENODE_ARR]#'SOURCE_FILENAME' is SOURCE_MAP "sources"
[, 'SOURCE_CODE']) #'SOURCE_CODE' is SOURCE_MAP "names"
SOURCE_NODE.add|prepend
('COMPILED_CODE'|SOURCE_NODE_ARR)#Append|prepend children
SOURCE_NODE.join
('COMPILED_CODE'|SOURCE_NODE) #Insert it between each child
SOURCE_NODE.replaceRight(...) #Performs replace(...) on last child
#E.g. to remove trailing whitespaces
SOURCE_NODE.line|column #NUM|null
SOURCE_NODE.source #'SOURCE_FILENAME'|null
SOURCE_NODE.children #'COMPILED_NODE'|SOURCENODE_ARR
SOURCE_NODE.name #'SOURCE_CODE'|null
SOURCE_NODE.setSourceContent
('SOURCE_PATH', STR) #Add to "sourceContent"
SOURCE_NODE.sourceContents
.SOURCE_PATH #STR
SOURCE_NODE.toStringWithSourceMap #Returns OBJ:
([GENERATOR_OPTS])->OBJ # - map GENERATOR
# - code 'JAVASCRIPT_CODE': same as SOURCE_NODE.toString()
SOURCE_NODE.toString()
->'COMPILED_CODE' #
SOURCE_NODE.walk #Iterate over "mappings" OBJ:
(FUNC('COMPILED_CODE', OBJ)) # - source 'SOURCE_PATH'
# - line|column NUM
# - name 'SOURCE_CODE'|null
SOURCE_NODE.walkSourceContents
(FUNC('SOURCE_PATH', STR)) #Iterate over "sourceContent"
/=+===============================+=\
/ : : \
)==: CONSUMER :==(
\ :_______________________________: /
\=+===============================+=/
CONSUMER ==> #Reads|parses a source map
new SourceMapConsumer #Throws if invalid JSON
(SOURCE_MAP_OBJ|STR #Rejects PROMISE if invalid SOURCE_MAP:
[, 'SOURCEMAP_URI']) # - missing "version", "sources", "mappings"
->PROMISE_CONSUMER # - version !== 3
CONSUMER.destroy() #Removes WASM-related data
SourceMapConsumer.with(SOURCE_MAP,
'SOURCEMAP_URI'|null, #Like new SourceMapConsumer() except CONSUMER.destroy() is automatically called when ASYNC_FUNC ends
ASYNC_FUNC(CONSUMER))->PROMIS_VAL#PROMISE_VAL is ASYNC_FUNC's return value
CONSUMER.sources #Source map "sources" resolved to absolute URIs
CONSUMER.sourceRoot #'DIR'|null (SOURCE_MAP "sourceRoot")
CONSUMER.sourceContent #STR|null_ARR (SOURCE_MAP "sourceContent")
CONSUMER.file #'COMPILED_FILENAME'|null (SOURCE_MAP "file")
CONSUMER.originalPositionFor(OBJ) #Use "mappings" to map compiled file index OBJ:
->OBJ2 # - line|column NUM
# - bias SourceMapConsumer.GREATEST_LOWER|UPPER_BOUND (def: LOWER):
# - if between two positions, whether to pick the previous|next one
#To source file position OBJ2:
# - source 'SOURCE_PATH'|null
# - line|column NUM|null
# - name 'SOURCE_CODE'|null
CONSUMR.generatedPositionFor(OBJ2)#Inverse, i.e. maps source file position to compiled file index
->OBJ #With:
# - OBJ2: source|file|column
# - OBJ: line|column|lastColumn NUM|null
CONSUMER.allGeneratedPositionsFor #Same except:
(OBJ2)->OBJ # - column is optional
# - returns all mappings, i.e. OBJ_ARR
CONSUMER.computeColumnSpans() #Make 'last[Generated]Column' available (otherwise undefined), i.e. the next position's column - 1
#If no next position, Infinity
CONSUMER.eachMapping #Iterates over "mappings" OBJ:
(FUNC(OBJ)[, THIS][, VAL]) # - source 'SOURCE_PATH'|null
# - generated|originalLine|Column|LastGeneratedColumn NUM|null
# - name 'SOURCE_CODE'|null
#VAL is SourceMapConsumer.GENERATED|ORIGINAL_ORDER (def: GENERATED)
CONSUMER.sourceContentFor #Returns "sourceContent"
('SOURCE_PATH'[, BOOL])->STR #If not found, throws if BOOL false (def) or returns null if BOOL true.
CONSUMER.hasContentsOfAllSources()
->BOOL #True if every source has "sourceContent", i.e. is completely inline source map
SourceMapGenerator.fromSourceMap
(CONSUMER)->GENERATOR #Re-serialize (GENERATOR) a parsed source map (CONSUMER)
/=+===============================+=\
/ : : \
)==: REVERSE COMPILATION :==(
\ :_______________________________: /
\=+===============================+=/
SourceNode.fromStringWithSourceMap#Create a SOURCE_NODE from full 'COMPILED_CODE' + its source map (CONSUMER)
('COMPILED_CODE', CONSUMER #I.e. help compiled -> source reverse translation.
[, 'DIR'])->SOURCE_NODE #'DIR' is relative path
/=+===============================+=\
/ : : \
)==: MULTI-MAPPING :==(
\ :_______________________________: /
\=+===============================+=/
GENERATOR.applySourceMap #Multi-mapping:
(CONSUMER[, 'SOURCE_PATH'] # - CONSUMER is compilation from source file to intermediate file
[, 'SOURCE_DIR']) # - GENERATOR is compilation from intermediate file to compiled file
#Will make GENERATOR's source map from source file to compiled file instead
#Def 'SOURCE_PATH': CONSUMER.file