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
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.55.0",
|
|
3
3
|
"name": "metro-source-map",
|
|
4
4
|
"description": "🚇 Source map generator for Metro.",
|
|
5
5
|
"main": "src/source-map.js",
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@babel/traverse": "^7.0.0",
|
|
16
16
|
"@babel/types": "^7.0.0",
|
|
17
|
-
"
|
|
17
|
+
"invariant": "^2.2.4",
|
|
18
|
+
"metro-symbolicate": "0.55.0",
|
|
19
|
+
"ob1": "0.55.0",
|
|
20
|
+
"source-map": "^0.5.6",
|
|
21
|
+
"vlq": "^1.0.0"
|
|
18
22
|
},
|
|
19
23
|
"license": "MIT",
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"@babel/parser": "^7.0.0",
|
|
22
|
-
"
|
|
26
|
+
"uglify-es": "^3.1.9"
|
|
23
27
|
}
|
|
24
28
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {IndexMap, IndexMapSection,
|
|
13
|
+
import type {IndexMap, IndexMapSection, MixedSourceMap} from './source-map';
|
|
14
14
|
|
|
15
15
|
const EMPTY_MAP = {
|
|
16
16
|
version: 3,
|
|
@@ -50,7 +50,7 @@ class BundleBuilder {
|
|
|
50
50
|
this._afterMappedContent = false;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
_pushMapSection(map:
|
|
53
|
+
_pushMapSection(map: MixedSourceMap) {
|
|
54
54
|
this._sections.push({
|
|
55
55
|
map,
|
|
56
56
|
offset: {column: this._column, line: this._line},
|
|
@@ -64,7 +64,7 @@ class BundleBuilder {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
append(code: string, map: ?
|
|
67
|
+
append(code: string, map: ?MixedSourceMap): this {
|
|
68
68
|
if (!code.length) {
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
@@ -86,7 +86,7 @@ class BundleBuilder {
|
|
|
86
86
|
return this;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
getMap():
|
|
89
|
+
getMap(): MixedSourceMap {
|
|
90
90
|
this._endMappedContent();
|
|
91
91
|
return createIndexMap(this._file, this._sections);
|
|
92
92
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
const _require = require("./constants"),
|
|
15
|
+
GENERATED_ORDER = _require.GENERATED_ORDER,
|
|
16
|
+
iterationOrderToString = _require.iterationOrderToString;
|
|
17
|
+
|
|
18
|
+
// Implementation details shared between MappingsConsumer and SectionsConsumer
|
|
19
|
+
class AbstractConsumer {
|
|
20
|
+
constructor(sourceMap) {
|
|
21
|
+
this._sourceMap = sourceMap;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
originalPositionFor(generatedPosition) {
|
|
25
|
+
invariant(false, "Not implemented");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
generatedMappings() {
|
|
29
|
+
invariant(false, "Not implemented");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
eachMapping(callback) {
|
|
33
|
+
let context =
|
|
34
|
+
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
35
|
+
let order =
|
|
36
|
+
arguments.length > 2 && arguments[2] !== undefined
|
|
37
|
+
? arguments[2]
|
|
38
|
+
: GENERATED_ORDER;
|
|
39
|
+
invariant(
|
|
40
|
+
order === GENERATED_ORDER,
|
|
41
|
+
`Iteration order not implemented: ${iterationOrderToString(order)}`
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
for (const mapping of this.generatedMappings()) {
|
|
45
|
+
callback.call(context, mapping);
|
|
46
|
+
}
|
|
47
|
+
} // flowlint unsafe-getters-setters:off
|
|
48
|
+
|
|
49
|
+
get file() {
|
|
50
|
+
return this._sourceMap.file;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = AbstractConsumer;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
const {GENERATED_ORDER, iterationOrderToString} = require('./constants');
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
SourcePosition,
|
|
19
|
+
GeneratedPositionLookup,
|
|
20
|
+
Mapping,
|
|
21
|
+
IConsumer,
|
|
22
|
+
IterationOrder,
|
|
23
|
+
} from './types.flow';
|
|
24
|
+
|
|
25
|
+
// Implementation details shared between MappingsConsumer and SectionsConsumer
|
|
26
|
+
class AbstractConsumer implements IConsumer {
|
|
27
|
+
_sourceMap: {+file?: string};
|
|
28
|
+
|
|
29
|
+
constructor(sourceMap: {+file?: string}) {
|
|
30
|
+
this._sourceMap = sourceMap;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
originalPositionFor(
|
|
34
|
+
generatedPosition: GeneratedPositionLookup,
|
|
35
|
+
): SourcePosition {
|
|
36
|
+
invariant(false, 'Not implemented');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
generatedMappings(): Iterable<Mapping> {
|
|
40
|
+
invariant(false, 'Not implemented');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
eachMapping(
|
|
44
|
+
callback: (mapping: Mapping) => mixed,
|
|
45
|
+
context?: mixed = null,
|
|
46
|
+
order?: IterationOrder = GENERATED_ORDER,
|
|
47
|
+
) {
|
|
48
|
+
invariant(
|
|
49
|
+
order === GENERATED_ORDER,
|
|
50
|
+
`Iteration order not implemented: ${iterationOrderToString(order)}`,
|
|
51
|
+
);
|
|
52
|
+
for (const mapping of this.generatedMappings()) {
|
|
53
|
+
callback.call(context, mapping);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// flowlint unsafe-getters-setters:off
|
|
58
|
+
get file(): ?string {
|
|
59
|
+
return this._sourceMap.file;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = AbstractConsumer;
|
|
@@ -0,0 +1,74 @@
|
|
|
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 _defineProperty(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const createConsumer = require("./createConsumer");
|
|
27
|
+
|
|
28
|
+
const _require = require("./constants"),
|
|
29
|
+
GENERATED_ORDER = _require.GENERATED_ORDER,
|
|
30
|
+
ORIGINAL_ORDER = _require.ORIGINAL_ORDER,
|
|
31
|
+
GREATEST_LOWER_BOUND = _require.GREATEST_LOWER_BOUND,
|
|
32
|
+
LEAST_UPPER_BOUND = _require.LEAST_UPPER_BOUND;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A source map consumer that supports both "basic" and "indexed" source maps.
|
|
36
|
+
* Uses `MappingsConsumer` and `SectionsConsumer` under the hood (via
|
|
37
|
+
* `createConsumer`).
|
|
38
|
+
*/
|
|
39
|
+
class DelegatingConsumer {
|
|
40
|
+
constructor(sourceMap) {
|
|
41
|
+
this._rootConsumer = createConsumer(sourceMap);
|
|
42
|
+
return this._rootConsumer;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
originalPositionFor(generatedPosition) {
|
|
46
|
+
return this._rootConsumer.originalPositionFor(generatedPosition);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
generatedMappings() {
|
|
50
|
+
return this._rootConsumer.generatedMappings();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
eachMapping(callback, context, order) {
|
|
54
|
+
return this._rootConsumer.eachMapping(callback, context, order);
|
|
55
|
+
} // flowlint unsafe-getters-setters:off
|
|
56
|
+
|
|
57
|
+
get file() {
|
|
58
|
+
return this._rootConsumer.file;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_defineProperty(DelegatingConsumer, "GENERATED_ORDER", GENERATED_ORDER);
|
|
63
|
+
|
|
64
|
+
_defineProperty(DelegatingConsumer, "ORIGINAL_ORDER", ORIGINAL_ORDER);
|
|
65
|
+
|
|
66
|
+
_defineProperty(
|
|
67
|
+
DelegatingConsumer,
|
|
68
|
+
"GREATEST_LOWER_BOUND",
|
|
69
|
+
GREATEST_LOWER_BOUND
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
_defineProperty(DelegatingConsumer, "LEAST_UPPER_BOUND", LEAST_UPPER_BOUND);
|
|
73
|
+
|
|
74
|
+
module.exports = DelegatingConsumer;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 createConsumer = require('./createConsumer');
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
GENERATED_ORDER,
|
|
17
|
+
ORIGINAL_ORDER,
|
|
18
|
+
GREATEST_LOWER_BOUND,
|
|
19
|
+
LEAST_UPPER_BOUND,
|
|
20
|
+
} = require('./constants');
|
|
21
|
+
|
|
22
|
+
import type {MixedSourceMap} from '../source-map';
|
|
23
|
+
import type {
|
|
24
|
+
SourcePosition,
|
|
25
|
+
GeneratedPositionLookup,
|
|
26
|
+
Mapping,
|
|
27
|
+
IConsumer,
|
|
28
|
+
IterationOrder,
|
|
29
|
+
} from './types.flow';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A source map consumer that supports both "basic" and "indexed" source maps.
|
|
33
|
+
* Uses `MappingsConsumer` and `SectionsConsumer` under the hood (via
|
|
34
|
+
* `createConsumer`).
|
|
35
|
+
*/
|
|
36
|
+
class DelegatingConsumer implements IConsumer {
|
|
37
|
+
static +GENERATED_ORDER = GENERATED_ORDER;
|
|
38
|
+
static +ORIGINAL_ORDER = ORIGINAL_ORDER;
|
|
39
|
+
static +GREATEST_LOWER_BOUND = GREATEST_LOWER_BOUND;
|
|
40
|
+
static +LEAST_UPPER_BOUND = LEAST_UPPER_BOUND;
|
|
41
|
+
|
|
42
|
+
_rootConsumer: IConsumer;
|
|
43
|
+
|
|
44
|
+
constructor(sourceMap: MixedSourceMap) {
|
|
45
|
+
this._rootConsumer = createConsumer(sourceMap);
|
|
46
|
+
return this._rootConsumer;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
originalPositionFor(
|
|
50
|
+
generatedPosition: GeneratedPositionLookup,
|
|
51
|
+
): SourcePosition {
|
|
52
|
+
return this._rootConsumer.originalPositionFor(generatedPosition);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
generatedMappings(): Iterable<Mapping> {
|
|
56
|
+
return this._rootConsumer.generatedMappings();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
eachMapping(
|
|
60
|
+
callback: (mapping: Mapping) => mixed,
|
|
61
|
+
context?: mixed,
|
|
62
|
+
order?: IterationOrder,
|
|
63
|
+
): void {
|
|
64
|
+
return this._rootConsumer.eachMapping(callback, context, order);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// flowlint unsafe-getters-setters:off
|
|
68
|
+
get file(): ?string {
|
|
69
|
+
return this._rootConsumer.file;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = DelegatingConsumer;
|
|
@@ -0,0 +1,313 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
function _toConsumableArray(arr) {
|
|
13
|
+
return (
|
|
14
|
+
_arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread()
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _nonIterableSpread() {
|
|
19
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function _iterableToArray(iter) {
|
|
23
|
+
if (
|
|
24
|
+
Symbol.iterator in Object(iter) ||
|
|
25
|
+
Object.prototype.toString.call(iter) === "[object Arguments]"
|
|
26
|
+
)
|
|
27
|
+
return Array.from(iter);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _arrayWithoutHoles(arr) {
|
|
31
|
+
if (Array.isArray(arr)) {
|
|
32
|
+
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++)
|
|
33
|
+
arr2[i] = arr[i];
|
|
34
|
+
return arr2;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _slicedToArray(arr, i) {
|
|
39
|
+
return (
|
|
40
|
+
_arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _nonIterableRest() {
|
|
45
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _iterableToArrayLimit(arr, i) {
|
|
49
|
+
var _arr = [];
|
|
50
|
+
var _n = true;
|
|
51
|
+
var _d = false;
|
|
52
|
+
var _e = undefined;
|
|
53
|
+
try {
|
|
54
|
+
for (
|
|
55
|
+
var _i = arr[Symbol.iterator](), _s;
|
|
56
|
+
!(_n = (_s = _i.next()).done);
|
|
57
|
+
_n = true
|
|
58
|
+
) {
|
|
59
|
+
_arr.push(_s.value);
|
|
60
|
+
if (i && _arr.length === i) break;
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_d = true;
|
|
64
|
+
_e = err;
|
|
65
|
+
} finally {
|
|
66
|
+
try {
|
|
67
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
68
|
+
} finally {
|
|
69
|
+
if (_d) throw _e;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return _arr;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _arrayWithHoles(arr) {
|
|
76
|
+
if (Array.isArray(arr)) return arr;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function _objectSpread(target) {
|
|
80
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
81
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
82
|
+
var ownKeys = Object.keys(source);
|
|
83
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
84
|
+
ownKeys = ownKeys.concat(
|
|
85
|
+
Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
86
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
ownKeys.forEach(function(key) {
|
|
91
|
+
_defineProperty(target, key, source[key]);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function _defineProperty(obj, key, value) {
|
|
98
|
+
if (key in obj) {
|
|
99
|
+
Object.defineProperty(obj, key, {
|
|
100
|
+
value: value,
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
obj[key] = value;
|
|
107
|
+
}
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const AbstractConsumer = require("./AbstractConsumer");
|
|
112
|
+
|
|
113
|
+
const invariant = require("invariant");
|
|
114
|
+
|
|
115
|
+
const normalizeSourcePath = require("./normalizeSourcePath");
|
|
116
|
+
|
|
117
|
+
const _require = require("./constants"),
|
|
118
|
+
FIRST_COLUMN = _require.FIRST_COLUMN,
|
|
119
|
+
FIRST_LINE = _require.FIRST_LINE,
|
|
120
|
+
GREATEST_LOWER_BOUND = _require.GREATEST_LOWER_BOUND,
|
|
121
|
+
EMPTY_POSITION = _require.EMPTY_POSITION,
|
|
122
|
+
lookupBiasToString = _require.lookupBiasToString;
|
|
123
|
+
|
|
124
|
+
const _require2 = require("./search"),
|
|
125
|
+
greatestLowerBound = _require2.greatestLowerBound;
|
|
126
|
+
|
|
127
|
+
const _require3 = require("ob1"),
|
|
128
|
+
add = _require3.add,
|
|
129
|
+
get0 = _require3.get0,
|
|
130
|
+
add0 = _require3.add0,
|
|
131
|
+
sub = _require3.sub,
|
|
132
|
+
inc = _require3.inc;
|
|
133
|
+
|
|
134
|
+
const _require4 = require("vlq"),
|
|
135
|
+
decodeVlq = _require4.decode;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A source map consumer that supports "basic" source maps (that have a
|
|
139
|
+
* `mappings` field and no sections).
|
|
140
|
+
*/
|
|
141
|
+
class MappingsConsumer extends AbstractConsumer {
|
|
142
|
+
constructor(sourceMap) {
|
|
143
|
+
super(sourceMap);
|
|
144
|
+
this._sourceMap = sourceMap;
|
|
145
|
+
this._decodedMappings = null;
|
|
146
|
+
this._normalizedSources = null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
originalPositionFor(generatedPosition) {
|
|
150
|
+
const line = generatedPosition.line,
|
|
151
|
+
column = generatedPosition.column;
|
|
152
|
+
|
|
153
|
+
if (line == null || column == null) {
|
|
154
|
+
return _objectSpread({}, EMPTY_POSITION);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (generatedPosition.bias != null) {
|
|
158
|
+
invariant(
|
|
159
|
+
generatedPosition.bias === GREATEST_LOWER_BOUND,
|
|
160
|
+
`Unimplemented lookup bias: ${lookupBiasToString(
|
|
161
|
+
generatedPosition.bias
|
|
162
|
+
)}`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const mappings = this._decodeAndCacheMappings();
|
|
167
|
+
|
|
168
|
+
const index = greatestLowerBound(
|
|
169
|
+
mappings,
|
|
170
|
+
{
|
|
171
|
+
line,
|
|
172
|
+
column
|
|
173
|
+
},
|
|
174
|
+
(position, mapping) => {
|
|
175
|
+
if (position.line === mapping.generatedLine) {
|
|
176
|
+
return get0(sub(position.column, mapping.generatedColumn));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return get0(sub(position.line, mapping.generatedLine));
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (
|
|
184
|
+
index != null &&
|
|
185
|
+
mappings[index].generatedLine === generatedPosition.line
|
|
186
|
+
) {
|
|
187
|
+
const mapping = mappings[index];
|
|
188
|
+
return {
|
|
189
|
+
source: mapping.source,
|
|
190
|
+
name: mapping.name,
|
|
191
|
+
line: mapping.originalLine,
|
|
192
|
+
column: mapping.originalColumn
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return _objectSpread({}, EMPTY_POSITION);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
*_decodeMappings() {
|
|
200
|
+
let generatedLine = FIRST_LINE;
|
|
201
|
+
let generatedColumn = FIRST_COLUMN;
|
|
202
|
+
let originalLine = FIRST_LINE;
|
|
203
|
+
let originalColumn = FIRST_COLUMN;
|
|
204
|
+
let nameIndex = add0(0);
|
|
205
|
+
let sourceIndex = add0(0);
|
|
206
|
+
|
|
207
|
+
const normalizedSources = this._normalizeAndCacheSources();
|
|
208
|
+
|
|
209
|
+
const _this$_sourceMap = this._sourceMap,
|
|
210
|
+
mappingsRaw = _this$_sourceMap.mappings,
|
|
211
|
+
names = _this$_sourceMap.names;
|
|
212
|
+
let next;
|
|
213
|
+
const vlqCache = new Map();
|
|
214
|
+
|
|
215
|
+
for (let i = 0; i < mappingsRaw.length; i = next) {
|
|
216
|
+
switch (mappingsRaw[i]) {
|
|
217
|
+
case ";":
|
|
218
|
+
generatedLine = inc(generatedLine);
|
|
219
|
+
generatedColumn = FIRST_COLUMN;
|
|
220
|
+
|
|
221
|
+
/* falls through */
|
|
222
|
+
|
|
223
|
+
case ",":
|
|
224
|
+
next = i + 1;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
findNext: for (next = i + 1; next < mappingsRaw.length; ++next) {
|
|
229
|
+
switch (mappingsRaw[next]) {
|
|
230
|
+
case ";":
|
|
231
|
+
/* falls through */
|
|
232
|
+
|
|
233
|
+
case ",":
|
|
234
|
+
break findNext;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const mappingRaw = mappingsRaw.slice(i, next);
|
|
239
|
+
let decodedVlqValues;
|
|
240
|
+
|
|
241
|
+
if (vlqCache.has(mappingRaw)) {
|
|
242
|
+
decodedVlqValues = vlqCache.get(mappingRaw);
|
|
243
|
+
} else {
|
|
244
|
+
decodedVlqValues = decodeVlq(mappingRaw);
|
|
245
|
+
vlqCache.set(mappingRaw, decodedVlqValues);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
invariant(Array.isArray(decodedVlqValues), "Decoding VLQ tuple failed");
|
|
249
|
+
|
|
250
|
+
const _decodedVlqValues = decodedVlqValues,
|
|
251
|
+
_decodedVlqValues2 = _slicedToArray(_decodedVlqValues, 5),
|
|
252
|
+
generatedColumnDelta = _decodedVlqValues2[0],
|
|
253
|
+
sourceIndexDelta = _decodedVlqValues2[1],
|
|
254
|
+
originalLineDelta = _decodedVlqValues2[2],
|
|
255
|
+
originalColumnDelta = _decodedVlqValues2[3],
|
|
256
|
+
nameIndexDelta = _decodedVlqValues2[4];
|
|
257
|
+
|
|
258
|
+
decodeVlq(mappingRaw);
|
|
259
|
+
invariant(generatedColumnDelta != null, "Invalid generated column delta");
|
|
260
|
+
generatedColumn = add(generatedColumn, generatedColumnDelta);
|
|
261
|
+
const mapping = {
|
|
262
|
+
generatedLine,
|
|
263
|
+
generatedColumn,
|
|
264
|
+
source: null,
|
|
265
|
+
name: null,
|
|
266
|
+
originalLine: null,
|
|
267
|
+
originalColumn: null
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
if (sourceIndexDelta != null) {
|
|
271
|
+
sourceIndex = add(sourceIndex, sourceIndexDelta);
|
|
272
|
+
mapping.source = normalizedSources[get0(sourceIndex)];
|
|
273
|
+
invariant(originalLineDelta != null, "Invalid original line delta");
|
|
274
|
+
invariant(originalColumnDelta != null, "Invalid original column delta");
|
|
275
|
+
originalLine = add(originalLine, originalLineDelta);
|
|
276
|
+
originalColumn = add(originalColumn, originalColumnDelta);
|
|
277
|
+
mapping.originalLine = originalLine;
|
|
278
|
+
mapping.originalColumn = originalColumn;
|
|
279
|
+
|
|
280
|
+
if (nameIndexDelta != null) {
|
|
281
|
+
nameIndex = add(nameIndex, nameIndexDelta);
|
|
282
|
+
mapping.name = names[get0(nameIndex)];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
yield mapping;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
_normalizeAndCacheSources() {
|
|
291
|
+
if (!this._normalizedSources) {
|
|
292
|
+
this._normalizedSources = this._sourceMap.sources.map(source =>
|
|
293
|
+
normalizeSourcePath(source, this._sourceMap)
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return this._normalizedSources;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
_decodeAndCacheMappings() {
|
|
301
|
+
if (!this._decodedMappings) {
|
|
302
|
+
this._decodedMappings = _toConsumableArray(this._decodeMappings());
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return this._decodedMappings;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
generatedMappings() {
|
|
309
|
+
return this._decodeAndCacheMappings();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
module.exports = MappingsConsumer;
|