@sveltejs/vite-plugin-svelte 1.3.1 → 1.4.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/dist/index.cjs +456 -346
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -13
- package/dist/index.js +448 -339
- package/dist/index.js.map +1 -1
- package/dist/preprocess.cjs +127 -0
- package/dist/preprocess.cjs.map +1 -0
- package/dist/preprocess.d.ts +9 -0
- package/dist/preprocess.js +96 -0
- package/dist/preprocess.js.map +1 -0
- package/package.json +5 -15
- package/src/handle-hot-update.ts +24 -24
- package/src/index.ts +23 -24
- package/src/preprocess.ts +114 -0
- package/src/utils/compile.ts +71 -23
- package/src/utils/id.ts +55 -3
- package/src/utils/load-raw.ts +132 -0
- package/src/utils/options.ts +16 -9
- package/src/utils/preprocess.ts +9 -150
- package/src/utils/__tests__/sourcemap.spec.ts +0 -25
- package/src/utils/sourcemap.ts +0 -58
package/src/utils/sourcemap.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import MagicString, { MagicStringOptions } from 'magic-string';
|
|
2
|
-
import { log } from './log';
|
|
3
|
-
|
|
4
|
-
export async function buildMagicString(
|
|
5
|
-
from: string,
|
|
6
|
-
to: string,
|
|
7
|
-
options?: MagicStringOptions
|
|
8
|
-
): Promise<MagicString | null> {
|
|
9
|
-
let diff_match_patch, DIFF_DELETE: number, DIFF_INSERT: number;
|
|
10
|
-
try {
|
|
11
|
-
const dmpPkg = await import('diff-match-patch');
|
|
12
|
-
diff_match_patch = dmpPkg.diff_match_patch;
|
|
13
|
-
DIFF_INSERT = dmpPkg.DIFF_INSERT;
|
|
14
|
-
DIFF_DELETE = dmpPkg.DIFF_DELETE;
|
|
15
|
-
} catch (e) {
|
|
16
|
-
log.error.once(
|
|
17
|
-
'Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.'
|
|
18
|
-
);
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const dmp = new diff_match_patch();
|
|
23
|
-
const diffs = dmp.diff_main(from, to);
|
|
24
|
-
dmp.diff_cleanupSemantic(diffs);
|
|
25
|
-
const m = new MagicString(from, options);
|
|
26
|
-
let pos = 0;
|
|
27
|
-
for (let i = 0; i < diffs.length; i++) {
|
|
28
|
-
const diff = diffs[i];
|
|
29
|
-
const nextDiff = diffs[i + 1];
|
|
30
|
-
if (diff[0] === DIFF_DELETE) {
|
|
31
|
-
if (nextDiff?.[0] === DIFF_INSERT) {
|
|
32
|
-
// delete followed by insert, use overwrite and skip ahead
|
|
33
|
-
m.overwrite(pos, pos + diff[1].length, nextDiff[1]);
|
|
34
|
-
i++;
|
|
35
|
-
} else {
|
|
36
|
-
m.remove(pos, pos + diff[1].length);
|
|
37
|
-
}
|
|
38
|
-
pos += diff[1].length;
|
|
39
|
-
} else if (diff[0] === DIFF_INSERT) {
|
|
40
|
-
if (nextDiff) {
|
|
41
|
-
m.appendRight(pos, diff[1]);
|
|
42
|
-
} else {
|
|
43
|
-
m.append(diff[1]);
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
// unchanged block, advance pos
|
|
47
|
-
pos += diff[1].length;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// at this point m.toString() === to
|
|
51
|
-
return m;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function buildSourceMap(from: string, to: string, filename?: string) {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
const m = await buildMagicString(from, to, { filename });
|
|
57
|
-
return m ? m.generateDecodedMap({ source: filename, hires: true, includeContent: false }) : null;
|
|
58
|
-
}
|