metro-source-map 0.53.0 → 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 +13 -3
- package/src/BundleBuilder.js +132 -0
- package/src/BundleBuilder.js.flow +126 -0
- 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 +36 -3
- package/src/Generator.js.flow +43 -5
- package/src/composeSourceMaps.js +105 -0
- package/src/composeSourceMaps.js.flow +115 -0
- package/src/generateFunctionMap.js +531 -0
- package/src/generateFunctionMap.js.flow +421 -0
- package/src/source-map.js +136 -25
- package/src/source-map.js.flow +137 -48
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",
|
|
@@ -12,7 +12,17 @@
|
|
|
12
12
|
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
15
|
+
"@babel/traverse": "^7.0.0",
|
|
16
|
+
"@babel/types": "^7.0.0",
|
|
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"
|
|
16
22
|
},
|
|
17
|
-
"license": "MIT"
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/parser": "^7.0.0",
|
|
26
|
+
"uglify-es": "^3.1.9"
|
|
27
|
+
}
|
|
18
28
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
const EMPTY_MAP = {
|
|
13
|
+
version: 3,
|
|
14
|
+
sources: [],
|
|
15
|
+
names: [],
|
|
16
|
+
mappings: "A"
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Builds a source-mapped bundle by concatenating strings and their
|
|
20
|
+
* corresponding source maps (if any).
|
|
21
|
+
*
|
|
22
|
+
* Usage:
|
|
23
|
+
*
|
|
24
|
+
* const builder = new BundleBuilder('bundle.js');
|
|
25
|
+
* builder
|
|
26
|
+
* .append('foo\n', fooMap)
|
|
27
|
+
* .append('bar\n')
|
|
28
|
+
* // ...
|
|
29
|
+
* const code = builder.getCode();
|
|
30
|
+
* const map = builder.getMap();
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
class BundleBuilder {
|
|
34
|
+
constructor(file) {
|
|
35
|
+
this._file = file;
|
|
36
|
+
this._sections = [];
|
|
37
|
+
this._line = 0;
|
|
38
|
+
this._column = 0;
|
|
39
|
+
this._code = "";
|
|
40
|
+
this._afterMappedContent = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_pushMapSection(map) {
|
|
44
|
+
this._sections.push({
|
|
45
|
+
map,
|
|
46
|
+
offset: {
|
|
47
|
+
column: this._column,
|
|
48
|
+
line: this._line
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_endMappedContent() {
|
|
54
|
+
if (this._afterMappedContent) {
|
|
55
|
+
this._pushMapSection(EMPTY_MAP);
|
|
56
|
+
|
|
57
|
+
this._afterMappedContent = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
append(code, map) {
|
|
62
|
+
if (!code.length) {
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const _measureString = measureString(code),
|
|
67
|
+
lineBreaks = _measureString.lineBreaks,
|
|
68
|
+
lastLineColumns = _measureString.lastLineColumns;
|
|
69
|
+
|
|
70
|
+
if (map) {
|
|
71
|
+
this._pushMapSection(map);
|
|
72
|
+
|
|
73
|
+
this._afterMappedContent = true;
|
|
74
|
+
} else {
|
|
75
|
+
this._endMappedContent();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this._afterMappedContent = !!map;
|
|
79
|
+
this._line = this._line + lineBreaks;
|
|
80
|
+
|
|
81
|
+
if (lineBreaks > 0) {
|
|
82
|
+
this._column = lastLineColumns;
|
|
83
|
+
} else {
|
|
84
|
+
this._column = this._column + lastLineColumns;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this._code = this._code + code;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getMap() {
|
|
92
|
+
this._endMappedContent();
|
|
93
|
+
|
|
94
|
+
return createIndexMap(this._file, this._sections);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getCode() {
|
|
98
|
+
return this._code;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const reLineBreak = /\r\n|\r|\n/g;
|
|
103
|
+
|
|
104
|
+
function measureString(str) {
|
|
105
|
+
let lineBreaks = 0;
|
|
106
|
+
let match;
|
|
107
|
+
let lastLineStart = 0;
|
|
108
|
+
|
|
109
|
+
while ((match = reLineBreak.exec(str))) {
|
|
110
|
+
++lineBreaks;
|
|
111
|
+
lastLineStart = match.index + match[0].length;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const lastLineColumns = str.length - lastLineStart;
|
|
115
|
+
return {
|
|
116
|
+
lineBreaks,
|
|
117
|
+
lastLineColumns
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function createIndexMap(file, sections) {
|
|
122
|
+
return {
|
|
123
|
+
version: 3,
|
|
124
|
+
file,
|
|
125
|
+
sections
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
BundleBuilder,
|
|
131
|
+
createIndexMap
|
|
132
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
import type {IndexMap, IndexMapSection, MixedSourceMap} from './source-map';
|
|
14
|
+
|
|
15
|
+
const EMPTY_MAP = {
|
|
16
|
+
version: 3,
|
|
17
|
+
sources: [],
|
|
18
|
+
names: [],
|
|
19
|
+
mappings: 'A',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds a source-mapped bundle by concatenating strings and their
|
|
24
|
+
* corresponding source maps (if any).
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
*
|
|
28
|
+
* const builder = new BundleBuilder('bundle.js');
|
|
29
|
+
* builder
|
|
30
|
+
* .append('foo\n', fooMap)
|
|
31
|
+
* .append('bar\n')
|
|
32
|
+
* // ...
|
|
33
|
+
* const code = builder.getCode();
|
|
34
|
+
* const map = builder.getMap();
|
|
35
|
+
*/
|
|
36
|
+
class BundleBuilder {
|
|
37
|
+
_file: string;
|
|
38
|
+
_sections: Array<IndexMapSection>;
|
|
39
|
+
_line: number;
|
|
40
|
+
_column: number;
|
|
41
|
+
_code: string;
|
|
42
|
+
_afterMappedContent: boolean;
|
|
43
|
+
|
|
44
|
+
constructor(file: string) {
|
|
45
|
+
this._file = file;
|
|
46
|
+
this._sections = [];
|
|
47
|
+
this._line = 0;
|
|
48
|
+
this._column = 0;
|
|
49
|
+
this._code = '';
|
|
50
|
+
this._afterMappedContent = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_pushMapSection(map: MixedSourceMap) {
|
|
54
|
+
this._sections.push({
|
|
55
|
+
map,
|
|
56
|
+
offset: {column: this._column, line: this._line},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_endMappedContent() {
|
|
61
|
+
if (this._afterMappedContent) {
|
|
62
|
+
this._pushMapSection(EMPTY_MAP);
|
|
63
|
+
this._afterMappedContent = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
append(code: string, map: ?MixedSourceMap): this {
|
|
68
|
+
if (!code.length) {
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
const {lineBreaks, lastLineColumns} = measureString(code);
|
|
72
|
+
if (map) {
|
|
73
|
+
this._pushMapSection(map);
|
|
74
|
+
this._afterMappedContent = true;
|
|
75
|
+
} else {
|
|
76
|
+
this._endMappedContent();
|
|
77
|
+
}
|
|
78
|
+
this._afterMappedContent = !!map;
|
|
79
|
+
this._line = this._line + lineBreaks;
|
|
80
|
+
if (lineBreaks > 0) {
|
|
81
|
+
this._column = lastLineColumns;
|
|
82
|
+
} else {
|
|
83
|
+
this._column = this._column + lastLineColumns;
|
|
84
|
+
}
|
|
85
|
+
this._code = this._code + code;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getMap(): MixedSourceMap {
|
|
90
|
+
this._endMappedContent();
|
|
91
|
+
return createIndexMap(this._file, this._sections);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getCode(): string {
|
|
95
|
+
return this._code;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const reLineBreak = /\r\n|\r|\n/g;
|
|
100
|
+
|
|
101
|
+
function measureString(
|
|
102
|
+
str: string,
|
|
103
|
+
): {|lineBreaks: number, lastLineColumns: number|} {
|
|
104
|
+
let lineBreaks = 0;
|
|
105
|
+
let match;
|
|
106
|
+
let lastLineStart = 0;
|
|
107
|
+
while ((match = reLineBreak.exec(str))) {
|
|
108
|
+
++lineBreaks;
|
|
109
|
+
lastLineStart = match.index + match[0].length;
|
|
110
|
+
}
|
|
111
|
+
const lastLineColumns = str.length - lastLineStart;
|
|
112
|
+
return {lineBreaks, lastLineColumns};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function createIndexMap(
|
|
116
|
+
file: string,
|
|
117
|
+
sections: Array<IndexMapSection>,
|
|
118
|
+
): IndexMap {
|
|
119
|
+
return {
|
|
120
|
+
version: 3,
|
|
121
|
+
file,
|
|
122
|
+
sections,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = {BundleBuilder, createIndexMap};
|
|
@@ -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;
|