@marko/runtime-tags 6.2.4 → 6.3.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/debug/dom.js +12 -11
- package/dist/debug/dom.mjs +12 -11
- package/dist/debug/html.js +6 -12
- package/dist/debug/html.mjs +6 -12
- package/dist/dom/dom.d.ts +1 -1
- package/dist/dom.js +8 -8
- package/dist/dom.mjs +8 -8
- package/dist/html.js +7 -6
- package/dist/html.mjs +7 -6
- package/dist/translator/index.js +64 -25
- package/dist/translator/util/assert.d.ts +1 -0
- package/dist/translator/util/references.d.ts +4 -0
- package/package.json +1 -1
- package/tags/lifecycle.d.marko +7 -4
package/dist/debug/dom.js
CHANGED
|
@@ -128,10 +128,7 @@ function normalizeDynamicRenderer(value) {
|
|
|
128
128
|
const lowercaseEventHandlerReg = /^on[a-z]/;
|
|
129
129
|
function assertValidAttrValue(name, value) {
|
|
130
130
|
if (value && typeof value !== "string" && lowercaseEventHandlerReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
|
|
131
|
-
if (typeof value === "function") {
|
|
132
|
-
if (name === "content" || /^on/i.test(name) || /Change$/.test(name)) return;
|
|
133
|
-
throw new Error(`The \`${name}\` attribute cannot be a function.`);
|
|
134
|
-
}
|
|
131
|
+
if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
|
|
135
132
|
const unrenderable = describeUnrenderable(value);
|
|
136
133
|
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
137
134
|
}
|
|
@@ -431,9 +428,9 @@ function _const(valueAccessor, fn) {
|
|
|
431
428
|
}
|
|
432
429
|
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
|
|
433
430
|
return (scope) => {
|
|
434
|
-
if (scope["#Gen"] === runId) if (id in scope) {
|
|
435
|
-
if (!--scope[id]) fn(scope);
|
|
436
|
-
} else scope[id] = defaultPending;
|
|
431
|
+
if (scope["#Gen"] === runId) if (~id in scope) {
|
|
432
|
+
if (!--scope[~id]) fn(scope);
|
|
433
|
+
} else scope[~id] = defaultPending;
|
|
437
434
|
else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
438
435
|
};
|
|
439
436
|
}
|
|
@@ -1362,7 +1359,11 @@ function _lifecycle(scope, thisObj, index = 0) {
|
|
|
1362
1359
|
instance.onUpdate?.();
|
|
1363
1360
|
} else {
|
|
1364
1361
|
scope[accessor] = thisObj;
|
|
1365
|
-
|
|
1362
|
+
{
|
|
1363
|
+
const snapshot = { ...thisObj };
|
|
1364
|
+
Object.assign(thisObj, thisObj.onMount?.());
|
|
1365
|
+
for (const prop in snapshot) if (!Object.is(snapshot[prop], thisObj[prop])) throw new Error(`Tried to overwrite existing property "${prop}" in <lifecycle> onMount.`);
|
|
1366
|
+
}
|
|
1366
1367
|
$signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
|
|
1367
1368
|
}
|
|
1368
1369
|
}
|
|
@@ -1809,10 +1810,10 @@ const caughtError = /* @__PURE__ */ new WeakSet();
|
|
|
1809
1810
|
const placeholderShown = /* @__PURE__ */ new WeakSet();
|
|
1810
1811
|
let pendingEffects = [];
|
|
1811
1812
|
let pendingRenders = [];
|
|
1812
|
-
const scopeKeyOffset =
|
|
1813
|
+
const scopeKeyOffset = 1e6;
|
|
1813
1814
|
function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
|
|
1814
1815
|
let render;
|
|
1815
|
-
if (signalKey >= 0 && (render = scope[signalKey
|
|
1816
|
+
if (signalKey >= 0 && (render = scope[signalKey])) {
|
|
1816
1817
|
render["value"] = value;
|
|
1817
1818
|
if (render["gen"] === runId || catchEnabled && render["pending"]) return;
|
|
1818
1819
|
render["gen"] = runId;
|
|
@@ -1824,7 +1825,7 @@ function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
|
|
|
1824
1825
|
["value"]: value,
|
|
1825
1826
|
["gen"]: runId
|
|
1826
1827
|
};
|
|
1827
|
-
if (signalKey >= 0) scope[signalKey
|
|
1828
|
+
if (signalKey >= 0) scope[signalKey] = render;
|
|
1828
1829
|
}
|
|
1829
1830
|
queuePendingRender(render);
|
|
1830
1831
|
}
|
package/dist/debug/dom.mjs
CHANGED
|
@@ -126,10 +126,7 @@ function normalizeDynamicRenderer(value) {
|
|
|
126
126
|
const lowercaseEventHandlerReg = /^on[a-z]/;
|
|
127
127
|
function assertValidAttrValue(name, value) {
|
|
128
128
|
if (value && typeof value !== "string" && lowercaseEventHandlerReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
|
|
129
|
-
if (typeof value === "function") {
|
|
130
|
-
if (name === "content" || /^on/i.test(name) || /Change$/.test(name)) return;
|
|
131
|
-
throw new Error(`The \`${name}\` attribute cannot be a function.`);
|
|
132
|
-
}
|
|
129
|
+
if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
|
|
133
130
|
const unrenderable = describeUnrenderable(value);
|
|
134
131
|
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
135
132
|
}
|
|
@@ -429,9 +426,9 @@ function _const(valueAccessor, fn) {
|
|
|
429
426
|
}
|
|
430
427
|
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
|
|
431
428
|
return (scope) => {
|
|
432
|
-
if (scope["#Gen"] === runId) if (id in scope) {
|
|
433
|
-
if (!--scope[id]) fn(scope);
|
|
434
|
-
} else scope[id] = defaultPending;
|
|
429
|
+
if (scope["#Gen"] === runId) if (~id in scope) {
|
|
430
|
+
if (!--scope[~id]) fn(scope);
|
|
431
|
+
} else scope[~id] = defaultPending;
|
|
435
432
|
else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
436
433
|
};
|
|
437
434
|
}
|
|
@@ -1360,7 +1357,11 @@ function _lifecycle(scope, thisObj, index = 0) {
|
|
|
1360
1357
|
instance.onUpdate?.();
|
|
1361
1358
|
} else {
|
|
1362
1359
|
scope[accessor] = thisObj;
|
|
1363
|
-
|
|
1360
|
+
{
|
|
1361
|
+
const snapshot = { ...thisObj };
|
|
1362
|
+
Object.assign(thisObj, thisObj.onMount?.());
|
|
1363
|
+
for (const prop in snapshot) if (!Object.is(snapshot[prop], thisObj[prop])) throw new Error(`Tried to overwrite existing property "${prop}" in <lifecycle> onMount.`);
|
|
1364
|
+
}
|
|
1364
1365
|
$signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
|
|
1365
1366
|
}
|
|
1366
1367
|
}
|
|
@@ -1807,10 +1808,10 @@ const caughtError = /* @__PURE__ */ new WeakSet();
|
|
|
1807
1808
|
const placeholderShown = /* @__PURE__ */ new WeakSet();
|
|
1808
1809
|
let pendingEffects = [];
|
|
1809
1810
|
let pendingRenders = [];
|
|
1810
|
-
const scopeKeyOffset =
|
|
1811
|
+
const scopeKeyOffset = 1e6;
|
|
1811
1812
|
function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
|
|
1812
1813
|
let render;
|
|
1813
|
-
if (signalKey >= 0 && (render = scope[signalKey
|
|
1814
|
+
if (signalKey >= 0 && (render = scope[signalKey])) {
|
|
1814
1815
|
render["value"] = value;
|
|
1815
1816
|
if (render["gen"] === runId || catchEnabled && render["pending"]) return;
|
|
1816
1817
|
render["gen"] = runId;
|
|
@@ -1822,7 +1823,7 @@ function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
|
|
|
1822
1823
|
["value"]: value,
|
|
1823
1824
|
["gen"]: runId
|
|
1824
1825
|
};
|
|
1825
|
-
if (signalKey >= 0) scope[signalKey
|
|
1826
|
+
if (signalKey >= 0) scope[signalKey] = render;
|
|
1826
1827
|
}
|
|
1827
1828
|
queuePendingRender(render);
|
|
1828
1829
|
}
|
package/dist/debug/html.js
CHANGED
|
@@ -127,10 +127,7 @@ function normalizeDynamicRenderer(value) {
|
|
|
127
127
|
const lowercaseEventHandlerReg = /^on[a-z]/;
|
|
128
128
|
function assertValidAttrValue(name, value) {
|
|
129
129
|
if (value && typeof value !== "string" && lowercaseEventHandlerReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
|
|
130
|
-
if (typeof value === "function") {
|
|
131
|
-
if (name === "content" || /^on/i.test(name) || /Change$/.test(name)) return;
|
|
132
|
-
throw new Error(`The \`${name}\` attribute cannot be a function.`);
|
|
133
|
-
}
|
|
130
|
+
if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
|
|
134
131
|
const unrenderable = describeUnrenderable(value);
|
|
135
132
|
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
136
133
|
}
|
|
@@ -822,7 +819,7 @@ function writeObject(state, val, parent, accessor) {
|
|
|
822
819
|
return writeReferenceOr(state, writeUnknownObject, val, parent, accessor);
|
|
823
820
|
}
|
|
824
821
|
function writeUnknownObject(state, val, ref) {
|
|
825
|
-
switch (val
|
|
822
|
+
switch (Object.getPrototypeOf(val)?.constructor) {
|
|
826
823
|
case void 0: return writeNullObject(state, val, ref);
|
|
827
824
|
case Object: return writePlainObject(state, val, ref);
|
|
828
825
|
case Array: return writeArray(state, val, ref);
|
|
@@ -1024,15 +1021,15 @@ function writeWeakMap(state) {
|
|
|
1024
1021
|
function writeError(state, val, ref) {
|
|
1025
1022
|
const result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
|
|
1026
1023
|
if (val.cause !== void 0) {
|
|
1027
|
-
state.buf.push(result + ",{cause:");
|
|
1028
|
-
writeProp(state, val.cause, ref, "cause");
|
|
1029
|
-
state.buf.
|
|
1024
|
+
const pos = state.buf.push(result + ",{cause:") - 1;
|
|
1025
|
+
if (writeProp(state, val.cause, ref, "cause")) state.buf.push("})");
|
|
1026
|
+
else state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
|
|
1030
1027
|
} else state.buf.push(result + ")");
|
|
1031
1028
|
return true;
|
|
1032
1029
|
}
|
|
1033
1030
|
function writeAggregateError(state, val, ref) {
|
|
1034
1031
|
state.buf.push("new AggregateError(");
|
|
1035
|
-
writeProp(state, val.errors, ref, "errors");
|
|
1032
|
+
if (!writeProp(state, val.errors, ref, "errors")) state.buf.push("[]");
|
|
1036
1033
|
if (val.message) state.buf.push("," + quote(val.message + "", 0) + ")");
|
|
1037
1034
|
else state.buf.push(")");
|
|
1038
1035
|
return true;
|
|
@@ -2656,9 +2653,6 @@ function nonVoidAttr(name, value) {
|
|
|
2656
2653
|
case "string": return " " + name + attrAssignment(value);
|
|
2657
2654
|
case "boolean": return " " + name;
|
|
2658
2655
|
case "number": return " " + name + "=" + value;
|
|
2659
|
-
case "object":
|
|
2660
|
-
if (value instanceof RegExp) return " " + name + attrAssignment(value.source);
|
|
2661
|
-
break;
|
|
2662
2656
|
}
|
|
2663
2657
|
return " " + name + attrAssignment(value + "");
|
|
2664
2658
|
}
|
package/dist/debug/html.mjs
CHANGED
|
@@ -125,10 +125,7 @@ function normalizeDynamicRenderer(value) {
|
|
|
125
125
|
const lowercaseEventHandlerReg = /^on[a-z]/;
|
|
126
126
|
function assertValidAttrValue(name, value) {
|
|
127
127
|
if (value && typeof value !== "string" && lowercaseEventHandlerReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
|
|
128
|
-
if (typeof value === "function") {
|
|
129
|
-
if (name === "content" || /^on/i.test(name) || /Change$/.test(name)) return;
|
|
130
|
-
throw new Error(`The \`${name}\` attribute cannot be a function.`);
|
|
131
|
-
}
|
|
128
|
+
if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
|
|
132
129
|
const unrenderable = describeUnrenderable(value);
|
|
133
130
|
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
134
131
|
}
|
|
@@ -820,7 +817,7 @@ function writeObject(state, val, parent, accessor) {
|
|
|
820
817
|
return writeReferenceOr(state, writeUnknownObject, val, parent, accessor);
|
|
821
818
|
}
|
|
822
819
|
function writeUnknownObject(state, val, ref) {
|
|
823
|
-
switch (val
|
|
820
|
+
switch (Object.getPrototypeOf(val)?.constructor) {
|
|
824
821
|
case void 0: return writeNullObject(state, val, ref);
|
|
825
822
|
case Object: return writePlainObject(state, val, ref);
|
|
826
823
|
case Array: return writeArray(state, val, ref);
|
|
@@ -1022,15 +1019,15 @@ function writeWeakMap(state) {
|
|
|
1022
1019
|
function writeError(state, val, ref) {
|
|
1023
1020
|
const result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
|
|
1024
1021
|
if (val.cause !== void 0) {
|
|
1025
|
-
state.buf.push(result + ",{cause:");
|
|
1026
|
-
writeProp(state, val.cause, ref, "cause");
|
|
1027
|
-
state.buf.
|
|
1022
|
+
const pos = state.buf.push(result + ",{cause:") - 1;
|
|
1023
|
+
if (writeProp(state, val.cause, ref, "cause")) state.buf.push("})");
|
|
1024
|
+
else state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
|
|
1028
1025
|
} else state.buf.push(result + ")");
|
|
1029
1026
|
return true;
|
|
1030
1027
|
}
|
|
1031
1028
|
function writeAggregateError(state, val, ref) {
|
|
1032
1029
|
state.buf.push("new AggregateError(");
|
|
1033
|
-
writeProp(state, val.errors, ref, "errors");
|
|
1030
|
+
if (!writeProp(state, val.errors, ref, "errors")) state.buf.push("[]");
|
|
1034
1031
|
if (val.message) state.buf.push("," + quote(val.message + "", 0) + ")");
|
|
1035
1032
|
else state.buf.push(")");
|
|
1036
1033
|
return true;
|
|
@@ -2654,9 +2651,6 @@ function nonVoidAttr(name, value) {
|
|
|
2654
2651
|
case "string": return " " + name + attrAssignment(value);
|
|
2655
2652
|
case "boolean": return " " + name;
|
|
2656
2653
|
case "number": return " " + name + "=" + value;
|
|
2657
|
-
case "object":
|
|
2658
|
-
if (value instanceof RegExp) return " " + name + attrAssignment(value.source);
|
|
2659
|
-
break;
|
|
2660
2654
|
}
|
|
2661
2655
|
return " " + name + attrAssignment(value + "");
|
|
2662
2656
|
}
|
package/dist/dom/dom.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function _attrs_script(scope: Scope, nodeAccessor: Accessor): voi
|
|
|
21
21
|
export declare function _html(scope: Scope, value: unknown, accessor: Accessor): void;
|
|
22
22
|
export declare function normalizeAttrValue(value: unknown): string | undefined;
|
|
23
23
|
export declare function _lifecycle(scope: Scope, thisObj: Record<string, unknown> & {
|
|
24
|
-
onMount?: (this: unknown) => void;
|
|
24
|
+
onMount?: (this: unknown) => Record<string, unknown> | void;
|
|
25
25
|
onUpdate?: (this: unknown) => void;
|
|
26
26
|
onDestroy?: (this: unknown) => void;
|
|
27
27
|
}, index?: number): void;
|
package/dist/dom.js
CHANGED
|
@@ -49,7 +49,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
|
|
|
49
49
|
};
|
|
50
50
|
}, _for_of = /* @__PURE__ */ loop(([all, by = bySecondArg], cb) => {
|
|
51
51
|
typeof by == "string" ? forOf(all, (item, i) => cb(item[by], [item, i])) : forOf(all, (item, i) => cb(by(item, i), [item, i]));
|
|
52
|
-
}), _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))), _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))), _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))), rendering, runId = 2, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingRenders = [],
|
|
52
|
+
}), _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))), _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))), _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))), rendering, runId = 2, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingRenders = [], runEffects = ((effects) => {
|
|
53
53
|
for (let i = 0; i < effects.length;) effects[i++](effects[i++]);
|
|
54
54
|
}), runRender = (render) => render.c(render.b, render.d), catchEnabled, classIdToBranch = /* @__PURE__ */ new Map(), scopesByRender = /* @__PURE__ */ new WeakMap(), getRenderScopes = ($global) => {
|
|
55
55
|
let render = self[$global.runtimeId]?.[$global.renderId], scopes = render && scopesByRender.get(render);
|
|
@@ -289,7 +289,7 @@ function _let(id, fn) {
|
|
|
289
289
|
return (scope, value) => (rendering ? scope.H === runId && (scope[valueAccessor] = value, fn?.(scope)) : (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn) && (schedule(), queueRender(scope, fn, id)), value);
|
|
290
290
|
}
|
|
291
291
|
function _let_change(id, fn) {
|
|
292
|
-
let valueAccessor = decodeAccessor(id), valueChangeAccessor =
|
|
292
|
+
let valueAccessor = decodeAccessor(id), valueChangeAccessor = decodeAccessor(id + 1), base = _let(id, fn);
|
|
293
293
|
return (scope, value, valueChange) => (rendering ? (scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope)) ? (scope[valueAccessor] = value, fn?.(scope)) : base(scope, value) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : base(scope, value), value);
|
|
294
294
|
}
|
|
295
295
|
function _const(valueAccessor, fn) {
|
|
@@ -299,7 +299,7 @@ function _const(valueAccessor, fn) {
|
|
|
299
299
|
}
|
|
300
300
|
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "L") {
|
|
301
301
|
return scopeIdAccessor !== "L" && (scopeIdAccessor = decodeAccessor(scopeIdAccessor)), (scope) => {
|
|
302
|
-
scope.H === runId ? id in scope ? --scope[id] || fn(scope) : scope[id] = defaultPending : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
302
|
+
scope.H === runId ? ~id in scope ? --scope[~id] || fn(scope) : scope[~id] = defaultPending : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
function _for_closure(ownerLoopNodeAccessor, fn) {
|
|
@@ -366,7 +366,7 @@ function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
|
|
|
366
366
|
let closureSignal = ((scope) => {
|
|
367
367
|
scope[closureSignal.b] = closureSignal.c, fn(scope), subscribeToScopeSet(getOwnerScope ? getOwnerScope(scope) : scope._, closureSignal.a, scope);
|
|
368
368
|
});
|
|
369
|
-
return closureSignal.a =
|
|
369
|
+
return closureSignal.a = valueAccessor, closureSignal.b = "C" + valueAccessor, resumeId && _resume(resumeId, closureSignal), closureSignal;
|
|
370
370
|
}
|
|
371
371
|
function _child_setup(setup) {
|
|
372
372
|
return setup._ = (scope, owner) => {
|
|
@@ -894,7 +894,7 @@ function normalizeAttrValue(value) {
|
|
|
894
894
|
}
|
|
895
895
|
function _lifecycle(scope, thisObj, index = 0) {
|
|
896
896
|
let accessor = "K" + index, instance = scope[accessor];
|
|
897
|
-
instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, thisObj.onMount?.(), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
|
|
897
|
+
instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, Object.assign(thisObj, thisObj.onMount?.()), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
|
|
898
898
|
}
|
|
899
899
|
function removeChildNodes(startNode, endNode) {
|
|
900
900
|
let stop = endNode.nextSibling;
|
|
@@ -1117,16 +1117,16 @@ function byFirstArg(name) {
|
|
|
1117
1117
|
//#region src/dom/queue.ts
|
|
1118
1118
|
function queueRender(scope, signal, signalKey, value, scopeKey = scope.L) {
|
|
1119
1119
|
let render;
|
|
1120
|
-
if (signalKey >= 0 && (render = scope[signalKey
|
|
1120
|
+
if (signalKey >= 0 && (render = scope[signalKey])) {
|
|
1121
1121
|
if (render.d = value, render.e === runId || catchEnabled && render.f) return;
|
|
1122
1122
|
render.e = runId;
|
|
1123
1123
|
} else render = {
|
|
1124
|
-
a: scopeKey *
|
|
1124
|
+
a: scopeKey * 1e6 + signalKey,
|
|
1125
1125
|
b: scope,
|
|
1126
1126
|
c: signal,
|
|
1127
1127
|
d: value,
|
|
1128
1128
|
e: runId
|
|
1129
|
-
}, signalKey >= 0 && (scope[signalKey
|
|
1129
|
+
}, signalKey >= 0 && (scope[signalKey] = render);
|
|
1130
1130
|
queuePendingRender(render);
|
|
1131
1131
|
}
|
|
1132
1132
|
function queuePendingRender(render) {
|
package/dist/dom.mjs
CHANGED
|
@@ -49,7 +49,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
|
|
|
49
49
|
};
|
|
50
50
|
}, _for_of = /* @__PURE__ */ loop(([all, by = bySecondArg], cb) => {
|
|
51
51
|
typeof by == "string" ? forOf(all, (item, i) => cb(item[by], [item, i])) : forOf(all, (item, i) => cb(by(item, i), [item, i]));
|
|
52
|
-
}), _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))), _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))), _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))), rendering, runId = 2, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingRenders = [],
|
|
52
|
+
}), _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))), _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))), _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))), rendering, runId = 2, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingRenders = [], runEffects = ((effects) => {
|
|
53
53
|
for (let i = 0; i < effects.length;) effects[i++](effects[i++]);
|
|
54
54
|
}), runRender = (render) => render.c(render.b, render.d), catchEnabled, classIdToBranch = /* @__PURE__ */ new Map(), scopesByRender = /* @__PURE__ */ new WeakMap(), getRenderScopes = ($global) => {
|
|
55
55
|
let render = self[$global.runtimeId]?.[$global.renderId], scopes = render && scopesByRender.get(render);
|
|
@@ -288,7 +288,7 @@ function _let(id, fn) {
|
|
|
288
288
|
return (scope, value) => (rendering ? scope.H === runId && (scope[valueAccessor] = value, fn?.(scope)) : (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn) && (schedule(), queueRender(scope, fn, id)), value);
|
|
289
289
|
}
|
|
290
290
|
function _let_change(id, fn) {
|
|
291
|
-
let valueAccessor = decodeAccessor(id), valueChangeAccessor =
|
|
291
|
+
let valueAccessor = decodeAccessor(id), valueChangeAccessor = decodeAccessor(id + 1), base = _let(id, fn);
|
|
292
292
|
return (scope, value, valueChange) => (rendering ? (scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope)) ? (scope[valueAccessor] = value, fn?.(scope)) : base(scope, value) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : base(scope, value), value);
|
|
293
293
|
}
|
|
294
294
|
function _const(valueAccessor, fn) {
|
|
@@ -298,7 +298,7 @@ function _const(valueAccessor, fn) {
|
|
|
298
298
|
}
|
|
299
299
|
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "L") {
|
|
300
300
|
return scopeIdAccessor !== "L" && (scopeIdAccessor = decodeAccessor(scopeIdAccessor)), (scope) => {
|
|
301
|
-
scope.H === runId ? id in scope ? --scope[id] || fn(scope) : scope[id] = defaultPending : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
301
|
+
scope.H === runId ? ~id in scope ? --scope[~id] || fn(scope) : scope[~id] = defaultPending : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
function _for_closure(ownerLoopNodeAccessor, fn) {
|
|
@@ -365,7 +365,7 @@ function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
|
|
|
365
365
|
let closureSignal = ((scope) => {
|
|
366
366
|
scope[closureSignal.b] = closureSignal.c, fn(scope), subscribeToScopeSet(getOwnerScope ? getOwnerScope(scope) : scope._, closureSignal.a, scope);
|
|
367
367
|
});
|
|
368
|
-
return closureSignal.a =
|
|
368
|
+
return closureSignal.a = valueAccessor, closureSignal.b = "C" + valueAccessor, resumeId && _resume(resumeId, closureSignal), closureSignal;
|
|
369
369
|
}
|
|
370
370
|
function _child_setup(setup) {
|
|
371
371
|
return setup._ = (scope, owner) => {
|
|
@@ -893,7 +893,7 @@ function normalizeAttrValue(value) {
|
|
|
893
893
|
}
|
|
894
894
|
function _lifecycle(scope, thisObj, index = 0) {
|
|
895
895
|
let accessor = "K" + index, instance = scope[accessor];
|
|
896
|
-
instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, thisObj.onMount?.(), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
|
|
896
|
+
instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, Object.assign(thisObj, thisObj.onMount?.()), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
|
|
897
897
|
}
|
|
898
898
|
function removeChildNodes(startNode, endNode) {
|
|
899
899
|
let stop = endNode.nextSibling;
|
|
@@ -1116,16 +1116,16 @@ function byFirstArg(name) {
|
|
|
1116
1116
|
//#region src/dom/queue.ts
|
|
1117
1117
|
function queueRender(scope, signal, signalKey, value, scopeKey = scope.L) {
|
|
1118
1118
|
let render;
|
|
1119
|
-
if (signalKey >= 0 && (render = scope[signalKey
|
|
1119
|
+
if (signalKey >= 0 && (render = scope[signalKey])) {
|
|
1120
1120
|
if (render.d = value, render.e === runId || catchEnabled && render.f) return;
|
|
1121
1121
|
render.e = runId;
|
|
1122
1122
|
} else render = {
|
|
1123
|
-
a: scopeKey *
|
|
1123
|
+
a: scopeKey * 1e6 + signalKey,
|
|
1124
1124
|
b: scope,
|
|
1125
1125
|
c: signal,
|
|
1126
1126
|
d: value,
|
|
1127
1127
|
e: runId
|
|
1128
|
-
}, signalKey >= 0 && (scope[signalKey
|
|
1128
|
+
}, signalKey >= 0 && (scope[signalKey] = render);
|
|
1129
1129
|
queuePendingRender(render);
|
|
1130
1130
|
}
|
|
1131
1131
|
function queuePendingRender(render) {
|
package/dist/html.js
CHANGED
|
@@ -643,7 +643,7 @@ function writeObject(state, val, parent, accessor) {
|
|
|
643
643
|
return wellKnownObject ? (state.buf.push(wellKnownObject), !0) : writeReferenceOr(state, writeUnknownObject, val, parent, accessor);
|
|
644
644
|
}
|
|
645
645
|
function writeUnknownObject(state, val, ref) {
|
|
646
|
-
switch (val
|
|
646
|
+
switch (Object.getPrototypeOf(val)?.constructor) {
|
|
647
647
|
case void 0: return writeNullObject(state, val, ref);
|
|
648
648
|
case Object: return writePlainObject(state, val, ref);
|
|
649
649
|
case Array: return writeArray(state, val, ref);
|
|
@@ -769,10 +769,14 @@ function writeWeakMap(state) {
|
|
|
769
769
|
}
|
|
770
770
|
function writeError(state, val, ref) {
|
|
771
771
|
let result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
|
|
772
|
-
|
|
772
|
+
if (val.cause !== void 0) {
|
|
773
|
+
let pos = state.buf.push(result + ",{cause:") - 1;
|
|
774
|
+
writeProp(state, val.cause, ref, "cause") ? state.buf.push("})") : state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
|
|
775
|
+
} else state.buf.push(result + ")");
|
|
776
|
+
return !0;
|
|
773
777
|
}
|
|
774
778
|
function writeAggregateError(state, val, ref) {
|
|
775
|
-
return state.buf.push("new AggregateError("), writeProp(state, val.errors, ref, "errors"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), !0;
|
|
779
|
+
return state.buf.push("new AggregateError("), writeProp(state, val.errors, ref, "errors") || state.buf.push("[]"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), !0;
|
|
776
780
|
}
|
|
777
781
|
function writeURL(state, val) {
|
|
778
782
|
return state.buf.push("new URL(" + quote(val.toString(), 0) + ")"), !0;
|
|
@@ -1744,9 +1748,6 @@ function nonVoidAttr(name, value) {
|
|
|
1744
1748
|
case "string": return " " + name + attrAssignment(value);
|
|
1745
1749
|
case "boolean": return " " + name;
|
|
1746
1750
|
case "number": return " " + name + "=" + value;
|
|
1747
|
-
case "object":
|
|
1748
|
-
if (value instanceof RegExp) return " " + name + attrAssignment(value.source);
|
|
1749
|
-
break;
|
|
1750
1751
|
}
|
|
1751
1752
|
return " " + name + attrAssignment(value + "");
|
|
1752
1753
|
}
|
package/dist/html.mjs
CHANGED
|
@@ -642,7 +642,7 @@ function writeObject(state, val, parent, accessor) {
|
|
|
642
642
|
return wellKnownObject ? (state.buf.push(wellKnownObject), !0) : writeReferenceOr(state, writeUnknownObject, val, parent, accessor);
|
|
643
643
|
}
|
|
644
644
|
function writeUnknownObject(state, val, ref) {
|
|
645
|
-
switch (val
|
|
645
|
+
switch (Object.getPrototypeOf(val)?.constructor) {
|
|
646
646
|
case void 0: return writeNullObject(state, val, ref);
|
|
647
647
|
case Object: return writePlainObject(state, val, ref);
|
|
648
648
|
case Array: return writeArray(state, val, ref);
|
|
@@ -768,10 +768,14 @@ function writeWeakMap(state) {
|
|
|
768
768
|
}
|
|
769
769
|
function writeError(state, val, ref) {
|
|
770
770
|
let result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
|
|
771
|
-
|
|
771
|
+
if (val.cause !== void 0) {
|
|
772
|
+
let pos = state.buf.push(result + ",{cause:") - 1;
|
|
773
|
+
writeProp(state, val.cause, ref, "cause") ? state.buf.push("})") : state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
|
|
774
|
+
} else state.buf.push(result + ")");
|
|
775
|
+
return !0;
|
|
772
776
|
}
|
|
773
777
|
function writeAggregateError(state, val, ref) {
|
|
774
|
-
return state.buf.push("new AggregateError("), writeProp(state, val.errors, ref, "errors"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), !0;
|
|
778
|
+
return state.buf.push("new AggregateError("), writeProp(state, val.errors, ref, "errors") || state.buf.push("[]"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), !0;
|
|
775
779
|
}
|
|
776
780
|
function writeURL(state, val) {
|
|
777
781
|
return state.buf.push("new URL(" + quote(val.toString(), 0) + ")"), !0;
|
|
@@ -1743,9 +1747,6 @@ function nonVoidAttr(name, value) {
|
|
|
1743
1747
|
case "string": return " " + name + attrAssignment(value);
|
|
1744
1748
|
case "boolean": return " " + name;
|
|
1745
1749
|
case "number": return " " + name + "=" + value;
|
|
1746
|
-
case "object":
|
|
1747
|
-
if (value instanceof RegExp) return " " + name + attrAssignment(value.source);
|
|
1748
|
-
break;
|
|
1749
1750
|
}
|
|
1750
1751
|
return " " + name + attrAssignment(value + "");
|
|
1751
1752
|
}
|
package/dist/translator/index.js
CHANGED
|
@@ -48,6 +48,15 @@ function assertNoSpreadAttrs(tag) {
|
|
|
48
48
|
throw attr.buildCodeFrameError(`The [\`<${tagName}>\`](https://markojs.com/docs/reference/core-tag#${tagName}) tag does not support \`...spread\` attributes.`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
function assertNoTagVarMutation(tag) {
|
|
52
|
+
const tagVar = tag.node.var;
|
|
53
|
+
if (tagVar?.type === "Identifier") {
|
|
54
|
+
const constantViolations = tag.scope.getBinding(tagVar.name)?.constantViolations;
|
|
55
|
+
if (constantViolations?.length) {
|
|
56
|
+
for (const assignment of constantViolations) if (assignment.type !== "MarkoTag") throw assignment.buildCodeFrameError(`${tagVar.name} is readonly and cannot be mutated.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
51
60
|
function assertNoBodyContent(tag) {
|
|
52
61
|
if (tag.node.body.body.length) {
|
|
53
62
|
const tagName = tag.get("name");
|
|
@@ -1919,9 +1928,6 @@ function nonVoidAttr(name, value) {
|
|
|
1919
1928
|
case "string": return " " + name + attrAssignment(value);
|
|
1920
1929
|
case "boolean": return " " + name;
|
|
1921
1930
|
case "number": return " " + name + "=" + value;
|
|
1922
|
-
case "object":
|
|
1923
|
-
if (value instanceof RegExp) return " " + name + attrAssignment(value.source);
|
|
1924
|
-
break;
|
|
1925
1931
|
}
|
|
1926
1932
|
return " " + name + attrAssignment(value + "");
|
|
1927
1933
|
}
|
|
@@ -2821,7 +2827,7 @@ function setSectionSerializedValue(section, prop, expression) {
|
|
|
2821
2827
|
}
|
|
2822
2828
|
function setBindingSerializedValue(section, binding, expression, prefix) {
|
|
2823
2829
|
const reason = getSerializeReason(section, binding, prefix);
|
|
2824
|
-
if (reason) getSerializedAccessors(section).set(
|
|
2830
|
+
if (reason) getSerializedAccessors(section).set(prefix === void 0 ? getScopeAccessor(binding) : getPrefixedScopeAccessor(binding, prefix), {
|
|
2825
2831
|
expression,
|
|
2826
2832
|
reason
|
|
2827
2833
|
});
|
|
@@ -2905,7 +2911,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
2905
2911
|
const render = getSignalFn(signal);
|
|
2906
2912
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
|
2907
2913
|
if (closureSignalBuilder && !isDynamicClosure(section, closure)) return closureSignalBuilder(closure, render);
|
|
2908
|
-
return callRuntime("_closure_get", getScopeAccessorLiteral(closure, true), render, isImmediateOwner(section, closure) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), some(closure.closureSections, underTryPlaceholder) ? _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "pending")) : void 0);
|
|
2914
|
+
return callRuntime("_closure_get", isOptimize() ? _marko_compiler.types.numericLiteral(getClosureAccessorId(closure)) : getScopeAccessorLiteral(closure, true), render, isImmediateOwner(section, closure) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), some(closure.closureSections, underTryPlaceholder) ? _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "pending")) : void 0);
|
|
2909
2915
|
};
|
|
2910
2916
|
}
|
|
2911
2917
|
return signal;
|
|
@@ -5243,7 +5249,11 @@ function preAnalyze$1(tag) {
|
|
|
5243
5249
|
for (const child of tag.node.body.body) if (child.type === "MarkoText" || child.type === "MarkoPlaceholder" && child.escape) parts.push(child.value);
|
|
5244
5250
|
else throw tag.hub.file.hub.buildError(child, "Unexpected content in textarea, only text and placeholders are supported.", SyntaxError);
|
|
5245
5251
|
const textValue = normalizeStringExpression(parts);
|
|
5246
|
-
if (textValue)
|
|
5252
|
+
if (textValue) {
|
|
5253
|
+
const valueAttr = tag.node.attributes.find((attr) => _marko_compiler.types.isMarkoAttribute(attr) && attr.name === "value");
|
|
5254
|
+
if (valueAttr) throw tag.hub.file.hub.buildError(valueAttr, "A textarea cannot have both a value attribute and body content.", SyntaxError);
|
|
5255
|
+
tag.node.attributes.push(_marko_compiler.types.markoAttribute("value", textValue));
|
|
5256
|
+
}
|
|
5247
5257
|
tag.node.body.body = [];
|
|
5248
5258
|
}
|
|
5249
5259
|
}
|
|
@@ -6292,7 +6302,8 @@ function createBinding(name, type, refSection, upstreamAlias, property, excludeP
|
|
|
6292
6302
|
nullable: !sameSection || excludeProperties === void 0,
|
|
6293
6303
|
pruned: void 0,
|
|
6294
6304
|
exposed: false,
|
|
6295
|
-
forcePersist: false
|
|
6305
|
+
forcePersist: false,
|
|
6306
|
+
reserveSize: 0
|
|
6296
6307
|
};
|
|
6297
6308
|
if (property) {
|
|
6298
6309
|
if (declared) upstreamAlias.nullable = false;
|
|
@@ -6436,6 +6447,7 @@ function trackAssignment(assignment, binding) {
|
|
|
6436
6447
|
fnExtra.section = idExtra.section = section;
|
|
6437
6448
|
}
|
|
6438
6449
|
if (binding.upstreamAlias && binding.property !== void 0) {
|
|
6450
|
+
if (binding.upstreamAlias === binding.section.params) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag parameter and cannot be assigned to.`);
|
|
6439
6451
|
const changePropName = binding.property + "Change";
|
|
6440
6452
|
const changeBinding = binding.upstreamAlias.propertyAliases.get(changePropName) || createBinding(generateUid(changePropName), binding.type, binding.section, binding.upstreamAlias, changePropName, void 0, id.node.loc, true);
|
|
6441
6453
|
idExtra.assignmentTo = changeBinding;
|
|
@@ -6758,22 +6770,30 @@ function finalizeReferences() {
|
|
|
6758
6770
|
});
|
|
6759
6771
|
}
|
|
6760
6772
|
let intersectionIndex = 0;
|
|
6761
|
-
let
|
|
6773
|
+
let nextId = 0;
|
|
6762
6774
|
let intersection;
|
|
6763
|
-
forEach(filter(bindings, isOwnedBinding), (binding
|
|
6764
|
-
binding.id =
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6775
|
+
forEach(filter(bindings, isOwnedBinding), (binding) => {
|
|
6776
|
+
binding.id = nextId++;
|
|
6777
|
+
nextId += binding.reserveSize;
|
|
6778
|
+
while (intersectionIndex < intersections.length && (intersection = intersections[intersectionIndex]).filter(isOwnedBinding).at(-1) === binding) {
|
|
6779
|
+
intersectionIndex++;
|
|
6780
|
+
intersectionMeta.set(intersection, {
|
|
6781
|
+
id: nextId++,
|
|
6782
|
+
scopeOffset: getMaxOwnSourceOffset(intersection, section)
|
|
6783
|
+
});
|
|
6784
|
+
}
|
|
6769
6785
|
});
|
|
6770
6786
|
while (intersectionIndex < intersections.length) {
|
|
6771
6787
|
intersection = intersections[intersectionIndex];
|
|
6788
|
+
intersectionIndex++;
|
|
6772
6789
|
intersectionMeta.set(intersection, {
|
|
6773
|
-
id:
|
|
6790
|
+
id: nextId++,
|
|
6774
6791
|
scopeOffset: getMaxOwnSourceOffset(intersection, section)
|
|
6775
6792
|
});
|
|
6776
6793
|
}
|
|
6794
|
+
forEach(filter(bindings, isOwnedBinding), (binding) => {
|
|
6795
|
+
if (binding.closureSections) closureAccessorIds.set(binding, nextId++);
|
|
6796
|
+
});
|
|
6777
6797
|
});
|
|
6778
6798
|
const programSection = (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
6779
6799
|
if (programSection.returnValueExpr) programSection.returnSerializeReason = getSerializeSourcesForExpr(programSection.returnValueExpr);
|
|
@@ -6793,6 +6813,7 @@ function getMaxOwnSourceOffset(intersection, section) {
|
|
|
6793
6813
|
return scopeOffset;
|
|
6794
6814
|
}
|
|
6795
6815
|
const intersectionMeta = /* @__PURE__ */ new WeakMap();
|
|
6816
|
+
const closureAccessorIds = /* @__PURE__ */ new WeakMap();
|
|
6796
6817
|
const collapsedIntersectionSource = /* @__PURE__ */ new WeakMap();
|
|
6797
6818
|
function getCollapsibleIntersectionSource(intersection, section) {
|
|
6798
6819
|
let sources;
|
|
@@ -7009,6 +7030,20 @@ function getScopeAccessor(binding, encoded, includeId) {
|
|
|
7009
7030
|
else if (includeId || canonicalBinding.type === 0) return `${canonicalBinding.name}/${canonicalBinding.id}`;
|
|
7010
7031
|
return canonicalBinding.scopeAccessor ?? canonicalBinding.name;
|
|
7011
7032
|
}
|
|
7033
|
+
function getPrefixedScopeAccessor(binding, prefix) {
|
|
7034
|
+
const canonicalBinding = getCanonicalBinding(binding);
|
|
7035
|
+
if (isOptimize()) switch (prefix) {
|
|
7036
|
+
case getAccessorPrefix().TagVariableChange: return decodeAccessor(canonicalBinding.id + 1);
|
|
7037
|
+
case getAccessorPrefix().ClosureScopes: return decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
7038
|
+
case getAccessorPrefix().ClosureSignalIndex: return prefix + decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
7039
|
+
}
|
|
7040
|
+
return prefix + getScopeAccessor(binding);
|
|
7041
|
+
}
|
|
7042
|
+
function getClosureAccessorId(binding) {
|
|
7043
|
+
const id = closureAccessorIds.get(getCanonicalBinding(binding));
|
|
7044
|
+
if (id === void 0) throw new Error(`No closure accessor id was reserved for "${binding.name}".`);
|
|
7045
|
+
return id;
|
|
7046
|
+
}
|
|
7012
7047
|
function getDebugScopeAccess(binding) {
|
|
7013
7048
|
let root = binding;
|
|
7014
7049
|
let access = "";
|
|
@@ -7540,12 +7575,7 @@ var const_default = {
|
|
|
7540
7575
|
if (upstreamAlias) dropNodes(valueAttr.value);
|
|
7541
7576
|
const binding = trackVarReferences(tag, 5, upstreamAlias);
|
|
7542
7577
|
if (binding) {
|
|
7543
|
-
|
|
7544
|
-
const constantViolations = tag.scope.getBinding(node.var.name)?.constantViolations;
|
|
7545
|
-
if (constantViolations?.length) {
|
|
7546
|
-
for (const assignment of constantViolations) if (assignment.type !== "MarkoTag") throw assignment.buildCodeFrameError(`${node.var.name} is readonly and cannot be mutated.`);
|
|
7547
|
-
}
|
|
7548
|
-
}
|
|
7578
|
+
assertNoTagVarMutation(tag);
|
|
7549
7579
|
if (!valueExtra.nullable) binding.nullable = false;
|
|
7550
7580
|
if (!upstreamAlias) {
|
|
7551
7581
|
setBindingDownstream(binding, valueExtra);
|
|
@@ -7617,6 +7647,7 @@ var define_default = {
|
|
|
7617
7647
|
dropNodes(getAllTagReferenceNodes(tag.node));
|
|
7618
7648
|
return;
|
|
7619
7649
|
}
|
|
7650
|
+
assertNoTagVarMutation(tag);
|
|
7620
7651
|
const paramsBinding = trackParamsReferences(tagBody, 3);
|
|
7621
7652
|
setTagDownstream(tag, varBinding);
|
|
7622
7653
|
if (bodySection) {
|
|
@@ -7834,7 +7865,10 @@ var id_default = {
|
|
|
7834
7865
|
if (!_marko_compiler.types.isIdentifier(node.var)) throw tag.get("var").buildCodeFrameError("The [`<id>` tag](https://markojs.com/docs/reference/core-tag#id) cannot be destructured.");
|
|
7835
7866
|
if (tag.node.attributes.length > 1 || tag.node.attributes.length === 1 && (!_marko_compiler.types.isMarkoAttribute(valueAttr) || !valueAttr.default && valueAttr.name !== "value")) throw tag.get("name").buildCodeFrameError("The [`<id>` tag](https://markojs.com/docs/reference/core-tag#id) only supports the [`value=` attribute](https://markojs.com/docs/reference/language#shorthand-value).");
|
|
7836
7867
|
const binding = trackVarReferences(tag, 5);
|
|
7837
|
-
if (binding)
|
|
7868
|
+
if (binding) {
|
|
7869
|
+
assertNoTagVarMutation(tag);
|
|
7870
|
+
setBindingDownstream(binding, !!valueAttr && evaluate(valueAttr.value));
|
|
7871
|
+
}
|
|
7838
7872
|
addSetupExpr(getOrCreateSection(tag), valueAttr?.value);
|
|
7839
7873
|
},
|
|
7840
7874
|
translate: { exit(tag) {
|
|
@@ -7888,9 +7922,13 @@ var let_default = {
|
|
|
7888
7922
|
const tagVar = node.var;
|
|
7889
7923
|
let valueAttr;
|
|
7890
7924
|
let valueChangeAttr;
|
|
7891
|
-
for (const attr of node.attributes) if (_marko_compiler.types.isMarkoAttribute(attr)) if (attr.name === "value")
|
|
7892
|
-
|
|
7893
|
-
|
|
7925
|
+
for (const attr of node.attributes) if (_marko_compiler.types.isMarkoAttribute(attr)) if (attr.name === "value") {
|
|
7926
|
+
if (valueAttr) throw tag.hub.buildError(attr, "Invalid duplicate value attribute.");
|
|
7927
|
+
valueAttr = attr;
|
|
7928
|
+
} else if (attr.name === "valueChange") {
|
|
7929
|
+
if (valueChangeAttr) throw tag.hub.buildError(attr, "Invalid duplicate valueChange attribute.");
|
|
7930
|
+
valueChangeAttr = attr;
|
|
7931
|
+
} else {
|
|
7894
7932
|
const start = attr.loc?.start;
|
|
7895
7933
|
const end = attr.loc?.end;
|
|
7896
7934
|
const msg = "The [`<let>` tag](https://markojs.com/docs/reference/core-tag#let) only supports the [`value=` attribute](https://markojs.com/docs/reference/language#shorthand-value) and its change handler.";
|
|
@@ -7911,6 +7949,7 @@ var let_default = {
|
|
|
7911
7949
|
const binding = trackVarReferences(tag, 1);
|
|
7912
7950
|
const tagExtra = mergeReferences(tagSection, tag.node, [valueAttr?.value, valueChangeAttr?.value]);
|
|
7913
7951
|
if (valueChangeAttr) {
|
|
7952
|
+
binding.reserveSize = 1;
|
|
7914
7953
|
setBindingDownstream(binding, tagExtra);
|
|
7915
7954
|
if (binding.assignmentSections) addSerializeReason(tagSection, true, binding, getAccessorPrefix().TagVariableChange);
|
|
7916
7955
|
} else setBindingDownstream(binding, false);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { types as t } from "@marko/compiler";
|
|
2
2
|
export declare function assertNoSpreadAttrs(tag: t.NodePath<t.MarkoTag>): void;
|
|
3
|
+
export declare function assertNoTagVarMutation(tag: t.NodePath<t.MarkoTag>): void;
|
|
3
4
|
export declare function assertNoBodyContent(tag: t.NodePath<t.MarkoTag>): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { types as t } from "@marko/compiler";
|
|
2
|
+
import type { AccessorPrefix } from "../../common/accessor.debug";
|
|
2
3
|
import { type Many, type Opt, Sorted } from "./optional";
|
|
3
4
|
import { type Section } from "./sections";
|
|
4
5
|
import { type SerializeReason } from "./serialize-reasons";
|
|
@@ -50,6 +51,7 @@ export interface Binding {
|
|
|
50
51
|
pruned: boolean | undefined;
|
|
51
52
|
exposed: boolean;
|
|
52
53
|
forcePersist: boolean;
|
|
54
|
+
reserveSize: number;
|
|
53
55
|
}
|
|
54
56
|
export interface InputBinding extends Binding {
|
|
55
57
|
type: BindingType.input;
|
|
@@ -142,6 +144,8 @@ export declare function getCanonicalBinding(binding: Binding): Binding;
|
|
|
142
144
|
export declare function getAllTagReferenceNodes(tag: t.MarkoTag, referenceNodes?: t.Node[]): t.Node[];
|
|
143
145
|
export declare function getScopeAccessorLiteral(binding: Binding, encoded?: boolean, includeId?: boolean): t.NumericLiteral | t.StringLiteral;
|
|
144
146
|
export declare function getScopeAccessor(binding: Binding, encoded?: boolean, includeId?: boolean): string;
|
|
147
|
+
export declare function getPrefixedScopeAccessor(binding: Binding, prefix: AccessorPrefix): string;
|
|
148
|
+
export declare function getClosureAccessorId(binding: Binding): number;
|
|
145
149
|
export declare function getDebugScopeAccess(binding: Binding): {
|
|
146
150
|
root: Binding;
|
|
147
151
|
access: string;
|
package/package.json
CHANGED
package/tags/lifecycle.d.marko
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/** File for types only, not actual implementation **/
|
|
2
2
|
|
|
3
|
-
export type Input<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export type Input<
|
|
4
|
+
T extends object,
|
|
5
|
+
R extends object = {},
|
|
6
|
+
> = T & ThisType<T & R> & {
|
|
7
|
+
onMount?: () => R | void;
|
|
8
|
+
onUpdate?: () => void;
|
|
9
|
+
onDestroy?: () => void;
|
|
7
10
|
};
|