@depup/webpack-sources 3.3.4-depup.0 → 3.6.0-depup.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 (53) hide show
  1. package/README.md +2 -2
  2. package/changes.json +1 -1
  3. package/lib/CachedSource.js +257 -63
  4. package/lib/CompatSource.js +42 -1
  5. package/lib/ConcatSource.js +100 -28
  6. package/lib/OriginalSource.js +111 -45
  7. package/lib/PrefixSource.js +60 -11
  8. package/lib/RawSource.js +85 -29
  9. package/lib/ReplaceSource.js +269 -73
  10. package/lib/SizeOnlySource.js +10 -1
  11. package/lib/Source.js +39 -0
  12. package/lib/SourceMapSource.js +92 -10
  13. package/lib/helpers/createMappingsSerializer.js +307 -54
  14. package/lib/helpers/getFromStreamChunks.js +165 -73
  15. package/lib/helpers/getGeneratedSourceInfo.js +7 -4
  16. package/lib/helpers/readMappings.js +6 -3
  17. package/lib/helpers/scopes.js +438 -0
  18. package/lib/helpers/splitIntoLines.js +10 -9
  19. package/lib/helpers/splitIntoPotentialTokens.js +99 -26
  20. package/lib/helpers/streamAndGetSourceAndMap.js +61 -22
  21. package/lib/helpers/streamChunks.js +3 -2
  22. package/lib/helpers/streamChunksOfCombinedSourceMap.js +7 -3
  23. package/lib/helpers/streamChunksOfRawSource.js +23 -15
  24. package/lib/helpers/streamChunksOfSourceMap.js +50 -42
  25. package/lib/index.js +3 -0
  26. package/package.json +34 -23
  27. package/types/CachedSource.d.ts +192 -0
  28. package/types/CompatSource.d.ts +87 -0
  29. package/types/ConcatSource.d.ts +75 -0
  30. package/types/OriginalSource.d.ts +87 -0
  31. package/types/PrefixSource.d.ts +59 -0
  32. package/types/RawSource.d.ts +75 -0
  33. package/types/ReplaceSource.d.ts +107 -0
  34. package/types/SizeOnlySource.d.ts +24 -0
  35. package/types/Source.d.ts +189 -0
  36. package/types/SourceMapSource.d.ts +136 -0
  37. package/types/helpers/createMappingsSerializer.d.ts +60 -0
  38. package/types/helpers/getFromStreamChunks.d.ts +16 -0
  39. package/types/helpers/getGeneratedSourceInfo.d.ts +31 -0
  40. package/types/helpers/getName.d.ts +15 -0
  41. package/types/helpers/getSource.d.ts +15 -0
  42. package/types/helpers/readMappings.d.ts +19 -0
  43. package/types/helpers/scopes.d.ts +119 -0
  44. package/types/helpers/splitIntoLines.d.ts +6 -0
  45. package/types/helpers/splitIntoPotentialTokens.d.ts +37 -0
  46. package/types/helpers/streamAndGetSourceAndMap.d.ts +39 -0
  47. package/types/helpers/streamChunks.d.ts +56 -0
  48. package/types/helpers/streamChunksOfCombinedSourceMap.d.ts +42 -0
  49. package/types/helpers/streamChunksOfRawSource.d.ts +16 -0
  50. package/types/helpers/streamChunksOfSourceMap.d.ts +19 -0
  51. package/types/helpers/stringBufferUtils.d.ts +55 -0
  52. package/types/index.d.ts +50 -0
  53. package/types.d.ts +42 -439
@@ -0,0 +1,189 @@
1
+ export = Source;
2
+ /**
3
+ * @typedef {object} MapOptions
4
+ * @property {boolean=} columns need columns?
5
+ * @property {boolean=} module is module
6
+ * @property {boolean=} scopes emit the `scopes` field from the bindings the sources declare
7
+ */
8
+ /**
9
+ * @typedef {object} RawSourceMap
10
+ * @property {number} version version
11
+ * @property {string[]} sources sources
12
+ * @property {string[]} names names
13
+ * @property {string=} sourceRoot source root
14
+ * @property {string[]=} sourcesContent sources content
15
+ * @property {string} mappings mappings
16
+ * @property {string} file file
17
+ * @property {string=} debugId debug id
18
+ * @property {number[]=} ignoreList ignore list
19
+ * @property {string=} scopes encoded `scopes` field of the "Scopes" proposal
20
+ */
21
+ /** @typedef {string | Buffer} SourceValue */
22
+ /**
23
+ * @typedef {object} SourceAndMap
24
+ * @property {SourceValue} source source
25
+ * @property {RawSourceMap | null} map map
26
+ */
27
+ /**
28
+ * @typedef {object} HashLike
29
+ * @property {(data: string | Buffer, inputEncoding?: string) => HashLike} update make hash update
30
+ * @property {(encoding?: string) => string | Buffer} digest get hash digest
31
+ */
32
+ /**
33
+ * @typedef {object} ClearCacheOptions
34
+ * @property {boolean=} maps drop cached source maps (default `true`)
35
+ * @property {boolean=} source drop cached source/buffer copies (default `true`)
36
+ * @property {boolean=} parsedMap drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable.
37
+ */
38
+ declare class Source {
39
+ /**
40
+ * @returns {SourceValue} source
41
+ */
42
+ source(): SourceValue;
43
+ /**
44
+ * @returns {Buffer} buffer
45
+ */
46
+ buffer(): Buffer;
47
+ /**
48
+ * @returns {Buffer[]} buffers
49
+ */
50
+ buffers(): Buffer[];
51
+ /**
52
+ * @returns {number} size
53
+ */
54
+ size(): number;
55
+ /**
56
+ * @param {MapOptions=} options map options
57
+ * @returns {RawSourceMap | null} map
58
+ */
59
+ map(options?: MapOptions | undefined): RawSourceMap | null;
60
+ /**
61
+ * @param {MapOptions=} options map options
62
+ * @returns {SourceAndMap} source and map
63
+ */
64
+ sourceAndMap(options?: MapOptions | undefined): SourceAndMap;
65
+ /**
66
+ * @param {HashLike} hash hash
67
+ * @returns {void}
68
+ */
69
+ updateHash(hash: HashLike): void;
70
+ /**
71
+ * Release cached data held by this source. clearCache is a memory
72
+ * hint: it never affects correctness or output, only how expensive
73
+ * the next read is. Subclasses override; the base is a no-op so
74
+ * every Source supports the call. Composite sources always recurse
75
+ * into wrapped sources. When the same child is reachable via several
76
+ * parents (e.g. modules shared across webpack chunks), pass a shared
77
+ * `visited` WeakSet so each subtree is walked at most once.
78
+ * Not safe to call concurrently with source/map/sourceAndMap/
79
+ * streamChunks/updateHash on the same instance.
80
+ * @param {ClearCacheOptions=} options selectors
81
+ * @param {WeakSet<Source>=} visited de-duplication set shared across calls
82
+ * @returns {void}
83
+ */
84
+ clearCache(
85
+ options?: ClearCacheOptions | undefined,
86
+ visited?: WeakSet<Source> | undefined,
87
+ ): void;
88
+ }
89
+ declare namespace Source {
90
+ export {
91
+ MapOptions,
92
+ RawSourceMap,
93
+ SourceValue,
94
+ SourceAndMap,
95
+ HashLike,
96
+ ClearCacheOptions,
97
+ };
98
+ }
99
+ type MapOptions = {
100
+ /**
101
+ * need columns?
102
+ */
103
+ columns?: boolean | undefined;
104
+ /**
105
+ * is module
106
+ */
107
+ module?: boolean | undefined;
108
+ /**
109
+ * emit the `scopes` field from the bindings the sources declare
110
+ */
111
+ scopes?: boolean | undefined;
112
+ };
113
+ type RawSourceMap = {
114
+ /**
115
+ * version
116
+ */
117
+ version: number;
118
+ /**
119
+ * sources
120
+ */
121
+ sources: string[];
122
+ /**
123
+ * names
124
+ */
125
+ names: string[];
126
+ /**
127
+ * source root
128
+ */
129
+ sourceRoot?: string | undefined;
130
+ /**
131
+ * sources content
132
+ */
133
+ sourcesContent?: string[] | undefined;
134
+ /**
135
+ * mappings
136
+ */
137
+ mappings: string;
138
+ /**
139
+ * file
140
+ */
141
+ file: string;
142
+ /**
143
+ * debug id
144
+ */
145
+ debugId?: string | undefined;
146
+ /**
147
+ * ignore list
148
+ */
149
+ ignoreList?: number[] | undefined;
150
+ /**
151
+ * encoded `scopes` field of the "Scopes" proposal
152
+ */
153
+ scopes?: string | undefined;
154
+ };
155
+ type SourceValue = string | Buffer;
156
+ type SourceAndMap = {
157
+ /**
158
+ * source
159
+ */
160
+ source: SourceValue;
161
+ /**
162
+ * map
163
+ */
164
+ map: RawSourceMap | null;
165
+ };
166
+ type HashLike = {
167
+ /**
168
+ * make hash update
169
+ */
170
+ update: (data: string | Buffer, inputEncoding?: string) => HashLike;
171
+ /**
172
+ * get hash digest
173
+ */
174
+ digest: (encoding?: string) => string | Buffer;
175
+ };
176
+ type ClearCacheOptions = {
177
+ /**
178
+ * drop cached source maps (default `true`)
179
+ */
180
+ maps?: boolean | undefined;
181
+ /**
182
+ * drop cached source/buffer copies (default `true`)
183
+ */
184
+ source?: boolean | undefined;
185
+ /**
186
+ * drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable.
187
+ */
188
+ parsedMap?: boolean | undefined;
189
+ };
@@ -0,0 +1,136 @@
1
+ export = SourceMapSource;
2
+ /** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */
3
+ /** @typedef {import("./Source").HashLike} HashLike */
4
+ /** @typedef {import("./Source").MapOptions} MapOptions */
5
+ /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
6
+ /** @typedef {import("./Source").SourceAndMap} SourceAndMap */
7
+ /** @typedef {import("./Source").SourceValue} SourceValue */
8
+ /** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
9
+ /** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */
10
+ /** @typedef {import("./helpers/streamChunks").OnName} OnName */
11
+ /** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
12
+ /** @typedef {import("./helpers/streamChunks").Options} Options */
13
+ declare class SourceMapSource extends Source {
14
+ /**
15
+ * @param {string | Buffer} value value
16
+ * @param {string} name name
17
+ * @param {string | Buffer | RawSourceMap=} sourceMap source map
18
+ * @param {SourceValue=} originalSource original source
19
+ * @param {(null | string | Buffer | RawSourceMap)=} innerSourceMap inner source map
20
+ * @param {boolean=} removeOriginalSource do remove original source
21
+ */
22
+ constructor(
23
+ value: string | Buffer,
24
+ name: string,
25
+ sourceMap?: (string | Buffer | RawSourceMap) | undefined,
26
+ originalSource?: SourceValue | undefined,
27
+ innerSourceMap?: (null | string | Buffer | RawSourceMap) | undefined,
28
+ removeOriginalSource?: boolean | undefined,
29
+ );
30
+ /**
31
+ * @type {undefined | string}
32
+ */
33
+ _valueAsString: undefined | string;
34
+ /**
35
+ * @type {undefined | Buffer}
36
+ */
37
+ _valueAsBuffer: undefined | Buffer;
38
+ _name: string;
39
+ _hasSourceMap: boolean;
40
+ /**
41
+ * @type {undefined | RawSourceMap}
42
+ */
43
+ _sourceMapAsObject: undefined | RawSourceMap;
44
+ /**
45
+ * @type {undefined | string}
46
+ */
47
+ _sourceMapAsString: undefined | string;
48
+ /**
49
+ * @type {undefined | Buffer}
50
+ */
51
+ _sourceMapAsBuffer: undefined | Buffer;
52
+ _hasOriginalSource: boolean;
53
+ _originalSourceAsString: string | undefined;
54
+ _originalSourceAsBuffer: Buffer<ArrayBufferLike> | undefined;
55
+ _hasInnerSourceMap: boolean;
56
+ /**
57
+ * @type {undefined | RawSourceMap}
58
+ */
59
+ _innerSourceMapAsObject: undefined | RawSourceMap;
60
+ /**
61
+ * @type {undefined | string}
62
+ */
63
+ _innerSourceMapAsString: undefined | string;
64
+ /**
65
+ * @type {undefined | Buffer}
66
+ */
67
+ _innerSourceMapAsBuffer: undefined | Buffer;
68
+ _removeOriginalSource: boolean | undefined;
69
+ /**
70
+ * @returns {[Buffer, string, Buffer, Buffer | undefined, Buffer | undefined, boolean | undefined]} args
71
+ */
72
+ getArgsAsBuffers(): [
73
+ Buffer,
74
+ string,
75
+ Buffer,
76
+ Buffer | undefined,
77
+ Buffer | undefined,
78
+ boolean | undefined,
79
+ ];
80
+ _cachedSize: number | undefined;
81
+ /**
82
+ * @returns {undefined | Buffer} buffer
83
+ */
84
+ _originalSourceBuffer(): undefined | Buffer;
85
+ _originalSourceString(): string | undefined;
86
+ _innerSourceMapObject(): any;
87
+ _innerSourceMapBuffer(): Buffer<ArrayBufferLike> | undefined;
88
+ /**
89
+ * @returns {string} result
90
+ */
91
+ _innerSourceMapString(): string;
92
+ _sourceMapObject(): any;
93
+ _sourceMapBuffer(): Buffer<ArrayBufferLike>;
94
+ _sourceMapString(): string;
95
+ /**
96
+ * @param {Options} options options
97
+ * @param {OnChunk} onChunk called for each chunk of code
98
+ * @param {OnSource} onSource called for each source
99
+ * @param {OnName} onName called for each name
100
+ * @returns {GeneratedSourceInfo} generated source info
101
+ */
102
+ streamChunks(
103
+ options: Options,
104
+ onChunk: OnChunk,
105
+ onSource: OnSource,
106
+ onName: OnName,
107
+ ): GeneratedSourceInfo;
108
+ }
109
+ declare namespace SourceMapSource {
110
+ export {
111
+ ClearCacheOptions,
112
+ HashLike,
113
+ MapOptions,
114
+ RawSourceMap,
115
+ SourceAndMap,
116
+ SourceValue,
117
+ GeneratedSourceInfo,
118
+ OnChunk,
119
+ OnName,
120
+ OnSource,
121
+ Options,
122
+ };
123
+ }
124
+ import Source = require("./Source");
125
+ type ClearCacheOptions = import("./Source").ClearCacheOptions;
126
+ type HashLike = import("./Source").HashLike;
127
+ type MapOptions = import("./Source").MapOptions;
128
+ type RawSourceMap = import("./Source").RawSourceMap;
129
+ type SourceAndMap = import("./Source").SourceAndMap;
130
+ type SourceValue = import("./Source").SourceValue;
131
+ type GeneratedSourceInfo =
132
+ import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo;
133
+ type OnChunk = import("./helpers/streamChunks").OnChunk;
134
+ type OnName = import("./helpers/streamChunks").OnName;
135
+ type OnSource = import("./helpers/streamChunks").OnSource;
136
+ type Options = import("./helpers/streamChunks").Options;
@@ -0,0 +1,60 @@
1
+ export = createMappingsSerializer;
2
+ /**
3
+ * @param {{ columns?: boolean }=} options options
4
+ * @returns {MappingsSerializer} mappings serializer
5
+ */
6
+ declare function createMappingsSerializer(
7
+ options?:
8
+ | {
9
+ columns?: boolean;
10
+ }
11
+ | undefined,
12
+ ): MappingsSerializer;
13
+ declare namespace createMappingsSerializer {
14
+ export { createMappingsWriter, MappingsSerializer, MappingsWriter };
15
+ }
16
+ /**
17
+ * @param {{ columns?: boolean }=} options options
18
+ * @returns {MappingsWriter} push-based mappings writer
19
+ */
20
+ declare function createMappingsWriter(
21
+ options?:
22
+ | {
23
+ columns?: boolean;
24
+ }
25
+ | undefined,
26
+ ): MappingsWriter;
27
+ type MappingsSerializer = (
28
+ generatedLine: number,
29
+ generatedColumn: number,
30
+ sourceIndex: number,
31
+ originalLine: number,
32
+ originalColumn: number,
33
+ nameIndex: number,
34
+ ) => string;
35
+ /**
36
+ * A push-based serializer: `add()` appends one mapping to an internal
37
+ * byte buffer, `finish()` materialises the whole `mappings` string in a
38
+ * single allocation. Compared to the string-returning
39
+ * {@link MappingsSerializer} this avoids every per-mapping intermediate
40
+ * string (each VLQ digit concatenation) plus the caller-side
41
+ * `mappings += str` cons chain — together the dominant allocation site
42
+ * of `map()` / `sourceAndMap()`.
43
+ */
44
+ type MappingsWriter = {
45
+ /**
46
+ * append one mapping
47
+ */
48
+ add: (
49
+ generatedLine: number,
50
+ generatedColumn: number,
51
+ sourceIndex: number,
52
+ originalLine: number,
53
+ originalColumn: number,
54
+ nameIndex: number,
55
+ ) => void;
56
+ /**
57
+ * materialise the mappings string
58
+ */
59
+ finish: () => string;
60
+ };
@@ -0,0 +1,16 @@
1
+ export function getMap(
2
+ source: SourceLikeWithStreamChunks,
3
+ options?: Options | undefined,
4
+ ): RawSourceMap | null;
5
+ export function getSourceAndMap(
6
+ inputSource: SourceLikeWithStreamChunks,
7
+ options?: Options | undefined,
8
+ ): SourceAndMap;
9
+ export type RawSourceMap = import("../Source").RawSourceMap;
10
+ export type SourceAndMap = import("../Source").SourceAndMap;
11
+ export type Options = import("./streamChunks").Options;
12
+ export type StreamChunksFunction =
13
+ import("./streamChunks").StreamChunksFunction;
14
+ export type SourceLikeWithStreamChunks = {
15
+ streamChunks: StreamChunksFunction;
16
+ };
@@ -0,0 +1,31 @@
1
+ export = getGeneratedSourceInfo;
2
+ /**
3
+ * @typedef {object} GeneratedSourceInfo
4
+ * @property {number=} generatedLine generated line
5
+ * @property {number=} generatedColumn generated column
6
+ * @property {string=} source source
7
+ */
8
+ /**
9
+ * @param {string | undefined} source source
10
+ * @returns {GeneratedSourceInfo} source info
11
+ */
12
+ declare function getGeneratedSourceInfo(
13
+ source: string | undefined,
14
+ ): GeneratedSourceInfo;
15
+ declare namespace getGeneratedSourceInfo {
16
+ export { GeneratedSourceInfo };
17
+ }
18
+ type GeneratedSourceInfo = {
19
+ /**
20
+ * generated line
21
+ */
22
+ generatedLine?: number | undefined;
23
+ /**
24
+ * generated column
25
+ */
26
+ generatedColumn?: number | undefined;
27
+ /**
28
+ * source
29
+ */
30
+ source?: string | undefined;
31
+ };
@@ -0,0 +1,15 @@
1
+ export = getName;
2
+ /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
3
+ /**
4
+ * @param {RawSourceMap} sourceMap source map
5
+ * @param {number} index index
6
+ * @returns {string | undefined | null} name
7
+ */
8
+ declare function getName(
9
+ sourceMap: RawSourceMap,
10
+ index: number,
11
+ ): string | undefined | null;
12
+ declare namespace getName {
13
+ export { RawSourceMap };
14
+ }
15
+ type RawSourceMap = import("../Source").RawSourceMap;
@@ -0,0 +1,15 @@
1
+ export = getSource;
2
+ /** @typedef {import("../Source").RawSourceMap} RawSourceMap */
3
+ /**
4
+ * @param {RawSourceMap} sourceMap source map
5
+ * @param {number} index index
6
+ * @returns {string | null} name
7
+ */
8
+ declare function getSource(
9
+ sourceMap: RawSourceMap,
10
+ index: number,
11
+ ): string | null;
12
+ declare namespace getSource {
13
+ export { RawSourceMap };
14
+ }
15
+ type RawSourceMap = import("../Source").RawSourceMap;
@@ -0,0 +1,19 @@
1
+ export = readMappings;
2
+ /** @typedef {(generatedLine: number, generatedColumn: number, sourceIndex: number, originalLine: number, originalColumn: number, nameIndex: number) => void} OnMapping */
3
+ /**
4
+ * @param {string} mappings the mappings string
5
+ * @param {OnMapping} onMapping called for each mapping
6
+ * @returns {void}
7
+ */
8
+ declare function readMappings(mappings: string, onMapping: OnMapping): void;
9
+ declare namespace readMappings {
10
+ export { OnMapping };
11
+ }
12
+ type OnMapping = (
13
+ generatedLine: number,
14
+ generatedColumn: number,
15
+ sourceIndex: number,
16
+ originalLine: number,
17
+ originalColumn: number,
18
+ nameIndex: number,
19
+ ) => void;
@@ -0,0 +1,119 @@
1
+ export type RawSourceMap = import("../Source").RawSourceMap;
2
+ export type ScopeBindings = import("./streamChunks").ScopeBindings;
3
+ /**
4
+ * A generated or original position, both counted from zero.
5
+ */
6
+ export type ScopePosition = {
7
+ /**
8
+ * line
9
+ */
10
+ line: number;
11
+ /**
12
+ * column
13
+ */
14
+ column: number;
15
+ };
16
+ /**
17
+ * One source's scope, and the span of generated code it explains.
18
+ */
19
+ export type SourceScope = {
20
+ /**
21
+ * index into the map's `sources`
22
+ */
23
+ sourceIndex: number;
24
+ /**
25
+ * the names the source declares
26
+ */
27
+ variables: string[];
28
+ /**
29
+ * the generated expression each name evaluates to
30
+ */
31
+ values: string[];
32
+ /**
33
+ * end of the original scope, exclusive
34
+ */
35
+ originalEnd: ScopePosition;
36
+ /**
37
+ * start of each generated range, inclusive
38
+ */
39
+ rangeStarts: ScopePosition[];
40
+ /**
41
+ * end of each generated range, exclusive
42
+ */
43
+ rangeEnds: ScopePosition[];
44
+ };
45
+ /**
46
+ * Adds the `scopes` field of the "Scopes" proposal to a source map, naming for
47
+ * each source the bindings a debugger cannot resolve on its own and the
48
+ * generated expression each one evaluates to. Does nothing when no source
49
+ * contributes a binding.
50
+ * @param {RawSourceMap} sourceMap the map to extend in place
51
+ * @param {(sourceIndex: number) => Map<string, string> | undefined} getBindings binding expressions per source
52
+ * @returns {void}
53
+ */
54
+ export function addScopesToSourceMap(
55
+ sourceMap: RawSourceMap,
56
+ getBindings: (sourceIndex: number) => Map<string, string> | undefined,
57
+ ): void;
58
+ /**
59
+ * Groups a finished map's segments into one entry per source. Prefer the
60
+ * collector when the segments are still being written, which saves decoding
61
+ * back what was just encoded.
62
+ * @param {string} mappings the map's `mappings` field
63
+ * @param {number} sourceCount number of entries in the map's `sources`
64
+ * @returns {SourceScope[]} one entry per source that the mappings reach, in source order
65
+ */
66
+ export function collectSourceScopes(
67
+ mappings: string,
68
+ sourceCount: number,
69
+ ): SourceScope[];
70
+ /**
71
+ * Collects, segment by segment, the generated runs each source explains and how
72
+ * far into it the map reaches. Both lines are counted from zero, so a caller
73
+ * whose lines start at one subtracts before feeding a segment in.
74
+ * @param {number=} sourceCount number of entries in the map's `sources`, when known
75
+ * @returns {{ add: (generatedLine: number, generatedColumn: number, sourceIndex: number, originalLine: number) => void, finish: (lastLine: number, lastColumn?: number) => SourceScope[] }} collector
76
+ */
77
+ export function createScopeCollector(sourceCount?: number | undefined): {
78
+ add: (
79
+ generatedLine: number,
80
+ generatedColumn: number,
81
+ sourceIndex: number,
82
+ originalLine: number,
83
+ ) => void;
84
+ finish: (lastLine: number, lastColumn?: number) => SourceScope[];
85
+ };
86
+ /**
87
+ * Builds the `scopes` field while a map is being written, so the segments are
88
+ * read as they are produced rather than decoded back out of `mappings`. Lines
89
+ * are the one-based ones the chunk stream reports; `finish` takes the position
90
+ * the generated code ends at, where the last range closes.
91
+ * @returns {{ add: (generatedLine: number, generatedColumn: number, sourceIndex: number, originalLine: number) => void, addSource: (sourceIndex: number, scopeBindings?: ScopeBindings) => void, finish: (map: RawSourceMap, generatedLine: number, generatedColumn?: number) => void }} writer
92
+ */
93
+ export function createScopesWriter(): {
94
+ add: (
95
+ generatedLine: number,
96
+ generatedColumn: number,
97
+ sourceIndex: number,
98
+ originalLine: number,
99
+ ) => void;
100
+ addSource: (sourceIndex: number, scopeBindings?: ScopeBindings) => void;
101
+ finish: (
102
+ map: RawSourceMap,
103
+ generatedLine: number,
104
+ generatedColumn?: number,
105
+ ) => void;
106
+ };
107
+ /**
108
+ * Encodes the scope tree into the `scopes` field of the proposal, appending any
109
+ * name it needs to the map's `names`.
110
+ * @param {SourceScope[]} scopes the scopes to encode, in source order
111
+ * @param {number} sourceCount number of entries in the map's `sources`
112
+ * @param {string[]} names the map's `names`, extended in place
113
+ * @returns {string} the encoded `scopes` field
114
+ */
115
+ export function encodeScopes(
116
+ scopes: SourceScope[],
117
+ sourceCount: number,
118
+ names: string[],
119
+ ): string;
@@ -0,0 +1,6 @@
1
+ export = splitIntoLines;
2
+ /**
3
+ * @param {string} str string
4
+ * @returns {string[]} array of string separated by lines
5
+ */
6
+ declare function splitIntoLines(str: string): string[];
@@ -0,0 +1,37 @@
1
+ export = splitIntoPotentialTokens;
2
+ /**
3
+ * Array-returning variant. Kept as a standalone loop rather than wrapping
4
+ * `eachPotentialToken` with a per-token callback: the callback indirection
5
+ * measurably slows this hot scan (V8 can no longer inline the slice/push),
6
+ * and the two only share the same small, well-tested classification table.
7
+ * @param {string} str string
8
+ * @returns {string[] | null} array of string separated by potential tokens
9
+ */
10
+ declare function splitIntoPotentialTokens(str: string): string[] | null;
11
+ declare namespace splitIntoPotentialTokens {
12
+ export { eachPotentialToken, OnPotentialToken };
13
+ }
14
+ /**
15
+ * @callback OnPotentialToken
16
+ * @param {number} start start offset (inclusive)
17
+ * @param {number} end end offset (exclusive)
18
+ * @param {boolean} newline whether the token ends with a `\n`
19
+ * @returns {void}
20
+ */
21
+ /**
22
+ * Streaming core: report each potential token by its `[start, end)` bounds
23
+ * instead of materialising substrings. The single real consumer
24
+ * (`OriginalSource.streamChunks`) slices on demand — and skips slicing
25
+ * entirely when emitting the final source (the `map()` / `sourceAndMap()`
26
+ * paths, which discard the chunk text) — so this avoids both the
27
+ * intermediate results array and every per-token `String.slice` allocation
28
+ * in the dominant case.
29
+ * @param {string} str string
30
+ * @param {OnPotentialToken} onToken called for each token
31
+ * @returns {void}
32
+ */
33
+ declare function eachPotentialToken(
34
+ str: string,
35
+ onToken: OnPotentialToken,
36
+ ): void;
37
+ type OnPotentialToken = (start: number, end: number, newline: boolean) => void;
@@ -0,0 +1,39 @@
1
+ export = streamAndGetSourceAndMap;
2
+ /**
3
+ * @param {SourceMaybeWithStreamChunksFunction} inputSource input source
4
+ * @param {Options} options options
5
+ * @param {OnChunk} onChunk on chunk
6
+ * @param {OnSource} onSource on source
7
+ * @param {OnName} onName on name
8
+ * @returns {{ result: GeneratedSourceInfo, source: string, map: RawSourceMap | null }} result
9
+ */
10
+ declare function streamAndGetSourceAndMap(
11
+ inputSource: SourceMaybeWithStreamChunksFunction,
12
+ options: Options,
13
+ onChunk: OnChunk,
14
+ onSource: OnSource,
15
+ onName: OnName,
16
+ ): {
17
+ result: GeneratedSourceInfo;
18
+ source: string;
19
+ map: RawSourceMap | null;
20
+ };
21
+ declare namespace streamAndGetSourceAndMap {
22
+ export {
23
+ RawSourceMap,
24
+ GeneratedSourceInfo,
25
+ OnChunk,
26
+ OnName,
27
+ OnSource,
28
+ Options,
29
+ SourceMaybeWithStreamChunksFunction,
30
+ };
31
+ }
32
+ type RawSourceMap = import("../Source").RawSourceMap;
33
+ type GeneratedSourceInfo = import("./streamChunks").GeneratedSourceInfo;
34
+ type OnChunk = import("./streamChunks").OnChunk;
35
+ type OnName = import("./streamChunks").OnName;
36
+ type OnSource = import("./streamChunks").OnSource;
37
+ type Options = import("./streamChunks").Options;
38
+ type SourceMaybeWithStreamChunksFunction =
39
+ import("./streamChunks").SourceMaybeWithStreamChunksFunction;