metro-source-map 0.83.1 → 0.83.2

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 (55) hide show
  1. package/package.json +3 -3
  2. package/src/B64Builder.d.ts +47 -0
  3. package/src/B64Builder.js +10 -3
  4. package/src/B64Builder.js.flow +2 -6
  5. package/src/BundleBuilder.d.ts +43 -0
  6. package/src/BundleBuilder.js +6 -4
  7. package/src/BundleBuilder.js.flow +2 -6
  8. package/src/Consumer/AbstractConsumer.d.ts +37 -0
  9. package/src/Consumer/AbstractConsumer.js +17 -10
  10. package/src/Consumer/AbstractConsumer.js.flow +4 -8
  11. package/src/Consumer/DelegatingConsumer.d.ts +47 -0
  12. package/src/Consumer/DelegatingConsumer.js +15 -13
  13. package/src/Consumer/DelegatingConsumer.js.flow +6 -9
  14. package/src/Consumer/MappingsConsumer.d.ts +43 -0
  15. package/src/Consumer/MappingsConsumer.js +68 -51
  16. package/src/Consumer/MappingsConsumer.js.flow +14 -15
  17. package/src/Consumer/SectionsConsumer.d.ts +40 -0
  18. package/src/Consumer/SectionsConsumer.js +38 -24
  19. package/src/Consumer/SectionsConsumer.js.flow +11 -12
  20. package/src/Consumer/constants.d.ts +39 -0
  21. package/src/Consumer/constants.js +23 -20
  22. package/src/Consumer/constants.js.flow +8 -5
  23. package/src/Consumer/createConsumer.d.ts +15 -0
  24. package/src/Consumer/createConsumer.js +14 -8
  25. package/src/Consumer/createConsumer.js.flow +5 -9
  26. package/src/Consumer/index.d.ts +16 -0
  27. package/src/Consumer/index.js +11 -2
  28. package/src/Consumer/index.js.flow +2 -4
  29. package/src/Consumer/normalizeSourcePath.d.ts +15 -0
  30. package/src/Consumer/normalizeSourcePath.js +13 -5
  31. package/src/Consumer/normalizeSourcePath.js.flow +2 -6
  32. package/src/Consumer/positionMath.d.ts +25 -0
  33. package/src/Consumer/positionMath.js +14 -12
  34. package/src/Consumer/positionMath.js.flow +4 -8
  35. package/src/Consumer/search.d.ts +15 -0
  36. package/src/Consumer/search.js +4 -3
  37. package/src/Consumer/search.js.flow +1 -5
  38. package/src/Consumer/types.d.ts +57 -0
  39. package/src/Consumer/{types.flow.js.flow → types.js.flow} +0 -2
  40. package/src/Generator.d.ts +107 -0
  41. package/src/Generator.js +16 -13
  42. package/src/Generator.js.flow +2 -6
  43. package/src/composeSourceMaps.d.ts +16 -0
  44. package/src/composeSourceMaps.js +19 -11
  45. package/src/composeSourceMaps.js.flow +11 -11
  46. package/src/encode.d.ts +66 -0
  47. package/src/encode.js +4 -1
  48. package/src/encode.js.flow +9 -5
  49. package/src/generateFunctionMap.d.ts +45 -0
  50. package/src/generateFunctionMap.js +51 -25
  51. package/src/generateFunctionMap.js.flow +21 -22
  52. package/src/source-map.d.ts +130 -36
  53. package/src/source-map.js +77 -25
  54. package/src/source-map.js.flow +39 -14
  55. /package/src/Consumer/{types.flow.js → types.js} +0 -0
@@ -8,54 +8,148 @@
8
8
  * @oncall react_native
9
9
  */
10
10
 
11
- export type GeneratedCodeMapping = [number, number];
12
- export type SourceMapping = [number, number, number, number];
13
- export type SourceMappingWithName = [number, number, number, number, string];
11
+ import type {IConsumer} from './Consumer/types';
14
12
 
13
+ import {BundleBuilder, createIndexMap} from './BundleBuilder';
14
+ import composeSourceMaps from './composeSourceMaps';
15
+ import Consumer from './Consumer';
16
+ import normalizeSourcePath from './Consumer/normalizeSourcePath';
17
+ import {
18
+ functionMapBabelPlugin,
19
+ generateFunctionMap,
20
+ } from './generateFunctionMap';
21
+ import Generator from './Generator';
22
+
23
+ export type {IConsumer};
24
+ type GeneratedCodeMapping = [number, number];
25
+ type SourceMapping = [number, number, number, number];
26
+ type SourceMappingWithName = [number, number, number, number, string];
15
27
  export type MetroSourceMapSegmentTuple =
16
28
  | SourceMappingWithName
17
29
  | SourceMapping
18
30
  | GeneratedCodeMapping;
19
-
20
- export interface HermesFunctionOffsets {
21
- [id: number]: ReadonlyArray<number>;
22
- }
23
-
24
- export type FBSourcesArray = ReadonlyArray<FBSourceMetadata | null>;
25
- export type FBSourceMetadata = [FBSourceFunctionMap | null];
26
- export interface FBSourceFunctionMap {
31
+ export type HermesFunctionOffsets = {
32
+ [$$Key$$: number]: ReadonlyArray<number>;
33
+ };
34
+ export type FBSourcesArray = ReadonlyArray<null | undefined | FBSourceMetadata>;
35
+ export type FBSourceMetadata = [null | undefined | FBSourceFunctionMap];
36
+ export type FBSourceFunctionMap = {
27
37
  readonly names: ReadonlyArray<string>;
28
38
  readonly mappings: string;
29
- }
30
-
31
- export interface FBSegmentMap {
32
- [id: string]: MixedSourceMap;
33
- }
34
-
35
- export interface BasicSourceMap {
39
+ };
40
+ export type BabelSourceMapSegment = Readonly<{
41
+ generated: Readonly<{column: number; line: number}>;
42
+ original?: Readonly<{column: number; line: number}>;
43
+ source?: null | undefined | string;
44
+ name?: null | undefined | string;
45
+ }>;
46
+ export type FBSegmentMap = {[id: string]: MixedSourceMap};
47
+ export type BasicSourceMap = {
36
48
  readonly file?: string;
37
49
  readonly mappings: string;
38
- readonly names: string[];
50
+ readonly names: Array<string>;
39
51
  readonly sourceRoot?: string;
40
- readonly sources: string[];
41
- readonly sourcesContent?: Array<string | undefined>;
52
+ readonly sources: Array<string>;
53
+ readonly sourcesContent?: Array<null | undefined | string>;
42
54
  readonly version: number;
43
- }
44
-
45
- export interface IndexMapSection {
55
+ readonly x_facebook_offsets?: Array<number>;
56
+ readonly x_metro_module_paths?: Array<string>;
57
+ readonly x_facebook_sources?: FBSourcesArray;
58
+ readonly x_facebook_segments?: FBSegmentMap;
59
+ readonly x_hermes_function_offsets?: HermesFunctionOffsets;
60
+ readonly x_google_ignoreList?: Array<number>;
61
+ };
62
+ export type IndexMapSection = {
46
63
  map: IndexMap | BasicSourceMap;
47
- offset: {
48
- line: number;
49
- column: number;
50
- };
51
- }
52
-
53
- export interface IndexMap {
64
+ offset: {line: number; column: number};
65
+ };
66
+ export type IndexMap = {
54
67
  readonly file?: string;
55
- readonly mappings?: unknown;
56
- readonly sourcesContent?: unknown;
57
- readonly sections: IndexMapSection[];
68
+ readonly mappings?: void;
69
+ readonly sourcesContent?: void;
70
+ readonly sections: Array<IndexMapSection>;
58
71
  readonly version: number;
59
- }
60
-
72
+ readonly x_facebook_offsets?: Array<number>;
73
+ readonly x_metro_module_paths?: Array<string>;
74
+ readonly x_facebook_sources?: void;
75
+ readonly x_facebook_segments?: FBSegmentMap;
76
+ readonly x_hermes_function_offsets?: HermesFunctionOffsets;
77
+ readonly x_google_ignoreList?: void;
78
+ };
61
79
  export type MixedSourceMap = IndexMap | BasicSourceMap;
80
+ /**
81
+ * Creates a source map from modules with "raw mappings", i.e. an array of
82
+ * tuples with either 2, 4, or 5 elements:
83
+ * generated line, generated column, source line, source line, symbol name.
84
+ * Accepts an `offsetLines` argument in case modules' code is to be offset in
85
+ * the resulting bundle, e.g. by some prefix code.
86
+ */
87
+ declare function fromRawMappings(
88
+ modules: ReadonlyArray<{
89
+ readonly map: null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>;
90
+ readonly functionMap: null | undefined | FBSourceFunctionMap;
91
+ readonly path: string;
92
+ readonly source: string;
93
+ readonly code: string;
94
+ readonly isIgnored: boolean;
95
+ readonly lineCount?: number;
96
+ }>,
97
+ offsetLines?: number,
98
+ ): Generator;
99
+ declare function fromRawMappingsNonBlocking(
100
+ modules: ReadonlyArray<{
101
+ readonly map: null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>;
102
+ readonly functionMap: null | undefined | FBSourceFunctionMap;
103
+ readonly path: string;
104
+ readonly source: string;
105
+ readonly code: string;
106
+ readonly isIgnored: boolean;
107
+ readonly lineCount?: number;
108
+ }>,
109
+ offsetLines?: number,
110
+ ): Promise<Generator>;
111
+ /**
112
+ * Transforms a standard source map object into a Raw Mappings object, to be
113
+ * used across the bundler.
114
+ */
115
+ declare function toBabelSegments(
116
+ sourceMap: BasicSourceMap,
117
+ ): Array<BabelSourceMapSegment>;
118
+ declare function toSegmentTuple(
119
+ mapping: BabelSourceMapSegment,
120
+ ): MetroSourceMapSegmentTuple;
121
+ export {
122
+ BundleBuilder,
123
+ composeSourceMaps,
124
+ Consumer,
125
+ createIndexMap,
126
+ generateFunctionMap,
127
+ fromRawMappings,
128
+ fromRawMappingsNonBlocking,
129
+ functionMapBabelPlugin,
130
+ normalizeSourcePath,
131
+ toBabelSegments,
132
+ toSegmentTuple,
133
+ };
134
+ /**
135
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
136
+ * Do not add to this list.
137
+ *
138
+ * @deprecated Default import from 'metro-source-map' is deprecated, use named exports.
139
+ */
140
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: {
141
+ BundleBuilder: typeof BundleBuilder;
142
+ composeSourceMaps: typeof composeSourceMaps;
143
+ Consumer: typeof Consumer;
144
+ createIndexMap: typeof createIndexMap;
145
+ generateFunctionMap: typeof generateFunctionMap;
146
+ fromRawMappings: typeof fromRawMappings;
147
+ fromRawMappingsNonBlocking: typeof fromRawMappingsNonBlocking;
148
+ functionMapBabelPlugin: typeof functionMapBabelPlugin;
149
+ normalizeSourcePath: typeof normalizeSourcePath;
150
+ toBabelSegments: typeof toBabelSegments;
151
+ toSegmentTuple: typeof toSegmentTuple;
152
+ };
153
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
154
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
155
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/src/source-map.js CHANGED
@@ -1,18 +1,70 @@
1
1
  "use strict";
2
2
 
3
- const { BundleBuilder, createIndexMap } = require("./BundleBuilder");
4
- const composeSourceMaps = require("./composeSourceMaps");
5
- const Consumer = require("./Consumer");
6
- const normalizeSourcePath = require("./Consumer/normalizeSourcePath");
7
- const {
8
- functionMapBabelPlugin,
9
- generateFunctionMap,
10
- } = require("./generateFunctionMap");
11
- const Generator = require("./Generator");
12
- const SourceMap = require("source-map");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ Object.defineProperty(exports, "BundleBuilder", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _BundleBuilder.BundleBuilder;
10
+ },
11
+ });
12
+ Object.defineProperty(exports, "Consumer", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Consumer.default;
16
+ },
17
+ });
18
+ Object.defineProperty(exports, "composeSourceMaps", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _composeSourceMaps.default;
22
+ },
23
+ });
24
+ Object.defineProperty(exports, "createIndexMap", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _BundleBuilder.createIndexMap;
28
+ },
29
+ });
30
+ exports.default = void 0;
31
+ exports.fromRawMappings = fromRawMappings;
32
+ exports.fromRawMappingsNonBlocking = fromRawMappingsNonBlocking;
33
+ Object.defineProperty(exports, "functionMapBabelPlugin", {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _generateFunctionMap.functionMapBabelPlugin;
37
+ },
38
+ });
39
+ Object.defineProperty(exports, "generateFunctionMap", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _generateFunctionMap.generateFunctionMap;
43
+ },
44
+ });
45
+ Object.defineProperty(exports, "normalizeSourcePath", {
46
+ enumerable: true,
47
+ get: function () {
48
+ return _normalizeSourcePath.default;
49
+ },
50
+ });
51
+ exports.toBabelSegments = toBabelSegments;
52
+ exports.toSegmentTuple = toSegmentTuple;
53
+ var _BundleBuilder = require("./BundleBuilder");
54
+ var _composeSourceMaps = _interopRequireDefault(require("./composeSourceMaps"));
55
+ var _Consumer = _interopRequireDefault(require("./Consumer"));
56
+ var _normalizeSourcePath = _interopRequireDefault(
57
+ require("./Consumer/normalizeSourcePath"),
58
+ );
59
+ var _generateFunctionMap = require("./generateFunctionMap");
60
+ var _Generator = _interopRequireDefault(require("./Generator"));
61
+ var _sourceMap = _interopRequireDefault(require("source-map"));
62
+ function _interopRequireDefault(e) {
63
+ return e && e.__esModule ? e : { default: e };
64
+ }
13
65
  function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
14
66
  const modulesToProcess = modules.slice();
15
- const generator = new Generator();
67
+ const generator = new _Generator.default();
16
68
  let carryOver = offsetLines;
17
69
  function processNextModule() {
18
70
  if (modulesToProcess.length === 0) {
@@ -24,7 +76,7 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
24
76
  addMappingsForFile(generator, map, mod, carryOver);
25
77
  } else if (map != null) {
26
78
  throw new Error(
27
- `Unexpected module with full source map found: ${mod.path}`
79
+ `Unexpected module with full source map found: ${mod.path}`,
28
80
  );
29
81
  }
30
82
  carryOver = carryOver + countLines(code);
@@ -58,7 +110,7 @@ function fromRawMappings(modules, offsetLines = 0) {
58
110
  generator = g;
59
111
  },
60
112
  modules,
61
- offsetLines
113
+ offsetLines,
62
114
  );
63
115
  if (generator == null) {
64
116
  throw new Error("Expected fromRawMappingsImpl() to finish synchronously.");
@@ -72,7 +124,7 @@ async function fromRawMappingsNonBlocking(modules, offsetLines = 0) {
72
124
  }
73
125
  function toBabelSegments(sourceMap) {
74
126
  const rawMappings = [];
75
- new SourceMap.SourceMapConsumer(sourceMap).eachMapping((map) => {
127
+ new _sourceMap.default.SourceMapConsumer(sourceMap).eachMapping((map) => {
76
128
  rawMappings.push(
77
129
  map.originalLine == null || map.originalColumn == null
78
130
  ? {
@@ -94,7 +146,7 @@ function toBabelSegments(sourceMap) {
94
146
  },
95
147
  source: map.source,
96
148
  name: map.name,
97
- }
149
+ },
98
150
  );
99
151
  });
100
152
  return rawMappings;
@@ -135,7 +187,7 @@ function addMapping(generator, mapping, carryOver) {
135
187
  column,
136
188
  mapping[2],
137
189
  mapping[3],
138
- mapping[4]
190
+ mapping[4],
139
191
  );
140
192
  return;
141
193
  }
@@ -143,16 +195,16 @@ function addMapping(generator, mapping, carryOver) {
143
195
  }
144
196
  const newline = /\r\n?|\n|\u2028|\u2029/g;
145
197
  const countLines = (string) => (string.match(newline) || []).length + 1;
146
- module.exports = {
147
- BundleBuilder,
148
- composeSourceMaps,
149
- Consumer,
150
- createIndexMap,
151
- generateFunctionMap,
198
+ var _default = (exports.default = {
199
+ BundleBuilder: _BundleBuilder.BundleBuilder,
200
+ composeSourceMaps: _composeSourceMaps.default,
201
+ Consumer: _Consumer.default,
202
+ createIndexMap: _BundleBuilder.createIndexMap,
203
+ generateFunctionMap: _generateFunctionMap.generateFunctionMap,
152
204
  fromRawMappings,
153
205
  fromRawMappingsNonBlocking,
154
- functionMapBabelPlugin,
155
- normalizeSourcePath,
206
+ functionMapBabelPlugin: _generateFunctionMap.functionMapBabelPlugin,
207
+ normalizeSourcePath: _normalizeSourcePath.default,
156
208
  toBabelSegments,
157
209
  toSegmentTuple,
158
- };
210
+ });
@@ -9,23 +9,20 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
12
+ import type {IConsumer} from './Consumer/types';
13
13
 
14
- import type {IConsumer} from './Consumer/types.flow';
15
- import type {BabelSourceMapSegment} from '@babel/generator';
16
-
17
- const {BundleBuilder, createIndexMap} = require('./BundleBuilder');
18
- const composeSourceMaps = require('./composeSourceMaps');
19
- const Consumer = require('./Consumer');
14
+ import {BundleBuilder, createIndexMap} from './BundleBuilder';
15
+ import composeSourceMaps from './composeSourceMaps';
16
+ import Consumer from './Consumer';
20
17
  // We need to export this for `metro-symbolicate`
21
- const normalizeSourcePath = require('./Consumer/normalizeSourcePath');
22
- const {
18
+ import normalizeSourcePath from './Consumer/normalizeSourcePath';
19
+ import {
23
20
  functionMapBabelPlugin,
24
21
  generateFunctionMap,
25
- } = require('./generateFunctionMap');
26
- const Generator = require('./Generator');
22
+ } from './generateFunctionMap';
23
+ import Generator from './Generator';
27
24
  // $FlowFixMe[untyped-import] - source-map
28
- const SourceMap = require('source-map');
25
+ import SourceMap from 'source-map';
29
26
 
30
27
  export type {IConsumer};
31
28
 
@@ -47,6 +44,14 @@ export type FBSourceFunctionMap = {
47
44
  +mappings: string,
48
45
  };
49
46
 
47
+ export type BabelSourceMapSegment = $ReadOnly<{
48
+ generated: $ReadOnly<{column: number, line: number, ...}>,
49
+ original?: $ReadOnly<{column: number, line: number, ...}>,
50
+ source?: ?string,
51
+ name?: ?string,
52
+ ...
53
+ }>;
54
+
50
55
  export type FBSegmentMap = {[id: string]: MixedSourceMap, ...};
51
56
 
52
57
  export type BasicSourceMap = {
@@ -127,7 +132,7 @@ function fromRawMappingsImpl(
127
132
  // $FlowFixMe[incompatible-use]
128
133
  const {code, map} = mod;
129
134
  if (Array.isArray(map)) {
130
- // $FlowFixMe[incompatible-call]
135
+ // $FlowFixMe[incompatible-type]
131
136
  addMappingsForFile(generator, map, mod, carryOver);
132
137
  } else if (map != null) {
133
138
  throw new Error(
@@ -332,7 +337,27 @@ const newline = /\r\n?|\n|\u2028|\u2029/g;
332
337
  const countLines = (string: string): number =>
333
338
  (string.match(newline) || []).length + 1;
334
339
 
335
- module.exports = {
340
+ export {
341
+ BundleBuilder,
342
+ composeSourceMaps,
343
+ Consumer,
344
+ createIndexMap,
345
+ generateFunctionMap,
346
+ fromRawMappings,
347
+ fromRawMappingsNonBlocking,
348
+ functionMapBabelPlugin,
349
+ normalizeSourcePath,
350
+ toBabelSegments,
351
+ toSegmentTuple,
352
+ };
353
+
354
+ /**
355
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
356
+ * Do not add to this list.
357
+ *
358
+ * @deprecated Default import from 'metro-source-map' is deprecated, use named exports.
359
+ */
360
+ export default {
336
361
  BundleBuilder,
337
362
  composeSourceMaps,
338
363
  Consumer,
File without changes