olum-compiler 1.5.0 → 1.6.1
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/bin/build.js +1 -1
- package/bin/bundle.js +32 -30
- package/bin/compiler.js +20 -10
- package/bin/copySrc.js +45 -41
- package/bin/dev.js +46 -39
- package/bin/index.js +6 -3
- package/bin/server.js +58 -33
- package/bin/watcher.js +11 -14
- package/bin/ws.js +16 -11
- package/lib/attr.js +1 -25
- package/lib/boolAttr.js +32 -15
- package/lib/chokidar.js +52 -101
- package/lib/colors.js +1 -7
- package/lib/compPlaceholder.js +5 -3
- package/lib/compiler.js +3 -6
- package/lib/coreLibs.js +1 -10
- package/lib/cross-spawn.js +45 -59
- package/lib/cssParser.js +61 -37
- package/lib/domEvents.js +6 -2
- package/lib/events.js +75 -77
- package/lib/for.js +56 -28
- package/lib/getImports.js +35 -17
- package/lib/getTempPath.js +8 -4
- package/lib/helpers.js +289 -184
- package/lib/html.js +3 -10
- package/lib/htmlParser.js +45 -45
- package/lib/if.js +40 -20
- package/lib/importMap.js +49 -24
- package/lib/jsParser.js +8 -13
- package/lib/lineCounter.js +18 -5
- package/lib/liveProps.js +124 -78
- package/lib/log.js +30 -0
- package/lib/magic-string.js +45 -52
- package/lib/models.js +8 -7
- package/lib/parser.js +76 -44
- package/lib/placeholder.js +73 -58
- package/lib/regex.js +4 -3
- package/lib/show.js +16 -8
- package/lib/sourcemap.js +23 -24
- package/lib/styles.js +7 -13
- package/lib/textarea.js +3 -6
- package/lib/toJs.js +1 -1
- package/lib/tokens.js +10 -22
- package/lib/transition.js +86 -0
- package/lib/websocket.js +68 -62
- package/package.json +1 -1
- package/tests/compiler.test.js +423 -188
- package/.claude/settings.local.json +0 -12
package/lib/liveProps.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
// liveProps.js — compiler pass: LIVE destructured props.
|
|
2
|
-
//
|
|
3
|
-
// `const { color, size = "md", theme: t } = props()` normally freezes values at factory
|
|
4
|
-
// time (destructuring copies). This pass injects ONE shared live accessor per instance —
|
|
5
|
-
// `const __props = props(_storeKey);` (the props proxy is stateless, so one allocation
|
|
6
|
-
// serves every read) — and rewrites every later REFERENCE to those bindings into a live
|
|
7
|
-
// read through it:
|
|
8
|
-
// color -> __props.color
|
|
9
|
-
// size -> (__props.size === undefined ? ("md") : __props.size)
|
|
10
|
-
// t -> __props.theme
|
|
11
|
-
// so destructured props are always current — in templates, methods, and closures alike.
|
|
12
|
-
//
|
|
13
|
-
// Runs on the fully-assembled compiled module (after parser.js has already rewritten
|
|
14
|
-
// props() -> props(_storeKey)), so template interpolations, anonymous event handlers and
|
|
15
|
-
// generated scope getters are all covered by a single AST walk.
|
|
16
|
-
//
|
|
17
|
-
// SAFETY MODEL — degrade to the old snapshot semantics, never break the build:
|
|
18
|
-
// - the original declaration is KEPT (its bindings just become unused); if a reference
|
|
19
|
-
// is skipped for any reason the code still runs with the old snapshot value.
|
|
20
|
-
// - a reference is rewritten only when NO scope between it and the factory body
|
|
21
|
-
// redeclares the name (function params, hoisted var/function names, let/const/class
|
|
22
|
-
// in ancestor blocks, catch params, loop heads) — shadowed names are left alone.
|
|
23
|
-
// - unsupported pattern parts (rest `...r`, nested `{ a: { b } }`, computed keys) keep
|
|
24
|
-
// snapshot semantics for those bindings only.
|
|
25
|
-
// - every edit is inline (line count unchanged), so the identity source map stays aligned.
|
|
26
|
-
// - any parse failure returns the input untouched.
|
|
27
|
-
|
|
28
1
|
const acorn = require("acorn");
|
|
29
2
|
const walk = require("acorn-walk");
|
|
30
3
|
|
|
31
|
-
// all names bound by a declaration pattern (id of a declarator, a param, a catch param)
|
|
32
4
|
function patternNames(node, set) {
|
|
33
5
|
if (!node) return;
|
|
34
6
|
switch (node.type) {
|
|
@@ -36,7 +8,9 @@ function patternNames(node, set) {
|
|
|
36
8
|
set.add(node.name);
|
|
37
9
|
break;
|
|
38
10
|
case "ObjectPattern":
|
|
39
|
-
node.properties.forEach((p) =>
|
|
11
|
+
node.properties.forEach((p) =>
|
|
12
|
+
patternNames(p.type === "Property" ? p.value : p.argument, set),
|
|
13
|
+
);
|
|
40
14
|
break;
|
|
41
15
|
case "ArrayPattern":
|
|
42
16
|
node.elements.forEach((el) => patternNames(el, set));
|
|
@@ -50,8 +24,6 @@ function patternNames(node, set) {
|
|
|
50
24
|
}
|
|
51
25
|
}
|
|
52
26
|
|
|
53
|
-
// names hoisted to a FUNCTION scope: `var` declarations and function declarations
|
|
54
|
-
// anywhere inside, without descending into nested functions (their own scopes)
|
|
55
27
|
function hoistedNames(node, set) {
|
|
56
28
|
(function rec(n) {
|
|
57
29
|
if (!n || typeof n !== "object") return;
|
|
@@ -59,10 +31,12 @@ function hoistedNames(node, set) {
|
|
|
59
31
|
if (typeof n.type !== "string") return;
|
|
60
32
|
if (n.type === "FunctionDeclaration") {
|
|
61
33
|
if (n.id) set.add(n.id.name);
|
|
62
|
-
return;
|
|
34
|
+
return;
|
|
63
35
|
}
|
|
64
|
-
if (n.type === "FunctionExpression" || n.type === "ArrowFunctionExpression")
|
|
65
|
-
|
|
36
|
+
if (n.type === "FunctionExpression" || n.type === "ArrowFunctionExpression")
|
|
37
|
+
return;
|
|
38
|
+
if (n.type === "VariableDeclaration" && n.kind === "var")
|
|
39
|
+
n.declarations.forEach((d) => patternNames(d.id, set));
|
|
66
40
|
for (const k in n) {
|
|
67
41
|
if (k === "type" || k === "start" || k === "end") continue;
|
|
68
42
|
rec(n[k]);
|
|
@@ -70,12 +44,19 @@ function hoistedNames(node, set) {
|
|
|
70
44
|
})(node);
|
|
71
45
|
}
|
|
72
46
|
|
|
73
|
-
// names declared DIRECTLY in a lexical scope node (block, loop head, catch, switch)
|
|
74
47
|
function lexicalNames(node, set) {
|
|
75
48
|
const fromStatements = (stmts) =>
|
|
76
49
|
stmts.forEach((st) => {
|
|
77
|
-
if (
|
|
78
|
-
|
|
50
|
+
if (
|
|
51
|
+
st.type === "VariableDeclaration" &&
|
|
52
|
+
(st.kind === "let" || st.kind === "const")
|
|
53
|
+
)
|
|
54
|
+
st.declarations.forEach((d) => patternNames(d.id, set));
|
|
55
|
+
else if (
|
|
56
|
+
st.type === "FunctionDeclaration" ||
|
|
57
|
+
st.type === "ClassDeclaration"
|
|
58
|
+
)
|
|
59
|
+
st.id && set.add(st.id.name);
|
|
79
60
|
});
|
|
80
61
|
switch (node.type) {
|
|
81
62
|
case "BlockStatement":
|
|
@@ -83,11 +64,13 @@ function lexicalNames(node, set) {
|
|
|
83
64
|
fromStatements(node.body);
|
|
84
65
|
break;
|
|
85
66
|
case "ForStatement":
|
|
86
|
-
if (node.init && node.init.type === "VariableDeclaration")
|
|
67
|
+
if (node.init && node.init.type === "VariableDeclaration")
|
|
68
|
+
node.init.declarations.forEach((d) => patternNames(d.id, set));
|
|
87
69
|
break;
|
|
88
70
|
case "ForInStatement":
|
|
89
71
|
case "ForOfStatement":
|
|
90
|
-
if (node.left.type === "VariableDeclaration")
|
|
72
|
+
if (node.left.type === "VariableDeclaration")
|
|
73
|
+
node.left.declarations.forEach((d) => patternNames(d.id, set));
|
|
91
74
|
break;
|
|
92
75
|
case "CatchClause":
|
|
93
76
|
patternNames(node.param, set);
|
|
@@ -98,11 +81,14 @@ function lexicalNames(node, set) {
|
|
|
98
81
|
}
|
|
99
82
|
}
|
|
100
83
|
|
|
101
|
-
const isFn = (t) =>
|
|
102
|
-
|
|
84
|
+
const isFn = (t) =>
|
|
85
|
+
t === "FunctionDeclaration" ||
|
|
86
|
+
t === "FunctionExpression" ||
|
|
87
|
+
t === "ArrowFunctionExpression";
|
|
88
|
+
const within = (node, container) =>
|
|
89
|
+
container && node.start >= container.start && node.end <= container.end;
|
|
103
90
|
|
|
104
91
|
function transform(code) {
|
|
105
|
-
// fast path: no `const { ... } = props(_storeKey)` destructure anywhere
|
|
106
92
|
if (!/\}\s*=\s*props\(_storeKey\)/.test(code)) return code;
|
|
107
93
|
|
|
108
94
|
let ast;
|
|
@@ -112,78 +98,123 @@ function transform(code) {
|
|
|
112
98
|
return code;
|
|
113
99
|
}
|
|
114
100
|
|
|
115
|
-
// 1 ── locate the compiled factory: `export default (_instanceKey) => { ... }`
|
|
116
101
|
let factory = null;
|
|
117
102
|
ast.body.forEach((st) => {
|
|
118
|
-
if (st.type === "ExportDefaultDeclaration" && isFn(st.declaration.type))
|
|
103
|
+
if (st.type === "ExportDefaultDeclaration" && isFn(st.declaration.type))
|
|
104
|
+
factory = st.declaration;
|
|
119
105
|
});
|
|
120
106
|
if (!factory || factory.body.type !== "BlockStatement") return code;
|
|
121
107
|
const factoryBody = factory.body;
|
|
122
108
|
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const declPatterns = []; // ObjectPattern nodes of the target declarations (skip refs inside)
|
|
109
|
+
const bindings = {};
|
|
110
|
+
const declPatterns = [];
|
|
126
111
|
factoryBody.body.forEach((st) => {
|
|
127
112
|
if (st.type !== "VariableDeclaration") return;
|
|
128
113
|
st.declarations.forEach((decl) => {
|
|
129
114
|
if (!decl.id || decl.id.type !== "ObjectPattern") return;
|
|
130
|
-
if (
|
|
115
|
+
if (
|
|
116
|
+
!decl.init ||
|
|
117
|
+
decl.init.type !== "CallExpression" ||
|
|
118
|
+
!decl.init.callee ||
|
|
119
|
+
decl.init.callee.name !== "props"
|
|
120
|
+
)
|
|
121
|
+
return;
|
|
131
122
|
declPatterns.push(decl.id);
|
|
132
123
|
decl.id.properties.forEach((p) => {
|
|
133
|
-
if (p.type !== "Property" || p.computed || !p.key || !p.key.name)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
bindings[p.value.
|
|
137
|
-
|
|
124
|
+
if (p.type !== "Property" || p.computed || !p.key || !p.key.name)
|
|
125
|
+
return;
|
|
126
|
+
if (p.value.type === "Identifier")
|
|
127
|
+
bindings[p.value.name] = { key: p.key.name, dflt: null };
|
|
128
|
+
else if (
|
|
129
|
+
p.value.type === "AssignmentPattern" &&
|
|
130
|
+
p.value.left.type === "Identifier"
|
|
131
|
+
)
|
|
132
|
+
bindings[p.value.left.name] = {
|
|
133
|
+
key: p.key.name,
|
|
134
|
+
dflt: code.slice(p.value.right.start, p.value.right.end),
|
|
135
|
+
};
|
|
138
136
|
});
|
|
139
137
|
});
|
|
140
138
|
});
|
|
141
139
|
if (!Object.keys(bindings).length) return code;
|
|
142
140
|
|
|
143
|
-
// one shared live accessor per instance; suffix the name on the off chance it collides
|
|
144
141
|
let propsRef = "__props";
|
|
145
142
|
while (code.indexOf(propsRef) !== -1) propsRef += "$";
|
|
146
143
|
|
|
147
144
|
const repl = (name) => {
|
|
148
145
|
const b = bindings[name];
|
|
149
146
|
const read = propsRef + "." + b.key;
|
|
150
|
-
return b.dflt === null
|
|
147
|
+
return b.dflt === null
|
|
148
|
+
? read
|
|
149
|
+
: "(" + read + " === undefined ? (" + b.dflt + ") : " + read + ")";
|
|
151
150
|
};
|
|
152
151
|
|
|
153
|
-
// 3 ── walk every identifier, classify, shadow-check, collect edits
|
|
154
152
|
const edits = [];
|
|
155
153
|
walk.fullAncestor(ast, (node, state, ancestors) => {
|
|
156
154
|
if (node.type !== "Identifier" || !bindings[node.name]) return;
|
|
157
155
|
const parent = ancestors[ancestors.length - 2];
|
|
158
156
|
if (!parent) return;
|
|
159
157
|
|
|
160
|
-
// inside one of the target destructure patterns (the kept declaration itself)
|
|
161
158
|
if (declPatterns.some((dp) => within(node, dp))) return;
|
|
162
159
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
160
|
+
if (
|
|
161
|
+
parent.type === "Property" &&
|
|
162
|
+
parent.key === node &&
|
|
163
|
+
!parent.computed &&
|
|
164
|
+
!parent.shorthand
|
|
165
|
+
)
|
|
166
|
+
return;
|
|
167
|
+
if (
|
|
168
|
+
parent.type === "MemberExpression" &&
|
|
169
|
+
parent.property === node &&
|
|
170
|
+
!parent.computed
|
|
171
|
+
)
|
|
172
|
+
return;
|
|
173
|
+
if (
|
|
174
|
+
(parent.type === "MethodDefinition" ||
|
|
175
|
+
parent.type === "PropertyDefinition") &&
|
|
176
|
+
parent.key === node &&
|
|
177
|
+
!parent.computed
|
|
178
|
+
)
|
|
179
|
+
return;
|
|
180
|
+
if (
|
|
181
|
+
parent.type.indexOf("Import") === 0 ||
|
|
182
|
+
parent.type === "ExportSpecifier"
|
|
183
|
+
)
|
|
184
|
+
return;
|
|
185
|
+
if (
|
|
186
|
+
(parent.type === "LabeledStatement" ||
|
|
187
|
+
parent.type === "BreakStatement" ||
|
|
188
|
+
parent.type === "ContinueStatement") &&
|
|
189
|
+
parent.label === node
|
|
190
|
+
)
|
|
191
|
+
return;
|
|
169
192
|
if (isFn(parent.type) && parent.id === node) return;
|
|
170
|
-
if (
|
|
193
|
+
if (
|
|
194
|
+
parent.type === "ClassDeclaration" ||
|
|
195
|
+
parent.type === "ClassExpression"
|
|
196
|
+
) {
|
|
171
197
|
if (parent.id === node) return;
|
|
172
198
|
}
|
|
173
199
|
|
|
174
|
-
// binding positions & shadow scopes — walk ancestors innermost -> factory body
|
|
175
200
|
let inFactory = false;
|
|
176
201
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
177
202
|
const a = ancestors[i];
|
|
178
203
|
if (a === factoryBody) {
|
|
179
204
|
inFactory = true;
|
|
180
|
-
break;
|
|
205
|
+
break;
|
|
181
206
|
}
|
|
182
|
-
|
|
207
|
+
|
|
183
208
|
if (a.type === "VariableDeclarator" && within(node, a.id)) return;
|
|
184
|
-
if (
|
|
209
|
+
if (
|
|
210
|
+
isFn(a.type) &&
|
|
211
|
+
a.params.length &&
|
|
212
|
+
node.start >= a.params[0].start &&
|
|
213
|
+
node.end <= a.params[a.params.length - 1].end
|
|
214
|
+
)
|
|
215
|
+
return;
|
|
185
216
|
if (a.type === "CatchClause" && a.param && within(node, a.param)) return;
|
|
186
|
-
|
|
217
|
+
|
|
187
218
|
const declared = new Set();
|
|
188
219
|
if (isFn(a.type)) {
|
|
189
220
|
a.params.forEach((p) => patternNames(p, declared));
|
|
@@ -193,27 +224,42 @@ function transform(code) {
|
|
|
193
224
|
}
|
|
194
225
|
if (declared.has(node.name)) return;
|
|
195
226
|
}
|
|
196
|
-
if (!inFactory) return;
|
|
227
|
+
if (!inFactory) return;
|
|
197
228
|
|
|
198
|
-
// `({ color })` shorthand in an object EXPRESSION needs the key spelled out
|
|
199
229
|
const grand = ancestors[ancestors.length - 3];
|
|
200
|
-
if (
|
|
201
|
-
|
|
230
|
+
if (
|
|
231
|
+
parent.type === "Property" &&
|
|
232
|
+
parent.shorthand &&
|
|
233
|
+
parent.value === node &&
|
|
234
|
+
grand &&
|
|
235
|
+
grand.type === "ObjectExpression"
|
|
236
|
+
) {
|
|
237
|
+
edits.push({
|
|
238
|
+
start: node.start,
|
|
239
|
+
end: node.end,
|
|
240
|
+
text: node.name + ": " + repl(node.name),
|
|
241
|
+
});
|
|
202
242
|
return;
|
|
203
243
|
}
|
|
204
|
-
if (parent.type === "Property" && parent.shorthand && parent.value === node)
|
|
244
|
+
if (parent.type === "Property" && parent.shorthand && parent.value === node)
|
|
245
|
+
return;
|
|
205
246
|
|
|
206
247
|
edits.push({ start: node.start, end: node.end, text: repl(node.name) });
|
|
207
248
|
});
|
|
208
249
|
|
|
209
250
|
if (!edits.length) return code;
|
|
210
|
-
|
|
211
|
-
// (`const _storeKey = ...;`) — same line, so line numbering is unchanged
|
|
251
|
+
|
|
212
252
|
const anchor = factoryBody.body[0];
|
|
213
|
-
edits.push({
|
|
253
|
+
edits.push({
|
|
254
|
+
start: anchor.end,
|
|
255
|
+
end: anchor.end,
|
|
256
|
+
text: " const " + propsRef + " = props(_storeKey);",
|
|
257
|
+
});
|
|
214
258
|
edits.sort((a, b) => b.start - a.start);
|
|
215
259
|
let out = code;
|
|
216
|
-
edits.forEach(
|
|
260
|
+
edits.forEach(
|
|
261
|
+
(e) => (out = out.slice(0, e.start) + e.text + out.slice(e.end)),
|
|
262
|
+
);
|
|
217
263
|
return out;
|
|
218
264
|
}
|
|
219
265
|
|
package/lib/log.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { getLineInfo } = require("./lineCounter");
|
|
2
|
+
const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
|
|
3
|
+
|
|
4
|
+
function handleLog(body, counter, filePath) {
|
|
5
|
+
const elms = new Array().slice.call(body.querySelectorAll("log"));
|
|
6
|
+
elms.forEach((item) => {
|
|
7
|
+
const raw = (item.textContent || "").trim();
|
|
8
|
+
const match = raw.match(/^\{([\s\S]*)\}$/);
|
|
9
|
+
if (!match || !match[1].trim()) {
|
|
10
|
+
getLineInfo(
|
|
11
|
+
counter,
|
|
12
|
+
item,
|
|
13
|
+
filePath,
|
|
14
|
+
"Empty or malformed <log> — expected <log>{expr}</log>:",
|
|
15
|
+
);
|
|
16
|
+
item.remove();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const expr = shieldOps(match[1].trim());
|
|
20
|
+
const encoded = expr.replace(/{/g, "<-olum->");
|
|
21
|
+
|
|
22
|
+
item.insertAdjacentHTML(
|
|
23
|
+
"beforebegin",
|
|
24
|
+
RAW_OPEN + "(console.log(" + encoded + "), '')" + RAW_CLOSE,
|
|
25
|
+
);
|
|
26
|
+
item.remove();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = handleLog;
|
package/lib/magic-string.js
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* magic-string.js — standalone single-file source map generator
|
|
3
|
-
* Minimal replacement for the `magic-string` package (v0.30.21), using only
|
|
4
|
-
* node built-ins. This project (lib/sourcemap.js) only ever builds an
|
|
5
|
-
* IDENTITY map — `new MagicString(str)` with zero edits, then
|
|
6
|
-
* `generateMap({ source, file, includeContent })` — so that surface is ported
|
|
7
|
-
* faithfully (byte-identical output, including the VLQ `mappings`, JSON key
|
|
8
|
-
* order and `toString()`/`toUrl()`):
|
|
9
|
-
*
|
|
10
|
-
* const MagicString = require("./magic-string");
|
|
11
|
-
* const map = new MagicString(code).generateMap({ source, file, includeContent, hires });
|
|
12
|
-
* map.mappings / map.toString() / map.toUrl()
|
|
13
|
-
*
|
|
14
|
-
* Supported: generateMap / generateDecodedMap with options
|
|
15
|
-
* `source`, `file`, `includeContent`, `hires` (true | "boundary" | falsy).
|
|
16
|
-
*
|
|
17
|
-
* KNOWN LIMITATIONS vs the real magic-string (future maintenance):
|
|
18
|
-
* The string EDITING api (overwrite, update, appendLeft/Right, prepend,
|
|
19
|
-
* append, remove, move, indent, trim, slice, clone, addSourcemapLocation,
|
|
20
|
-
* Bundle, ...) is NOT implemented — those methods throw with a clear message
|
|
21
|
-
* instead of failing silently. If the compiler ever needs to transform code
|
|
22
|
-
* while tracking mappings (e.g. the sourcemap.js TODO about mapping html
|
|
23
|
-
* above the script tag), either extend this file's char-walk in
|
|
24
|
-
* generateDecodedMap to consume an edit list, or reinstall the real package.
|
|
25
|
-
*/
|
|
26
1
|
"use strict";
|
|
27
2
|
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
const BASE64 =
|
|
4
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
30
5
|
|
|
31
6
|
function encodeVlq(num) {
|
|
32
7
|
num = num < 0 ? (-num << 1) | 1 : num << 1;
|
|
@@ -34,15 +9,12 @@ function encodeVlq(num) {
|
|
|
34
9
|
do {
|
|
35
10
|
let digit = num & 31;
|
|
36
11
|
num >>>= 5;
|
|
37
|
-
if (num > 0) digit |= 32;
|
|
12
|
+
if (num > 0) digit |= 32;
|
|
38
13
|
out += BASE64[digit];
|
|
39
14
|
} while (num > 0);
|
|
40
15
|
return out;
|
|
41
16
|
}
|
|
42
17
|
|
|
43
|
-
// encode decoded mappings ([[ [genCol, srcIdx, srcLine, srcCol, name?], ...], ...])
|
|
44
|
-
// into the standard delta-encoded VLQ string: fields are relative to the
|
|
45
|
-
// previous segment; generated column resets per line, the rest carry over
|
|
46
18
|
function encodeMappings(decoded) {
|
|
47
19
|
let sourceIndex = 0;
|
|
48
20
|
let sourceLine = 0;
|
|
@@ -50,14 +22,17 @@ function encodeMappings(decoded) {
|
|
|
50
22
|
let nameIndex = 0;
|
|
51
23
|
|
|
52
24
|
return decoded
|
|
53
|
-
.map(line => {
|
|
25
|
+
.map((line) => {
|
|
54
26
|
let genColumn = 0;
|
|
55
27
|
return line
|
|
56
|
-
.map(segment => {
|
|
28
|
+
.map((segment) => {
|
|
57
29
|
let out = encodeVlq(segment[0] - genColumn);
|
|
58
30
|
genColumn = segment[0];
|
|
59
31
|
if (segment.length > 1) {
|
|
60
|
-
out +=
|
|
32
|
+
out +=
|
|
33
|
+
encodeVlq(segment[1] - sourceIndex) +
|
|
34
|
+
encodeVlq(segment[2] - sourceLine) +
|
|
35
|
+
encodeVlq(segment[3] - sourceColumn);
|
|
61
36
|
sourceIndex = segment[1];
|
|
62
37
|
sourceLine = segment[2];
|
|
63
38
|
sourceColumn = segment[3];
|
|
@@ -73,12 +48,11 @@ function encodeMappings(decoded) {
|
|
|
73
48
|
.join(";");
|
|
74
49
|
}
|
|
75
50
|
|
|
76
|
-
// path of `to` relative to `from`'s directory (magic-string's own helper)
|
|
77
51
|
function getRelativePath(from, to) {
|
|
78
52
|
const fromParts = from.split(/[/\\]/);
|
|
79
53
|
const toParts = to.split(/[/\\]/);
|
|
80
54
|
|
|
81
|
-
fromParts.pop();
|
|
55
|
+
fromParts.pop();
|
|
82
56
|
|
|
83
57
|
while (fromParts[0] === toParts[0]) {
|
|
84
58
|
fromParts.shift();
|
|
@@ -93,7 +67,6 @@ function getRelativePath(from, to) {
|
|
|
93
67
|
return fromParts.concat(toParts).join("/");
|
|
94
68
|
}
|
|
95
69
|
|
|
96
|
-
// --------------------------------------------------------------- SourceMap
|
|
97
70
|
class SourceMap {
|
|
98
71
|
constructor(properties) {
|
|
99
72
|
this.version = 3;
|
|
@@ -105,15 +78,17 @@ class SourceMap {
|
|
|
105
78
|
}
|
|
106
79
|
|
|
107
80
|
toString() {
|
|
108
|
-
return JSON.stringify(this);
|
|
81
|
+
return JSON.stringify(this);
|
|
109
82
|
}
|
|
110
83
|
|
|
111
84
|
toUrl() {
|
|
112
|
-
return
|
|
85
|
+
return (
|
|
86
|
+
"data:application/json;charset=utf-8;base64," +
|
|
87
|
+
Buffer.from(this.toString(), "utf-8").toString("base64")
|
|
88
|
+
);
|
|
113
89
|
}
|
|
114
90
|
}
|
|
115
91
|
|
|
116
|
-
// -------------------------------------------------------------- MagicString
|
|
117
92
|
const wordRegex = /\w/;
|
|
118
93
|
|
|
119
94
|
class MagicString {
|
|
@@ -130,10 +105,6 @@ class MagicString {
|
|
|
130
105
|
return this.original.length;
|
|
131
106
|
}
|
|
132
107
|
|
|
133
|
-
// identity mapping: walk the original char by char, mirroring magic-string's
|
|
134
|
-
// Mappings.addUneditedChunk — a segment at the first char of every line
|
|
135
|
-
// (every char for hires: true, word boundaries for hires: "boundary");
|
|
136
|
-
// lines with no characters get no segment
|
|
137
108
|
generateDecodedMap(options = {}) {
|
|
138
109
|
const hires = options.hires;
|
|
139
110
|
const mappings = [];
|
|
@@ -157,7 +128,6 @@ class MagicString {
|
|
|
157
128
|
if (hires || first) {
|
|
158
129
|
const segment = [genColumn, 0, sourceLine, sourceColumn];
|
|
159
130
|
if (hires === "boundary") {
|
|
160
|
-
// one segment per word, plus one for every non-word char
|
|
161
131
|
if (wordRegex.test(this.original[i])) {
|
|
162
132
|
if (!inBoundary) {
|
|
163
133
|
line.push(segment);
|
|
@@ -180,7 +150,11 @@ class MagicString {
|
|
|
180
150
|
|
|
181
151
|
return {
|
|
182
152
|
file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
|
|
183
|
-
sources: [
|
|
153
|
+
sources: [
|
|
154
|
+
options.source
|
|
155
|
+
? getRelativePath(options.file || "", options.source)
|
|
156
|
+
: options.file || "",
|
|
157
|
+
],
|
|
184
158
|
sourcesContent: options.includeContent ? [this.original] : undefined,
|
|
185
159
|
names: [],
|
|
186
160
|
mappings,
|
|
@@ -192,18 +166,37 @@ class MagicString {
|
|
|
192
166
|
}
|
|
193
167
|
}
|
|
194
168
|
|
|
195
|
-
// editing api is intentionally absent — fail loudly, not silently
|
|
196
169
|
for (const method of [
|
|
197
|
-
"addSourcemapLocation",
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
170
|
+
"addSourcemapLocation",
|
|
171
|
+
"append",
|
|
172
|
+
"appendLeft",
|
|
173
|
+
"appendRight",
|
|
174
|
+
"clone",
|
|
175
|
+
"indent",
|
|
176
|
+
"insertLeft",
|
|
177
|
+
"insertRight",
|
|
178
|
+
"move",
|
|
179
|
+
"overwrite",
|
|
180
|
+
"prepend",
|
|
181
|
+
"prependLeft",
|
|
182
|
+
"prependRight",
|
|
183
|
+
"remove",
|
|
184
|
+
"replace",
|
|
185
|
+
"replaceAll",
|
|
186
|
+
"reset",
|
|
187
|
+
"slice",
|
|
188
|
+
"snip",
|
|
189
|
+
"trim",
|
|
190
|
+
"trimEnd",
|
|
191
|
+
"trimStart",
|
|
192
|
+
"trimLines",
|
|
193
|
+
"update",
|
|
201
194
|
]) {
|
|
202
195
|
MagicString.prototype[method] = function () {
|
|
203
196
|
throw new Error(
|
|
204
197
|
`MagicString#${method}() is not implemented in the standalone lib/magic-string.js — ` +
|
|
205
198
|
"only identity source map generation (generateMap) is supported. " +
|
|
206
|
-
"See the header comment for how to extend it, or reinstall the real magic-string package."
|
|
199
|
+
"See the header comment for how to extend it, or reinstall the real magic-string package.",
|
|
207
200
|
);
|
|
208
201
|
};
|
|
209
202
|
}
|
package/lib/models.js
CHANGED
|
@@ -4,7 +4,7 @@ const path = require("path");
|
|
|
4
4
|
function handleModels(body, counter, filePath) {
|
|
5
5
|
const elms = new Array().slice.call(body.querySelectorAll("[model]"));
|
|
6
6
|
const name = path.basename(filePath).replace(/\.html/i, "");
|
|
7
|
-
elms.forEach(item => {
|
|
7
|
+
elms.forEach((item) => {
|
|
8
8
|
const value = item.getAttribute("model").trim();
|
|
9
9
|
if (value) {
|
|
10
10
|
const data = value.split(".");
|
|
@@ -16,17 +16,18 @@ function handleModels(body, counter, filePath) {
|
|
|
16
16
|
item.setAttribute("data-o-model", prop + "," + name);
|
|
17
17
|
item.removeAttribute("model");
|
|
18
18
|
if (mode.length) item.setAttribute("data-o-model-mode", mode.join(","));
|
|
19
|
-
// console.log({ index, data, prop, mode });
|
|
20
|
-
// console.log(item.outerHTML + "\n----------");
|
|
21
19
|
} else if (index === false) {
|
|
22
20
|
const prop = data.join(".");
|
|
23
21
|
item.setAttribute("data-o-e", "true");
|
|
24
22
|
item.setAttribute("data-o-model", prop + "," + name);
|
|
25
23
|
item.removeAttribute("model");
|
|
26
|
-
// console.log({ index, data, prop });
|
|
27
|
-
// console.log(item.outerHTML + "\n----------");
|
|
28
24
|
} else if (index === 0) {
|
|
29
|
-
getLineInfo(
|
|
25
|
+
getLineInfo(
|
|
26
|
+
counter,
|
|
27
|
+
item,
|
|
28
|
+
filePath,
|
|
29
|
+
"Can't start model attribute with a modifier!",
|
|
30
|
+
);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
});
|
|
@@ -42,7 +43,7 @@ function hasMode(data) {
|
|
|
42
43
|
mode3 = mode3 === -1 ? max : mode3;
|
|
43
44
|
const indexArr = [mode1, mode2, mode3];
|
|
44
45
|
const min = Math.min(...indexArr);
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
if (min === max) return false;
|
|
47
48
|
else if (min === 0) return 0;
|
|
48
49
|
return min;
|