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.
Files changed (33) hide show
  1. package/package.json +13 -3
  2. package/src/BundleBuilder.js +132 -0
  3. package/src/BundleBuilder.js.flow +126 -0
  4. package/src/Consumer/AbstractConsumer.js +54 -0
  5. package/src/Consumer/AbstractConsumer.js.flow +63 -0
  6. package/src/Consumer/DelegatingConsumer.js +74 -0
  7. package/src/Consumer/DelegatingConsumer.js.flow +73 -0
  8. package/src/Consumer/MappingsConsumer.js +313 -0
  9. package/src/Consumer/MappingsConsumer.js.flow +197 -0
  10. package/src/Consumer/SectionsConsumer.js +201 -0
  11. package/src/Consumer/SectionsConsumer.js.flow +116 -0
  12. package/src/Consumer/constants.js +47 -0
  13. package/src/Consumer/constants.js.flow +50 -0
  14. package/src/Consumer/createConsumer.js +31 -0
  15. package/src/Consumer/createConsumer.js.flow +33 -0
  16. package/src/Consumer/index.js +14 -0
  17. package/src/Consumer/index.js.flow +16 -0
  18. package/src/Consumer/normalizeSourcePath.js +33 -0
  19. package/src/Consumer/normalizeSourcePath.js.flow +41 -0
  20. package/src/Consumer/positionMath.js +65 -0
  21. package/src/Consumer/positionMath.js.flow +39 -0
  22. package/src/Consumer/search.js +36 -0
  23. package/src/Consumer/search.js.flow +36 -0
  24. package/src/Consumer/types.flow.js +13 -0
  25. package/src/Consumer/types.flow.js.flow +57 -0
  26. package/src/Generator.js +36 -3
  27. package/src/Generator.js.flow +43 -5
  28. package/src/composeSourceMaps.js +105 -0
  29. package/src/composeSourceMaps.js.flow +115 -0
  30. package/src/generateFunctionMap.js +531 -0
  31. package/src/generateFunctionMap.js.flow +421 -0
  32. package/src/source-map.js +136 -25
  33. package/src/source-map.js.flow +137 -48
@@ -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;
@@ -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
+ * strict-local
8
+ * @format
9
+ */
10
+ "use strict"; // flowlint-next-line untyped-import:off
11
+
12
+ const util = require("source-map/lib/util"); // Extracted from source-map@0.5.6's SourceMapConsumer
13
+
14
+ function normalizeSourcePath(sourceInput, map) {
15
+ const sourceRoot = map.sourceRoot;
16
+ let source = sourceInput;
17
+ source = String(source); // Some source maps produce relative source paths like "./foo.js" instead of
18
+ // "foo.js". Normalize these first so that future comparisons will succeed.
19
+ // See bugzil.la/1090768.
20
+
21
+ source = util.normalize(source); // Always ensure that absolute sources are internally stored relative to
22
+ // the source root, if the source root is absolute. Not doing this would
23
+ // be particularly problematic when the source root is a prefix of the
24
+ // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
25
+
26
+ source =
27
+ sourceRoot != null && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
28
+ ? util.relative(sourceRoot, source)
29
+ : source;
30
+ return source;
31
+ }
32
+
33
+ module.exports = normalizeSourcePath;
@@ -0,0 +1,41 @@
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
+ // flowlint-next-line untyped-import:off
14
+ const util = require('source-map/lib/util');
15
+
16
+ // Extracted from source-map@0.5.6's SourceMapConsumer
17
+ function normalizeSourcePath(
18
+ sourceInput: string,
19
+ map: {+sourceRoot?: ?string},
20
+ ): string {
21
+ const {sourceRoot} = map;
22
+ let source = sourceInput;
23
+
24
+ source = String(source);
25
+ // Some source maps produce relative source paths like "./foo.js" instead of
26
+ // "foo.js". Normalize these first so that future comparisons will succeed.
27
+ // See bugzil.la/1090768.
28
+ source = util.normalize(source);
29
+ // Always ensure that absolute sources are internally stored relative to
30
+ // the source root, if the source root is absolute. Not doing this would
31
+ // be particularly problematic when the source root is a prefix of the
32
+ // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
33
+ source =
34
+ sourceRoot != null && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
35
+ ? util.relative(sourceRoot, source)
36
+ : source;
37
+
38
+ return source;
39
+ }
40
+
41
+ module.exports = normalizeSourcePath;
@@ -0,0 +1,65 @@
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
+ const _require = require("ob1"),
45
+ add = _require.add,
46
+ neg = _require.neg;
47
+
48
+ function shiftPositionByOffset(pos, offset) {
49
+ return _objectSpread({}, pos, {
50
+ line: pos.line != null ? add(pos.line, offset.lines) : null,
51
+ column: pos.column != null ? add(pos.column, offset.columns) : null
52
+ });
53
+ }
54
+
55
+ function subtractOffsetFromPosition(pos, offset) {
56
+ return shiftPositionByOffset(pos, {
57
+ lines: neg(offset.lines),
58
+ columns: neg(offset.columns)
59
+ });
60
+ }
61
+
62
+ module.exports = {
63
+ shiftPositionByOffset,
64
+ subtractOffsetFromPosition
65
+ };
@@ -0,0 +1,39 @@
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 {add, neg} = require('ob1');
14
+
15
+ import type {GeneratedOffset} from './types.flow';
16
+ import type {Number0, Number1} from 'ob1';
17
+
18
+ function shiftPositionByOffset<T: {+line: ?Number1, +column: ?Number0}>(
19
+ pos: T,
20
+ offset: GeneratedOffset,
21
+ ): T {
22
+ return {
23
+ ...pos,
24
+ line: pos.line != null ? add(pos.line, offset.lines) : null,
25
+ column: pos.column != null ? add(pos.column, offset.columns) : null,
26
+ };
27
+ }
28
+
29
+ function subtractOffsetFromPosition<T: {+line: ?Number1, +column: ?Number0}>(
30
+ pos: T,
31
+ offset: GeneratedOffset,
32
+ ): T {
33
+ return shiftPositionByOffset(pos, {
34
+ lines: neg(offset.lines),
35
+ columns: neg(offset.columns),
36
+ });
37
+ }
38
+
39
+ module.exports = {shiftPositionByOffset, subtractOffsetFromPosition};
@@ -0,0 +1,36 @@
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 greatestLowerBound(elements, target, comparator) {
13
+ let first = 0;
14
+ let it = 0;
15
+ let count = elements.length;
16
+ let step;
17
+
18
+ while (count > 0) {
19
+ it = first;
20
+ step = Math.floor(count / 2);
21
+ it = it + step;
22
+
23
+ if (comparator(target, elements[it]) >= 0) {
24
+ first = ++it;
25
+ count = count - (step + 1);
26
+ } else {
27
+ count = step;
28
+ }
29
+ }
30
+
31
+ return first ? first - 1 : null;
32
+ }
33
+
34
+ module.exports = {
35
+ greatestLowerBound
36
+ };
@@ -0,0 +1,36 @@
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
+ function greatestLowerBound<T, U>(
14
+ elements: $ReadOnlyArray<T>,
15
+ target: U,
16
+ comparator: (U, T) => number,
17
+ ): ?number {
18
+ let first = 0;
19
+ let it = 0;
20
+ let count = elements.length;
21
+ let step;
22
+ while (count > 0) {
23
+ it = first;
24
+ step = Math.floor(count / 2);
25
+ it = it + step;
26
+ if (comparator(target, elements[it]) >= 0) {
27
+ first = ++it;
28
+ count = count - (step + 1);
29
+ } else {
30
+ count = step;
31
+ }
32
+ }
33
+ return first ? first - 1 : null;
34
+ }
35
+
36
+ module.exports = {greatestLowerBound};
@@ -0,0 +1,13 @@
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
+ // NOTE: The linter and formatter are fighting over the following lint rule.
11
+
12
+ /* eslint-disable flowtype/object-type-delimiter */
13
+ "use strict";
@@ -0,0 +1,57 @@
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
+ // NOTE: The linter and formatter are fighting over the following lint rule.
12
+ /* eslint-disable flowtype/object-type-delimiter */
13
+
14
+ 'use strict';
15
+
16
+ import type {IterationOrder, LookupBias} from './constants';
17
+ import type {Number0, Number1} from 'ob1';
18
+ export type {IterationOrder, LookupBias};
19
+ export type GeneratedOffset = {|+lines: Number0, +columns: Number0|};
20
+ export type SourcePosition = {
21
+ +source: ?string,
22
+ +line: ?Number1,
23
+ +column: ?Number0,
24
+ +name: ?string,
25
+ };
26
+ export type GeneratedPosition = {+line: Number1, +column: Number0};
27
+ export type GeneratedPositionLookup = {
28
+ +line: ?Number1,
29
+ +column: ?Number0,
30
+ +bias?: LookupBias,
31
+ };
32
+
33
+ export type Mapping = {
34
+ source: ?string,
35
+ generatedLine: Number1,
36
+ generatedColumn: Number0,
37
+ originalLine: ?Number1,
38
+ originalColumn: ?Number0,
39
+ name: ?string,
40
+ };
41
+
42
+ export interface IConsumer {
43
+ originalPositionFor(
44
+ generatedPosition: GeneratedPositionLookup,
45
+ ): SourcePosition;
46
+
47
+ generatedMappings(): Iterable<Mapping>;
48
+
49
+ eachMapping(
50
+ callback: (mapping: Mapping) => mixed,
51
+ context?: mixed,
52
+ order?: IterationOrder,
53
+ ): void;
54
+
55
+ // flowlint unsafe-getters-setters:off
56
+ get file(): ?string;
57
+ }