vite 4.4.8 → 5.0.0-beta.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/client.d.ts +5 -5
- package/dist/client/client.mjs +6 -7
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-d502c17d.js → dep-1d1f72b4.js} +1 -1
- package/dist/node/chunks/{dep-def3b363.js → dep-3d0847ee.js} +1 -1
- package/dist/node/chunks/{dep-75f53616.js → dep-4033fb3a.js} +359 -220
- package/dist/node/cli.js +16 -7
- package/dist/node/index.d.ts +22 -97
- package/dist/node/index.js +3 -2
- package/dist/node-cjs/publicUtils.cjs +1268 -9
- package/package.json +23 -24
- package/types/importGlob.d.ts +0 -24
- package/types/importMeta.d.ts +0 -6
|
@@ -49,6 +49,8 @@ var UrlType;
|
|
|
49
49
|
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
50
50
|
})(UrlType || (UrlType = {}));
|
|
51
51
|
|
|
52
|
+
const comma = ','.charCodeAt(0);
|
|
53
|
+
const semicolon = ';'.charCodeAt(0);
|
|
52
54
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
53
55
|
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
54
56
|
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
@@ -57,6 +59,83 @@ for (let i = 0; i < chars.length; i++) {
|
|
|
57
59
|
intToChar[i] = c;
|
|
58
60
|
charToInt[c] = i;
|
|
59
61
|
}
|
|
62
|
+
// Provide a fallback for older environments.
|
|
63
|
+
const td = typeof TextDecoder !== 'undefined'
|
|
64
|
+
? /* #__PURE__ */ new TextDecoder()
|
|
65
|
+
: typeof Buffer !== 'undefined'
|
|
66
|
+
? {
|
|
67
|
+
decode(buf) {
|
|
68
|
+
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
69
|
+
return out.toString();
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
: {
|
|
73
|
+
decode(buf) {
|
|
74
|
+
let out = '';
|
|
75
|
+
for (let i = 0; i < buf.length; i++) {
|
|
76
|
+
out += String.fromCharCode(buf[i]);
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
function encode(decoded) {
|
|
82
|
+
const state = new Int32Array(5);
|
|
83
|
+
const bufLength = 1024 * 16;
|
|
84
|
+
const subLength = bufLength - 36;
|
|
85
|
+
const buf = new Uint8Array(bufLength);
|
|
86
|
+
const sub = buf.subarray(0, subLength);
|
|
87
|
+
let pos = 0;
|
|
88
|
+
let out = '';
|
|
89
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
90
|
+
const line = decoded[i];
|
|
91
|
+
if (i > 0) {
|
|
92
|
+
if (pos === bufLength) {
|
|
93
|
+
out += td.decode(buf);
|
|
94
|
+
pos = 0;
|
|
95
|
+
}
|
|
96
|
+
buf[pos++] = semicolon;
|
|
97
|
+
}
|
|
98
|
+
if (line.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
state[0] = 0;
|
|
101
|
+
for (let j = 0; j < line.length; j++) {
|
|
102
|
+
const segment = line[j];
|
|
103
|
+
// We can push up to 5 ints, each int can take at most 7 chars, and we
|
|
104
|
+
// may push a comma.
|
|
105
|
+
if (pos > subLength) {
|
|
106
|
+
out += td.decode(sub);
|
|
107
|
+
buf.copyWithin(0, subLength, pos);
|
|
108
|
+
pos -= subLength;
|
|
109
|
+
}
|
|
110
|
+
if (j > 0)
|
|
111
|
+
buf[pos++] = comma;
|
|
112
|
+
pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
|
|
113
|
+
if (segment.length === 1)
|
|
114
|
+
continue;
|
|
115
|
+
pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
|
|
116
|
+
pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
|
|
117
|
+
pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
|
|
118
|
+
if (segment.length === 4)
|
|
119
|
+
continue;
|
|
120
|
+
pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out + td.decode(buf.subarray(0, pos));
|
|
124
|
+
}
|
|
125
|
+
function encodeInteger(buf, pos, state, segment, j) {
|
|
126
|
+
const next = segment[j];
|
|
127
|
+
let num = next - state[j];
|
|
128
|
+
state[j] = next;
|
|
129
|
+
num = num < 0 ? (-num << 1) | 1 : num << 1;
|
|
130
|
+
do {
|
|
131
|
+
let clamped = num & 0b011111;
|
|
132
|
+
num >>>= 5;
|
|
133
|
+
if (num > 0)
|
|
134
|
+
clamped |= 0b100000;
|
|
135
|
+
buf[pos++] = intToChar[clamped];
|
|
136
|
+
} while (num > 0);
|
|
137
|
+
return pos;
|
|
138
|
+
}
|
|
60
139
|
|
|
61
140
|
function getDefaultExportFromCjs (x) {
|
|
62
141
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -2875,7 +2954,7 @@ const scan = scan_1;
|
|
|
2875
2954
|
const parse$1 = parse_1$1;
|
|
2876
2955
|
const utils = utils$3;
|
|
2877
2956
|
const constants = constants$2;
|
|
2878
|
-
const isObject$
|
|
2957
|
+
const isObject$2 = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
2879
2958
|
|
|
2880
2959
|
/**
|
|
2881
2960
|
* Creates a matcher function from one or more glob patterns. The
|
|
@@ -2912,7 +2991,7 @@ const picomatch$1 = (glob, options, returnState = false) => {
|
|
|
2912
2991
|
return arrayMatcher;
|
|
2913
2992
|
}
|
|
2914
2993
|
|
|
2915
|
-
const isState = isObject$
|
|
2994
|
+
const isState = isObject$2(glob) && glob.tokens && glob.input;
|
|
2916
2995
|
|
|
2917
2996
|
if (glob === '' || (typeof glob !== 'string' && !isState)) {
|
|
2918
2997
|
throw new TypeError('Expected pattern to be a non-empty string');
|
|
@@ -3377,7 +3456,12 @@ const postfixRE = /[?#].*$/s;
|
|
|
3377
3456
|
function cleanUrl(url) {
|
|
3378
3457
|
return url.replace(postfixRE, '');
|
|
3379
3458
|
}
|
|
3380
|
-
|
|
3459
|
+
const trailingSeparatorRE = /[?&]$/;
|
|
3460
|
+
const timestampRE = /\bt=\d{13}&?\b/;
|
|
3461
|
+
function removeTimestampQuery(url) {
|
|
3462
|
+
return url.replace(timestampRE, '').replace(trailingSeparatorRE, '');
|
|
3463
|
+
}
|
|
3464
|
+
function isObject$1(value) {
|
|
3381
3465
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
3382
3466
|
}
|
|
3383
3467
|
function tryStatSync(file) {
|
|
@@ -3451,7 +3535,7 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
|
3451
3535
|
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
|
|
3452
3536
|
continue;
|
|
3453
3537
|
}
|
|
3454
|
-
if (isObject(existing) && isObject(value)) {
|
|
3538
|
+
if (isObject$1(existing) && isObject$1(value)) {
|
|
3455
3539
|
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
|
|
3456
3540
|
continue;
|
|
3457
3541
|
}
|
|
@@ -3470,7 +3554,7 @@ function mergeAlias(a, b) {
|
|
|
3470
3554
|
return b;
|
|
3471
3555
|
if (!b)
|
|
3472
3556
|
return a;
|
|
3473
|
-
if (isObject(a) && isObject(b)) {
|
|
3557
|
+
if (isObject$1(a) && isObject$1(b)) {
|
|
3474
3558
|
return { ...a, ...b };
|
|
3475
3559
|
}
|
|
3476
3560
|
// the order is flipped because the alias is resolved from top-down,
|
|
@@ -3518,6 +3602,7 @@ const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
|
|
|
3518
3602
|
// The cache needs to be reset on buildStart for watch mode to work correctly
|
|
3519
3603
|
// Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
|
|
3520
3604
|
class SplitVendorChunkCache {
|
|
3605
|
+
cache;
|
|
3521
3606
|
constructor() {
|
|
3522
3607
|
this.cache = new Map();
|
|
3523
3608
|
}
|
|
@@ -3641,7 +3726,7 @@ var Stats = fs$2.Stats;
|
|
|
3641
3726
|
* @private
|
|
3642
3727
|
*/
|
|
3643
3728
|
|
|
3644
|
-
var toString = Object.prototype.toString;
|
|
3729
|
+
var toString$1 = Object.prototype.toString;
|
|
3645
3730
|
|
|
3646
3731
|
/**
|
|
3647
3732
|
* Generate an entity tag.
|
|
@@ -3724,8 +3809,8 @@ function isstats (obj) {
|
|
|
3724
3809
|
|
|
3725
3810
|
// quack quack
|
|
3726
3811
|
return obj && typeof obj === 'object' &&
|
|
3727
|
-
'ctime' in obj && toString.call(obj.ctime) === '[object Date]' &&
|
|
3728
|
-
'mtime' in obj && toString.call(obj.mtime) === '[object Date]' &&
|
|
3812
|
+
'ctime' in obj && toString$1.call(obj.ctime) === '[object Date]' &&
|
|
3813
|
+
'mtime' in obj && toString$1.call(obj.mtime) === '[object Date]' &&
|
|
3729
3814
|
'ino' in obj && typeof obj.ino === 'number' &&
|
|
3730
3815
|
'size' in obj && typeof obj.size === 'number'
|
|
3731
3816
|
}
|
|
@@ -3747,6 +3832,1173 @@ function stattag (stat) {
|
|
|
3747
3832
|
|
|
3748
3833
|
var getEtag = /*@__PURE__*/getDefaultExportFromCjs(etag_1);
|
|
3749
3834
|
|
|
3835
|
+
class BitSet {
|
|
3836
|
+
constructor(arg) {
|
|
3837
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
3838
|
+
}
|
|
3839
|
+
|
|
3840
|
+
add(n) {
|
|
3841
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
has(n) {
|
|
3845
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
class Chunk {
|
|
3850
|
+
constructor(start, end, content) {
|
|
3851
|
+
this.start = start;
|
|
3852
|
+
this.end = end;
|
|
3853
|
+
this.original = content;
|
|
3854
|
+
|
|
3855
|
+
this.intro = '';
|
|
3856
|
+
this.outro = '';
|
|
3857
|
+
|
|
3858
|
+
this.content = content;
|
|
3859
|
+
this.storeName = false;
|
|
3860
|
+
this.edited = false;
|
|
3861
|
+
|
|
3862
|
+
{
|
|
3863
|
+
this.previous = null;
|
|
3864
|
+
this.next = null;
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
appendLeft(content) {
|
|
3869
|
+
this.outro += content;
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
appendRight(content) {
|
|
3873
|
+
this.intro = this.intro + content;
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
clone() {
|
|
3877
|
+
const chunk = new Chunk(this.start, this.end, this.original);
|
|
3878
|
+
|
|
3879
|
+
chunk.intro = this.intro;
|
|
3880
|
+
chunk.outro = this.outro;
|
|
3881
|
+
chunk.content = this.content;
|
|
3882
|
+
chunk.storeName = this.storeName;
|
|
3883
|
+
chunk.edited = this.edited;
|
|
3884
|
+
|
|
3885
|
+
return chunk;
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
contains(index) {
|
|
3889
|
+
return this.start < index && index < this.end;
|
|
3890
|
+
}
|
|
3891
|
+
|
|
3892
|
+
eachNext(fn) {
|
|
3893
|
+
let chunk = this;
|
|
3894
|
+
while (chunk) {
|
|
3895
|
+
fn(chunk);
|
|
3896
|
+
chunk = chunk.next;
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
eachPrevious(fn) {
|
|
3901
|
+
let chunk = this;
|
|
3902
|
+
while (chunk) {
|
|
3903
|
+
fn(chunk);
|
|
3904
|
+
chunk = chunk.previous;
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
edit(content, storeName, contentOnly) {
|
|
3909
|
+
this.content = content;
|
|
3910
|
+
if (!contentOnly) {
|
|
3911
|
+
this.intro = '';
|
|
3912
|
+
this.outro = '';
|
|
3913
|
+
}
|
|
3914
|
+
this.storeName = storeName;
|
|
3915
|
+
|
|
3916
|
+
this.edited = true;
|
|
3917
|
+
|
|
3918
|
+
return this;
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
prependLeft(content) {
|
|
3922
|
+
this.outro = content + this.outro;
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
prependRight(content) {
|
|
3926
|
+
this.intro = content + this.intro;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
split(index) {
|
|
3930
|
+
const sliceIndex = index - this.start;
|
|
3931
|
+
|
|
3932
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
3933
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
3934
|
+
|
|
3935
|
+
this.original = originalBefore;
|
|
3936
|
+
|
|
3937
|
+
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
3938
|
+
newChunk.outro = this.outro;
|
|
3939
|
+
this.outro = '';
|
|
3940
|
+
|
|
3941
|
+
this.end = index;
|
|
3942
|
+
|
|
3943
|
+
if (this.edited) {
|
|
3944
|
+
// TODO is this block necessary?...
|
|
3945
|
+
newChunk.edit('', false);
|
|
3946
|
+
this.content = '';
|
|
3947
|
+
} else {
|
|
3948
|
+
this.content = originalBefore;
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
newChunk.next = this.next;
|
|
3952
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
3953
|
+
newChunk.previous = this;
|
|
3954
|
+
this.next = newChunk;
|
|
3955
|
+
|
|
3956
|
+
return newChunk;
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
toString() {
|
|
3960
|
+
return this.intro + this.content + this.outro;
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
trimEnd(rx) {
|
|
3964
|
+
this.outro = this.outro.replace(rx, '');
|
|
3965
|
+
if (this.outro.length) return true;
|
|
3966
|
+
|
|
3967
|
+
const trimmed = this.content.replace(rx, '');
|
|
3968
|
+
|
|
3969
|
+
if (trimmed.length) {
|
|
3970
|
+
if (trimmed !== this.content) {
|
|
3971
|
+
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
3972
|
+
}
|
|
3973
|
+
return true;
|
|
3974
|
+
} else {
|
|
3975
|
+
this.edit('', undefined, true);
|
|
3976
|
+
|
|
3977
|
+
this.intro = this.intro.replace(rx, '');
|
|
3978
|
+
if (this.intro.length) return true;
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
trimStart(rx) {
|
|
3983
|
+
this.intro = this.intro.replace(rx, '');
|
|
3984
|
+
if (this.intro.length) return true;
|
|
3985
|
+
|
|
3986
|
+
const trimmed = this.content.replace(rx, '');
|
|
3987
|
+
|
|
3988
|
+
if (trimmed.length) {
|
|
3989
|
+
if (trimmed !== this.content) {
|
|
3990
|
+
this.split(this.end - trimmed.length);
|
|
3991
|
+
this.edit('', undefined, true);
|
|
3992
|
+
}
|
|
3993
|
+
return true;
|
|
3994
|
+
} else {
|
|
3995
|
+
this.edit('', undefined, true);
|
|
3996
|
+
|
|
3997
|
+
this.outro = this.outro.replace(rx, '');
|
|
3998
|
+
if (this.outro.length) return true;
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
|
|
4003
|
+
function getBtoa() {
|
|
4004
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
4005
|
+
return (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
4006
|
+
} else if (typeof Buffer === 'function') {
|
|
4007
|
+
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
4008
|
+
} else {
|
|
4009
|
+
return () => {
|
|
4010
|
+
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
4011
|
+
};
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
|
|
4015
|
+
const btoa = /*#__PURE__*/ getBtoa();
|
|
4016
|
+
|
|
4017
|
+
class SourceMap {
|
|
4018
|
+
constructor(properties) {
|
|
4019
|
+
this.version = 3;
|
|
4020
|
+
this.file = properties.file;
|
|
4021
|
+
this.sources = properties.sources;
|
|
4022
|
+
this.sourcesContent = properties.sourcesContent;
|
|
4023
|
+
this.names = properties.names;
|
|
4024
|
+
this.mappings = encode(properties.mappings);
|
|
4025
|
+
if (typeof properties.x_google_ignoreList !== 'undefined') {
|
|
4026
|
+
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
toString() {
|
|
4031
|
+
return JSON.stringify(this);
|
|
4032
|
+
}
|
|
4033
|
+
|
|
4034
|
+
toUrl() {
|
|
4035
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
function guessIndent(code) {
|
|
4040
|
+
const lines = code.split('\n');
|
|
4041
|
+
|
|
4042
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
4043
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
4044
|
+
|
|
4045
|
+
if (tabbed.length === 0 && spaced.length === 0) {
|
|
4046
|
+
return null;
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
// More lines tabbed than spaced? Assume tabs, and
|
|
4050
|
+
// default to tabs in the case of a tie (or nothing
|
|
4051
|
+
// to go on)
|
|
4052
|
+
if (tabbed.length >= spaced.length) {
|
|
4053
|
+
return '\t';
|
|
4054
|
+
}
|
|
4055
|
+
|
|
4056
|
+
// Otherwise, we need to guess the multiple
|
|
4057
|
+
const min = spaced.reduce((previous, current) => {
|
|
4058
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
4059
|
+
return Math.min(numSpaces, previous);
|
|
4060
|
+
}, Infinity);
|
|
4061
|
+
|
|
4062
|
+
return new Array(min + 1).join(' ');
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
function getRelativePath(from, to) {
|
|
4066
|
+
const fromParts = from.split(/[/\\]/);
|
|
4067
|
+
const toParts = to.split(/[/\\]/);
|
|
4068
|
+
|
|
4069
|
+
fromParts.pop(); // get dirname
|
|
4070
|
+
|
|
4071
|
+
while (fromParts[0] === toParts[0]) {
|
|
4072
|
+
fromParts.shift();
|
|
4073
|
+
toParts.shift();
|
|
4074
|
+
}
|
|
4075
|
+
|
|
4076
|
+
if (fromParts.length) {
|
|
4077
|
+
let i = fromParts.length;
|
|
4078
|
+
while (i--) fromParts[i] = '..';
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
return fromParts.concat(toParts).join('/');
|
|
4082
|
+
}
|
|
4083
|
+
|
|
4084
|
+
const toString = Object.prototype.toString;
|
|
4085
|
+
|
|
4086
|
+
function isObject(thing) {
|
|
4087
|
+
return toString.call(thing) === '[object Object]';
|
|
4088
|
+
}
|
|
4089
|
+
|
|
4090
|
+
function getLocator(source) {
|
|
4091
|
+
const originalLines = source.split('\n');
|
|
4092
|
+
const lineOffsets = [];
|
|
4093
|
+
|
|
4094
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
4095
|
+
lineOffsets.push(pos);
|
|
4096
|
+
pos += originalLines[i].length + 1;
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
return function locate(index) {
|
|
4100
|
+
let i = 0;
|
|
4101
|
+
let j = lineOffsets.length;
|
|
4102
|
+
while (i < j) {
|
|
4103
|
+
const m = (i + j) >> 1;
|
|
4104
|
+
if (index < lineOffsets[m]) {
|
|
4105
|
+
j = m;
|
|
4106
|
+
} else {
|
|
4107
|
+
i = m + 1;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
const line = i - 1;
|
|
4111
|
+
const column = index - lineOffsets[line];
|
|
4112
|
+
return { line, column };
|
|
4113
|
+
};
|
|
4114
|
+
}
|
|
4115
|
+
|
|
4116
|
+
const wordRegex = /\w/;
|
|
4117
|
+
|
|
4118
|
+
class Mappings {
|
|
4119
|
+
constructor(hires) {
|
|
4120
|
+
this.hires = hires;
|
|
4121
|
+
this.generatedCodeLine = 0;
|
|
4122
|
+
this.generatedCodeColumn = 0;
|
|
4123
|
+
this.raw = [];
|
|
4124
|
+
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
4125
|
+
this.pending = null;
|
|
4126
|
+
}
|
|
4127
|
+
|
|
4128
|
+
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
4129
|
+
if (content.length) {
|
|
4130
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
4131
|
+
if (nameIndex >= 0) {
|
|
4132
|
+
segment.push(nameIndex);
|
|
4133
|
+
}
|
|
4134
|
+
this.rawSegments.push(segment);
|
|
4135
|
+
} else if (this.pending) {
|
|
4136
|
+
this.rawSegments.push(this.pending);
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
this.advance(content);
|
|
4140
|
+
this.pending = null;
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
4144
|
+
let originalCharIndex = chunk.start;
|
|
4145
|
+
let first = true;
|
|
4146
|
+
// when iterating each char, check if it's in a word boundary
|
|
4147
|
+
let charInHiresBoundary = false;
|
|
4148
|
+
|
|
4149
|
+
while (originalCharIndex < chunk.end) {
|
|
4150
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
4151
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
4152
|
+
|
|
4153
|
+
if (this.hires === 'boundary') {
|
|
4154
|
+
// in hires "boundary", group segments per word boundary than per char
|
|
4155
|
+
if (wordRegex.test(original[originalCharIndex])) {
|
|
4156
|
+
// for first char in the boundary found, start the boundary by pushing a segment
|
|
4157
|
+
if (!charInHiresBoundary) {
|
|
4158
|
+
this.rawSegments.push(segment);
|
|
4159
|
+
charInHiresBoundary = true;
|
|
4160
|
+
}
|
|
4161
|
+
} else {
|
|
4162
|
+
// for non-word char, end the boundary by pushing a segment
|
|
4163
|
+
this.rawSegments.push(segment);
|
|
4164
|
+
charInHiresBoundary = false;
|
|
4165
|
+
}
|
|
4166
|
+
} else {
|
|
4167
|
+
this.rawSegments.push(segment);
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
if (original[originalCharIndex] === '\n') {
|
|
4172
|
+
loc.line += 1;
|
|
4173
|
+
loc.column = 0;
|
|
4174
|
+
this.generatedCodeLine += 1;
|
|
4175
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
4176
|
+
this.generatedCodeColumn = 0;
|
|
4177
|
+
first = true;
|
|
4178
|
+
} else {
|
|
4179
|
+
loc.column += 1;
|
|
4180
|
+
this.generatedCodeColumn += 1;
|
|
4181
|
+
first = false;
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
originalCharIndex += 1;
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
this.pending = null;
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4190
|
+
advance(str) {
|
|
4191
|
+
if (!str) return;
|
|
4192
|
+
|
|
4193
|
+
const lines = str.split('\n');
|
|
4194
|
+
|
|
4195
|
+
if (lines.length > 1) {
|
|
4196
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
4197
|
+
this.generatedCodeLine++;
|
|
4198
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
4199
|
+
}
|
|
4200
|
+
this.generatedCodeColumn = 0;
|
|
4201
|
+
}
|
|
4202
|
+
|
|
4203
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
4204
|
+
}
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
const n = '\n';
|
|
4208
|
+
|
|
4209
|
+
const warned = {
|
|
4210
|
+
insertLeft: false,
|
|
4211
|
+
insertRight: false,
|
|
4212
|
+
storeName: false,
|
|
4213
|
+
};
|
|
4214
|
+
|
|
4215
|
+
class MagicString {
|
|
4216
|
+
constructor(string, options = {}) {
|
|
4217
|
+
const chunk = new Chunk(0, string.length, string);
|
|
4218
|
+
|
|
4219
|
+
Object.defineProperties(this, {
|
|
4220
|
+
original: { writable: true, value: string },
|
|
4221
|
+
outro: { writable: true, value: '' },
|
|
4222
|
+
intro: { writable: true, value: '' },
|
|
4223
|
+
firstChunk: { writable: true, value: chunk },
|
|
4224
|
+
lastChunk: { writable: true, value: chunk },
|
|
4225
|
+
lastSearchedChunk: { writable: true, value: chunk },
|
|
4226
|
+
byStart: { writable: true, value: {} },
|
|
4227
|
+
byEnd: { writable: true, value: {} },
|
|
4228
|
+
filename: { writable: true, value: options.filename },
|
|
4229
|
+
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
4230
|
+
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
4231
|
+
storedNames: { writable: true, value: {} },
|
|
4232
|
+
indentStr: { writable: true, value: undefined },
|
|
4233
|
+
ignoreList: { writable: true, value: options.ignoreList },
|
|
4234
|
+
});
|
|
4235
|
+
|
|
4236
|
+
this.byStart[0] = chunk;
|
|
4237
|
+
this.byEnd[string.length] = chunk;
|
|
4238
|
+
}
|
|
4239
|
+
|
|
4240
|
+
addSourcemapLocation(char) {
|
|
4241
|
+
this.sourcemapLocations.add(char);
|
|
4242
|
+
}
|
|
4243
|
+
|
|
4244
|
+
append(content) {
|
|
4245
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
4246
|
+
|
|
4247
|
+
this.outro += content;
|
|
4248
|
+
return this;
|
|
4249
|
+
}
|
|
4250
|
+
|
|
4251
|
+
appendLeft(index, content) {
|
|
4252
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
4253
|
+
|
|
4254
|
+
this._split(index);
|
|
4255
|
+
|
|
4256
|
+
const chunk = this.byEnd[index];
|
|
4257
|
+
|
|
4258
|
+
if (chunk) {
|
|
4259
|
+
chunk.appendLeft(content);
|
|
4260
|
+
} else {
|
|
4261
|
+
this.intro += content;
|
|
4262
|
+
}
|
|
4263
|
+
return this;
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
appendRight(index, content) {
|
|
4267
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
4268
|
+
|
|
4269
|
+
this._split(index);
|
|
4270
|
+
|
|
4271
|
+
const chunk = this.byStart[index];
|
|
4272
|
+
|
|
4273
|
+
if (chunk) {
|
|
4274
|
+
chunk.appendRight(content);
|
|
4275
|
+
} else {
|
|
4276
|
+
this.outro += content;
|
|
4277
|
+
}
|
|
4278
|
+
return this;
|
|
4279
|
+
}
|
|
4280
|
+
|
|
4281
|
+
clone() {
|
|
4282
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
4283
|
+
|
|
4284
|
+
let originalChunk = this.firstChunk;
|
|
4285
|
+
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
4286
|
+
|
|
4287
|
+
while (originalChunk) {
|
|
4288
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
4289
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
4290
|
+
|
|
4291
|
+
const nextOriginalChunk = originalChunk.next;
|
|
4292
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
4293
|
+
|
|
4294
|
+
if (nextClonedChunk) {
|
|
4295
|
+
clonedChunk.next = nextClonedChunk;
|
|
4296
|
+
nextClonedChunk.previous = clonedChunk;
|
|
4297
|
+
|
|
4298
|
+
clonedChunk = nextClonedChunk;
|
|
4299
|
+
}
|
|
4300
|
+
|
|
4301
|
+
originalChunk = nextOriginalChunk;
|
|
4302
|
+
}
|
|
4303
|
+
|
|
4304
|
+
cloned.lastChunk = clonedChunk;
|
|
4305
|
+
|
|
4306
|
+
if (this.indentExclusionRanges) {
|
|
4307
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
4308
|
+
}
|
|
4309
|
+
|
|
4310
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
4311
|
+
|
|
4312
|
+
cloned.intro = this.intro;
|
|
4313
|
+
cloned.outro = this.outro;
|
|
4314
|
+
|
|
4315
|
+
return cloned;
|
|
4316
|
+
}
|
|
4317
|
+
|
|
4318
|
+
generateDecodedMap(options) {
|
|
4319
|
+
options = options || {};
|
|
4320
|
+
|
|
4321
|
+
const sourceIndex = 0;
|
|
4322
|
+
const names = Object.keys(this.storedNames);
|
|
4323
|
+
const mappings = new Mappings(options.hires);
|
|
4324
|
+
|
|
4325
|
+
const locate = getLocator(this.original);
|
|
4326
|
+
|
|
4327
|
+
if (this.intro) {
|
|
4328
|
+
mappings.advance(this.intro);
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4331
|
+
this.firstChunk.eachNext((chunk) => {
|
|
4332
|
+
const loc = locate(chunk.start);
|
|
4333
|
+
|
|
4334
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
4335
|
+
|
|
4336
|
+
if (chunk.edited) {
|
|
4337
|
+
mappings.addEdit(
|
|
4338
|
+
sourceIndex,
|
|
4339
|
+
chunk.content,
|
|
4340
|
+
loc,
|
|
4341
|
+
chunk.storeName ? names.indexOf(chunk.original) : -1,
|
|
4342
|
+
);
|
|
4343
|
+
} else {
|
|
4344
|
+
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
4348
|
+
});
|
|
4349
|
+
|
|
4350
|
+
return {
|
|
4351
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
|
|
4352
|
+
sources: [
|
|
4353
|
+
options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
|
|
4354
|
+
],
|
|
4355
|
+
sourcesContent: options.includeContent ? [this.original] : undefined,
|
|
4356
|
+
names,
|
|
4357
|
+
mappings: mappings.raw,
|
|
4358
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
|
|
4359
|
+
};
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
generateMap(options) {
|
|
4363
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
4364
|
+
}
|
|
4365
|
+
|
|
4366
|
+
_ensureindentStr() {
|
|
4367
|
+
if (this.indentStr === undefined) {
|
|
4368
|
+
this.indentStr = guessIndent(this.original);
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
|
|
4372
|
+
_getRawIndentString() {
|
|
4373
|
+
this._ensureindentStr();
|
|
4374
|
+
return this.indentStr;
|
|
4375
|
+
}
|
|
4376
|
+
|
|
4377
|
+
getIndentString() {
|
|
4378
|
+
this._ensureindentStr();
|
|
4379
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
4380
|
+
}
|
|
4381
|
+
|
|
4382
|
+
indent(indentStr, options) {
|
|
4383
|
+
const pattern = /^[^\r\n]/gm;
|
|
4384
|
+
|
|
4385
|
+
if (isObject(indentStr)) {
|
|
4386
|
+
options = indentStr;
|
|
4387
|
+
indentStr = undefined;
|
|
4388
|
+
}
|
|
4389
|
+
|
|
4390
|
+
if (indentStr === undefined) {
|
|
4391
|
+
this._ensureindentStr();
|
|
4392
|
+
indentStr = this.indentStr || '\t';
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4395
|
+
if (indentStr === '') return this; // noop
|
|
4396
|
+
|
|
4397
|
+
options = options || {};
|
|
4398
|
+
|
|
4399
|
+
// Process exclusion ranges
|
|
4400
|
+
const isExcluded = {};
|
|
4401
|
+
|
|
4402
|
+
if (options.exclude) {
|
|
4403
|
+
const exclusions =
|
|
4404
|
+
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
4405
|
+
exclusions.forEach((exclusion) => {
|
|
4406
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
4407
|
+
isExcluded[i] = true;
|
|
4408
|
+
}
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
|
|
4412
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
4413
|
+
const replacer = (match) => {
|
|
4414
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
4415
|
+
shouldIndentNextCharacter = true;
|
|
4416
|
+
return match;
|
|
4417
|
+
};
|
|
4418
|
+
|
|
4419
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
4420
|
+
|
|
4421
|
+
let charIndex = 0;
|
|
4422
|
+
let chunk = this.firstChunk;
|
|
4423
|
+
|
|
4424
|
+
while (chunk) {
|
|
4425
|
+
const end = chunk.end;
|
|
4426
|
+
|
|
4427
|
+
if (chunk.edited) {
|
|
4428
|
+
if (!isExcluded[charIndex]) {
|
|
4429
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
4430
|
+
|
|
4431
|
+
if (chunk.content.length) {
|
|
4432
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
} else {
|
|
4436
|
+
charIndex = chunk.start;
|
|
4437
|
+
|
|
4438
|
+
while (charIndex < end) {
|
|
4439
|
+
if (!isExcluded[charIndex]) {
|
|
4440
|
+
const char = this.original[charIndex];
|
|
4441
|
+
|
|
4442
|
+
if (char === '\n') {
|
|
4443
|
+
shouldIndentNextCharacter = true;
|
|
4444
|
+
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
4445
|
+
shouldIndentNextCharacter = false;
|
|
4446
|
+
|
|
4447
|
+
if (charIndex === chunk.start) {
|
|
4448
|
+
chunk.prependRight(indentStr);
|
|
4449
|
+
} else {
|
|
4450
|
+
this._splitChunk(chunk, charIndex);
|
|
4451
|
+
chunk = chunk.next;
|
|
4452
|
+
chunk.prependRight(indentStr);
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
charIndex += 1;
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
charIndex = chunk.end;
|
|
4462
|
+
chunk = chunk.next;
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4465
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
4466
|
+
|
|
4467
|
+
return this;
|
|
4468
|
+
}
|
|
4469
|
+
|
|
4470
|
+
insert() {
|
|
4471
|
+
throw new Error(
|
|
4472
|
+
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
insertLeft(index, content) {
|
|
4477
|
+
if (!warned.insertLeft) {
|
|
4478
|
+
console.warn(
|
|
4479
|
+
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
|
|
4480
|
+
); // eslint-disable-line no-console
|
|
4481
|
+
warned.insertLeft = true;
|
|
4482
|
+
}
|
|
4483
|
+
|
|
4484
|
+
return this.appendLeft(index, content);
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
insertRight(index, content) {
|
|
4488
|
+
if (!warned.insertRight) {
|
|
4489
|
+
console.warn(
|
|
4490
|
+
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
|
|
4491
|
+
); // eslint-disable-line no-console
|
|
4492
|
+
warned.insertRight = true;
|
|
4493
|
+
}
|
|
4494
|
+
|
|
4495
|
+
return this.prependRight(index, content);
|
|
4496
|
+
}
|
|
4497
|
+
|
|
4498
|
+
move(start, end, index) {
|
|
4499
|
+
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
4500
|
+
|
|
4501
|
+
this._split(start);
|
|
4502
|
+
this._split(end);
|
|
4503
|
+
this._split(index);
|
|
4504
|
+
|
|
4505
|
+
const first = this.byStart[start];
|
|
4506
|
+
const last = this.byEnd[end];
|
|
4507
|
+
|
|
4508
|
+
const oldLeft = first.previous;
|
|
4509
|
+
const oldRight = last.next;
|
|
4510
|
+
|
|
4511
|
+
const newRight = this.byStart[index];
|
|
4512
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
4513
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
4514
|
+
|
|
4515
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
4516
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
4517
|
+
|
|
4518
|
+
if (newLeft) newLeft.next = first;
|
|
4519
|
+
if (newRight) newRight.previous = last;
|
|
4520
|
+
|
|
4521
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
4522
|
+
if (!last.next) {
|
|
4523
|
+
this.lastChunk = first.previous;
|
|
4524
|
+
this.lastChunk.next = null;
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
first.previous = newLeft;
|
|
4528
|
+
last.next = newRight || null;
|
|
4529
|
+
|
|
4530
|
+
if (!newLeft) this.firstChunk = first;
|
|
4531
|
+
if (!newRight) this.lastChunk = last;
|
|
4532
|
+
return this;
|
|
4533
|
+
}
|
|
4534
|
+
|
|
4535
|
+
overwrite(start, end, content, options) {
|
|
4536
|
+
options = options || {};
|
|
4537
|
+
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
update(start, end, content, options) {
|
|
4541
|
+
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
4542
|
+
|
|
4543
|
+
while (start < 0) start += this.original.length;
|
|
4544
|
+
while (end < 0) end += this.original.length;
|
|
4545
|
+
|
|
4546
|
+
if (end > this.original.length) throw new Error('end is out of bounds');
|
|
4547
|
+
if (start === end)
|
|
4548
|
+
throw new Error(
|
|
4549
|
+
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
|
|
4550
|
+
);
|
|
4551
|
+
|
|
4552
|
+
this._split(start);
|
|
4553
|
+
this._split(end);
|
|
4554
|
+
|
|
4555
|
+
if (options === true) {
|
|
4556
|
+
if (!warned.storeName) {
|
|
4557
|
+
console.warn(
|
|
4558
|
+
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
|
|
4559
|
+
); // eslint-disable-line no-console
|
|
4560
|
+
warned.storeName = true;
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4563
|
+
options = { storeName: true };
|
|
4564
|
+
}
|
|
4565
|
+
const storeName = options !== undefined ? options.storeName : false;
|
|
4566
|
+
const overwrite = options !== undefined ? options.overwrite : false;
|
|
4567
|
+
|
|
4568
|
+
if (storeName) {
|
|
4569
|
+
const original = this.original.slice(start, end);
|
|
4570
|
+
Object.defineProperty(this.storedNames, original, {
|
|
4571
|
+
writable: true,
|
|
4572
|
+
value: true,
|
|
4573
|
+
enumerable: true,
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
const first = this.byStart[start];
|
|
4578
|
+
const last = this.byEnd[end];
|
|
4579
|
+
|
|
4580
|
+
if (first) {
|
|
4581
|
+
let chunk = first;
|
|
4582
|
+
while (chunk !== last) {
|
|
4583
|
+
if (chunk.next !== this.byStart[chunk.end]) {
|
|
4584
|
+
throw new Error('Cannot overwrite across a split point');
|
|
4585
|
+
}
|
|
4586
|
+
chunk = chunk.next;
|
|
4587
|
+
chunk.edit('', false);
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
first.edit(content, storeName, !overwrite);
|
|
4591
|
+
} else {
|
|
4592
|
+
// must be inserting at the end
|
|
4593
|
+
const newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
4594
|
+
|
|
4595
|
+
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
4596
|
+
last.next = newChunk;
|
|
4597
|
+
newChunk.previous = last;
|
|
4598
|
+
}
|
|
4599
|
+
return this;
|
|
4600
|
+
}
|
|
4601
|
+
|
|
4602
|
+
prepend(content) {
|
|
4603
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
4604
|
+
|
|
4605
|
+
this.intro = content + this.intro;
|
|
4606
|
+
return this;
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4609
|
+
prependLeft(index, content) {
|
|
4610
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
4611
|
+
|
|
4612
|
+
this._split(index);
|
|
4613
|
+
|
|
4614
|
+
const chunk = this.byEnd[index];
|
|
4615
|
+
|
|
4616
|
+
if (chunk) {
|
|
4617
|
+
chunk.prependLeft(content);
|
|
4618
|
+
} else {
|
|
4619
|
+
this.intro = content + this.intro;
|
|
4620
|
+
}
|
|
4621
|
+
return this;
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
prependRight(index, content) {
|
|
4625
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
4626
|
+
|
|
4627
|
+
this._split(index);
|
|
4628
|
+
|
|
4629
|
+
const chunk = this.byStart[index];
|
|
4630
|
+
|
|
4631
|
+
if (chunk) {
|
|
4632
|
+
chunk.prependRight(content);
|
|
4633
|
+
} else {
|
|
4634
|
+
this.outro = content + this.outro;
|
|
4635
|
+
}
|
|
4636
|
+
return this;
|
|
4637
|
+
}
|
|
4638
|
+
|
|
4639
|
+
remove(start, end) {
|
|
4640
|
+
while (start < 0) start += this.original.length;
|
|
4641
|
+
while (end < 0) end += this.original.length;
|
|
4642
|
+
|
|
4643
|
+
if (start === end) return this;
|
|
4644
|
+
|
|
4645
|
+
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
4646
|
+
if (start > end) throw new Error('end must be greater than start');
|
|
4647
|
+
|
|
4648
|
+
this._split(start);
|
|
4649
|
+
this._split(end);
|
|
4650
|
+
|
|
4651
|
+
let chunk = this.byStart[start];
|
|
4652
|
+
|
|
4653
|
+
while (chunk) {
|
|
4654
|
+
chunk.intro = '';
|
|
4655
|
+
chunk.outro = '';
|
|
4656
|
+
chunk.edit('');
|
|
4657
|
+
|
|
4658
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
4659
|
+
}
|
|
4660
|
+
return this;
|
|
4661
|
+
}
|
|
4662
|
+
|
|
4663
|
+
lastChar() {
|
|
4664
|
+
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
4665
|
+
let chunk = this.lastChunk;
|
|
4666
|
+
do {
|
|
4667
|
+
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
4668
|
+
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
4669
|
+
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
4670
|
+
} while ((chunk = chunk.previous));
|
|
4671
|
+
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
4672
|
+
return '';
|
|
4673
|
+
}
|
|
4674
|
+
|
|
4675
|
+
lastLine() {
|
|
4676
|
+
let lineIndex = this.outro.lastIndexOf(n);
|
|
4677
|
+
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
4678
|
+
let lineStr = this.outro;
|
|
4679
|
+
let chunk = this.lastChunk;
|
|
4680
|
+
do {
|
|
4681
|
+
if (chunk.outro.length > 0) {
|
|
4682
|
+
lineIndex = chunk.outro.lastIndexOf(n);
|
|
4683
|
+
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
4684
|
+
lineStr = chunk.outro + lineStr;
|
|
4685
|
+
}
|
|
4686
|
+
|
|
4687
|
+
if (chunk.content.length > 0) {
|
|
4688
|
+
lineIndex = chunk.content.lastIndexOf(n);
|
|
4689
|
+
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
4690
|
+
lineStr = chunk.content + lineStr;
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4693
|
+
if (chunk.intro.length > 0) {
|
|
4694
|
+
lineIndex = chunk.intro.lastIndexOf(n);
|
|
4695
|
+
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
4696
|
+
lineStr = chunk.intro + lineStr;
|
|
4697
|
+
}
|
|
4698
|
+
} while ((chunk = chunk.previous));
|
|
4699
|
+
lineIndex = this.intro.lastIndexOf(n);
|
|
4700
|
+
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
4701
|
+
return this.intro + lineStr;
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
slice(start = 0, end = this.original.length) {
|
|
4705
|
+
while (start < 0) start += this.original.length;
|
|
4706
|
+
while (end < 0) end += this.original.length;
|
|
4707
|
+
|
|
4708
|
+
let result = '';
|
|
4709
|
+
|
|
4710
|
+
// find start chunk
|
|
4711
|
+
let chunk = this.firstChunk;
|
|
4712
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
4713
|
+
// found end chunk before start
|
|
4714
|
+
if (chunk.start < end && chunk.end >= end) {
|
|
4715
|
+
return result;
|
|
4716
|
+
}
|
|
4717
|
+
|
|
4718
|
+
chunk = chunk.next;
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4721
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
4722
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
4723
|
+
|
|
4724
|
+
const startChunk = chunk;
|
|
4725
|
+
while (chunk) {
|
|
4726
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
4727
|
+
result += chunk.intro;
|
|
4728
|
+
}
|
|
4729
|
+
|
|
4730
|
+
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
4731
|
+
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
4732
|
+
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
4733
|
+
|
|
4734
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
4735
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
4736
|
+
|
|
4737
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
4738
|
+
|
|
4739
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
4740
|
+
result += chunk.outro;
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4743
|
+
if (containsEnd) {
|
|
4744
|
+
break;
|
|
4745
|
+
}
|
|
4746
|
+
|
|
4747
|
+
chunk = chunk.next;
|
|
4748
|
+
}
|
|
4749
|
+
|
|
4750
|
+
return result;
|
|
4751
|
+
}
|
|
4752
|
+
|
|
4753
|
+
// TODO deprecate this? not really very useful
|
|
4754
|
+
snip(start, end) {
|
|
4755
|
+
const clone = this.clone();
|
|
4756
|
+
clone.remove(0, start);
|
|
4757
|
+
clone.remove(end, clone.original.length);
|
|
4758
|
+
|
|
4759
|
+
return clone;
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4762
|
+
_split(index) {
|
|
4763
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
4764
|
+
|
|
4765
|
+
let chunk = this.lastSearchedChunk;
|
|
4766
|
+
const searchForward = index > chunk.end;
|
|
4767
|
+
|
|
4768
|
+
while (chunk) {
|
|
4769
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
4770
|
+
|
|
4771
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
|
|
4775
|
+
_splitChunk(chunk, index) {
|
|
4776
|
+
if (chunk.edited && chunk.content.length) {
|
|
4777
|
+
// zero-length edited chunks are a special case (overlapping replacements)
|
|
4778
|
+
const loc = getLocator(this.original)(index);
|
|
4779
|
+
throw new Error(
|
|
4780
|
+
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
|
|
4781
|
+
);
|
|
4782
|
+
}
|
|
4783
|
+
|
|
4784
|
+
const newChunk = chunk.split(index);
|
|
4785
|
+
|
|
4786
|
+
this.byEnd[index] = chunk;
|
|
4787
|
+
this.byStart[index] = newChunk;
|
|
4788
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
4789
|
+
|
|
4790
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
4791
|
+
|
|
4792
|
+
this.lastSearchedChunk = chunk;
|
|
4793
|
+
return true;
|
|
4794
|
+
}
|
|
4795
|
+
|
|
4796
|
+
toString() {
|
|
4797
|
+
let str = this.intro;
|
|
4798
|
+
|
|
4799
|
+
let chunk = this.firstChunk;
|
|
4800
|
+
while (chunk) {
|
|
4801
|
+
str += chunk.toString();
|
|
4802
|
+
chunk = chunk.next;
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4805
|
+
return str + this.outro;
|
|
4806
|
+
}
|
|
4807
|
+
|
|
4808
|
+
isEmpty() {
|
|
4809
|
+
let chunk = this.firstChunk;
|
|
4810
|
+
do {
|
|
4811
|
+
if (
|
|
4812
|
+
(chunk.intro.length && chunk.intro.trim()) ||
|
|
4813
|
+
(chunk.content.length && chunk.content.trim()) ||
|
|
4814
|
+
(chunk.outro.length && chunk.outro.trim())
|
|
4815
|
+
)
|
|
4816
|
+
return false;
|
|
4817
|
+
} while ((chunk = chunk.next));
|
|
4818
|
+
return true;
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
length() {
|
|
4822
|
+
let chunk = this.firstChunk;
|
|
4823
|
+
let length = 0;
|
|
4824
|
+
do {
|
|
4825
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
4826
|
+
} while ((chunk = chunk.next));
|
|
4827
|
+
return length;
|
|
4828
|
+
}
|
|
4829
|
+
|
|
4830
|
+
trimLines() {
|
|
4831
|
+
return this.trim('[\\r\\n]');
|
|
4832
|
+
}
|
|
4833
|
+
|
|
4834
|
+
trim(charType) {
|
|
4835
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4838
|
+
trimEndAborted(charType) {
|
|
4839
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
4840
|
+
|
|
4841
|
+
this.outro = this.outro.replace(rx, '');
|
|
4842
|
+
if (this.outro.length) return true;
|
|
4843
|
+
|
|
4844
|
+
let chunk = this.lastChunk;
|
|
4845
|
+
|
|
4846
|
+
do {
|
|
4847
|
+
const end = chunk.end;
|
|
4848
|
+
const aborted = chunk.trimEnd(rx);
|
|
4849
|
+
|
|
4850
|
+
// if chunk was trimmed, we have a new lastChunk
|
|
4851
|
+
if (chunk.end !== end) {
|
|
4852
|
+
if (this.lastChunk === chunk) {
|
|
4853
|
+
this.lastChunk = chunk.next;
|
|
4854
|
+
}
|
|
4855
|
+
|
|
4856
|
+
this.byEnd[chunk.end] = chunk;
|
|
4857
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
4858
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
4859
|
+
}
|
|
4860
|
+
|
|
4861
|
+
if (aborted) return true;
|
|
4862
|
+
chunk = chunk.previous;
|
|
4863
|
+
} while (chunk);
|
|
4864
|
+
|
|
4865
|
+
return false;
|
|
4866
|
+
}
|
|
4867
|
+
|
|
4868
|
+
trimEnd(charType) {
|
|
4869
|
+
this.trimEndAborted(charType);
|
|
4870
|
+
return this;
|
|
4871
|
+
}
|
|
4872
|
+
trimStartAborted(charType) {
|
|
4873
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
4874
|
+
|
|
4875
|
+
this.intro = this.intro.replace(rx, '');
|
|
4876
|
+
if (this.intro.length) return true;
|
|
4877
|
+
|
|
4878
|
+
let chunk = this.firstChunk;
|
|
4879
|
+
|
|
4880
|
+
do {
|
|
4881
|
+
const end = chunk.end;
|
|
4882
|
+
const aborted = chunk.trimStart(rx);
|
|
4883
|
+
|
|
4884
|
+
if (chunk.end !== end) {
|
|
4885
|
+
// special case...
|
|
4886
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
4887
|
+
|
|
4888
|
+
this.byEnd[chunk.end] = chunk;
|
|
4889
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
4890
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
4891
|
+
}
|
|
4892
|
+
|
|
4893
|
+
if (aborted) return true;
|
|
4894
|
+
chunk = chunk.next;
|
|
4895
|
+
} while (chunk);
|
|
4896
|
+
|
|
4897
|
+
return false;
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4900
|
+
trimStart(charType) {
|
|
4901
|
+
this.trimStartAborted(charType);
|
|
4902
|
+
return this;
|
|
4903
|
+
}
|
|
4904
|
+
|
|
4905
|
+
hasChanged() {
|
|
4906
|
+
return this.original !== this.toString();
|
|
4907
|
+
}
|
|
4908
|
+
|
|
4909
|
+
_replaceRegexp(searchValue, replacement) {
|
|
4910
|
+
function getReplacement(match, str) {
|
|
4911
|
+
if (typeof replacement === 'string') {
|
|
4912
|
+
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
4913
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
|
|
4914
|
+
if (i === '$') return '$';
|
|
4915
|
+
if (i === '&') return match[0];
|
|
4916
|
+
const num = +i;
|
|
4917
|
+
if (num < match.length) return match[+i];
|
|
4918
|
+
return `$${i}`;
|
|
4919
|
+
});
|
|
4920
|
+
} else {
|
|
4921
|
+
return replacement(...match, match.index, str, match.groups);
|
|
4922
|
+
}
|
|
4923
|
+
}
|
|
4924
|
+
function matchAll(re, str) {
|
|
4925
|
+
let match;
|
|
4926
|
+
const matches = [];
|
|
4927
|
+
while ((match = re.exec(str))) {
|
|
4928
|
+
matches.push(match);
|
|
4929
|
+
}
|
|
4930
|
+
return matches;
|
|
4931
|
+
}
|
|
4932
|
+
if (searchValue.global) {
|
|
4933
|
+
const matches = matchAll(searchValue, this.original);
|
|
4934
|
+
matches.forEach((match) => {
|
|
4935
|
+
if (match.index != null)
|
|
4936
|
+
this.overwrite(
|
|
4937
|
+
match.index,
|
|
4938
|
+
match.index + match[0].length,
|
|
4939
|
+
getReplacement(match, this.original),
|
|
4940
|
+
);
|
|
4941
|
+
});
|
|
4942
|
+
} else {
|
|
4943
|
+
const match = this.original.match(searchValue);
|
|
4944
|
+
if (match && match.index != null)
|
|
4945
|
+
this.overwrite(
|
|
4946
|
+
match.index,
|
|
4947
|
+
match.index + match[0].length,
|
|
4948
|
+
getReplacement(match, this.original),
|
|
4949
|
+
);
|
|
4950
|
+
}
|
|
4951
|
+
return this;
|
|
4952
|
+
}
|
|
4953
|
+
|
|
4954
|
+
_replaceString(string, replacement) {
|
|
4955
|
+
const { original } = this;
|
|
4956
|
+
const index = original.indexOf(string);
|
|
4957
|
+
|
|
4958
|
+
if (index !== -1) {
|
|
4959
|
+
this.overwrite(index, index + string.length, replacement);
|
|
4960
|
+
}
|
|
4961
|
+
|
|
4962
|
+
return this;
|
|
4963
|
+
}
|
|
4964
|
+
|
|
4965
|
+
replace(searchValue, replacement) {
|
|
4966
|
+
if (typeof searchValue === 'string') {
|
|
4967
|
+
return this._replaceString(searchValue, replacement);
|
|
4968
|
+
}
|
|
4969
|
+
|
|
4970
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4973
|
+
_replaceAllString(string, replacement) {
|
|
4974
|
+
const { original } = this;
|
|
4975
|
+
const stringLength = string.length;
|
|
4976
|
+
for (
|
|
4977
|
+
let index = original.indexOf(string);
|
|
4978
|
+
index !== -1;
|
|
4979
|
+
index = original.indexOf(string, index + stringLength)
|
|
4980
|
+
) {
|
|
4981
|
+
this.overwrite(index, index + stringLength, replacement);
|
|
4982
|
+
}
|
|
4983
|
+
|
|
4984
|
+
return this;
|
|
4985
|
+
}
|
|
4986
|
+
|
|
4987
|
+
replaceAll(searchValue, replacement) {
|
|
4988
|
+
if (typeof searchValue === 'string') {
|
|
4989
|
+
return this._replaceAllString(searchValue, replacement);
|
|
4990
|
+
}
|
|
4991
|
+
|
|
4992
|
+
if (!searchValue.global) {
|
|
4993
|
+
throw new TypeError(
|
|
4994
|
+
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
|
|
4995
|
+
);
|
|
4996
|
+
}
|
|
4997
|
+
|
|
4998
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
4999
|
+
}
|
|
5000
|
+
}
|
|
5001
|
+
|
|
3750
5002
|
const debug = createDebugger('vite:sourcemap', {
|
|
3751
5003
|
onlyWhenFocused: true,
|
|
3752
5004
|
});
|
|
@@ -3794,11 +5046,18 @@ function send(req, res, content, type, options) {
|
|
|
3794
5046
|
}
|
|
3795
5047
|
}
|
|
3796
5048
|
// inject source map reference
|
|
3797
|
-
if (map && map.mappings) {
|
|
5049
|
+
if (map && 'version' in map && map.mappings) {
|
|
3798
5050
|
if (type === 'js' || type === 'css') {
|
|
3799
5051
|
content = getCodeWithSourcemap(type, content.toString(), map);
|
|
3800
5052
|
}
|
|
3801
5053
|
}
|
|
5054
|
+
else {
|
|
5055
|
+
if (type === 'js' && (!map || map.mappings !== '')) {
|
|
5056
|
+
const urlWithoutTimestamp = removeTimestampQuery(req.url);
|
|
5057
|
+
const ms = new MagicString(content.toString());
|
|
5058
|
+
content = getCodeWithSourcemap(type, content.toString(), ms.generateMap({ source: urlWithoutTimestamp, hires: 'boundary' }));
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
3802
5061
|
res.statusCode = 200;
|
|
3803
5062
|
res.end(content);
|
|
3804
5063
|
return;
|