Skip to content

Commit

Permalink
refactor: binding renames, binding assignments, register functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Dec 10, 2024
1 parent 1c91300 commit 032afa1
Show file tree
Hide file tree
Showing 343 changed files with 4,677 additions and 4,129 deletions.
7 changes: 7 additions & 0 deletions .changeset/honest-trainers-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@marko/translator-tags": patch
"@marko/runtime-tags": patch
"@marko/babel-utils": patch
---

Refactor and improve logic around functon registration, binding renaming, and binding assignments.
50 changes: 25 additions & 25 deletions .sizes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@
{
"name": "*",
"total": {
"min": 17931,
"brotli": 6479
"min": 18009,
"brotli": 6502
}
},
{
"name": "counter",
"user": {
"min": 209,
"min": 189,
"brotli": 144
},
"runtime": {
"min": 3761,
"brotli": 1585
"min": 3763,
"brotli": 1586
},
"total": {
"min": 3970,
"brotli": 1729
"min": 3952,
"brotli": 1730
}
},
{
"name": "counter 💧",
"user": {
"min": 131,
"brotli": 116
"min": 111,
"brotli": 100
},
"runtime": {
"min": 3161,
"brotli": 1425
"min": 3168,
"brotli": 1438
},
"total": {
"min": 3292,
"brotli": 1541
"min": 3279,
"brotli": 1538
}
},
{
"name": "comments",
"user": {
"min": 1173,
"brotli": 549
"min": 1153,
"brotli": 544
},
"runtime": {
"min": 7768,
"brotli": 3150
"min": 7770,
"brotli": 3154
},
"total": {
"min": 8941,
"brotli": 3699
"min": 8923,
"brotli": 3698
}
},
{
"name": "comments 💧",
"user": {
"min": 974,
"brotli": 487
"min": 954,
"brotli": 477
},
"runtime": {
"min": 8775,
"brotli": 3566
"min": 8782,
"brotli": 3567
},
"total": {
"min": 9749,
"brotli": 4053
"min": 9736,
"brotli": 4044
}
}
]
Expand Down
17 changes: 5 additions & 12 deletions .sizes/comments.csr/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// size: 1173 (min) 549 (brotli)
// size: 1153 (min) 544 (brotli)
const _expr_comment_comments_id$ifBody = intersection(
2,
(_scope) => {
Expand Down Expand Up @@ -39,17 +39,10 @@ const _expr_comment_comments_id$ifBody = intersection(
() => _id$forBody,
),
_if$forBody = conditional(4),
_open$forBody_effect = effect("a1", (_scope) =>
on(
_scope[2],
"click",
((_scope) => {
const { 11: open } = _scope;
return function () {
_open$forBody(_scope, !open);
};
})(_scope),
),
_open$forBody_effect = effect("a1", (_scope, { 11: open }) =>
on(_scope[2], "click", function () {
_open$forBody(_scope, !open);
}),
),
_open$forBody = state(11, (_scope, open) => {
attr(_scope[0], "hidden", !open),
Expand Down
17 changes: 5 additions & 12 deletions .sizes/comments.ssr/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// size: 974 (min) 487 (brotli)
// size: 954 (min) 477 (brotli)
const _expr_comment_comments_id$ifBody = intersection(
2,
(_scope) => {
Expand Down Expand Up @@ -39,17 +39,10 @@ const _expr_comment_comments_id$ifBody = intersection(
() => _id$forBody,
),
_if$forBody = conditional(4),
_open$forBody_effect = effect("a1", (_scope) =>
on(
_scope[2],
"click",
((_scope) => {
const { 11: open } = _scope;
return function () {
_open$forBody(_scope, !open);
};
})(_scope),
),
_open$forBody_effect = effect("a1", (_scope, { 11: open }) =>
on(_scope[2], "click", function () {
_open$forBody(_scope, !open);
}),
),
_open$forBody = state(11, (_scope, open) => {
attr(_scope[0], "hidden", !open),
Expand Down
17 changes: 5 additions & 12 deletions .sizes/counter.csr/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
// size: 209 (min) 144 (brotli)
const _clickCount_effect = effect("a0", (_scope) =>
on(
_scope[0],
"click",
((_scope) => {
const { 2: clickCount } = _scope;
return function () {
_clickCount(_scope, clickCount + 1);
};
})(_scope),
),
// size: 189 (min) 144 (brotli)
const _clickCount_effect = effect("a0", (_scope, { 2: clickCount }) =>
on(_scope[0], "click", function () {
_clickCount(_scope, clickCount + 1);
}),
),
_clickCount = state(2, (_scope, clickCount) => {
data(_scope[1], clickCount), _clickCount_effect(_scope);
Expand Down
17 changes: 5 additions & 12 deletions .sizes/counter.ssr/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
// size: 131 (min) 116 (brotli)
const _clickCount_effect = effect("a0", (_scope) =>
on(
_scope[0],
"click",
((_scope) => {
const { 2: clickCount } = _scope;
return function () {
_clickCount(_scope, clickCount + 1);
};
})(_scope),
),
// size: 111 (min) 100 (brotli)
const _clickCount_effect = effect("a0", (_scope, { 2: clickCount }) =>
on(_scope[0], "click", function () {
_clickCount(_scope, clickCount + 1);
}),
),
_clickCount = state(2, (_scope, clickCount) => {
data(_scope[1], clickCount), _clickCount_effect(_scope);
Expand Down
20 changes: 14 additions & 6 deletions .sizes/dom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// size: 17931 (min) 6479 (brotli)
// size: 18009 (min) 6502 (brotli)
var empty = [],
rest = Symbol();
function attrTag(attrs2) {
Expand Down Expand Up @@ -193,7 +193,10 @@ var registeredValues = {},
} else
i === len || "string" != typeof resumes[i]
? delete this.z[this.o]
: registeredValues[resumes[i++]](scopeLookup[resumeData]);
: registeredValues[resumes[i++]](
scopeLookup[resumeData],
scopeLookup[resumeData],
);
}
} finally {
isResuming = !1;
Expand Down Expand Up @@ -489,7 +492,7 @@ function prepareEffects(fn) {
function runEffects(effects = pendingEffects) {
for (let i = 0; i < effects.length; i += 2) {
let scope = effects[i];
(0, effects[i + 1])(scope);
(0, effects[i + 1])(scope, scope);
}
}
function runSignals(signals) {
Expand Down Expand Up @@ -875,11 +878,13 @@ function styleAttr(element, value2) {
);
}
function data(node, value2) {
let normalizedValue = (function (value2) {
return value2 || 0 === value2 ? value2 + "" : "‍";
})(value2);
let normalizedValue = normalizeString(value2);
node.data !== normalizedValue && (node.data = normalizedValue);
}
function textContent(node, value2) {
let normalizedValue = normalizeString(value2);
node.textContent !== normalizedValue && (node.textContent = normalizedValue);
}
function attrs(scope, nodeAccessor, nextAttrs) {
let el = scope[nodeAccessor];
for (let { name: name } of el.attributes)
Expand Down Expand Up @@ -1035,6 +1040,9 @@ function props(scope, nodeIndex, index) {
function normalizeAttrValue(value2) {
if (value2 || 0 === value2) return !0 === value2 ? "" : value2 + "";
}
function normalizeString(value2) {
return value2 || 0 === value2 ? value2 + "" : "‍";
}
function lifecycle(scope, index, thisObj) {
let instance = scope[index];
instance
Expand Down
2 changes: 1 addition & 1 deletion .sizes/name-cache.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"vars":{"props":{"$empty":"e","$rest":"t","$attrTag":"n","$attrTags":"r","$attrTagIterator":"i","$forIn":"l","$forOf":"o","$forTo":"f","$isScheduled":"u","$port2":"a","$flushAndWaitFrame":"c","$triggerMacroTask":"s","$createScope":"d","$emptyScope":"h","$getEmptyScope":"g","$destroyScope":"p","$_destroyScope":"v","$onDestroy":"b","$removeAndDestroyScope":"m","$insertBefore":"y","$registeredValues":"k","$Render":"w","$isResuming":"C","$register":"A","$registerBoundSignal":"S","$init":"N","$registerSubscriber":"x","$nodeRef":"$","$MARK":"M","$CLEAN":"E","$DIRTY":"I","$state":"T","$value":"_","$accessorId":"O","$intersection":"B","$defaultGetOwnerScope":"V","$closure":"j","$dynamicClosure":"R","$childClosures":"q","$dynamicSubscribers":"D","$setTagVar":"P","$tagVarSignal":"W","$setTagVarChange":"L","$tagVarSignalChange":"z","$renderBodyClosures":"F","$tagIdsByGlobal":"U","$nextTagId":"G","$inChild":"J","$intersections":"X","$effect":"Z","$pendingSignals":"H","$pendingEffects":"K","$rendering":"Q","$queueEffect":"Y","$run":"ee","$prepareEffects":"te","$runEffects":"ne","$runSignals":"re","$resetAbortSignal":"ie","$getAbortSignal":"le","$stringifyClassObject":"oe","$NON_DIMENSIONAL":"fe","$stringifyStyleObject":"ue","$toDelimitedString":"ae","$isEventHandler":"ce","$getEventHandlerName":"se","$normalizeDynamicRenderer":"de","$elementHandlersByEvent":"he","$defaultDelegator":"ge","$on":"pe","$createDelegator":"ve","$handleDelegated":"be","$stripSpacesAndPunctuation":"me","$controllable_input_checked":"ye","$controllable_input_checked_effect":"ke","$controllable_input_checkedValue":"we","$controllable_input_checkedValue_effect":"Ce","$controllable_input_value":"Ae","$controllable_input_value_effect":"Se","$controllable_select_value":"Ne","$controllable_select_value_effect":"xe","$setSelectOptions":"$e","$controllable_detailsOrDialog_open":"Me","$controllable_detailsOrDialog_open_effect":"Ee","$inputType":"Ie","$setValueAndUpdateSelection":"Te","$setCheckboxValue":"_e","$delegateFormControl":"Oe","$formChangeHandlers":"Be","$syncControllable":"Ve","$onFormChange":"je","$onFormReset":"Re","$hasValueChanged":"qe","$hasCheckboxChanged":"De","$hasSelectChanged":"Pe","$hasFormElementChanged":"We","$normalizeStrProp":"Le","$normalizeBoolProp":"ze","$toValueProp":"Fe","$fallback":"Ue","$parser":"Ge","$parseHTML":"Je","$attr":"Xe","$setAttribute":"Ze","$classAttr":"He","$styleAttr":"Ke","$data":"Qe","$attrs":"Ye","$hasAttrAlias":"et","$partialAttrs":"tt","$attrsInternal":"nt","$attrsEvents":"rt","$html":"it","$props":"lt","$normalizeAttrValue":"ot","$lifecycle":"ft","$walker":"ut","$trimWalkString":"at","$walk":"ct","$walkInternal":"st","$createScopeWithRenderer":"dt","$createScopeWithTagNameOrRenderer":"ht","$initRenderer":"gt","$dynamicTagAttrs":"pt","$createRendererWithOwner":"vt","$createRenderer":"bt","$_clone":"mt","$conditional":"yt","$inConditionalScope":"kt","$conditionalOnlyChild":"wt","$setConditionalRendererOnlyChild":"Ct","$emptyMarkerMap":"At","$emptyMarkerArray":"St","$emptyMap":"Nt","$emptyArray":"xt","$loopOf":"$t","$loopIn":"Mt","$loopTo":"Et","$loop":"It","$inLoopScope":"Tt","$bySecondArg":"_t","$byFirstArg":"Ot","$isDifferentRenderer":"Bt","$classIdToScope":"Vt","$compat":"jt","$noop":"Rt","$createTemplate":"qt","$mount":"Dt","$parseHTMLOrSingleNode":"Wt","$marker":"Ft","$_clickCount_effect":"Qt","$_clickCount":"Yt","$_setup_":"zt","$_expr_comment_comments_id$ifBody":"ss","$_id$ifBody":"as","$_comment_comments$ifBody":"ts","$_ifBody":"ns","$_expr_input_path_i$forBody":"os","$_if$forBody":"cs","$_open$forBody_effect":"is","$_open$forBody":"ms","$_id$forBody":"ls","$_i$forBody":"us","$_comment_comments$forBody":"es","$_comment_text$forBody":"ds","$_comment$forBody":"rs","$_params_2$forBody":"bs","$_input_path$forBody":"ps","$_for":"hs","$_input_path_":"vs","$_input_comments_":"fs","$_input_$1":"js","$_input_":"ks","$_params__":"Ss","$noop2":"Pt"}}}
{"vars":{"props":{"$empty":"e","$rest":"t","$attrTag":"n","$attrTags":"r","$attrTagIterator":"i","$forIn":"l","$forOf":"o","$forTo":"f","$isScheduled":"u","$port2":"a","$flushAndWaitFrame":"c","$triggerMacroTask":"s","$createScope":"d","$emptyScope":"h","$getEmptyScope":"g","$destroyScope":"p","$_destroyScope":"v","$onDestroy":"b","$removeAndDestroyScope":"m","$insertBefore":"y","$registeredValues":"k","$Render":"w","$isResuming":"C","$register":"A","$registerBoundSignal":"S","$init":"N","$registerSubscriber":"x","$nodeRef":"$","$MARK":"M","$CLEAN":"E","$DIRTY":"I","$state":"T","$value":"_","$accessorId":"O","$intersection":"B","$defaultGetOwnerScope":"V","$closure":"j","$dynamicClosure":"R","$childClosures":"q","$dynamicSubscribers":"D","$setTagVar":"P","$tagVarSignal":"W","$setTagVarChange":"L","$tagVarSignalChange":"z","$renderBodyClosures":"F","$tagIdsByGlobal":"U","$nextTagId":"G","$inChild":"J","$intersections":"X","$effect":"Z","$pendingSignals":"H","$pendingEffects":"K","$rendering":"Q","$queueEffect":"Y","$run":"ee","$prepareEffects":"te","$runEffects":"ne","$runSignals":"re","$resetAbortSignal":"ie","$getAbortSignal":"le","$stringifyClassObject":"oe","$NON_DIMENSIONAL":"fe","$stringifyStyleObject":"ue","$toDelimitedString":"ae","$isEventHandler":"ce","$getEventHandlerName":"se","$normalizeDynamicRenderer":"de","$elementHandlersByEvent":"he","$defaultDelegator":"ge","$on":"pe","$createDelegator":"ve","$handleDelegated":"be","$stripSpacesAndPunctuation":"me","$controllable_input_checked":"ye","$controllable_input_checked_effect":"ke","$controllable_input_checkedValue":"we","$controllable_input_checkedValue_effect":"Ce","$controllable_input_value":"Ae","$controllable_input_value_effect":"Se","$controllable_select_value":"Ne","$controllable_select_value_effect":"xe","$setSelectOptions":"$e","$controllable_detailsOrDialog_open":"Me","$controllable_detailsOrDialog_open_effect":"Ee","$inputType":"Ie","$setValueAndUpdateSelection":"Te","$setCheckboxValue":"_e","$delegateFormControl":"Oe","$formChangeHandlers":"Be","$syncControllable":"Ve","$onFormChange":"je","$onFormReset":"Re","$hasValueChanged":"qe","$hasCheckboxChanged":"De","$hasSelectChanged":"Pe","$hasFormElementChanged":"We","$normalizeStrProp":"Le","$normalizeBoolProp":"ze","$toValueProp":"Fe","$fallback":"Ue","$parser":"Ge","$parseHTML":"Je","$attr":"Xe","$setAttribute":"Ze","$classAttr":"He","$styleAttr":"Ke","$data":"Qe","$attrs":"Ye","$hasAttrAlias":"et","$partialAttrs":"tt","$attrsInternal":"nt","$attrsEvents":"rt","$html":"it","$props":"lt","$normalizeAttrValue":"ot","$lifecycle":"ft","$walker":"ut","$trimWalkString":"at","$walk":"ct","$walkInternal":"st","$createScopeWithRenderer":"dt","$createScopeWithTagNameOrRenderer":"ht","$initRenderer":"gt","$dynamicTagAttrs":"pt","$createRendererWithOwner":"vt","$createRenderer":"bt","$_clone":"mt","$conditional":"yt","$inConditionalScope":"kt","$conditionalOnlyChild":"wt","$setConditionalRendererOnlyChild":"Ct","$emptyMarkerMap":"At","$emptyMarkerArray":"St","$emptyMap":"Nt","$emptyArray":"xt","$loopOf":"$t","$loopIn":"Mt","$loopTo":"Et","$loop":"It","$inLoopScope":"Tt","$bySecondArg":"_t","$byFirstArg":"Ot","$isDifferentRenderer":"Bt","$classIdToScope":"Vt","$compat":"jt","$noop":"Rt","$createTemplate":"qt","$mount":"Dt","$parseHTMLOrSingleNode":"Wt","$marker":"Ft","$_clickCount_effect":"Qt","$_clickCount":"Yt","$_setup_":"zt","$_expr_comment_comments_id$ifBody":"ss","$_id$ifBody":"as","$_comment_comments$ifBody":"ts","$_ifBody":"ns","$_expr_input_path_i$forBody":"os","$_if$forBody":"cs","$_open$forBody_effect":"is","$_open$forBody":"ms","$_id$forBody":"ls","$_i$forBody":"us","$_comment_comments$forBody":"es","$_comment_text$forBody":"ds","$_comment$forBody":"rs","$_params_2$forBody":"bs","$_input_path$forBody":"ps","$_for":"hs","$_input_path_":"vs","$_input_comments_":"fs","$_input_$1":"js","$_input_":"ks","$_params__":"Ss","$noop2":"Pt","$textContent":"Lt","$normalizeString":"Ut"}}}
5 changes: 3 additions & 2 deletions packages/babel-utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export interface TagDefinition {
migrators?: PluginDefinition<t.MarkoTag>[];
parseOptions?: {
text?: boolean;
openTagOnly?: boolean;
statement?: boolean;
controlFlow?: boolean;
openTagOnly?: boolean;
rawOpenTag?: boolean;
preserveWhitespace?: boolean;
};
Expand Down Expand Up @@ -136,7 +137,7 @@ export interface Tag {
controlFlow?: boolean;
ignoreAttributes?: boolean;
relaxRequireCommas?: boolean;
state?: "html" | "static-text" | "parsed-text" | "cdata";
text?: boolean;
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/runtime-tags/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export {
partialAttrs,
props,
styleAttr,
textContent,
} from "./dom/dom";
export { on } from "./dom/event";
export { run } from "./dom/queue";
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime-tags/src/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export function data(node: Text | Comment, value: unknown) {
}
}

export function textContent(node: ParentNode, value: unknown) {
const normalizedValue = normalizeString(value);
// TODO: benchmark if it is actually faster to check data first
if (node.textContent !== normalizedValue) {
node.textContent = normalizedValue;
}
}

export function attrs(
scope: Scope,
nodeAccessor: Accessor,
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-tags/src/dom/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function prepareEffects(fn: () => void): unknown[] {
export function runEffects(effects: unknown[] = pendingEffects) {
for (let i = 0; i < effects.length; i += PendingEffectOffset.Total) {
const scope = effects[i] as Scope;
const fn = effects[i + 1] as (scope: Scope) => void;
fn(scope);
const fn = effects[i + 1] as (a: Scope, b: Scope) => void;
fn(scope, scope);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-tags/src/dom/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class Render implements RenderData {
} else if (i === len || typeof resumes[i] !== "string") {
delete this.___renders[this.___renderId];
} else {
(registeredValues[resumes[i++] as string] as RegisteredFn)(
(registeredValues[resumes[i++] as string] as any)(
scopeLookup[resumeData],
scopeLookup[resumeData],
);
}
Expand Down
16 changes: 6 additions & 10 deletions packages/runtime-tags/src/html/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export class State {
public hasReorderRuntime = false;
public hasWrittenResume = false;
public trailerHTML = "";
public nonceAttr = "";
public serializer = new Serializer();
public writeReorders: Chunk[] | null = null;
public scopes = new Map<number, PartialScope>();
Expand All @@ -340,6 +341,9 @@ export class State {
},
) {
this.$global = $global;
if ($global.cspNonce) {
this.nonceAttr = " " + escapeAttrValue($global.cspNonce + "");
}
}

get runtimePrefix() {
Expand Down Expand Up @@ -545,10 +549,7 @@ export function prepareChunk(chunk: Chunk) {
const head = chunk.consume();
const { boundary, effects } = head;
const { state } = boundary;
const { $global, runtimePrefix, serializer } = state;
const nonceAttr = $global.cspNonce
? " nonce=" + escapeAttrValue($global.cspNonce + "")
: "";
const { $global, runtimePrefix, serializer, nonceAttr } = state;
let { html, scripts } = head;
let hasWalk = false;
head.effects = "";
Expand Down Expand Up @@ -704,12 +705,7 @@ export function flushChunk(head: Chunk, last: boolean) {
head.html = head.scripts = "";

if (scripts) {
result +=
($global.cspNonce
? "<script nonce=" + escapeAttrValue($global.cspNonce + "") + ">"
: "<script>") +
scripts +
"</script>";
result += "<script" + state.nonceAttr + ">" + scripts + "</script>";
}

if (__flush__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ const _expr_Text_x_y = /* @__PURE__ */_$.intersection(3, _scope => {
} = _scope;
_inputRenderBody_input(_scope, () => [x, y]);
}, () => _inputRenderBody_input);
const _onClick = _scope => {
const {
x,
y
} = _scope;
return function () {
_x(_scope, x + 1);
_y(_scope, y + 1);
};
};
const _expr_x_y_effect = _$.effect("packages/translator-interop/src/__tests__/fixtures/custom-tag-parameters-from-args/components/custom-tag.marko_0_x_y", _scope => _$.on(_scope["#button/0"], "click", _onClick(_scope)));
const _expr_x_y_effect = _$.effect("packages/translator-interop/src/__tests__/fixtures/custom-tag-parameters-from-args/components/custom-tag.marko_0_x_y", (_scope, {
x,
y
}) => _$.on(_scope["#button/0"], "click", function () {
_x(_scope, x + 1), x;
_y(_scope, y + 1), y;
}));
const _expr_x_y = /* @__PURE__ */_$.intersection(2, _scope => {
const {
x,
Expand Down
Loading

0 comments on commit 032afa1

Please sign in to comment.