metro-source-map 0.54.1 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -3
- package/src/BundleBuilder.js.flow +4 -4
- package/src/Consumer/AbstractConsumer.js +54 -0
- package/src/Consumer/AbstractConsumer.js.flow +63 -0
- package/src/Consumer/DelegatingConsumer.js +74 -0
- package/src/Consumer/DelegatingConsumer.js.flow +73 -0
- package/src/Consumer/MappingsConsumer.js +313 -0
- package/src/Consumer/MappingsConsumer.js.flow +197 -0
- package/src/Consumer/SectionsConsumer.js +201 -0
- package/src/Consumer/SectionsConsumer.js.flow +116 -0
- package/src/Consumer/constants.js +47 -0
- package/src/Consumer/constants.js.flow +50 -0
- package/src/Consumer/createConsumer.js +31 -0
- package/src/Consumer/createConsumer.js.flow +33 -0
- package/src/Consumer/index.js +14 -0
- package/src/Consumer/index.js.flow +16 -0
- package/src/Consumer/normalizeSourcePath.js +33 -0
- package/src/Consumer/normalizeSourcePath.js.flow +41 -0
- package/src/Consumer/positionMath.js +65 -0
- package/src/Consumer/positionMath.js.flow +39 -0
- package/src/Consumer/search.js +36 -0
- package/src/Consumer/search.js.flow +36 -0
- package/src/Consumer/types.flow.js +13 -0
- package/src/Consumer/types.flow.js.flow +57 -0
- package/src/Generator.js +33 -3
- package/src/Generator.js.flow +40 -5
- package/src/composeSourceMaps.js +105 -0
- package/src/composeSourceMaps.js.flow +115 -0
- package/src/source-map.js +127 -17
- package/src/source-map.js.flow +131 -36
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const AbstractConsumer = require('./AbstractConsumer');
|
|
14
|
+
|
|
15
|
+
const invariant = require('invariant');
|
|
16
|
+
const normalizeSourcePath = require('./normalizeSourcePath');
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
FIRST_COLUMN,
|
|
20
|
+
FIRST_LINE,
|
|
21
|
+
GREATEST_LOWER_BOUND,
|
|
22
|
+
EMPTY_POSITION,
|
|
23
|
+
lookupBiasToString,
|
|
24
|
+
} = require('./constants');
|
|
25
|
+
const {greatestLowerBound} = require('./search');
|
|
26
|
+
const {add, get0, add0, sub, inc} = require('ob1');
|
|
27
|
+
const {decode: decodeVlq} = require('vlq');
|
|
28
|
+
|
|
29
|
+
import type {BasicSourceMap} from '../source-map';
|
|
30
|
+
import type {
|
|
31
|
+
SourcePosition,
|
|
32
|
+
GeneratedPositionLookup,
|
|
33
|
+
Mapping,
|
|
34
|
+
IConsumer,
|
|
35
|
+
} from './types.flow';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A source map consumer that supports "basic" source maps (that have a
|
|
39
|
+
* `mappings` field and no sections).
|
|
40
|
+
*/
|
|
41
|
+
class MappingsConsumer extends AbstractConsumer implements IConsumer {
|
|
42
|
+
_sourceMap: BasicSourceMap;
|
|
43
|
+
_decodedMappings: ?$ReadOnlyArray<Mapping>;
|
|
44
|
+
_normalizedSources: ?$ReadOnlyArray<string>;
|
|
45
|
+
|
|
46
|
+
constructor(sourceMap: BasicSourceMap) {
|
|
47
|
+
super(sourceMap);
|
|
48
|
+
this._sourceMap = sourceMap;
|
|
49
|
+
this._decodedMappings = null;
|
|
50
|
+
this._normalizedSources = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
originalPositionFor(
|
|
54
|
+
generatedPosition: GeneratedPositionLookup,
|
|
55
|
+
): SourcePosition {
|
|
56
|
+
const {line, column} = generatedPosition;
|
|
57
|
+
if (line == null || column == null) {
|
|
58
|
+
return {...EMPTY_POSITION};
|
|
59
|
+
}
|
|
60
|
+
if (generatedPosition.bias != null) {
|
|
61
|
+
invariant(
|
|
62
|
+
generatedPosition.bias === GREATEST_LOWER_BOUND,
|
|
63
|
+
`Unimplemented lookup bias: ${lookupBiasToString(
|
|
64
|
+
generatedPosition.bias,
|
|
65
|
+
)}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const mappings = this._decodeAndCacheMappings();
|
|
69
|
+
const index = greatestLowerBound(
|
|
70
|
+
mappings,
|
|
71
|
+
{line, column},
|
|
72
|
+
(position, mapping) => {
|
|
73
|
+
if (position.line === mapping.generatedLine) {
|
|
74
|
+
return get0(sub(position.column, mapping.generatedColumn));
|
|
75
|
+
}
|
|
76
|
+
return get0(sub(position.line, mapping.generatedLine));
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
if (
|
|
80
|
+
index != null &&
|
|
81
|
+
mappings[index].generatedLine === generatedPosition.line
|
|
82
|
+
) {
|
|
83
|
+
const mapping = mappings[index];
|
|
84
|
+
return {
|
|
85
|
+
source: mapping.source,
|
|
86
|
+
name: mapping.name,
|
|
87
|
+
line: mapping.originalLine,
|
|
88
|
+
column: mapping.originalColumn,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {...EMPTY_POSITION};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
*_decodeMappings() {
|
|
95
|
+
let generatedLine = FIRST_LINE;
|
|
96
|
+
let generatedColumn = FIRST_COLUMN;
|
|
97
|
+
let originalLine = FIRST_LINE;
|
|
98
|
+
let originalColumn = FIRST_COLUMN;
|
|
99
|
+
let nameIndex = add0(0);
|
|
100
|
+
let sourceIndex = add0(0);
|
|
101
|
+
|
|
102
|
+
const normalizedSources = this._normalizeAndCacheSources();
|
|
103
|
+
|
|
104
|
+
const {mappings: mappingsRaw, names} = this._sourceMap;
|
|
105
|
+
let next;
|
|
106
|
+
const vlqCache = new Map();
|
|
107
|
+
for (let i = 0; i < mappingsRaw.length; i = next) {
|
|
108
|
+
switch (mappingsRaw[i]) {
|
|
109
|
+
case ';':
|
|
110
|
+
generatedLine = inc(generatedLine);
|
|
111
|
+
generatedColumn = FIRST_COLUMN;
|
|
112
|
+
/* falls through */
|
|
113
|
+
case ',':
|
|
114
|
+
next = i + 1;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
findNext: for (next = i + 1; next < mappingsRaw.length; ++next) {
|
|
118
|
+
switch (mappingsRaw[next]) {
|
|
119
|
+
case ';':
|
|
120
|
+
/* falls through */
|
|
121
|
+
case ',':
|
|
122
|
+
break findNext;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const mappingRaw = mappingsRaw.slice(i, next);
|
|
126
|
+
let decodedVlqValues;
|
|
127
|
+
if (vlqCache.has(mappingRaw)) {
|
|
128
|
+
decodedVlqValues = vlqCache.get(mappingRaw);
|
|
129
|
+
} else {
|
|
130
|
+
decodedVlqValues = decodeVlq(mappingRaw);
|
|
131
|
+
vlqCache.set(mappingRaw, decodedVlqValues);
|
|
132
|
+
}
|
|
133
|
+
invariant(Array.isArray(decodedVlqValues), 'Decoding VLQ tuple failed');
|
|
134
|
+
const [
|
|
135
|
+
generatedColumnDelta,
|
|
136
|
+
sourceIndexDelta,
|
|
137
|
+
originalLineDelta,
|
|
138
|
+
originalColumnDelta,
|
|
139
|
+
nameIndexDelta,
|
|
140
|
+
] = decodedVlqValues;
|
|
141
|
+
decodeVlq(mappingRaw);
|
|
142
|
+
invariant(generatedColumnDelta != null, 'Invalid generated column delta');
|
|
143
|
+
generatedColumn = add(generatedColumn, generatedColumnDelta);
|
|
144
|
+
const mapping: Mapping = {
|
|
145
|
+
generatedLine,
|
|
146
|
+
generatedColumn,
|
|
147
|
+
source: null,
|
|
148
|
+
name: null,
|
|
149
|
+
originalLine: null,
|
|
150
|
+
originalColumn: null,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
if (sourceIndexDelta != null) {
|
|
154
|
+
sourceIndex = add(sourceIndex, sourceIndexDelta);
|
|
155
|
+
mapping.source = normalizedSources[get0(sourceIndex)];
|
|
156
|
+
|
|
157
|
+
invariant(originalLineDelta != null, 'Invalid original line delta');
|
|
158
|
+
invariant(originalColumnDelta != null, 'Invalid original column delta');
|
|
159
|
+
|
|
160
|
+
originalLine = add(originalLine, originalLineDelta);
|
|
161
|
+
originalColumn = add(originalColumn, originalColumnDelta);
|
|
162
|
+
|
|
163
|
+
mapping.originalLine = originalLine;
|
|
164
|
+
mapping.originalColumn = originalColumn;
|
|
165
|
+
|
|
166
|
+
if (nameIndexDelta != null) {
|
|
167
|
+
nameIndex = add(nameIndex, nameIndexDelta);
|
|
168
|
+
mapping.name = names[get0(nameIndex)];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
yield mapping;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_normalizeAndCacheSources(): $ReadOnlyArray<string> {
|
|
177
|
+
if (!this._normalizedSources) {
|
|
178
|
+
this._normalizedSources = this._sourceMap.sources.map(source =>
|
|
179
|
+
normalizeSourcePath(source, this._sourceMap),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return this._normalizedSources;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_decodeAndCacheMappings(): $ReadOnlyArray<Mapping> {
|
|
186
|
+
if (!this._decodedMappings) {
|
|
187
|
+
this._decodedMappings = [...this._decodeMappings()];
|
|
188
|
+
}
|
|
189
|
+
return this._decodedMappings;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
generatedMappings(): Iterable<Mapping> {
|
|
193
|
+
return this._decodeAndCacheMappings();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = MappingsConsumer;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) {
|
|
13
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
15
|
+
var ownKeys = Object.keys(source);
|
|
16
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
17
|
+
ownKeys = ownKeys.concat(
|
|
18
|
+
Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
19
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _defineProperty(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _slicedToArray(arr, i) {
|
|
45
|
+
return (
|
|
46
|
+
_arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _nonIterableRest() {
|
|
51
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _iterableToArrayLimit(arr, i) {
|
|
55
|
+
var _arr = [];
|
|
56
|
+
var _n = true;
|
|
57
|
+
var _d = false;
|
|
58
|
+
var _e = undefined;
|
|
59
|
+
try {
|
|
60
|
+
for (
|
|
61
|
+
var _i = arr[Symbol.iterator](), _s;
|
|
62
|
+
!(_n = (_s = _i.next()).done);
|
|
63
|
+
_n = true
|
|
64
|
+
) {
|
|
65
|
+
_arr.push(_s.value);
|
|
66
|
+
if (i && _arr.length === i) break;
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
_d = true;
|
|
70
|
+
_e = err;
|
|
71
|
+
} finally {
|
|
72
|
+
try {
|
|
73
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
74
|
+
} finally {
|
|
75
|
+
if (_d) throw _e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return _arr;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function _arrayWithHoles(arr) {
|
|
82
|
+
if (Array.isArray(arr)) return arr;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const AbstractConsumer = require("./AbstractConsumer");
|
|
86
|
+
|
|
87
|
+
const createConsumer = require("./createConsumer");
|
|
88
|
+
|
|
89
|
+
const _require = require("./constants"),
|
|
90
|
+
FIRST_COLUMN = _require.FIRST_COLUMN,
|
|
91
|
+
FIRST_LINE = _require.FIRST_LINE,
|
|
92
|
+
EMPTY_POSITION = _require.EMPTY_POSITION;
|
|
93
|
+
|
|
94
|
+
const _require2 = require("./positionMath"),
|
|
95
|
+
subtractOffsetFromPosition = _require2.subtractOffsetFromPosition;
|
|
96
|
+
|
|
97
|
+
const _require3 = require("./search"),
|
|
98
|
+
greatestLowerBound = _require3.greatestLowerBound;
|
|
99
|
+
|
|
100
|
+
const _require4 = require("ob1"),
|
|
101
|
+
add = _require4.add,
|
|
102
|
+
get0 = _require4.get0,
|
|
103
|
+
get1 = _require4.get1,
|
|
104
|
+
add0 = _require4.add0,
|
|
105
|
+
sub1 = _require4.sub1,
|
|
106
|
+
sub = _require4.sub;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A source map consumer that supports "indexed" source maps (that have a
|
|
110
|
+
* `sections` field and no top-level mappings).
|
|
111
|
+
*/
|
|
112
|
+
class SectionsConsumer extends AbstractConsumer {
|
|
113
|
+
constructor(sourceMap) {
|
|
114
|
+
super(sourceMap);
|
|
115
|
+
this._consumers = sourceMap.sections.map((section, index) => {
|
|
116
|
+
const generatedOffset = {
|
|
117
|
+
lines: add0(section.offset.line),
|
|
118
|
+
columns: add0(section.offset.column)
|
|
119
|
+
};
|
|
120
|
+
const consumer = createConsumer(section.map);
|
|
121
|
+
return [generatedOffset, consumer];
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
originalPositionFor(generatedPosition) {
|
|
126
|
+
const _ref = this._consumerForPosition(generatedPosition) || [],
|
|
127
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
128
|
+
generatedOffset = _ref2[0],
|
|
129
|
+
consumer = _ref2[1];
|
|
130
|
+
|
|
131
|
+
if (!consumer) {
|
|
132
|
+
return EMPTY_POSITION;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return consumer.originalPositionFor(
|
|
136
|
+
subtractOffsetFromPosition(generatedPosition, generatedOffset)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
*generatedMappings() {
|
|
141
|
+
for (const _ref3 of this._consumers) {
|
|
142
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
143
|
+
|
|
144
|
+
const generatedOffset = _ref4[0];
|
|
145
|
+
const consumer = _ref4[1];
|
|
146
|
+
let first = true;
|
|
147
|
+
|
|
148
|
+
for (const mapping of consumer.generatedMappings()) {
|
|
149
|
+
if (
|
|
150
|
+
first &&
|
|
151
|
+
(get1(mapping.generatedLine) > 1 || get0(mapping.generatedColumn) > 0)
|
|
152
|
+
) {
|
|
153
|
+
yield {
|
|
154
|
+
generatedLine: FIRST_LINE,
|
|
155
|
+
generatedColumn: FIRST_COLUMN,
|
|
156
|
+
source: null,
|
|
157
|
+
name: null,
|
|
158
|
+
originalLine: null,
|
|
159
|
+
originalColumn: null
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
first = false;
|
|
164
|
+
yield _objectSpread({}, mapping, {
|
|
165
|
+
generatedLine: add(mapping.generatedLine, generatedOffset.lines),
|
|
166
|
+
generatedColumn: add(mapping.generatedColumn, generatedOffset.columns)
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
_consumerForPosition(generatedPosition) {
|
|
173
|
+
const line = generatedPosition.line,
|
|
174
|
+
column = generatedPosition.column;
|
|
175
|
+
|
|
176
|
+
if (line == null || column == null) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const index = greatestLowerBound(
|
|
181
|
+
this._consumers,
|
|
182
|
+
generatedPosition,
|
|
183
|
+
(position, _ref5) => {
|
|
184
|
+
let _ref6 = _slicedToArray(_ref5, 1),
|
|
185
|
+
offset = _ref6[0];
|
|
186
|
+
|
|
187
|
+
const line0 = sub1(line);
|
|
188
|
+
const column0 = column;
|
|
189
|
+
|
|
190
|
+
if (line0 === offset.lines) {
|
|
191
|
+
return get0(sub(column0, offset.columns));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return get0(sub(line0, offset.lines));
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
return index != null ? this._consumers[index] : null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
module.exports = SectionsConsumer;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const AbstractConsumer = require('./AbstractConsumer');
|
|
14
|
+
|
|
15
|
+
const createConsumer = require('./createConsumer');
|
|
16
|
+
|
|
17
|
+
const {FIRST_COLUMN, FIRST_LINE, EMPTY_POSITION} = require('./constants');
|
|
18
|
+
const {subtractOffsetFromPosition} = require('./positionMath');
|
|
19
|
+
const {greatestLowerBound} = require('./search');
|
|
20
|
+
const {add, get0, get1, add0, sub1, sub} = require('ob1');
|
|
21
|
+
|
|
22
|
+
import type {IndexMap} from '../source-map';
|
|
23
|
+
import type {
|
|
24
|
+
GeneratedOffset,
|
|
25
|
+
SourcePosition,
|
|
26
|
+
GeneratedPositionLookup,
|
|
27
|
+
Mapping,
|
|
28
|
+
IConsumer,
|
|
29
|
+
} from './types.flow';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A source map consumer that supports "indexed" source maps (that have a
|
|
33
|
+
* `sections` field and no top-level mappings).
|
|
34
|
+
*/
|
|
35
|
+
class SectionsConsumer extends AbstractConsumer implements IConsumer {
|
|
36
|
+
_consumers: $ReadOnlyArray<[GeneratedOffset, IConsumer]>;
|
|
37
|
+
|
|
38
|
+
constructor(sourceMap: IndexMap) {
|
|
39
|
+
super(sourceMap);
|
|
40
|
+
this._consumers = sourceMap.sections.map((section, index) => {
|
|
41
|
+
const generatedOffset = {
|
|
42
|
+
lines: add0(section.offset.line),
|
|
43
|
+
columns: add0(section.offset.column),
|
|
44
|
+
};
|
|
45
|
+
const consumer = createConsumer(section.map);
|
|
46
|
+
return [generatedOffset, consumer];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
originalPositionFor(
|
|
51
|
+
generatedPosition: GeneratedPositionLookup,
|
|
52
|
+
): SourcePosition {
|
|
53
|
+
const [generatedOffset, consumer] =
|
|
54
|
+
this._consumerForPosition(generatedPosition) || [];
|
|
55
|
+
if (!consumer) {
|
|
56
|
+
return EMPTY_POSITION;
|
|
57
|
+
}
|
|
58
|
+
return consumer.originalPositionFor(
|
|
59
|
+
subtractOffsetFromPosition(generatedPosition, generatedOffset),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
*generatedMappings(): Iterable<Mapping> {
|
|
64
|
+
for (const [generatedOffset, consumer] of this._consumers) {
|
|
65
|
+
let first = true;
|
|
66
|
+
for (const mapping of consumer.generatedMappings()) {
|
|
67
|
+
if (
|
|
68
|
+
first &&
|
|
69
|
+
(get1(mapping.generatedLine) > 1 || get0(mapping.generatedColumn) > 0)
|
|
70
|
+
) {
|
|
71
|
+
yield {
|
|
72
|
+
generatedLine: FIRST_LINE,
|
|
73
|
+
generatedColumn: FIRST_COLUMN,
|
|
74
|
+
source: null,
|
|
75
|
+
name: null,
|
|
76
|
+
originalLine: null,
|
|
77
|
+
originalColumn: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
first = false;
|
|
81
|
+
yield {
|
|
82
|
+
...mapping,
|
|
83
|
+
generatedLine: add(mapping.generatedLine, generatedOffset.lines),
|
|
84
|
+
generatedColumn: add(
|
|
85
|
+
mapping.generatedColumn,
|
|
86
|
+
generatedOffset.columns,
|
|
87
|
+
),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_consumerForPosition(
|
|
94
|
+
generatedPosition: GeneratedPositionLookup,
|
|
95
|
+
): ?[GeneratedOffset, IConsumer] {
|
|
96
|
+
const {line, column} = generatedPosition;
|
|
97
|
+
if (line == null || column == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const index = greatestLowerBound(
|
|
101
|
+
this._consumers,
|
|
102
|
+
generatedPosition,
|
|
103
|
+
(position, [offset]) => {
|
|
104
|
+
const line0 = sub1(line);
|
|
105
|
+
const column0 = column;
|
|
106
|
+
if (line0 === offset.lines) {
|
|
107
|
+
return get0(sub(column0, offset.columns));
|
|
108
|
+
}
|
|
109
|
+
return get0(sub(line0, offset.lines));
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
return index != null ? this._consumers[index] : null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = SectionsConsumer;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
const _require = require("ob1"),
|
|
13
|
+
add0 = _require.add0,
|
|
14
|
+
add1 = _require.add1;
|
|
15
|
+
|
|
16
|
+
const FIRST_COLUMN = add0(0);
|
|
17
|
+
const FIRST_LINE = add1(0);
|
|
18
|
+
const GENERATED_ORDER = "GENERATED_ORDER";
|
|
19
|
+
const ORIGINAL_ORDER = "ORIGINAL_ORDER";
|
|
20
|
+
const GREATEST_LOWER_BOUND = "GREATEST_LOWER_BOUND";
|
|
21
|
+
const LEAST_UPPER_BOUND = "LEAST_UPPER_BOUND";
|
|
22
|
+
const EMPTY_POSITION = Object.freeze({
|
|
23
|
+
source: null,
|
|
24
|
+
name: null,
|
|
25
|
+
line: null,
|
|
26
|
+
column: null
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function iterationOrderToString(x) {
|
|
30
|
+
return x;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function lookupBiasToString(x) {
|
|
34
|
+
return x;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
FIRST_COLUMN,
|
|
39
|
+
FIRST_LINE,
|
|
40
|
+
GENERATED_ORDER,
|
|
41
|
+
ORIGINAL_ORDER,
|
|
42
|
+
GREATEST_LOWER_BOUND,
|
|
43
|
+
LEAST_UPPER_BOUND,
|
|
44
|
+
EMPTY_POSITION,
|
|
45
|
+
iterationOrderToString,
|
|
46
|
+
lookupBiasToString
|
|
47
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const {add0, add1} = require('ob1');
|
|
14
|
+
const FIRST_COLUMN = add0(0);
|
|
15
|
+
const FIRST_LINE = add1(0);
|
|
16
|
+
|
|
17
|
+
export opaque type IterationOrder = 'GENERATED_ORDER' | 'ORIGINAL_ORDER';
|
|
18
|
+
const GENERATED_ORDER: IterationOrder = 'GENERATED_ORDER';
|
|
19
|
+
const ORIGINAL_ORDER: IterationOrder = 'ORIGINAL_ORDER';
|
|
20
|
+
|
|
21
|
+
export opaque type LookupBias = 'GREATEST_LOWER_BOUND' | 'LEAST_UPPER_BOUND';
|
|
22
|
+
const GREATEST_LOWER_BOUND: LookupBias = 'GREATEST_LOWER_BOUND';
|
|
23
|
+
const LEAST_UPPER_BOUND: LookupBias = 'LEAST_UPPER_BOUND';
|
|
24
|
+
|
|
25
|
+
const EMPTY_POSITION = Object.freeze({
|
|
26
|
+
source: null,
|
|
27
|
+
name: null,
|
|
28
|
+
line: null,
|
|
29
|
+
column: null,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function iterationOrderToString(x: IterationOrder): string {
|
|
33
|
+
return x;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function lookupBiasToString(x: LookupBias): string {
|
|
37
|
+
return x;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
FIRST_COLUMN,
|
|
42
|
+
FIRST_LINE,
|
|
43
|
+
GENERATED_ORDER,
|
|
44
|
+
ORIGINAL_ORDER,
|
|
45
|
+
GREATEST_LOWER_BOUND,
|
|
46
|
+
LEAST_UPPER_BOUND,
|
|
47
|
+
EMPTY_POSITION,
|
|
48
|
+
iterationOrderToString,
|
|
49
|
+
lookupBiasToString,
|
|
50
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
const invariant = require("invariant");
|
|
13
|
+
|
|
14
|
+
function createConsumer(sourceMap) {
|
|
15
|
+
invariant(
|
|
16
|
+
sourceMap.version === "3" || sourceMap.version === 3,
|
|
17
|
+
`Unrecognized source map format version: ${sourceMap.version}`
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const MappingsConsumer = require("./MappingsConsumer");
|
|
21
|
+
|
|
22
|
+
const SectionsConsumer = require("./SectionsConsumer"); // eslint-disable-next-line lint/strictly-null
|
|
23
|
+
|
|
24
|
+
if (sourceMap.mappings === undefined) {
|
|
25
|
+
return new SectionsConsumer(sourceMap);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new MappingsConsumer(sourceMap);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = createConsumer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const invariant = require('invariant');
|
|
14
|
+
|
|
15
|
+
import type {MixedSourceMap} from '../source-map';
|
|
16
|
+
import type {IConsumer} from './types.flow';
|
|
17
|
+
|
|
18
|
+
function createConsumer(sourceMap: MixedSourceMap): IConsumer {
|
|
19
|
+
invariant(
|
|
20
|
+
(sourceMap.version: mixed) === '3' || sourceMap.version === 3,
|
|
21
|
+
`Unrecognized source map format version: ${sourceMap.version}`,
|
|
22
|
+
);
|
|
23
|
+
const MappingsConsumer = require('./MappingsConsumer');
|
|
24
|
+
const SectionsConsumer = require('./SectionsConsumer');
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line lint/strictly-null
|
|
27
|
+
if (sourceMap.mappings === undefined) {
|
|
28
|
+
return new SectionsConsumer(sourceMap);
|
|
29
|
+
}
|
|
30
|
+
return new MappingsConsumer(sourceMap);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = createConsumer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
"use strict"; // Implements an API-compatible subset of source-map's `SourceMapConsumer`.
|
|
11
|
+
|
|
12
|
+
const DelegatingConsumer = require("./DelegatingConsumer");
|
|
13
|
+
|
|
14
|
+
module.exports = DelegatingConsumer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
// Implements an API-compatible subset of source-map's `SourceMapConsumer`.
|
|
14
|
+
const DelegatingConsumer = require('./DelegatingConsumer');
|
|
15
|
+
|
|
16
|
+
module.exports = DelegatingConsumer;
|