@depup/webpack-sources 3.3.4-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.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/lib/CachedSource.js +419 -0
- package/lib/CompatSource.js +109 -0
- package/lib/ConcatSource.js +398 -0
- package/lib/OriginalSource.js +202 -0
- package/lib/PrefixSource.js +162 -0
- package/lib/RawSource.js +140 -0
- package/lib/ReplaceSource.js +557 -0
- package/lib/SizeOnlySource.js +71 -0
- package/lib/Source.js +89 -0
- package/lib/SourceMapSource.js +367 -0
- package/lib/helpers/createMappingsSerializer.js +225 -0
- package/lib/helpers/getFromStreamChunks.js +159 -0
- package/lib/helpers/getGeneratedSourceInfo.js +44 -0
- package/lib/helpers/getName.js +21 -0
- package/lib/helpers/getSource.js +24 -0
- package/lib/helpers/readMappings.js +120 -0
- package/lib/helpers/splitIntoLines.js +33 -0
- package/lib/helpers/splitIntoPotentialTokens.js +53 -0
- package/lib/helpers/streamAndGetSourceAndMap.js +123 -0
- package/lib/helpers/streamChunks.js +62 -0
- package/lib/helpers/streamChunksOfCombinedSourceMap.js +366 -0
- package/lib/helpers/streamChunksOfRawSource.js +54 -0
- package/lib/helpers/streamChunksOfSourceMap.js +499 -0
- package/lib/helpers/stringBufferUtils.js +117 -0
- package/lib/index.js +120 -0
- package/package.json +71 -0
- package/types.d.ts +461 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const RawSource = require("./RawSource");
|
|
9
|
+
const Source = require("./Source");
|
|
10
|
+
const { getMap, getSourceAndMap } = require("./helpers/getFromStreamChunks");
|
|
11
|
+
const streamChunks = require("./helpers/streamChunks");
|
|
12
|
+
|
|
13
|
+
/** @typedef {import("./Source").HashLike} HashLike */
|
|
14
|
+
/** @typedef {import("./Source").MapOptions} MapOptions */
|
|
15
|
+
/** @typedef {import("./Source").RawSourceMap} RawSourceMap */
|
|
16
|
+
/** @typedef {import("./Source").SourceAndMap} SourceAndMap */
|
|
17
|
+
/** @typedef {import("./Source").SourceValue} SourceValue */
|
|
18
|
+
/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
|
|
19
|
+
/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */
|
|
20
|
+
/** @typedef {import("./helpers/streamChunks").OnName} OnName */
|
|
21
|
+
/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
|
|
22
|
+
/** @typedef {import("./helpers/streamChunks").Options} Options */
|
|
23
|
+
|
|
24
|
+
const REPLACE_REGEX = /\n(?=.|\s)/g;
|
|
25
|
+
|
|
26
|
+
class PrefixSource extends Source {
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} prefix prefix
|
|
29
|
+
* @param {string | Buffer | Source} source source
|
|
30
|
+
*/
|
|
31
|
+
constructor(prefix, source) {
|
|
32
|
+
super();
|
|
33
|
+
/**
|
|
34
|
+
* @private
|
|
35
|
+
* @type {string}
|
|
36
|
+
*/
|
|
37
|
+
this._prefix = prefix;
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
* @type {Source}
|
|
41
|
+
*/
|
|
42
|
+
this._source =
|
|
43
|
+
typeof source === "string" || Buffer.isBuffer(source)
|
|
44
|
+
? new RawSource(source, true)
|
|
45
|
+
: source;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getPrefix() {
|
|
49
|
+
return this._prefix;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
original() {
|
|
53
|
+
return this._source;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @returns {SourceValue} source
|
|
58
|
+
*/
|
|
59
|
+
source() {
|
|
60
|
+
const node = /** @type {string} */ (this._source.source());
|
|
61
|
+
const prefix = this._prefix;
|
|
62
|
+
return prefix + node.replace(REPLACE_REGEX, `\n${prefix}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TODO efficient buffer() implementation
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {MapOptions=} options map options
|
|
69
|
+
* @returns {RawSourceMap | null} map
|
|
70
|
+
*/
|
|
71
|
+
map(options) {
|
|
72
|
+
return getMap(this, options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {MapOptions=} options map options
|
|
77
|
+
* @returns {SourceAndMap} source and map
|
|
78
|
+
*/
|
|
79
|
+
sourceAndMap(options) {
|
|
80
|
+
return getSourceAndMap(this, options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {Options} options options
|
|
85
|
+
* @param {OnChunk} onChunk called for each chunk of code
|
|
86
|
+
* @param {OnSource} onSource called for each source
|
|
87
|
+
* @param {OnName} onName called for each name
|
|
88
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
89
|
+
*/
|
|
90
|
+
streamChunks(options, onChunk, onSource, onName) {
|
|
91
|
+
const prefix = this._prefix;
|
|
92
|
+
const prefixOffset = prefix.length;
|
|
93
|
+
const linesOnly = Boolean(options && options.columns === false);
|
|
94
|
+
const { generatedLine, generatedColumn, source } = streamChunks(
|
|
95
|
+
this._source,
|
|
96
|
+
options,
|
|
97
|
+
(
|
|
98
|
+
chunk,
|
|
99
|
+
generatedLine,
|
|
100
|
+
generatedColumn,
|
|
101
|
+
sourceIndex,
|
|
102
|
+
originalLine,
|
|
103
|
+
originalColumn,
|
|
104
|
+
nameIndex,
|
|
105
|
+
) => {
|
|
106
|
+
if (generatedColumn !== 0) {
|
|
107
|
+
// In the middle of the line, we just adject the column
|
|
108
|
+
generatedColumn += prefixOffset;
|
|
109
|
+
} else if (chunk !== undefined) {
|
|
110
|
+
// At the start of the line, when we have source content
|
|
111
|
+
// add the prefix as generated mapping
|
|
112
|
+
// (in lines only mode we just add it to the original mapping
|
|
113
|
+
// for performance reasons)
|
|
114
|
+
if (linesOnly || sourceIndex < 0) {
|
|
115
|
+
chunk = prefix + chunk;
|
|
116
|
+
} else if (prefixOffset > 0) {
|
|
117
|
+
onChunk(prefix, generatedLine, generatedColumn, -1, -1, -1, -1);
|
|
118
|
+
generatedColumn += prefixOffset;
|
|
119
|
+
}
|
|
120
|
+
} else if (!linesOnly) {
|
|
121
|
+
// Without source content, we only need to adject the column info
|
|
122
|
+
// expect in lines only mode where prefix is added to original mapping
|
|
123
|
+
generatedColumn += prefixOffset;
|
|
124
|
+
}
|
|
125
|
+
onChunk(
|
|
126
|
+
chunk,
|
|
127
|
+
generatedLine,
|
|
128
|
+
generatedColumn,
|
|
129
|
+
sourceIndex,
|
|
130
|
+
originalLine,
|
|
131
|
+
originalColumn,
|
|
132
|
+
nameIndex,
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
onSource,
|
|
136
|
+
onName,
|
|
137
|
+
);
|
|
138
|
+
return {
|
|
139
|
+
generatedLine,
|
|
140
|
+
generatedColumn:
|
|
141
|
+
generatedColumn === 0
|
|
142
|
+
? 0
|
|
143
|
+
: prefixOffset + /** @type {number} */ (generatedColumn),
|
|
144
|
+
source:
|
|
145
|
+
source !== undefined
|
|
146
|
+
? prefix + source.replace(REPLACE_REGEX, `\n${prefix}`)
|
|
147
|
+
: undefined,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {HashLike} hash hash
|
|
153
|
+
* @returns {void}
|
|
154
|
+
*/
|
|
155
|
+
updateHash(hash) {
|
|
156
|
+
hash.update("PrefixSource");
|
|
157
|
+
this._source.updateHash(hash);
|
|
158
|
+
hash.update(this._prefix);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = PrefixSource;
|
package/lib/RawSource.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Source = require("./Source");
|
|
9
|
+
const streamChunksOfRawSource = require("./helpers/streamChunksOfRawSource");
|
|
10
|
+
const {
|
|
11
|
+
internString,
|
|
12
|
+
isDualStringBufferCachingEnabled,
|
|
13
|
+
} = require("./helpers/stringBufferUtils");
|
|
14
|
+
|
|
15
|
+
/** @typedef {import("./Source").HashLike} HashLike */
|
|
16
|
+
/** @typedef {import("./Source").MapOptions} MapOptions */
|
|
17
|
+
/** @typedef {import("./Source").RawSourceMap} RawSourceMap */
|
|
18
|
+
/** @typedef {import("./Source").SourceValue} SourceValue */
|
|
19
|
+
/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
|
|
20
|
+
/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */
|
|
21
|
+
/** @typedef {import("./helpers/streamChunks").OnName} OnName */
|
|
22
|
+
/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
|
|
23
|
+
/** @typedef {import("./helpers/streamChunks").Options} Options */
|
|
24
|
+
|
|
25
|
+
class RawSource extends Source {
|
|
26
|
+
/**
|
|
27
|
+
* @param {string | Buffer} value value
|
|
28
|
+
* @param {boolean=} convertToString convert to string
|
|
29
|
+
*/
|
|
30
|
+
constructor(value, convertToString = false) {
|
|
31
|
+
super();
|
|
32
|
+
const isBuffer = Buffer.isBuffer(value);
|
|
33
|
+
if (!isBuffer && typeof value !== "string") {
|
|
34
|
+
throw new TypeError("argument 'value' must be either string or Buffer");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
* @type {boolean}
|
|
39
|
+
*/
|
|
40
|
+
this._valueIsBuffer = !convertToString && isBuffer;
|
|
41
|
+
const internedString =
|
|
42
|
+
typeof value === "string" ? internString(value) : undefined;
|
|
43
|
+
/**
|
|
44
|
+
* @private
|
|
45
|
+
* @type {undefined | string | Buffer}
|
|
46
|
+
*/
|
|
47
|
+
this._value =
|
|
48
|
+
convertToString && isBuffer
|
|
49
|
+
? undefined
|
|
50
|
+
: typeof value === "string"
|
|
51
|
+
? internedString
|
|
52
|
+
: value;
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
* @type {undefined | Buffer}
|
|
56
|
+
*/
|
|
57
|
+
this._valueAsBuffer = isBuffer ? value : undefined;
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
* @type {undefined | string}
|
|
61
|
+
*/
|
|
62
|
+
this._valueAsString = isBuffer ? undefined : internedString;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isBuffer() {
|
|
66
|
+
return this._valueIsBuffer;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @returns {SourceValue} source
|
|
71
|
+
*/
|
|
72
|
+
source() {
|
|
73
|
+
if (this._value === undefined) {
|
|
74
|
+
const value =
|
|
75
|
+
/** @type {Buffer} */
|
|
76
|
+
(this._valueAsBuffer).toString("utf8");
|
|
77
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
78
|
+
this._value = internString(value);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
return this._value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
buffer() {
|
|
86
|
+
if (this._valueAsBuffer === undefined) {
|
|
87
|
+
const value = Buffer.from(/** @type {string} */ (this._value), "utf8");
|
|
88
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
89
|
+
this._valueAsBuffer = value;
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
return this._valueAsBuffer;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {MapOptions=} options map options
|
|
98
|
+
* @returns {RawSourceMap | null} map
|
|
99
|
+
*/
|
|
100
|
+
// eslint-disable-next-line no-unused-vars
|
|
101
|
+
map(options) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {Options} options options
|
|
107
|
+
* @param {OnChunk} onChunk called for each chunk of code
|
|
108
|
+
* @param {OnSource} onSource called for each source
|
|
109
|
+
* @param {OnName} onName called for each name
|
|
110
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
111
|
+
*/
|
|
112
|
+
streamChunks(options, onChunk, onSource, onName) {
|
|
113
|
+
let strValue = this._valueAsString;
|
|
114
|
+
if (strValue === undefined) {
|
|
115
|
+
const value = this.source();
|
|
116
|
+
strValue = typeof value === "string" ? value : value.toString("utf8");
|
|
117
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
118
|
+
this._valueAsString = internString(strValue);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return streamChunksOfRawSource(
|
|
122
|
+
strValue,
|
|
123
|
+
onChunk,
|
|
124
|
+
onSource,
|
|
125
|
+
onName,
|
|
126
|
+
Boolean(options && options.finalSource),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {HashLike} hash hash
|
|
132
|
+
* @returns {void}
|
|
133
|
+
*/
|
|
134
|
+
updateHash(hash) {
|
|
135
|
+
hash.update("RawSource");
|
|
136
|
+
hash.update(this.buffer());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = RawSource;
|