vite-plugin-react-server 0.3.10 → 0.3.12
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/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +16 -14
- package/dist/plugin/assertServerCondition.d.ts +5 -1
- package/dist/plugin/assertServerCondition.d.ts.map +1 -1
- package/dist/plugin/assertServerCondition.js +1 -3
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +43 -58
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
- package/dist/plugin/collect-css-manifest.js +5 -0
- package/dist/plugin/collect-css-manifest.js.map +1 -1
- package/dist/plugin/components.js +10 -15
- package/dist/plugin/config/createModuleIdGenerator.d.ts +11 -0
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
- package/dist/plugin/config/createModuleIdGenerator.js +44 -0
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +27 -24
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +26 -31
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +223 -16
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +2 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +149 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +72 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +128 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +37 -9
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createPageLoader.js +0 -7
- package/dist/plugin/loader/css-loader.d.ts +16 -0
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +70 -0
- package/dist/plugin/loader/css-loader.js.map +1 -0
- package/dist/plugin/loader/react-loader.d.ts +17 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.js +647 -0
- package/dist/plugin/loader/react-loader.js.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.js +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
- package/dist/plugin/plugin.d.ts +0 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +3 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +2 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +19 -1
- package/dist/plugin/react-client/index.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +283 -10
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +2 -2
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +15 -9
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +15 -3
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +53 -36
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.js +5 -12
- package/dist/plugin/react-server/index.js +18 -9
- package/dist/plugin/react-server/index.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +147 -137
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts +2 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +68 -75
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +4 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +56 -20
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/logger.d.ts +9 -0
- package/dist/plugin/utils/logger.d.ts.map +1 -0
- package/dist/plugin/utils/logger.js +68 -0
- package/dist/plugin/utils/logger.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +1 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +23 -36
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +5 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +33 -28
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +10 -5
- package/dist/plugin/worker/html/renderPages.d.ts +7 -6
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +147 -93
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/loader.d.ts +1 -11
- package/dist/plugin/worker/loader.d.ts.map +1 -1
- package/dist/plugin/worker/loader.js +2 -2
- package/dist/plugin/worker/loader.js.map +1 -1
- package/dist/plugin/worker/plugin.d.ts +10 -1
- package/dist/plugin/worker/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/plugin.js +10 -1
- package/dist/plugin/worker/rsc/index.d.ts +1 -3
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -9
- package/dist/plugin/worker/rsc/index.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.js +107 -0
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +74 -80
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
- package/dist/plugin/worker/rsc/state.d.ts +11 -0
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/state.js +12 -0
- package/dist/plugin/worker/rsc/state.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +62 -35
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -14
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +46 -66
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +27 -20
- package/plugin/config/resolveOptions.ts +311 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +195 -61
- package/plugin/helpers/getBundleManifest.ts +113 -0
- package/plugin/helpers/inputNormalizer.ts +186 -25
- package/plugin/helpers/tryManifest.ts +3 -1
- package/plugin/loader/createBuildLoader.ts +50 -9
- package/plugin/loader/createPageLoader.ts +1 -7
- package/plugin/loader/css-loader.ts +96 -0
- package/plugin/loader/react-loader.ts +945 -0
- package/plugin/loader/rsc/messageHandler.tsx +1 -0
- package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
- package/plugin/plugin.ts +2 -1
- package/plugin/preserver/plugin.ts +2 -1
- package/plugin/react-client/index.ts +12 -1
- package/plugin/react-client/plugin.ts +351 -11
- package/plugin/react-server/createHandler.ts +16 -18
- package/plugin/react-server/createRscStream.ts +75 -42
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +192 -155
- package/plugin/transformer/plugin.ts +70 -104
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +120 -64
- package/plugin/utils/logger.ts +52 -0
- package/plugin/worker/createWorker.ts +43 -44
- package/plugin/worker/html/html-worker.production.tsx +7 -2
- package/plugin/worker/html/messageHandler.ts +42 -35
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +177 -123
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- package/plugin/worker/rsc/index.ts +4 -13
- package/plugin/worker/rsc/messageHandler.tsx +143 -0
- package/plugin/worker/rsc/plugin.ts +38 -37
- package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
- package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
- package/plugin/worker/rsc/rsc-worker.tsx +5 -128
- package/plugin/worker/rsc/state.ts +37 -0
- package/plugin/worker/types.ts +83 -38
- package/scripts/check-react-version.mjs +17 -7
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
- package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -1283
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.js +0 -14
- package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createServerBuildConfig.js +0 -40
- package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createSharedBuildConfig.js +0 -28
- package/dist/plugin/build/mergeInputs.d.ts +0 -9
- package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
- package/dist/plugin/build/mergeInputs.js +0 -56
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
- package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
- package/dist/plugin/config/moduleIdDefault.js +0 -23
- package/dist/plugin/config/moduleIdDefault.js.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
- package/dist/plugin/helpers/getModuleManifest.d.ts +0 -12
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -24
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
- package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
- package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveFilePath.js +0 -74
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
- package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
- package/dist/plugin/helpers/validateModuleBase.js +0 -16
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
- package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
- package/dist/plugin/react-server/createDevMiddleware.d.ts +0 -8
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.js +0 -68
- package/dist/plugin/react-server/createDevServer.d.ts +0 -4
- package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevServer.js +0 -4
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -21
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -61
- package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.js +0 -76
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.js +0 -39
- package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
- package/dist/plugin/worker/rsc/development.d.ts +0 -5
- package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/development.js +0 -13
- package/dist/plugin/worker/rsc/development.js.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js.map +0 -1
- package/dist/plugin/worker/rsc/production.d.ts +0 -5
- package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/production.js +0 -13
- package/dist/plugin/worker/rsc/production.js.map +0 -1
- package/plugin/build/createClientBuildConfig.ts +0 -21
- package/plugin/build/createServerBuildConfig.ts +0 -66
- package/plugin/build/createSharedBuildConfig.ts +0 -35
- package/plugin/build/mergeInputs.ts +0 -58
- package/plugin/config/moduleIdDefault.ts +0 -23
- package/plugin/helpers/createClientInputNormalizer.ts +0 -48
- package/plugin/helpers/createServerInputNormalizer.ts +0 -52
- package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
- package/plugin/helpers/getModuleManifest.ts +0 -31
- package/plugin/helpers/inputNormalizerWorker.ts +0 -47
- package/plugin/helpers/normalizedRelativePath.ts +0 -59
- package/plugin/helpers/resolveFilePath.ts +0 -108
- package/plugin/helpers/resolveWorkerModule.ts +0 -41
- package/plugin/helpers/validateModuleBase.ts +0 -30
- package/plugin/helpers/validateResolvedConfig.ts +0 -21
- package/plugin/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
- package/plugin/transformer/transformer-client-components.ts +0 -94
- package/plugin/transformer/transformer-server-actions.ts +0 -110
- package/plugin/worker/rsc/createRscStream.ts +0 -42
- package/plugin/worker/rsc/development.ts +0 -6
- package/plugin/worker/rsc/production.ts +0 -6
- package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
|
@@ -1,1283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vite-plugin-react-server
|
|
3
|
-
* Copyright (c) Nico Brinkkemper
|
|
4
|
-
* MIT License
|
|
5
|
-
*/
|
|
6
|
-
import { encode } from '@jridgewell/sourcemap-codec';
|
|
7
|
-
|
|
8
|
-
class BitSet {
|
|
9
|
-
constructor(arg) {
|
|
10
|
-
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
add(n) {
|
|
14
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
has(n) {
|
|
18
|
-
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class Chunk {
|
|
23
|
-
constructor(start, end, content) {
|
|
24
|
-
this.start = start;
|
|
25
|
-
this.end = end;
|
|
26
|
-
this.original = content;
|
|
27
|
-
|
|
28
|
-
this.intro = '';
|
|
29
|
-
this.outro = '';
|
|
30
|
-
|
|
31
|
-
this.content = content;
|
|
32
|
-
this.storeName = false;
|
|
33
|
-
this.edited = false;
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
this.previous = null;
|
|
37
|
-
this.next = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
appendLeft(content) {
|
|
42
|
-
this.outro += content;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
appendRight(content) {
|
|
46
|
-
this.intro = this.intro + content;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
clone() {
|
|
50
|
-
const chunk = new Chunk(this.start, this.end, this.original);
|
|
51
|
-
|
|
52
|
-
chunk.intro = this.intro;
|
|
53
|
-
chunk.outro = this.outro;
|
|
54
|
-
chunk.content = this.content;
|
|
55
|
-
chunk.storeName = this.storeName;
|
|
56
|
-
chunk.edited = this.edited;
|
|
57
|
-
|
|
58
|
-
return chunk;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
contains(index) {
|
|
62
|
-
return this.start < index && index < this.end;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
eachNext(fn) {
|
|
66
|
-
let chunk = this;
|
|
67
|
-
while (chunk) {
|
|
68
|
-
fn(chunk);
|
|
69
|
-
chunk = chunk.next;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
eachPrevious(fn) {
|
|
74
|
-
let chunk = this;
|
|
75
|
-
while (chunk) {
|
|
76
|
-
fn(chunk);
|
|
77
|
-
chunk = chunk.previous;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
edit(content, storeName, contentOnly) {
|
|
82
|
-
this.content = content;
|
|
83
|
-
if (!contentOnly) {
|
|
84
|
-
this.intro = '';
|
|
85
|
-
this.outro = '';
|
|
86
|
-
}
|
|
87
|
-
this.storeName = storeName;
|
|
88
|
-
|
|
89
|
-
this.edited = true;
|
|
90
|
-
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
prependLeft(content) {
|
|
95
|
-
this.outro = content + this.outro;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
prependRight(content) {
|
|
99
|
-
this.intro = content + this.intro;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
reset() {
|
|
103
|
-
this.intro = '';
|
|
104
|
-
this.outro = '';
|
|
105
|
-
if (this.edited) {
|
|
106
|
-
this.content = this.original;
|
|
107
|
-
this.storeName = false;
|
|
108
|
-
this.edited = false;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
split(index) {
|
|
113
|
-
const sliceIndex = index - this.start;
|
|
114
|
-
|
|
115
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
116
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
117
|
-
|
|
118
|
-
this.original = originalBefore;
|
|
119
|
-
|
|
120
|
-
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
121
|
-
newChunk.outro = this.outro;
|
|
122
|
-
this.outro = '';
|
|
123
|
-
|
|
124
|
-
this.end = index;
|
|
125
|
-
|
|
126
|
-
if (this.edited) {
|
|
127
|
-
// after split we should save the edit content record into the correct chunk
|
|
128
|
-
// to make sure sourcemap correct
|
|
129
|
-
// For example:
|
|
130
|
-
// ' test'.trim()
|
|
131
|
-
// split -> ' ' + 'test'
|
|
132
|
-
// ✔️ edit -> '' + 'test'
|
|
133
|
-
// ✖️ edit -> 'test' + ''
|
|
134
|
-
// TODO is this block necessary?...
|
|
135
|
-
newChunk.edit('', false);
|
|
136
|
-
this.content = '';
|
|
137
|
-
} else {
|
|
138
|
-
this.content = originalBefore;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
newChunk.next = this.next;
|
|
142
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
143
|
-
newChunk.previous = this;
|
|
144
|
-
this.next = newChunk;
|
|
145
|
-
|
|
146
|
-
return newChunk;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
toString() {
|
|
150
|
-
return this.intro + this.content + this.outro;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
trimEnd(rx) {
|
|
154
|
-
this.outro = this.outro.replace(rx, '');
|
|
155
|
-
if (this.outro.length) return true;
|
|
156
|
-
|
|
157
|
-
const trimmed = this.content.replace(rx, '');
|
|
158
|
-
|
|
159
|
-
if (trimmed.length) {
|
|
160
|
-
if (trimmed !== this.content) {
|
|
161
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
162
|
-
if (this.edited) {
|
|
163
|
-
// save the change, if it has been edited
|
|
164
|
-
this.edit(trimmed, this.storeName, true);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return true;
|
|
168
|
-
} else {
|
|
169
|
-
this.edit('', undefined, true);
|
|
170
|
-
|
|
171
|
-
this.intro = this.intro.replace(rx, '');
|
|
172
|
-
if (this.intro.length) return true;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
trimStart(rx) {
|
|
177
|
-
this.intro = this.intro.replace(rx, '');
|
|
178
|
-
if (this.intro.length) return true;
|
|
179
|
-
|
|
180
|
-
const trimmed = this.content.replace(rx, '');
|
|
181
|
-
|
|
182
|
-
if (trimmed.length) {
|
|
183
|
-
if (trimmed !== this.content) {
|
|
184
|
-
const newChunk = this.split(this.end - trimmed.length);
|
|
185
|
-
if (this.edited) {
|
|
186
|
-
// save the change, if it has been edited
|
|
187
|
-
newChunk.edit(trimmed, this.storeName, true);
|
|
188
|
-
}
|
|
189
|
-
this.edit('', undefined, true);
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
} else {
|
|
193
|
-
this.edit('', undefined, true);
|
|
194
|
-
|
|
195
|
-
this.outro = this.outro.replace(rx, '');
|
|
196
|
-
if (this.outro.length) return true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function getBtoa() {
|
|
202
|
-
if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
|
|
203
|
-
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
204
|
-
} else if (typeof Buffer === 'function') {
|
|
205
|
-
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
206
|
-
} else {
|
|
207
|
-
return () => {
|
|
208
|
-
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const btoa = /*#__PURE__*/ getBtoa();
|
|
214
|
-
|
|
215
|
-
class SourceMap {
|
|
216
|
-
constructor(properties) {
|
|
217
|
-
this.version = 3;
|
|
218
|
-
this.file = properties.file;
|
|
219
|
-
this.sources = properties.sources;
|
|
220
|
-
this.sourcesContent = properties.sourcesContent;
|
|
221
|
-
this.names = properties.names;
|
|
222
|
-
this.mappings = encode(properties.mappings);
|
|
223
|
-
if (typeof properties.x_google_ignoreList !== 'undefined') {
|
|
224
|
-
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
225
|
-
}
|
|
226
|
-
if (typeof properties.debugId !== 'undefined') {
|
|
227
|
-
this.debugId = properties.debugId;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
toString() {
|
|
232
|
-
return JSON.stringify(this);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
toUrl() {
|
|
236
|
-
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function guessIndent(code) {
|
|
241
|
-
const lines = code.split('\n');
|
|
242
|
-
|
|
243
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
244
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
245
|
-
|
|
246
|
-
if (tabbed.length === 0 && spaced.length === 0) {
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// More lines tabbed than spaced? Assume tabs, and
|
|
251
|
-
// default to tabs in the case of a tie (or nothing
|
|
252
|
-
// to go on)
|
|
253
|
-
if (tabbed.length >= spaced.length) {
|
|
254
|
-
return '\t';
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Otherwise, we need to guess the multiple
|
|
258
|
-
const min = spaced.reduce((previous, current) => {
|
|
259
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
260
|
-
return Math.min(numSpaces, previous);
|
|
261
|
-
}, Infinity);
|
|
262
|
-
|
|
263
|
-
return new Array(min + 1).join(' ');
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function getRelativePath(from, to) {
|
|
267
|
-
const fromParts = from.split(/[/\\]/);
|
|
268
|
-
const toParts = to.split(/[/\\]/);
|
|
269
|
-
|
|
270
|
-
fromParts.pop(); // get dirname
|
|
271
|
-
|
|
272
|
-
while (fromParts[0] === toParts[0]) {
|
|
273
|
-
fromParts.shift();
|
|
274
|
-
toParts.shift();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (fromParts.length) {
|
|
278
|
-
let i = fromParts.length;
|
|
279
|
-
while (i--) fromParts[i] = '..';
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return fromParts.concat(toParts).join('/');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const toString = Object.prototype.toString;
|
|
286
|
-
|
|
287
|
-
function isObject(thing) {
|
|
288
|
-
return toString.call(thing) === '[object Object]';
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function getLocator(source) {
|
|
292
|
-
const originalLines = source.split('\n');
|
|
293
|
-
const lineOffsets = [];
|
|
294
|
-
|
|
295
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
296
|
-
lineOffsets.push(pos);
|
|
297
|
-
pos += originalLines[i].length + 1;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return function locate(index) {
|
|
301
|
-
let i = 0;
|
|
302
|
-
let j = lineOffsets.length;
|
|
303
|
-
while (i < j) {
|
|
304
|
-
const m = (i + j) >> 1;
|
|
305
|
-
if (index < lineOffsets[m]) {
|
|
306
|
-
j = m;
|
|
307
|
-
} else {
|
|
308
|
-
i = m + 1;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const line = i - 1;
|
|
312
|
-
const column = index - lineOffsets[line];
|
|
313
|
-
return { line, column };
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const wordRegex = /\w/;
|
|
318
|
-
|
|
319
|
-
class Mappings {
|
|
320
|
-
constructor(hires) {
|
|
321
|
-
this.hires = hires;
|
|
322
|
-
this.generatedCodeLine = 0;
|
|
323
|
-
this.generatedCodeColumn = 0;
|
|
324
|
-
this.raw = [];
|
|
325
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
326
|
-
this.pending = null;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
330
|
-
if (content.length) {
|
|
331
|
-
const contentLengthMinusOne = content.length - 1;
|
|
332
|
-
let contentLineEnd = content.indexOf('\n', 0);
|
|
333
|
-
let previousContentLineEnd = -1;
|
|
334
|
-
// Loop through each line in the content and add a segment, but stop if the last line is empty,
|
|
335
|
-
// else code afterwards would fill one line too many
|
|
336
|
-
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
337
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
338
|
-
if (nameIndex >= 0) {
|
|
339
|
-
segment.push(nameIndex);
|
|
340
|
-
}
|
|
341
|
-
this.rawSegments.push(segment);
|
|
342
|
-
|
|
343
|
-
this.generatedCodeLine += 1;
|
|
344
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
345
|
-
this.generatedCodeColumn = 0;
|
|
346
|
-
|
|
347
|
-
previousContentLineEnd = contentLineEnd;
|
|
348
|
-
contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
352
|
-
if (nameIndex >= 0) {
|
|
353
|
-
segment.push(nameIndex);
|
|
354
|
-
}
|
|
355
|
-
this.rawSegments.push(segment);
|
|
356
|
-
|
|
357
|
-
this.advance(content.slice(previousContentLineEnd + 1));
|
|
358
|
-
} else if (this.pending) {
|
|
359
|
-
this.rawSegments.push(this.pending);
|
|
360
|
-
this.advance(content);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
this.pending = null;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
367
|
-
let originalCharIndex = chunk.start;
|
|
368
|
-
let first = true;
|
|
369
|
-
// when iterating each char, check if it's in a word boundary
|
|
370
|
-
let charInHiresBoundary = false;
|
|
371
|
-
|
|
372
|
-
while (originalCharIndex < chunk.end) {
|
|
373
|
-
if (original[originalCharIndex] === '\n') {
|
|
374
|
-
loc.line += 1;
|
|
375
|
-
loc.column = 0;
|
|
376
|
-
this.generatedCodeLine += 1;
|
|
377
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
378
|
-
this.generatedCodeColumn = 0;
|
|
379
|
-
first = true;
|
|
380
|
-
charInHiresBoundary = false;
|
|
381
|
-
} else {
|
|
382
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
383
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
384
|
-
|
|
385
|
-
if (this.hires === 'boundary') {
|
|
386
|
-
// in hires "boundary", group segments per word boundary than per char
|
|
387
|
-
if (wordRegex.test(original[originalCharIndex])) {
|
|
388
|
-
// for first char in the boundary found, start the boundary by pushing a segment
|
|
389
|
-
if (!charInHiresBoundary) {
|
|
390
|
-
this.rawSegments.push(segment);
|
|
391
|
-
charInHiresBoundary = true;
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
// for non-word char, end the boundary by pushing a segment
|
|
395
|
-
this.rawSegments.push(segment);
|
|
396
|
-
charInHiresBoundary = false;
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
this.rawSegments.push(segment);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
loc.column += 1;
|
|
404
|
-
this.generatedCodeColumn += 1;
|
|
405
|
-
first = false;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
originalCharIndex += 1;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
this.pending = null;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
advance(str) {
|
|
415
|
-
if (!str) return;
|
|
416
|
-
|
|
417
|
-
const lines = str.split('\n');
|
|
418
|
-
|
|
419
|
-
if (lines.length > 1) {
|
|
420
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
421
|
-
this.generatedCodeLine++;
|
|
422
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
423
|
-
}
|
|
424
|
-
this.generatedCodeColumn = 0;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const n = '\n';
|
|
432
|
-
|
|
433
|
-
const warned = {
|
|
434
|
-
insertLeft: false,
|
|
435
|
-
insertRight: false,
|
|
436
|
-
storeName: false,
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
class MagicString {
|
|
440
|
-
constructor(string, options = {}) {
|
|
441
|
-
const chunk = new Chunk(0, string.length, string);
|
|
442
|
-
|
|
443
|
-
Object.defineProperties(this, {
|
|
444
|
-
original: { writable: true, value: string },
|
|
445
|
-
outro: { writable: true, value: '' },
|
|
446
|
-
intro: { writable: true, value: '' },
|
|
447
|
-
firstChunk: { writable: true, value: chunk },
|
|
448
|
-
lastChunk: { writable: true, value: chunk },
|
|
449
|
-
lastSearchedChunk: { writable: true, value: chunk },
|
|
450
|
-
byStart: { writable: true, value: {} },
|
|
451
|
-
byEnd: { writable: true, value: {} },
|
|
452
|
-
filename: { writable: true, value: options.filename },
|
|
453
|
-
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
454
|
-
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
455
|
-
storedNames: { writable: true, value: {} },
|
|
456
|
-
indentStr: { writable: true, value: undefined },
|
|
457
|
-
ignoreList: { writable: true, value: options.ignoreList },
|
|
458
|
-
offset: { writable: true, value: options.offset || 0 },
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
this.byStart[0] = chunk;
|
|
462
|
-
this.byEnd[string.length] = chunk;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
addSourcemapLocation(char) {
|
|
466
|
-
this.sourcemapLocations.add(char);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
append(content) {
|
|
470
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
471
|
-
|
|
472
|
-
this.outro += content;
|
|
473
|
-
return this;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
appendLeft(index, content) {
|
|
477
|
-
index = index + this.offset;
|
|
478
|
-
|
|
479
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
480
|
-
|
|
481
|
-
this._split(index);
|
|
482
|
-
|
|
483
|
-
const chunk = this.byEnd[index];
|
|
484
|
-
|
|
485
|
-
if (chunk) {
|
|
486
|
-
chunk.appendLeft(content);
|
|
487
|
-
} else {
|
|
488
|
-
this.intro += content;
|
|
489
|
-
}
|
|
490
|
-
return this;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
appendRight(index, content) {
|
|
494
|
-
index = index + this.offset;
|
|
495
|
-
|
|
496
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
497
|
-
|
|
498
|
-
this._split(index);
|
|
499
|
-
|
|
500
|
-
const chunk = this.byStart[index];
|
|
501
|
-
|
|
502
|
-
if (chunk) {
|
|
503
|
-
chunk.appendRight(content);
|
|
504
|
-
} else {
|
|
505
|
-
this.outro += content;
|
|
506
|
-
}
|
|
507
|
-
return this;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
clone() {
|
|
511
|
-
const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
|
|
512
|
-
|
|
513
|
-
let originalChunk = this.firstChunk;
|
|
514
|
-
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
515
|
-
|
|
516
|
-
while (originalChunk) {
|
|
517
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
518
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
519
|
-
|
|
520
|
-
const nextOriginalChunk = originalChunk.next;
|
|
521
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
522
|
-
|
|
523
|
-
if (nextClonedChunk) {
|
|
524
|
-
clonedChunk.next = nextClonedChunk;
|
|
525
|
-
nextClonedChunk.previous = clonedChunk;
|
|
526
|
-
|
|
527
|
-
clonedChunk = nextClonedChunk;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
originalChunk = nextOriginalChunk;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
cloned.lastChunk = clonedChunk;
|
|
534
|
-
|
|
535
|
-
if (this.indentExclusionRanges) {
|
|
536
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
540
|
-
|
|
541
|
-
cloned.intro = this.intro;
|
|
542
|
-
cloned.outro = this.outro;
|
|
543
|
-
|
|
544
|
-
return cloned;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
generateDecodedMap(options) {
|
|
548
|
-
options = options || {};
|
|
549
|
-
|
|
550
|
-
const sourceIndex = 0;
|
|
551
|
-
const names = Object.keys(this.storedNames);
|
|
552
|
-
const mappings = new Mappings(options.hires);
|
|
553
|
-
|
|
554
|
-
const locate = getLocator(this.original);
|
|
555
|
-
|
|
556
|
-
if (this.intro) {
|
|
557
|
-
mappings.advance(this.intro);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
this.firstChunk.eachNext((chunk) => {
|
|
561
|
-
const loc = locate(chunk.start);
|
|
562
|
-
|
|
563
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
564
|
-
|
|
565
|
-
if (chunk.edited) {
|
|
566
|
-
mappings.addEdit(
|
|
567
|
-
sourceIndex,
|
|
568
|
-
chunk.content,
|
|
569
|
-
loc,
|
|
570
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1,
|
|
571
|
-
);
|
|
572
|
-
} else {
|
|
573
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
return {
|
|
580
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
|
|
581
|
-
sources: [
|
|
582
|
-
options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
|
|
583
|
-
],
|
|
584
|
-
sourcesContent: options.includeContent ? [this.original] : undefined,
|
|
585
|
-
names,
|
|
586
|
-
mappings: mappings.raw,
|
|
587
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
generateMap(options) {
|
|
592
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
_ensureindentStr() {
|
|
596
|
-
if (this.indentStr === undefined) {
|
|
597
|
-
this.indentStr = guessIndent(this.original);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
_getRawIndentString() {
|
|
602
|
-
this._ensureindentStr();
|
|
603
|
-
return this.indentStr;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
getIndentString() {
|
|
607
|
-
this._ensureindentStr();
|
|
608
|
-
return this.indentStr === null ? '\t' : this.indentStr;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
indent(indentStr, options) {
|
|
612
|
-
const pattern = /^[^\r\n]/gm;
|
|
613
|
-
|
|
614
|
-
if (isObject(indentStr)) {
|
|
615
|
-
options = indentStr;
|
|
616
|
-
indentStr = undefined;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
if (indentStr === undefined) {
|
|
620
|
-
this._ensureindentStr();
|
|
621
|
-
indentStr = this.indentStr || '\t';
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (indentStr === '') return this; // noop
|
|
625
|
-
|
|
626
|
-
options = options || {};
|
|
627
|
-
|
|
628
|
-
// Process exclusion ranges
|
|
629
|
-
const isExcluded = {};
|
|
630
|
-
|
|
631
|
-
if (options.exclude) {
|
|
632
|
-
const exclusions =
|
|
633
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
634
|
-
exclusions.forEach((exclusion) => {
|
|
635
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
636
|
-
isExcluded[i] = true;
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
642
|
-
const replacer = (match) => {
|
|
643
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
644
|
-
shouldIndentNextCharacter = true;
|
|
645
|
-
return match;
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
649
|
-
|
|
650
|
-
let charIndex = 0;
|
|
651
|
-
let chunk = this.firstChunk;
|
|
652
|
-
|
|
653
|
-
while (chunk) {
|
|
654
|
-
const end = chunk.end;
|
|
655
|
-
|
|
656
|
-
if (chunk.edited) {
|
|
657
|
-
if (!isExcluded[charIndex]) {
|
|
658
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
659
|
-
|
|
660
|
-
if (chunk.content.length) {
|
|
661
|
-
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
} else {
|
|
665
|
-
charIndex = chunk.start;
|
|
666
|
-
|
|
667
|
-
while (charIndex < end) {
|
|
668
|
-
if (!isExcluded[charIndex]) {
|
|
669
|
-
const char = this.original[charIndex];
|
|
670
|
-
|
|
671
|
-
if (char === '\n') {
|
|
672
|
-
shouldIndentNextCharacter = true;
|
|
673
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
674
|
-
shouldIndentNextCharacter = false;
|
|
675
|
-
|
|
676
|
-
if (charIndex === chunk.start) {
|
|
677
|
-
chunk.prependRight(indentStr);
|
|
678
|
-
} else {
|
|
679
|
-
this._splitChunk(chunk, charIndex);
|
|
680
|
-
chunk = chunk.next;
|
|
681
|
-
chunk.prependRight(indentStr);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
charIndex += 1;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
charIndex = chunk.end;
|
|
691
|
-
chunk = chunk.next;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
695
|
-
|
|
696
|
-
return this;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
insert() {
|
|
700
|
-
throw new Error(
|
|
701
|
-
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
|
|
702
|
-
);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
insertLeft(index, content) {
|
|
706
|
-
if (!warned.insertLeft) {
|
|
707
|
-
console.warn(
|
|
708
|
-
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
|
|
709
|
-
);
|
|
710
|
-
warned.insertLeft = true;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
return this.appendLeft(index, content);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
insertRight(index, content) {
|
|
717
|
-
if (!warned.insertRight) {
|
|
718
|
-
console.warn(
|
|
719
|
-
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
|
|
720
|
-
);
|
|
721
|
-
warned.insertRight = true;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
return this.prependRight(index, content);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
move(start, end, index) {
|
|
728
|
-
start = start + this.offset;
|
|
729
|
-
end = end + this.offset;
|
|
730
|
-
index = index + this.offset;
|
|
731
|
-
|
|
732
|
-
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
733
|
-
|
|
734
|
-
this._split(start);
|
|
735
|
-
this._split(end);
|
|
736
|
-
this._split(index);
|
|
737
|
-
|
|
738
|
-
const first = this.byStart[start];
|
|
739
|
-
const last = this.byEnd[end];
|
|
740
|
-
|
|
741
|
-
const oldLeft = first.previous;
|
|
742
|
-
const oldRight = last.next;
|
|
743
|
-
|
|
744
|
-
const newRight = this.byStart[index];
|
|
745
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
746
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
747
|
-
|
|
748
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
749
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
750
|
-
|
|
751
|
-
if (newLeft) newLeft.next = first;
|
|
752
|
-
if (newRight) newRight.previous = last;
|
|
753
|
-
|
|
754
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
755
|
-
if (!last.next) {
|
|
756
|
-
this.lastChunk = first.previous;
|
|
757
|
-
this.lastChunk.next = null;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
first.previous = newLeft;
|
|
761
|
-
last.next = newRight || null;
|
|
762
|
-
|
|
763
|
-
if (!newLeft) this.firstChunk = first;
|
|
764
|
-
if (!newRight) this.lastChunk = last;
|
|
765
|
-
return this;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
overwrite(start, end, content, options) {
|
|
769
|
-
options = options || {};
|
|
770
|
-
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
update(start, end, content, options) {
|
|
774
|
-
start = start + this.offset;
|
|
775
|
-
end = end + this.offset;
|
|
776
|
-
|
|
777
|
-
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
778
|
-
|
|
779
|
-
if (this.original.length !== 0) {
|
|
780
|
-
while (start < 0) start += this.original.length;
|
|
781
|
-
while (end < 0) end += this.original.length;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
if (end > this.original.length) throw new Error('end is out of bounds');
|
|
785
|
-
if (start === end)
|
|
786
|
-
throw new Error(
|
|
787
|
-
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
|
|
788
|
-
);
|
|
789
|
-
|
|
790
|
-
this._split(start);
|
|
791
|
-
this._split(end);
|
|
792
|
-
|
|
793
|
-
if (options === true) {
|
|
794
|
-
if (!warned.storeName) {
|
|
795
|
-
console.warn(
|
|
796
|
-
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
|
|
797
|
-
);
|
|
798
|
-
warned.storeName = true;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
options = { storeName: true };
|
|
802
|
-
}
|
|
803
|
-
const storeName = options !== undefined ? options.storeName : false;
|
|
804
|
-
const overwrite = options !== undefined ? options.overwrite : false;
|
|
805
|
-
|
|
806
|
-
if (storeName) {
|
|
807
|
-
const original = this.original.slice(start, end);
|
|
808
|
-
Object.defineProperty(this.storedNames, original, {
|
|
809
|
-
writable: true,
|
|
810
|
-
value: true,
|
|
811
|
-
enumerable: true,
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
const first = this.byStart[start];
|
|
816
|
-
const last = this.byEnd[end];
|
|
817
|
-
|
|
818
|
-
if (first) {
|
|
819
|
-
let chunk = first;
|
|
820
|
-
while (chunk !== last) {
|
|
821
|
-
if (chunk.next !== this.byStart[chunk.end]) {
|
|
822
|
-
throw new Error('Cannot overwrite across a split point');
|
|
823
|
-
}
|
|
824
|
-
chunk = chunk.next;
|
|
825
|
-
chunk.edit('', false);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
first.edit(content, storeName, !overwrite);
|
|
829
|
-
} else {
|
|
830
|
-
// must be inserting at the end
|
|
831
|
-
const newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
832
|
-
|
|
833
|
-
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
834
|
-
last.next = newChunk;
|
|
835
|
-
newChunk.previous = last;
|
|
836
|
-
}
|
|
837
|
-
return this;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
prepend(content) {
|
|
841
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
842
|
-
|
|
843
|
-
this.intro = content + this.intro;
|
|
844
|
-
return this;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
prependLeft(index, content) {
|
|
848
|
-
index = index + this.offset;
|
|
849
|
-
|
|
850
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
851
|
-
|
|
852
|
-
this._split(index);
|
|
853
|
-
|
|
854
|
-
const chunk = this.byEnd[index];
|
|
855
|
-
|
|
856
|
-
if (chunk) {
|
|
857
|
-
chunk.prependLeft(content);
|
|
858
|
-
} else {
|
|
859
|
-
this.intro = content + this.intro;
|
|
860
|
-
}
|
|
861
|
-
return this;
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
prependRight(index, content) {
|
|
865
|
-
index = index + this.offset;
|
|
866
|
-
|
|
867
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
868
|
-
|
|
869
|
-
this._split(index);
|
|
870
|
-
|
|
871
|
-
const chunk = this.byStart[index];
|
|
872
|
-
|
|
873
|
-
if (chunk) {
|
|
874
|
-
chunk.prependRight(content);
|
|
875
|
-
} else {
|
|
876
|
-
this.outro = content + this.outro;
|
|
877
|
-
}
|
|
878
|
-
return this;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
remove(start, end) {
|
|
882
|
-
start = start + this.offset;
|
|
883
|
-
end = end + this.offset;
|
|
884
|
-
|
|
885
|
-
if (this.original.length !== 0) {
|
|
886
|
-
while (start < 0) start += this.original.length;
|
|
887
|
-
while (end < 0) end += this.original.length;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
if (start === end) return this;
|
|
891
|
-
|
|
892
|
-
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
893
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
894
|
-
|
|
895
|
-
this._split(start);
|
|
896
|
-
this._split(end);
|
|
897
|
-
|
|
898
|
-
let chunk = this.byStart[start];
|
|
899
|
-
|
|
900
|
-
while (chunk) {
|
|
901
|
-
chunk.intro = '';
|
|
902
|
-
chunk.outro = '';
|
|
903
|
-
chunk.edit('');
|
|
904
|
-
|
|
905
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
906
|
-
}
|
|
907
|
-
return this;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
reset(start, end) {
|
|
911
|
-
start = start + this.offset;
|
|
912
|
-
end = end + this.offset;
|
|
913
|
-
|
|
914
|
-
if (this.original.length !== 0) {
|
|
915
|
-
while (start < 0) start += this.original.length;
|
|
916
|
-
while (end < 0) end += this.original.length;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
if (start === end) return this;
|
|
920
|
-
|
|
921
|
-
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
922
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
923
|
-
|
|
924
|
-
this._split(start);
|
|
925
|
-
this._split(end);
|
|
926
|
-
|
|
927
|
-
let chunk = this.byStart[start];
|
|
928
|
-
|
|
929
|
-
while (chunk) {
|
|
930
|
-
chunk.reset();
|
|
931
|
-
|
|
932
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
933
|
-
}
|
|
934
|
-
return this;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
lastChar() {
|
|
938
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
939
|
-
let chunk = this.lastChunk;
|
|
940
|
-
do {
|
|
941
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
942
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
943
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
944
|
-
} while ((chunk = chunk.previous));
|
|
945
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
946
|
-
return '';
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
lastLine() {
|
|
950
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
951
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
952
|
-
let lineStr = this.outro;
|
|
953
|
-
let chunk = this.lastChunk;
|
|
954
|
-
do {
|
|
955
|
-
if (chunk.outro.length > 0) {
|
|
956
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
957
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
958
|
-
lineStr = chunk.outro + lineStr;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
if (chunk.content.length > 0) {
|
|
962
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
963
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
964
|
-
lineStr = chunk.content + lineStr;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
if (chunk.intro.length > 0) {
|
|
968
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
969
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
970
|
-
lineStr = chunk.intro + lineStr;
|
|
971
|
-
}
|
|
972
|
-
} while ((chunk = chunk.previous));
|
|
973
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
974
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
975
|
-
return this.intro + lineStr;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
slice(start = 0, end = this.original.length - this.offset) {
|
|
979
|
-
start = start + this.offset;
|
|
980
|
-
end = end + this.offset;
|
|
981
|
-
|
|
982
|
-
if (this.original.length !== 0) {
|
|
983
|
-
while (start < 0) start += this.original.length;
|
|
984
|
-
while (end < 0) end += this.original.length;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
let result = '';
|
|
988
|
-
|
|
989
|
-
// find start chunk
|
|
990
|
-
let chunk = this.firstChunk;
|
|
991
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
992
|
-
// found end chunk before start
|
|
993
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
994
|
-
return result;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
chunk = chunk.next;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
if (chunk && chunk.edited && chunk.start !== start)
|
|
1001
|
-
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1002
|
-
|
|
1003
|
-
const startChunk = chunk;
|
|
1004
|
-
while (chunk) {
|
|
1005
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
1006
|
-
result += chunk.intro;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
1010
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
1011
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1012
|
-
|
|
1013
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1014
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1015
|
-
|
|
1016
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1017
|
-
|
|
1018
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
1019
|
-
result += chunk.outro;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
if (containsEnd) {
|
|
1023
|
-
break;
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
chunk = chunk.next;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
return result;
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
// TODO deprecate this? not really very useful
|
|
1033
|
-
snip(start, end) {
|
|
1034
|
-
const clone = this.clone();
|
|
1035
|
-
clone.remove(0, start);
|
|
1036
|
-
clone.remove(end, clone.original.length);
|
|
1037
|
-
|
|
1038
|
-
return clone;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
_split(index) {
|
|
1042
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1043
|
-
|
|
1044
|
-
let chunk = this.lastSearchedChunk;
|
|
1045
|
-
const searchForward = index > chunk.end;
|
|
1046
|
-
|
|
1047
|
-
while (chunk) {
|
|
1048
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1049
|
-
|
|
1050
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
_splitChunk(chunk, index) {
|
|
1055
|
-
if (chunk.edited && chunk.content.length) {
|
|
1056
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1057
|
-
const loc = getLocator(this.original)(index);
|
|
1058
|
-
throw new Error(
|
|
1059
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
|
|
1060
|
-
);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
const newChunk = chunk.split(index);
|
|
1064
|
-
|
|
1065
|
-
this.byEnd[index] = chunk;
|
|
1066
|
-
this.byStart[index] = newChunk;
|
|
1067
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1068
|
-
|
|
1069
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1070
|
-
|
|
1071
|
-
this.lastSearchedChunk = chunk;
|
|
1072
|
-
return true;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
toString() {
|
|
1076
|
-
let str = this.intro;
|
|
1077
|
-
|
|
1078
|
-
let chunk = this.firstChunk;
|
|
1079
|
-
while (chunk) {
|
|
1080
|
-
str += chunk.toString();
|
|
1081
|
-
chunk = chunk.next;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
return str + this.outro;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
isEmpty() {
|
|
1088
|
-
let chunk = this.firstChunk;
|
|
1089
|
-
do {
|
|
1090
|
-
if (
|
|
1091
|
-
(chunk.intro.length && chunk.intro.trim()) ||
|
|
1092
|
-
(chunk.content.length && chunk.content.trim()) ||
|
|
1093
|
-
(chunk.outro.length && chunk.outro.trim())
|
|
1094
|
-
)
|
|
1095
|
-
return false;
|
|
1096
|
-
} while ((chunk = chunk.next));
|
|
1097
|
-
return true;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
length() {
|
|
1101
|
-
let chunk = this.firstChunk;
|
|
1102
|
-
let length = 0;
|
|
1103
|
-
do {
|
|
1104
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1105
|
-
} while ((chunk = chunk.next));
|
|
1106
|
-
return length;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
trimLines() {
|
|
1110
|
-
return this.trim('[\\r\\n]');
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
trim(charType) {
|
|
1114
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
trimEndAborted(charType) {
|
|
1118
|
-
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1119
|
-
|
|
1120
|
-
this.outro = this.outro.replace(rx, '');
|
|
1121
|
-
if (this.outro.length) return true;
|
|
1122
|
-
|
|
1123
|
-
let chunk = this.lastChunk;
|
|
1124
|
-
|
|
1125
|
-
do {
|
|
1126
|
-
const end = chunk.end;
|
|
1127
|
-
const aborted = chunk.trimEnd(rx);
|
|
1128
|
-
|
|
1129
|
-
// if chunk was trimmed, we have a new lastChunk
|
|
1130
|
-
if (chunk.end !== end) {
|
|
1131
|
-
if (this.lastChunk === chunk) {
|
|
1132
|
-
this.lastChunk = chunk.next;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
this.byEnd[chunk.end] = chunk;
|
|
1136
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1137
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
if (aborted) return true;
|
|
1141
|
-
chunk = chunk.previous;
|
|
1142
|
-
} while (chunk);
|
|
1143
|
-
|
|
1144
|
-
return false;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
trimEnd(charType) {
|
|
1148
|
-
this.trimEndAborted(charType);
|
|
1149
|
-
return this;
|
|
1150
|
-
}
|
|
1151
|
-
trimStartAborted(charType) {
|
|
1152
|
-
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1153
|
-
|
|
1154
|
-
this.intro = this.intro.replace(rx, '');
|
|
1155
|
-
if (this.intro.length) return true;
|
|
1156
|
-
|
|
1157
|
-
let chunk = this.firstChunk;
|
|
1158
|
-
|
|
1159
|
-
do {
|
|
1160
|
-
const end = chunk.end;
|
|
1161
|
-
const aborted = chunk.trimStart(rx);
|
|
1162
|
-
|
|
1163
|
-
if (chunk.end !== end) {
|
|
1164
|
-
// special case...
|
|
1165
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1166
|
-
|
|
1167
|
-
this.byEnd[chunk.end] = chunk;
|
|
1168
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1169
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
if (aborted) return true;
|
|
1173
|
-
chunk = chunk.next;
|
|
1174
|
-
} while (chunk);
|
|
1175
|
-
|
|
1176
|
-
return false;
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
trimStart(charType) {
|
|
1180
|
-
this.trimStartAborted(charType);
|
|
1181
|
-
return this;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
hasChanged() {
|
|
1185
|
-
return this.original !== this.toString();
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
_replaceRegexp(searchValue, replacement) {
|
|
1189
|
-
function getReplacement(match, str) {
|
|
1190
|
-
if (typeof replacement === 'string') {
|
|
1191
|
-
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1192
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
|
|
1193
|
-
if (i === '$') return '$';
|
|
1194
|
-
if (i === '&') return match[0];
|
|
1195
|
-
const num = +i;
|
|
1196
|
-
if (num < match.length) return match[+i];
|
|
1197
|
-
return `$${i}`;
|
|
1198
|
-
});
|
|
1199
|
-
} else {
|
|
1200
|
-
return replacement(...match, match.index, str, match.groups);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
function matchAll(re, str) {
|
|
1204
|
-
let match;
|
|
1205
|
-
const matches = [];
|
|
1206
|
-
while ((match = re.exec(str))) {
|
|
1207
|
-
matches.push(match);
|
|
1208
|
-
}
|
|
1209
|
-
return matches;
|
|
1210
|
-
}
|
|
1211
|
-
if (searchValue.global) {
|
|
1212
|
-
const matches = matchAll(searchValue, this.original);
|
|
1213
|
-
matches.forEach((match) => {
|
|
1214
|
-
if (match.index != null) {
|
|
1215
|
-
const replacement = getReplacement(match, this.original);
|
|
1216
|
-
if (replacement !== match[0]) {
|
|
1217
|
-
this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
} else {
|
|
1222
|
-
const match = this.original.match(searchValue);
|
|
1223
|
-
if (match && match.index != null) {
|
|
1224
|
-
const replacement = getReplacement(match, this.original);
|
|
1225
|
-
if (replacement !== match[0]) {
|
|
1226
|
-
this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
return this;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
_replaceString(string, replacement) {
|
|
1234
|
-
const { original } = this;
|
|
1235
|
-
const index = original.indexOf(string);
|
|
1236
|
-
|
|
1237
|
-
if (index !== -1) {
|
|
1238
|
-
this.overwrite(index, index + string.length, replacement);
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
return this;
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
replace(searchValue, replacement) {
|
|
1245
|
-
if (typeof searchValue === 'string') {
|
|
1246
|
-
return this._replaceString(searchValue, replacement);
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
_replaceAllString(string, replacement) {
|
|
1253
|
-
const { original } = this;
|
|
1254
|
-
const stringLength = string.length;
|
|
1255
|
-
for (
|
|
1256
|
-
let index = original.indexOf(string);
|
|
1257
|
-
index !== -1;
|
|
1258
|
-
index = original.indexOf(string, index + stringLength)
|
|
1259
|
-
) {
|
|
1260
|
-
const previous = original.slice(index, index + stringLength);
|
|
1261
|
-
if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
return this;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
replaceAll(searchValue, replacement) {
|
|
1268
|
-
if (typeof searchValue === 'string') {
|
|
1269
|
-
return this._replaceAllString(searchValue, replacement);
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
if (!searchValue.global) {
|
|
1273
|
-
throw new TypeError(
|
|
1274
|
-
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
export { SourceMap, MagicString as default };
|
|
1283
|
-
//# sourceMappingURL=magic-string.es.js.map
|