@noma.to/qwik-testing-library 1.0.4 → 1.1.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/README.md +61 -0
- package/lib/_virtual/_commonjsHelpers.qwik.cjs +2 -0
- package/lib/_virtual/_commonjsHelpers.qwik.mjs +2 -0
- package/lib/_virtual/sourcemap-codec.umd.qwik.cjs +4 -0
- package/lib/_virtual/sourcemap-codec.umd.qwik.mjs +4 -0
- package/lib/index.qwik.cjs +4 -0
- package/lib/index.qwik.mjs +4 -0
- package/lib/lib/mock.qwik.cjs +14 -0
- package/lib/lib/mock.qwik.mjs +14 -0
- package/lib/lib/qwik-testing-library.qwik.cjs +4 -0
- package/lib/lib/qwik-testing-library.qwik.mjs +4 -0
- package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.cjs +425 -0
- package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.mjs +425 -0
- package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.cjs +1967 -0
- package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.mjs +1967 -0
- package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +1202 -0
- package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +1202 -0
- package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +44 -0
- package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +44 -0
- package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.cjs +665 -0
- package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.mjs +665 -0
- package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.cjs +1641 -0
- package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.mjs +1641 -0
- package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.cjs +148 -0
- package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.mjs +148 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.cjs +158 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.mjs +158 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.cjs +1731 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.mjs +1731 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.cjs +137 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.mjs +137 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.cjs +150 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.mjs +150 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.cjs +81 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.mjs +81 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.cjs +216 -0
- package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.mjs +216 -0
- package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.cjs +3905 -0
- package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.mjs +3905 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.cjs +9 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.mjs +10 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.cjs +16 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.mjs +17 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.cjs +9 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.mjs +10 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.cjs +16 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.mjs +17 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.cjs +12 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.mjs +13 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.cjs +30 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.mjs +31 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.cjs +11 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.mjs +12 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.cjs +160 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.mjs +160 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.cjs +36 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.mjs +36 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.cjs +130 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.mjs +130 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.cjs +25 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.mjs +26 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.cjs +19 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.mjs +20 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.cjs +24 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.mjs +25 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.cjs +17 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.mjs +18 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.cjs +9 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.mjs +10 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.cjs +16 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.mjs +17 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.cjs +24 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.mjs +25 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.cjs +8 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.mjs +9 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.cjs +34 -0
- package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.mjs +35 -0
- package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.cjs +968 -0
- package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.mjs +968 -0
- package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.cjs +101 -0
- package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.mjs +101 -0
- package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +7 -0
- package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +8 -0
- package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +80 -0
- package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +80 -0
- package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +104 -0
- package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +104 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +8 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +8 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.cjs +6 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.mjs +6 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +56 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +56 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.cjs +16 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.mjs +16 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.cjs +2556 -0
- package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.mjs +2556 -0
- package/lib-types/lib/mock.d.ts +34 -0
- package/lib-types/lib/qwik-testing-library.d.ts +2 -1
- package/package.json +5 -4
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const sourcemapCodec_umd = require("../../../../@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.cjs");
|
|
4
|
+
class BitSet {
|
|
5
|
+
constructor(arg) {
|
|
6
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
7
|
+
}
|
|
8
|
+
add(n2) {
|
|
9
|
+
this.bits[n2 >> 5] |= 1 << (n2 & 31);
|
|
10
|
+
}
|
|
11
|
+
has(n2) {
|
|
12
|
+
return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class Chunk {
|
|
16
|
+
constructor(start, end, content) {
|
|
17
|
+
this.start = start;
|
|
18
|
+
this.end = end;
|
|
19
|
+
this.original = content;
|
|
20
|
+
this.intro = "";
|
|
21
|
+
this.outro = "";
|
|
22
|
+
this.content = content;
|
|
23
|
+
this.storeName = false;
|
|
24
|
+
this.edited = false;
|
|
25
|
+
{
|
|
26
|
+
this.previous = null;
|
|
27
|
+
this.next = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
appendLeft(content) {
|
|
31
|
+
this.outro += content;
|
|
32
|
+
}
|
|
33
|
+
appendRight(content) {
|
|
34
|
+
this.intro = this.intro + content;
|
|
35
|
+
}
|
|
36
|
+
clone() {
|
|
37
|
+
const chunk = new Chunk(this.start, this.end, this.original);
|
|
38
|
+
chunk.intro = this.intro;
|
|
39
|
+
chunk.outro = this.outro;
|
|
40
|
+
chunk.content = this.content;
|
|
41
|
+
chunk.storeName = this.storeName;
|
|
42
|
+
chunk.edited = this.edited;
|
|
43
|
+
return chunk;
|
|
44
|
+
}
|
|
45
|
+
contains(index) {
|
|
46
|
+
return this.start < index && index < this.end;
|
|
47
|
+
}
|
|
48
|
+
eachNext(fn) {
|
|
49
|
+
let chunk = this;
|
|
50
|
+
while (chunk) {
|
|
51
|
+
fn(chunk);
|
|
52
|
+
chunk = chunk.next;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
eachPrevious(fn) {
|
|
56
|
+
let chunk = this;
|
|
57
|
+
while (chunk) {
|
|
58
|
+
fn(chunk);
|
|
59
|
+
chunk = chunk.previous;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
edit(content, storeName, contentOnly) {
|
|
63
|
+
this.content = content;
|
|
64
|
+
if (!contentOnly) {
|
|
65
|
+
this.intro = "";
|
|
66
|
+
this.outro = "";
|
|
67
|
+
}
|
|
68
|
+
this.storeName = storeName;
|
|
69
|
+
this.edited = true;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
prependLeft(content) {
|
|
73
|
+
this.outro = content + this.outro;
|
|
74
|
+
}
|
|
75
|
+
prependRight(content) {
|
|
76
|
+
this.intro = content + this.intro;
|
|
77
|
+
}
|
|
78
|
+
reset() {
|
|
79
|
+
this.intro = "";
|
|
80
|
+
this.outro = "";
|
|
81
|
+
if (this.edited) {
|
|
82
|
+
this.content = this.original;
|
|
83
|
+
this.storeName = false;
|
|
84
|
+
this.edited = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
split(index) {
|
|
88
|
+
const sliceIndex = index - this.start;
|
|
89
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
90
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
91
|
+
this.original = originalBefore;
|
|
92
|
+
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
93
|
+
newChunk.outro = this.outro;
|
|
94
|
+
this.outro = "";
|
|
95
|
+
this.end = index;
|
|
96
|
+
if (this.edited) {
|
|
97
|
+
newChunk.edit("", false);
|
|
98
|
+
this.content = "";
|
|
99
|
+
} else {
|
|
100
|
+
this.content = originalBefore;
|
|
101
|
+
}
|
|
102
|
+
newChunk.next = this.next;
|
|
103
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
104
|
+
newChunk.previous = this;
|
|
105
|
+
this.next = newChunk;
|
|
106
|
+
return newChunk;
|
|
107
|
+
}
|
|
108
|
+
toString() {
|
|
109
|
+
return this.intro + this.content + this.outro;
|
|
110
|
+
}
|
|
111
|
+
trimEnd(rx) {
|
|
112
|
+
this.outro = this.outro.replace(rx, "");
|
|
113
|
+
if (this.outro.length) return true;
|
|
114
|
+
const trimmed = this.content.replace(rx, "");
|
|
115
|
+
if (trimmed.length) {
|
|
116
|
+
if (trimmed !== this.content) {
|
|
117
|
+
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
118
|
+
if (this.edited) {
|
|
119
|
+
this.edit(trimmed, this.storeName, true);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
} else {
|
|
124
|
+
this.edit("", void 0, true);
|
|
125
|
+
this.intro = this.intro.replace(rx, "");
|
|
126
|
+
if (this.intro.length) return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
trimStart(rx) {
|
|
130
|
+
this.intro = this.intro.replace(rx, "");
|
|
131
|
+
if (this.intro.length) return true;
|
|
132
|
+
const trimmed = this.content.replace(rx, "");
|
|
133
|
+
if (trimmed.length) {
|
|
134
|
+
if (trimmed !== this.content) {
|
|
135
|
+
const newChunk = this.split(this.end - trimmed.length);
|
|
136
|
+
if (this.edited) {
|
|
137
|
+
newChunk.edit(trimmed, this.storeName, true);
|
|
138
|
+
}
|
|
139
|
+
this.edit("", void 0, true);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
} else {
|
|
143
|
+
this.edit("", void 0, true);
|
|
144
|
+
this.outro = this.outro.replace(rx, "");
|
|
145
|
+
if (this.outro.length) return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function getBtoa() {
|
|
150
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
|
|
151
|
+
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
152
|
+
} else if (typeof Buffer === "function") {
|
|
153
|
+
return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
154
|
+
} else {
|
|
155
|
+
return () => {
|
|
156
|
+
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const btoa = /* @__PURE__ */ getBtoa();
|
|
161
|
+
class SourceMap {
|
|
162
|
+
constructor(properties) {
|
|
163
|
+
this.version = 3;
|
|
164
|
+
this.file = properties.file;
|
|
165
|
+
this.sources = properties.sources;
|
|
166
|
+
this.sourcesContent = properties.sourcesContent;
|
|
167
|
+
this.names = properties.names;
|
|
168
|
+
this.mappings = sourcemapCodec_umd.sourcemapCodec_umdExports.encode(properties.mappings);
|
|
169
|
+
if (typeof properties.x_google_ignoreList !== "undefined") {
|
|
170
|
+
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
toString() {
|
|
174
|
+
return JSON.stringify(this);
|
|
175
|
+
}
|
|
176
|
+
toUrl() {
|
|
177
|
+
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function guessIndent(code) {
|
|
181
|
+
const lines = code.split("\n");
|
|
182
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
183
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
184
|
+
if (tabbed.length === 0 && spaced.length === 0) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
if (tabbed.length >= spaced.length) {
|
|
188
|
+
return " ";
|
|
189
|
+
}
|
|
190
|
+
const min = spaced.reduce((previous, current) => {
|
|
191
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
192
|
+
return Math.min(numSpaces, previous);
|
|
193
|
+
}, Infinity);
|
|
194
|
+
return new Array(min + 1).join(" ");
|
|
195
|
+
}
|
|
196
|
+
function getRelativePath(from, to) {
|
|
197
|
+
const fromParts = from.split(/[/\\]/);
|
|
198
|
+
const toParts = to.split(/[/\\]/);
|
|
199
|
+
fromParts.pop();
|
|
200
|
+
while (fromParts[0] === toParts[0]) {
|
|
201
|
+
fromParts.shift();
|
|
202
|
+
toParts.shift();
|
|
203
|
+
}
|
|
204
|
+
if (fromParts.length) {
|
|
205
|
+
let i = fromParts.length;
|
|
206
|
+
while (i--) fromParts[i] = "..";
|
|
207
|
+
}
|
|
208
|
+
return fromParts.concat(toParts).join("/");
|
|
209
|
+
}
|
|
210
|
+
const toString = Object.prototype.toString;
|
|
211
|
+
function isObject(thing) {
|
|
212
|
+
return toString.call(thing) === "[object Object]";
|
|
213
|
+
}
|
|
214
|
+
function getLocator(source) {
|
|
215
|
+
const originalLines = source.split("\n");
|
|
216
|
+
const lineOffsets = [];
|
|
217
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
218
|
+
lineOffsets.push(pos);
|
|
219
|
+
pos += originalLines[i].length + 1;
|
|
220
|
+
}
|
|
221
|
+
return function locate(index) {
|
|
222
|
+
let i = 0;
|
|
223
|
+
let j = lineOffsets.length;
|
|
224
|
+
while (i < j) {
|
|
225
|
+
const m = i + j >> 1;
|
|
226
|
+
if (index < lineOffsets[m]) {
|
|
227
|
+
j = m;
|
|
228
|
+
} else {
|
|
229
|
+
i = m + 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const line = i - 1;
|
|
233
|
+
const column = index - lineOffsets[line];
|
|
234
|
+
return { line, column };
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const wordRegex = /\w/;
|
|
238
|
+
class Mappings {
|
|
239
|
+
constructor(hires) {
|
|
240
|
+
this.hires = hires;
|
|
241
|
+
this.generatedCodeLine = 0;
|
|
242
|
+
this.generatedCodeColumn = 0;
|
|
243
|
+
this.raw = [];
|
|
244
|
+
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
245
|
+
this.pending = null;
|
|
246
|
+
}
|
|
247
|
+
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
248
|
+
if (content.length) {
|
|
249
|
+
const contentLengthMinusOne = content.length - 1;
|
|
250
|
+
let contentLineEnd = content.indexOf("\n", 0);
|
|
251
|
+
let previousContentLineEnd = -1;
|
|
252
|
+
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
253
|
+
const segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
254
|
+
if (nameIndex >= 0) {
|
|
255
|
+
segment2.push(nameIndex);
|
|
256
|
+
}
|
|
257
|
+
this.rawSegments.push(segment2);
|
|
258
|
+
this.generatedCodeLine += 1;
|
|
259
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
260
|
+
this.generatedCodeColumn = 0;
|
|
261
|
+
previousContentLineEnd = contentLineEnd;
|
|
262
|
+
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
263
|
+
}
|
|
264
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
265
|
+
if (nameIndex >= 0) {
|
|
266
|
+
segment.push(nameIndex);
|
|
267
|
+
}
|
|
268
|
+
this.rawSegments.push(segment);
|
|
269
|
+
this.advance(content.slice(previousContentLineEnd + 1));
|
|
270
|
+
} else if (this.pending) {
|
|
271
|
+
this.rawSegments.push(this.pending);
|
|
272
|
+
this.advance(content);
|
|
273
|
+
}
|
|
274
|
+
this.pending = null;
|
|
275
|
+
}
|
|
276
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
277
|
+
let originalCharIndex = chunk.start;
|
|
278
|
+
let first = true;
|
|
279
|
+
let charInHiresBoundary = false;
|
|
280
|
+
while (originalCharIndex < chunk.end) {
|
|
281
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
282
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
283
|
+
if (this.hires === "boundary") {
|
|
284
|
+
if (wordRegex.test(original[originalCharIndex])) {
|
|
285
|
+
if (!charInHiresBoundary) {
|
|
286
|
+
this.rawSegments.push(segment);
|
|
287
|
+
charInHiresBoundary = true;
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
this.rawSegments.push(segment);
|
|
291
|
+
charInHiresBoundary = false;
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
this.rawSegments.push(segment);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (original[originalCharIndex] === "\n") {
|
|
298
|
+
loc.line += 1;
|
|
299
|
+
loc.column = 0;
|
|
300
|
+
this.generatedCodeLine += 1;
|
|
301
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
302
|
+
this.generatedCodeColumn = 0;
|
|
303
|
+
first = true;
|
|
304
|
+
} else {
|
|
305
|
+
loc.column += 1;
|
|
306
|
+
this.generatedCodeColumn += 1;
|
|
307
|
+
first = false;
|
|
308
|
+
}
|
|
309
|
+
originalCharIndex += 1;
|
|
310
|
+
}
|
|
311
|
+
this.pending = null;
|
|
312
|
+
}
|
|
313
|
+
advance(str) {
|
|
314
|
+
if (!str) return;
|
|
315
|
+
const lines = str.split("\n");
|
|
316
|
+
if (lines.length > 1) {
|
|
317
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
318
|
+
this.generatedCodeLine++;
|
|
319
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
320
|
+
}
|
|
321
|
+
this.generatedCodeColumn = 0;
|
|
322
|
+
}
|
|
323
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const n = "\n";
|
|
327
|
+
const warned = {
|
|
328
|
+
insertLeft: false,
|
|
329
|
+
insertRight: false,
|
|
330
|
+
storeName: false
|
|
331
|
+
};
|
|
332
|
+
class MagicString {
|
|
333
|
+
constructor(string, options = {}) {
|
|
334
|
+
const chunk = new Chunk(0, string.length, string);
|
|
335
|
+
Object.defineProperties(this, {
|
|
336
|
+
original: { writable: true, value: string },
|
|
337
|
+
outro: { writable: true, value: "" },
|
|
338
|
+
intro: { writable: true, value: "" },
|
|
339
|
+
firstChunk: { writable: true, value: chunk },
|
|
340
|
+
lastChunk: { writable: true, value: chunk },
|
|
341
|
+
lastSearchedChunk: { writable: true, value: chunk },
|
|
342
|
+
byStart: { writable: true, value: {} },
|
|
343
|
+
byEnd: { writable: true, value: {} },
|
|
344
|
+
filename: { writable: true, value: options.filename },
|
|
345
|
+
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
346
|
+
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
347
|
+
storedNames: { writable: true, value: {} },
|
|
348
|
+
indentStr: { writable: true, value: void 0 },
|
|
349
|
+
ignoreList: { writable: true, value: options.ignoreList }
|
|
350
|
+
});
|
|
351
|
+
this.byStart[0] = chunk;
|
|
352
|
+
this.byEnd[string.length] = chunk;
|
|
353
|
+
}
|
|
354
|
+
addSourcemapLocation(char) {
|
|
355
|
+
this.sourcemapLocations.add(char);
|
|
356
|
+
}
|
|
357
|
+
append(content) {
|
|
358
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
359
|
+
this.outro += content;
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
appendLeft(index, content) {
|
|
363
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
364
|
+
this._split(index);
|
|
365
|
+
const chunk = this.byEnd[index];
|
|
366
|
+
if (chunk) {
|
|
367
|
+
chunk.appendLeft(content);
|
|
368
|
+
} else {
|
|
369
|
+
this.intro += content;
|
|
370
|
+
}
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
appendRight(index, content) {
|
|
374
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
375
|
+
this._split(index);
|
|
376
|
+
const chunk = this.byStart[index];
|
|
377
|
+
if (chunk) {
|
|
378
|
+
chunk.appendRight(content);
|
|
379
|
+
} else {
|
|
380
|
+
this.outro += content;
|
|
381
|
+
}
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
clone() {
|
|
385
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
386
|
+
let originalChunk = this.firstChunk;
|
|
387
|
+
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
388
|
+
while (originalChunk) {
|
|
389
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
390
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
391
|
+
const nextOriginalChunk = originalChunk.next;
|
|
392
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
393
|
+
if (nextClonedChunk) {
|
|
394
|
+
clonedChunk.next = nextClonedChunk;
|
|
395
|
+
nextClonedChunk.previous = clonedChunk;
|
|
396
|
+
clonedChunk = nextClonedChunk;
|
|
397
|
+
}
|
|
398
|
+
originalChunk = nextOriginalChunk;
|
|
399
|
+
}
|
|
400
|
+
cloned.lastChunk = clonedChunk;
|
|
401
|
+
if (this.indentExclusionRanges) {
|
|
402
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
403
|
+
}
|
|
404
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
405
|
+
cloned.intro = this.intro;
|
|
406
|
+
cloned.outro = this.outro;
|
|
407
|
+
return cloned;
|
|
408
|
+
}
|
|
409
|
+
generateDecodedMap(options) {
|
|
410
|
+
options = options || {};
|
|
411
|
+
const sourceIndex = 0;
|
|
412
|
+
const names = Object.keys(this.storedNames);
|
|
413
|
+
const mappings = new Mappings(options.hires);
|
|
414
|
+
const locate = getLocator(this.original);
|
|
415
|
+
if (this.intro) {
|
|
416
|
+
mappings.advance(this.intro);
|
|
417
|
+
}
|
|
418
|
+
this.firstChunk.eachNext((chunk) => {
|
|
419
|
+
const loc = locate(chunk.start);
|
|
420
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
421
|
+
if (chunk.edited) {
|
|
422
|
+
mappings.addEdit(
|
|
423
|
+
sourceIndex,
|
|
424
|
+
chunk.content,
|
|
425
|
+
loc,
|
|
426
|
+
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
427
|
+
);
|
|
428
|
+
} else {
|
|
429
|
+
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
430
|
+
}
|
|
431
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
432
|
+
});
|
|
433
|
+
return {
|
|
434
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
435
|
+
sources: [
|
|
436
|
+
options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
|
|
437
|
+
],
|
|
438
|
+
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
439
|
+
names,
|
|
440
|
+
mappings: mappings.raw,
|
|
441
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
generateMap(options) {
|
|
445
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
446
|
+
}
|
|
447
|
+
_ensureindentStr() {
|
|
448
|
+
if (this.indentStr === void 0) {
|
|
449
|
+
this.indentStr = guessIndent(this.original);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
_getRawIndentString() {
|
|
453
|
+
this._ensureindentStr();
|
|
454
|
+
return this.indentStr;
|
|
455
|
+
}
|
|
456
|
+
getIndentString() {
|
|
457
|
+
this._ensureindentStr();
|
|
458
|
+
return this.indentStr === null ? " " : this.indentStr;
|
|
459
|
+
}
|
|
460
|
+
indent(indentStr, options) {
|
|
461
|
+
const pattern = /^[^\r\n]/gm;
|
|
462
|
+
if (isObject(indentStr)) {
|
|
463
|
+
options = indentStr;
|
|
464
|
+
indentStr = void 0;
|
|
465
|
+
}
|
|
466
|
+
if (indentStr === void 0) {
|
|
467
|
+
this._ensureindentStr();
|
|
468
|
+
indentStr = this.indentStr || " ";
|
|
469
|
+
}
|
|
470
|
+
if (indentStr === "") return this;
|
|
471
|
+
options = options || {};
|
|
472
|
+
const isExcluded = {};
|
|
473
|
+
if (options.exclude) {
|
|
474
|
+
const exclusions = typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude;
|
|
475
|
+
exclusions.forEach((exclusion) => {
|
|
476
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
477
|
+
isExcluded[i] = true;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
482
|
+
const replacer = (match) => {
|
|
483
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
484
|
+
shouldIndentNextCharacter = true;
|
|
485
|
+
return match;
|
|
486
|
+
};
|
|
487
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
488
|
+
let charIndex = 0;
|
|
489
|
+
let chunk = this.firstChunk;
|
|
490
|
+
while (chunk) {
|
|
491
|
+
const end = chunk.end;
|
|
492
|
+
if (chunk.edited) {
|
|
493
|
+
if (!isExcluded[charIndex]) {
|
|
494
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
495
|
+
if (chunk.content.length) {
|
|
496
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
charIndex = chunk.start;
|
|
501
|
+
while (charIndex < end) {
|
|
502
|
+
if (!isExcluded[charIndex]) {
|
|
503
|
+
const char = this.original[charIndex];
|
|
504
|
+
if (char === "\n") {
|
|
505
|
+
shouldIndentNextCharacter = true;
|
|
506
|
+
} else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
507
|
+
shouldIndentNextCharacter = false;
|
|
508
|
+
if (charIndex === chunk.start) {
|
|
509
|
+
chunk.prependRight(indentStr);
|
|
510
|
+
} else {
|
|
511
|
+
this._splitChunk(chunk, charIndex);
|
|
512
|
+
chunk = chunk.next;
|
|
513
|
+
chunk.prependRight(indentStr);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
charIndex += 1;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
charIndex = chunk.end;
|
|
521
|
+
chunk = chunk.next;
|
|
522
|
+
}
|
|
523
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
insert() {
|
|
527
|
+
throw new Error(
|
|
528
|
+
"magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
insertLeft(index, content) {
|
|
532
|
+
if (!warned.insertLeft) {
|
|
533
|
+
console.warn(
|
|
534
|
+
"magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
|
|
535
|
+
);
|
|
536
|
+
warned.insertLeft = true;
|
|
537
|
+
}
|
|
538
|
+
return this.appendLeft(index, content);
|
|
539
|
+
}
|
|
540
|
+
insertRight(index, content) {
|
|
541
|
+
if (!warned.insertRight) {
|
|
542
|
+
console.warn(
|
|
543
|
+
"magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
|
|
544
|
+
);
|
|
545
|
+
warned.insertRight = true;
|
|
546
|
+
}
|
|
547
|
+
return this.prependRight(index, content);
|
|
548
|
+
}
|
|
549
|
+
move(start, end, index) {
|
|
550
|
+
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
551
|
+
this._split(start);
|
|
552
|
+
this._split(end);
|
|
553
|
+
this._split(index);
|
|
554
|
+
const first = this.byStart[start];
|
|
555
|
+
const last = this.byEnd[end];
|
|
556
|
+
const oldLeft = first.previous;
|
|
557
|
+
const oldRight = last.next;
|
|
558
|
+
const newRight = this.byStart[index];
|
|
559
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
560
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
561
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
562
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
563
|
+
if (newLeft) newLeft.next = first;
|
|
564
|
+
if (newRight) newRight.previous = last;
|
|
565
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
566
|
+
if (!last.next) {
|
|
567
|
+
this.lastChunk = first.previous;
|
|
568
|
+
this.lastChunk.next = null;
|
|
569
|
+
}
|
|
570
|
+
first.previous = newLeft;
|
|
571
|
+
last.next = newRight || null;
|
|
572
|
+
if (!newLeft) this.firstChunk = first;
|
|
573
|
+
if (!newRight) this.lastChunk = last;
|
|
574
|
+
return this;
|
|
575
|
+
}
|
|
576
|
+
overwrite(start, end, content, options) {
|
|
577
|
+
options = options || {};
|
|
578
|
+
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
579
|
+
}
|
|
580
|
+
update(start, end, content, options) {
|
|
581
|
+
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
582
|
+
if (this.original.length !== 0) {
|
|
583
|
+
while (start < 0) start += this.original.length;
|
|
584
|
+
while (end < 0) end += this.original.length;
|
|
585
|
+
}
|
|
586
|
+
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
587
|
+
if (start === end)
|
|
588
|
+
throw new Error(
|
|
589
|
+
"Cannot overwrite a zero-length range – use appendLeft or prependRight instead"
|
|
590
|
+
);
|
|
591
|
+
this._split(start);
|
|
592
|
+
this._split(end);
|
|
593
|
+
if (options === true) {
|
|
594
|
+
if (!warned.storeName) {
|
|
595
|
+
console.warn(
|
|
596
|
+
"The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
|
|
597
|
+
);
|
|
598
|
+
warned.storeName = true;
|
|
599
|
+
}
|
|
600
|
+
options = { storeName: true };
|
|
601
|
+
}
|
|
602
|
+
const storeName = options !== void 0 ? options.storeName : false;
|
|
603
|
+
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
604
|
+
if (storeName) {
|
|
605
|
+
const original = this.original.slice(start, end);
|
|
606
|
+
Object.defineProperty(this.storedNames, original, {
|
|
607
|
+
writable: true,
|
|
608
|
+
value: true,
|
|
609
|
+
enumerable: true
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
const first = this.byStart[start];
|
|
613
|
+
const last = this.byEnd[end];
|
|
614
|
+
if (first) {
|
|
615
|
+
let chunk = first;
|
|
616
|
+
while (chunk !== last) {
|
|
617
|
+
if (chunk.next !== this.byStart[chunk.end]) {
|
|
618
|
+
throw new Error("Cannot overwrite across a split point");
|
|
619
|
+
}
|
|
620
|
+
chunk = chunk.next;
|
|
621
|
+
chunk.edit("", false);
|
|
622
|
+
}
|
|
623
|
+
first.edit(content, storeName, !overwrite);
|
|
624
|
+
} else {
|
|
625
|
+
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
626
|
+
last.next = newChunk;
|
|
627
|
+
newChunk.previous = last;
|
|
628
|
+
}
|
|
629
|
+
return this;
|
|
630
|
+
}
|
|
631
|
+
prepend(content) {
|
|
632
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
633
|
+
this.intro = content + this.intro;
|
|
634
|
+
return this;
|
|
635
|
+
}
|
|
636
|
+
prependLeft(index, content) {
|
|
637
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
638
|
+
this._split(index);
|
|
639
|
+
const chunk = this.byEnd[index];
|
|
640
|
+
if (chunk) {
|
|
641
|
+
chunk.prependLeft(content);
|
|
642
|
+
} else {
|
|
643
|
+
this.intro = content + this.intro;
|
|
644
|
+
}
|
|
645
|
+
return this;
|
|
646
|
+
}
|
|
647
|
+
prependRight(index, content) {
|
|
648
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
649
|
+
this._split(index);
|
|
650
|
+
const chunk = this.byStart[index];
|
|
651
|
+
if (chunk) {
|
|
652
|
+
chunk.prependRight(content);
|
|
653
|
+
} else {
|
|
654
|
+
this.outro = content + this.outro;
|
|
655
|
+
}
|
|
656
|
+
return this;
|
|
657
|
+
}
|
|
658
|
+
remove(start, end) {
|
|
659
|
+
if (this.original.length !== 0) {
|
|
660
|
+
while (start < 0) start += this.original.length;
|
|
661
|
+
while (end < 0) end += this.original.length;
|
|
662
|
+
}
|
|
663
|
+
if (start === end) return this;
|
|
664
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
665
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
666
|
+
this._split(start);
|
|
667
|
+
this._split(end);
|
|
668
|
+
let chunk = this.byStart[start];
|
|
669
|
+
while (chunk) {
|
|
670
|
+
chunk.intro = "";
|
|
671
|
+
chunk.outro = "";
|
|
672
|
+
chunk.edit("");
|
|
673
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
674
|
+
}
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
reset(start, end) {
|
|
678
|
+
if (this.original.length !== 0) {
|
|
679
|
+
while (start < 0) start += this.original.length;
|
|
680
|
+
while (end < 0) end += this.original.length;
|
|
681
|
+
}
|
|
682
|
+
if (start === end) return this;
|
|
683
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
684
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
685
|
+
this._split(start);
|
|
686
|
+
this._split(end);
|
|
687
|
+
let chunk = this.byStart[start];
|
|
688
|
+
while (chunk) {
|
|
689
|
+
chunk.reset();
|
|
690
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
691
|
+
}
|
|
692
|
+
return this;
|
|
693
|
+
}
|
|
694
|
+
lastChar() {
|
|
695
|
+
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
696
|
+
let chunk = this.lastChunk;
|
|
697
|
+
do {
|
|
698
|
+
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
699
|
+
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
700
|
+
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
701
|
+
} while (chunk = chunk.previous);
|
|
702
|
+
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
703
|
+
return "";
|
|
704
|
+
}
|
|
705
|
+
lastLine() {
|
|
706
|
+
let lineIndex = this.outro.lastIndexOf(n);
|
|
707
|
+
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
708
|
+
let lineStr = this.outro;
|
|
709
|
+
let chunk = this.lastChunk;
|
|
710
|
+
do {
|
|
711
|
+
if (chunk.outro.length > 0) {
|
|
712
|
+
lineIndex = chunk.outro.lastIndexOf(n);
|
|
713
|
+
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
714
|
+
lineStr = chunk.outro + lineStr;
|
|
715
|
+
}
|
|
716
|
+
if (chunk.content.length > 0) {
|
|
717
|
+
lineIndex = chunk.content.lastIndexOf(n);
|
|
718
|
+
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
719
|
+
lineStr = chunk.content + lineStr;
|
|
720
|
+
}
|
|
721
|
+
if (chunk.intro.length > 0) {
|
|
722
|
+
lineIndex = chunk.intro.lastIndexOf(n);
|
|
723
|
+
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
724
|
+
lineStr = chunk.intro + lineStr;
|
|
725
|
+
}
|
|
726
|
+
} while (chunk = chunk.previous);
|
|
727
|
+
lineIndex = this.intro.lastIndexOf(n);
|
|
728
|
+
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
729
|
+
return this.intro + lineStr;
|
|
730
|
+
}
|
|
731
|
+
slice(start = 0, end = this.original.length) {
|
|
732
|
+
if (this.original.length !== 0) {
|
|
733
|
+
while (start < 0) start += this.original.length;
|
|
734
|
+
while (end < 0) end += this.original.length;
|
|
735
|
+
}
|
|
736
|
+
let result = "";
|
|
737
|
+
let chunk = this.firstChunk;
|
|
738
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
739
|
+
if (chunk.start < end && chunk.end >= end) {
|
|
740
|
+
return result;
|
|
741
|
+
}
|
|
742
|
+
chunk = chunk.next;
|
|
743
|
+
}
|
|
744
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
745
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
746
|
+
const startChunk = chunk;
|
|
747
|
+
while (chunk) {
|
|
748
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
749
|
+
result += chunk.intro;
|
|
750
|
+
}
|
|
751
|
+
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
752
|
+
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
753
|
+
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
754
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
755
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
756
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
757
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
758
|
+
result += chunk.outro;
|
|
759
|
+
}
|
|
760
|
+
if (containsEnd) {
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
chunk = chunk.next;
|
|
764
|
+
}
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
// TODO deprecate this? not really very useful
|
|
768
|
+
snip(start, end) {
|
|
769
|
+
const clone = this.clone();
|
|
770
|
+
clone.remove(0, start);
|
|
771
|
+
clone.remove(end, clone.original.length);
|
|
772
|
+
return clone;
|
|
773
|
+
}
|
|
774
|
+
_split(index) {
|
|
775
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
776
|
+
let chunk = this.lastSearchedChunk;
|
|
777
|
+
const searchForward = index > chunk.end;
|
|
778
|
+
while (chunk) {
|
|
779
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
780
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
_splitChunk(chunk, index) {
|
|
784
|
+
if (chunk.edited && chunk.content.length) {
|
|
785
|
+
const loc = getLocator(this.original)(index);
|
|
786
|
+
throw new Error(
|
|
787
|
+
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
const newChunk = chunk.split(index);
|
|
791
|
+
this.byEnd[index] = chunk;
|
|
792
|
+
this.byStart[index] = newChunk;
|
|
793
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
794
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
795
|
+
this.lastSearchedChunk = chunk;
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
toString() {
|
|
799
|
+
let str = this.intro;
|
|
800
|
+
let chunk = this.firstChunk;
|
|
801
|
+
while (chunk) {
|
|
802
|
+
str += chunk.toString();
|
|
803
|
+
chunk = chunk.next;
|
|
804
|
+
}
|
|
805
|
+
return str + this.outro;
|
|
806
|
+
}
|
|
807
|
+
isEmpty() {
|
|
808
|
+
let chunk = this.firstChunk;
|
|
809
|
+
do {
|
|
810
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
|
|
811
|
+
return false;
|
|
812
|
+
} while (chunk = chunk.next);
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
length() {
|
|
816
|
+
let chunk = this.firstChunk;
|
|
817
|
+
let length = 0;
|
|
818
|
+
do {
|
|
819
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
820
|
+
} while (chunk = chunk.next);
|
|
821
|
+
return length;
|
|
822
|
+
}
|
|
823
|
+
trimLines() {
|
|
824
|
+
return this.trim("[\\r\\n]");
|
|
825
|
+
}
|
|
826
|
+
trim(charType) {
|
|
827
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
828
|
+
}
|
|
829
|
+
trimEndAborted(charType) {
|
|
830
|
+
const rx = new RegExp((charType || "\\s") + "+$");
|
|
831
|
+
this.outro = this.outro.replace(rx, "");
|
|
832
|
+
if (this.outro.length) return true;
|
|
833
|
+
let chunk = this.lastChunk;
|
|
834
|
+
do {
|
|
835
|
+
const end = chunk.end;
|
|
836
|
+
const aborted = chunk.trimEnd(rx);
|
|
837
|
+
if (chunk.end !== end) {
|
|
838
|
+
if (this.lastChunk === chunk) {
|
|
839
|
+
this.lastChunk = chunk.next;
|
|
840
|
+
}
|
|
841
|
+
this.byEnd[chunk.end] = chunk;
|
|
842
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
843
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
844
|
+
}
|
|
845
|
+
if (aborted) return true;
|
|
846
|
+
chunk = chunk.previous;
|
|
847
|
+
} while (chunk);
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
trimEnd(charType) {
|
|
851
|
+
this.trimEndAborted(charType);
|
|
852
|
+
return this;
|
|
853
|
+
}
|
|
854
|
+
trimStartAborted(charType) {
|
|
855
|
+
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
856
|
+
this.intro = this.intro.replace(rx, "");
|
|
857
|
+
if (this.intro.length) return true;
|
|
858
|
+
let chunk = this.firstChunk;
|
|
859
|
+
do {
|
|
860
|
+
const end = chunk.end;
|
|
861
|
+
const aborted = chunk.trimStart(rx);
|
|
862
|
+
if (chunk.end !== end) {
|
|
863
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
864
|
+
this.byEnd[chunk.end] = chunk;
|
|
865
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
866
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
867
|
+
}
|
|
868
|
+
if (aborted) return true;
|
|
869
|
+
chunk = chunk.next;
|
|
870
|
+
} while (chunk);
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
trimStart(charType) {
|
|
874
|
+
this.trimStartAborted(charType);
|
|
875
|
+
return this;
|
|
876
|
+
}
|
|
877
|
+
hasChanged() {
|
|
878
|
+
return this.original !== this.toString();
|
|
879
|
+
}
|
|
880
|
+
_replaceRegexp(searchValue, replacement) {
|
|
881
|
+
function getReplacement(match, str) {
|
|
882
|
+
if (typeof replacement === "string") {
|
|
883
|
+
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
884
|
+
if (i === "$") return "$";
|
|
885
|
+
if (i === "&") return match[0];
|
|
886
|
+
const num = +i;
|
|
887
|
+
if (num < match.length) return match[+i];
|
|
888
|
+
return `$${i}`;
|
|
889
|
+
});
|
|
890
|
+
} else {
|
|
891
|
+
return replacement(...match, match.index, str, match.groups);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function matchAll(re, str) {
|
|
895
|
+
let match;
|
|
896
|
+
const matches = [];
|
|
897
|
+
while (match = re.exec(str)) {
|
|
898
|
+
matches.push(match);
|
|
899
|
+
}
|
|
900
|
+
return matches;
|
|
901
|
+
}
|
|
902
|
+
if (searchValue.global) {
|
|
903
|
+
const matches = matchAll(searchValue, this.original);
|
|
904
|
+
matches.forEach((match) => {
|
|
905
|
+
if (match.index != null) {
|
|
906
|
+
const replacement2 = getReplacement(match, this.original);
|
|
907
|
+
if (replacement2 !== match[0]) {
|
|
908
|
+
this.overwrite(
|
|
909
|
+
match.index,
|
|
910
|
+
match.index + match[0].length,
|
|
911
|
+
replacement2
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
} else {
|
|
917
|
+
const match = this.original.match(searchValue);
|
|
918
|
+
if (match && match.index != null) {
|
|
919
|
+
const replacement2 = getReplacement(match, this.original);
|
|
920
|
+
if (replacement2 !== match[0]) {
|
|
921
|
+
this.overwrite(
|
|
922
|
+
match.index,
|
|
923
|
+
match.index + match[0].length,
|
|
924
|
+
replacement2
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
_replaceString(string, replacement) {
|
|
932
|
+
const { original } = this;
|
|
933
|
+
const index = original.indexOf(string);
|
|
934
|
+
if (index !== -1) {
|
|
935
|
+
this.overwrite(index, index + string.length, replacement);
|
|
936
|
+
}
|
|
937
|
+
return this;
|
|
938
|
+
}
|
|
939
|
+
replace(searchValue, replacement) {
|
|
940
|
+
if (typeof searchValue === "string") {
|
|
941
|
+
return this._replaceString(searchValue, replacement);
|
|
942
|
+
}
|
|
943
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
944
|
+
}
|
|
945
|
+
_replaceAllString(string, replacement) {
|
|
946
|
+
const { original } = this;
|
|
947
|
+
const stringLength = string.length;
|
|
948
|
+
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
949
|
+
const previous = original.slice(index, index + stringLength);
|
|
950
|
+
if (previous !== replacement)
|
|
951
|
+
this.overwrite(index, index + stringLength, replacement);
|
|
952
|
+
}
|
|
953
|
+
return this;
|
|
954
|
+
}
|
|
955
|
+
replaceAll(searchValue, replacement) {
|
|
956
|
+
if (typeof searchValue === "string") {
|
|
957
|
+
return this._replaceAllString(searchValue, replacement);
|
|
958
|
+
}
|
|
959
|
+
if (!searchValue.global) {
|
|
960
|
+
throw new TypeError(
|
|
961
|
+
"MagicString.prototype.replaceAll called with a non-global RegExp argument"
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
exports.SourceMap = SourceMap;
|
|
968
|
+
exports.default = MagicString;
|