@macroforge/svelte-preprocessor 0.1.78 → 0.1.79
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.d.ts.map +1 -1
- package/dist/index.js +94 -5
- package/package.json +10 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA6OvE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,6BAAkC,GAC1C,iBAAiB,CA6JnB;AAED;;;;;;;GAOG;AACH,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,95 @@
|
|
|
26
26
|
* @packageDocumentation
|
|
27
27
|
*/
|
|
28
28
|
import { hasMacroAnnotations } from "@macroforge/shared";
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Source Map Generation
|
|
31
|
+
// ============================================================================
|
|
32
|
+
const VLQ_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
33
|
+
function vlqEncode(value) {
|
|
34
|
+
let vlq = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
35
|
+
let encoded = "";
|
|
36
|
+
do {
|
|
37
|
+
let digit = vlq & 0x1f;
|
|
38
|
+
vlq >>>= 5;
|
|
39
|
+
if (vlq > 0)
|
|
40
|
+
digit |= 0x20;
|
|
41
|
+
encoded += VLQ_CHARS[digit];
|
|
42
|
+
} while (vlq > 0);
|
|
43
|
+
return encoded;
|
|
44
|
+
}
|
|
45
|
+
/** Build line offsets table: lineOffsets[i] = byte offset of the start of line i */
|
|
46
|
+
function buildLineOffsets(text) {
|
|
47
|
+
const offsets = [0];
|
|
48
|
+
for (let i = 0; i < text.length; i++) {
|
|
49
|
+
if (text[i] === "\n")
|
|
50
|
+
offsets.push(i + 1);
|
|
51
|
+
}
|
|
52
|
+
return offsets;
|
|
53
|
+
}
|
|
54
|
+
/** Convert byte offset to { line, column } (0-based) */
|
|
55
|
+
function offsetToLineCol(offset, lineOffsets) {
|
|
56
|
+
let lo = 0, hi = lineOffsets.length - 1;
|
|
57
|
+
while (lo < hi) {
|
|
58
|
+
const mid = (lo + hi + 1) >> 1;
|
|
59
|
+
if (lineOffsets[mid] <= offset)
|
|
60
|
+
lo = mid;
|
|
61
|
+
else
|
|
62
|
+
hi = mid - 1;
|
|
63
|
+
}
|
|
64
|
+
return { line: lo, column: offset - lineOffsets[lo] };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build a v3 source map from macroforge's segment-based mapping.
|
|
68
|
+
* Each segment maps a byte range in the expanded code to a byte range in the original.
|
|
69
|
+
*/
|
|
70
|
+
function buildSourceMap(original, expanded, mapping, filename) {
|
|
71
|
+
const origOffsets = buildLineOffsets(original);
|
|
72
|
+
const expOffsets = buildLineOffsets(expanded);
|
|
73
|
+
// Group segments by expanded line
|
|
74
|
+
const lineSegments = new Map();
|
|
75
|
+
for (const seg of mapping.segments) {
|
|
76
|
+
const exp = offsetToLineCol(seg.expandedStart, expOffsets);
|
|
77
|
+
const orig = offsetToLineCol(seg.originalStart, origOffsets);
|
|
78
|
+
if (!lineSegments.has(exp.line))
|
|
79
|
+
lineSegments.set(exp.line, []);
|
|
80
|
+
lineSegments.get(exp.line).push({
|
|
81
|
+
expCol: exp.column,
|
|
82
|
+
origLine: orig.line,
|
|
83
|
+
origCol: orig.column,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Encode VLQ mappings
|
|
87
|
+
const totalLines = expOffsets.length;
|
|
88
|
+
const mappingsArr = [];
|
|
89
|
+
let prevOrigLine = 0, prevOrigCol = 0;
|
|
90
|
+
for (let line = 0; line < totalLines; line++) {
|
|
91
|
+
const segs = lineSegments.get(line);
|
|
92
|
+
if (!segs || segs.length === 0) {
|
|
93
|
+
mappingsArr.push("");
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
segs.sort((a, b) => a.expCol - b.expCol);
|
|
97
|
+
const parts = [];
|
|
98
|
+
let lineExpCol = 0;
|
|
99
|
+
for (const seg of segs) {
|
|
100
|
+
parts.push(vlqEncode(seg.expCol - lineExpCol) +
|
|
101
|
+
vlqEncode(0) + // source index (always 0)
|
|
102
|
+
vlqEncode(seg.origLine - prevOrigLine) +
|
|
103
|
+
vlqEncode(seg.origCol - prevOrigCol));
|
|
104
|
+
lineExpCol = seg.expCol;
|
|
105
|
+
prevOrigLine = seg.origLine;
|
|
106
|
+
prevOrigCol = seg.origCol;
|
|
107
|
+
}
|
|
108
|
+
mappingsArr.push(parts.join(","));
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
version: 3,
|
|
112
|
+
sources: [filename],
|
|
113
|
+
sourcesContent: [original],
|
|
114
|
+
names: [],
|
|
115
|
+
mappings: mappingsArr.join(";"),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
29
118
|
/**
|
|
30
119
|
* Cached reference to the native `expandSync` function from the macroforge package.
|
|
31
120
|
*
|
|
@@ -238,11 +327,11 @@ export function macroforgePreprocess(options = {}) {
|
|
|
238
327
|
* - map: Source map for debugging (optional, not yet implemented)
|
|
239
328
|
*/
|
|
240
329
|
if (result.code && result.code !== content) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
};
|
|
330
|
+
const mapping = result.sourceMapping;
|
|
331
|
+
const map = mapping?.segments?.length && filename
|
|
332
|
+
? buildSourceMap(content, result.code, mapping, filename)
|
|
333
|
+
: undefined;
|
|
334
|
+
return { code: result.code, map };
|
|
246
335
|
}
|
|
247
336
|
}
|
|
248
337
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@macroforge/shared": "
|
|
4
|
-
"macroforge": "
|
|
3
|
+
"@macroforge/shared": "file:../shared",
|
|
4
|
+
"macroforge": "file:../../crates/macroforge_ts"
|
|
5
5
|
},
|
|
6
6
|
"description": "Svelte preprocessor for expanding Macroforge macros in component script blocks",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"svelte": "^5.43.8",
|
|
9
9
|
"typescript": "^5.9.3"
|
|
10
10
|
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
11
17
|
"files": [
|
|
12
18
|
"dist"
|
|
13
19
|
],
|
|
@@ -28,7 +34,7 @@
|
|
|
28
34
|
"repository": {
|
|
29
35
|
"directory": "packages/svelte-preprocessor",
|
|
30
36
|
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/macroforge-ts/
|
|
37
|
+
"url": "git+https://github.com/macroforge-ts/macroforge-ts.git"
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"build": "deno install --node-modules-dir --quiet && deno run -A npm:typescript@5/tsc -p tsconfig.json",
|
|
@@ -38,5 +44,5 @@
|
|
|
38
44
|
},
|
|
39
45
|
"type": "module",
|
|
40
46
|
"types": "dist/index.d.ts",
|
|
41
|
-
"version": "0.1.
|
|
47
|
+
"version": "0.1.79"
|
|
42
48
|
}
|