marko 6.0.12 → 6.0.13
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/translator/index.js
CHANGED
@@ -3203,7 +3203,9 @@ function getSignalFn(signal) {
|
|
3203
3203
|
}
|
3204
3204
|
forEach(signal.intersection, (intersection) => {
|
3205
3205
|
signal.render.push(
|
3206
|
-
import_compiler20.types.expressionStatement(
|
3206
|
+
import_compiler20.types.expressionStatement(
|
3207
|
+
import_compiler20.types.callExpression(intersection.identifier, [scopeIdentifier])
|
3208
|
+
)
|
3207
3209
|
);
|
3208
3210
|
});
|
3209
3211
|
if (isValue && binding.sources) {
|
@@ -3310,10 +3312,7 @@ function subscribe(provider, subscriber) {
|
|
3310
3312
|
return;
|
3311
3313
|
}
|
3312
3314
|
const providerSignal = getSignal(subscriber.section, provider);
|
3313
|
-
providerSignal.intersection = push(
|
3314
|
-
providerSignal.intersection,
|
3315
|
-
subscriber.identifier
|
3316
|
-
);
|
3315
|
+
providerSignal.intersection = push(providerSignal.intersection, subscriber);
|
3317
3316
|
}
|
3318
3317
|
function generateSignalName(referencedBindings) {
|
3319
3318
|
let name2;
|
@@ -3436,56 +3435,20 @@ function getRegisterUID(section, name2) {
|
|
3436
3435
|
return id;
|
3437
3436
|
}
|
3438
3437
|
function writeSignals(section) {
|
3439
|
-
|
3440
|
-
|
3441
|
-
|
3442
|
-
|
3443
|
-
|
3444
|
-
|
3445
|
-
|
3446
|
-
|
3447
|
-
while (currentSection && currentSection !== hoistedBinding.section) {
|
3448
|
-
const parentSection = currentSection.parent;
|
3449
|
-
if (parentSection) {
|
3450
|
-
accessors.push(getSectionInstancesAccessorLiteral(currentSection));
|
3451
|
-
}
|
3452
|
-
currentSection = parentSection;
|
3453
|
-
}
|
3454
|
-
const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
|
3455
|
-
(0, import_babel_utils14.getProgram)().node.body.push(
|
3456
|
-
import_compiler20.types.variableDeclaration("const", [
|
3457
|
-
import_compiler20.types.variableDeclarator(
|
3458
|
-
hoistIdentifier,
|
3459
|
-
hoistedBinding.downstreamExpressions.size ? callRuntime(
|
3460
|
-
"register",
|
3461
|
-
import_compiler20.types.stringLiteral(
|
3462
|
-
getResumeRegisterId(
|
3463
|
-
hoistedBinding.section,
|
3464
|
-
hoistedBinding,
|
3465
|
-
"hoist"
|
3466
|
-
)
|
3467
|
-
),
|
3468
|
-
callRuntime("hoist", ...accessors)
|
3469
|
-
) : callRuntime("hoist", ...accessors)
|
3470
|
-
)
|
3471
|
-
])
|
3472
|
-
);
|
3473
|
-
if (hoistedBinding.downstreamExpressions.size) {
|
3474
|
-
addValue(
|
3475
|
-
hoistedBinding.section,
|
3476
|
-
void 0,
|
3477
|
-
initValue(hoistedBinding),
|
3478
|
-
import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
|
3479
|
-
);
|
3480
|
-
}
|
3481
|
-
}
|
3482
|
-
});
|
3483
|
-
const signals = [...getSignals(section).values()].sort(sortSignals);
|
3484
|
-
for (const signal of signals) {
|
3485
|
-
traverseReplace(signal, "render", replaceRenderNode);
|
3438
|
+
const seen = /* @__PURE__ */ new Set();
|
3439
|
+
writeHoists(section);
|
3440
|
+
for (const signal of getSignals(section).values()) {
|
3441
|
+
writeSignal(signal);
|
3442
|
+
}
|
3443
|
+
function writeSignal(signal) {
|
3444
|
+
if (seen.has(signal)) return;
|
3445
|
+
seen.add(signal);
|
3486
3446
|
for (const value2 of signal.values) {
|
3447
|
+
writeSignal(value2.signal);
|
3487
3448
|
traverseReplace(value2, "value", replaceRenderNode);
|
3488
3449
|
}
|
3450
|
+
forEach(signal.intersection, writeSignal);
|
3451
|
+
traverseReplace(signal, "render", replaceRenderNode);
|
3489
3452
|
let effectDeclarator;
|
3490
3453
|
if (signal.effect.length) {
|
3491
3454
|
traverseReplace(signal, "effect", replaceEffectNode);
|
@@ -3519,7 +3482,7 @@ function writeSignals(section) {
|
|
3519
3482
|
// This ignores writing out those signals in that case.
|
3520
3483
|
signal.referencedBindings && !Array.isArray(signal.referencedBindings) && signal.referencedBindings.upstreamAlias && !signal.referencedBindings.property && import_compiler20.types.isFunction(value) && import_compiler20.types.isBlockStatement(value.body) && !value.body.body.length
|
3521
3484
|
) {
|
3522
|
-
|
3485
|
+
return;
|
3523
3486
|
}
|
3524
3487
|
if (import_compiler20.types.isCallExpression(value)) {
|
3525
3488
|
replaceNullishAndEmptyFunctionsWith0(value.arguments);
|
@@ -3550,6 +3513,52 @@ function writeSignals(section) {
|
|
3550
3513
|
(0, import_babel_utils14.getProgram)().node.body.push(...signalStatements);
|
3551
3514
|
}
|
3552
3515
|
}
|
3516
|
+
function writeHoists(section) {
|
3517
|
+
forEach(section.hoisted, (binding) => {
|
3518
|
+
for (const hoistedBinding of binding.hoists.values()) {
|
3519
|
+
const accessors = [
|
3520
|
+
binding.type === 0 /* dom */ ? import_compiler20.types.stringLiteral(
|
3521
|
+
getAccessorPrefix().Getter + getScopeAccessor(binding)
|
3522
|
+
) : getScopeAccessorLiteral(binding)
|
3523
|
+
];
|
3524
|
+
let currentSection = section;
|
3525
|
+
while (currentSection && currentSection !== hoistedBinding.section) {
|
3526
|
+
const parentSection = currentSection.parent;
|
3527
|
+
if (parentSection) {
|
3528
|
+
accessors.push(getSectionInstancesAccessorLiteral(currentSection));
|
3529
|
+
}
|
3530
|
+
currentSection = parentSection;
|
3531
|
+
}
|
3532
|
+
const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
|
3533
|
+
(0, import_babel_utils14.getProgram)().node.body.push(
|
3534
|
+
import_compiler20.types.variableDeclaration("const", [
|
3535
|
+
import_compiler20.types.variableDeclarator(
|
3536
|
+
hoistIdentifier,
|
3537
|
+
hoistedBinding.downstreamExpressions.size ? callRuntime(
|
3538
|
+
"register",
|
3539
|
+
import_compiler20.types.stringLiteral(
|
3540
|
+
getResumeRegisterId(
|
3541
|
+
hoistedBinding.section,
|
3542
|
+
hoistedBinding,
|
3543
|
+
"hoist"
|
3544
|
+
)
|
3545
|
+
),
|
3546
|
+
callRuntime("hoist", ...accessors)
|
3547
|
+
) : callRuntime("hoist", ...accessors)
|
3548
|
+
)
|
3549
|
+
])
|
3550
|
+
);
|
3551
|
+
if (hoistedBinding.downstreamExpressions.size) {
|
3552
|
+
addValue(
|
3553
|
+
hoistedBinding.section,
|
3554
|
+
void 0,
|
3555
|
+
initValue(hoistedBinding),
|
3556
|
+
import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
|
3557
|
+
);
|
3558
|
+
}
|
3559
|
+
}
|
3560
|
+
});
|
3561
|
+
}
|
3553
3562
|
function writeRegisteredFns() {
|
3554
3563
|
const registeredFns = registeredFnsForProgram.get((0, import_babel_utils14.getProgram)().node);
|
3555
3564
|
const statements = [];
|
@@ -3608,27 +3617,6 @@ function toReturnedFunction(rawFn) {
|
|
3608
3617
|
const fn = simplifyFunction(rawFn);
|
3609
3618
|
return fn.type === "FunctionDeclaration" ? [fn, import_compiler20.types.returnStatement(fn.id)] : [import_compiler20.types.returnStatement(fn)];
|
3610
3619
|
}
|
3611
|
-
function sortSignals(a, b) {
|
3612
|
-
const aReferencedBindings = getReferencedBindings(a);
|
3613
|
-
const bReferencedBindings = getReferencedBindings(b);
|
3614
|
-
for (let i = Math.max(aReferencedBindings.length, bReferencedBindings.length) - 1; i >= 0; i--) {
|
3615
|
-
const diff = (bReferencedBindings[i] ?? -1) - (aReferencedBindings[i] ?? -1);
|
3616
|
-
if (diff !== 0) return diff;
|
3617
|
-
}
|
3618
|
-
return 0;
|
3619
|
-
}
|
3620
|
-
function getReferencedBindings({ referencedBindings: reserve }) {
|
3621
|
-
if (!reserve) {
|
3622
|
-
return [];
|
3623
|
-
} else if (Array.isArray(reserve)) {
|
3624
|
-
return reserve.map(getMappedId).sort();
|
3625
|
-
} else {
|
3626
|
-
return [getMappedId(reserve)];
|
3627
|
-
}
|
3628
|
-
}
|
3629
|
-
function getMappedId(reference) {
|
3630
|
-
return (reference.type === 0 /* dom */ ? 1 : 0) * 1e4 + reference.id;
|
3631
|
-
}
|
3632
3620
|
function addHTMLEffectCall(section, referencedBindings) {
|
3633
3621
|
addStatement("effect", section, referencedBindings, void 0, false);
|
3634
3622
|
}
|
@@ -4684,7 +4672,7 @@ function mergeReferences(section, target, nodes) {
|
|
4684
4672
|
return targetExtra;
|
4685
4673
|
}
|
4686
4674
|
function compareReferences(a, b) {
|
4687
|
-
return a === b ? 0 : Array.isArray(a) ? Array.isArray(b) ? compareIntersections(a, b) : -1 : Array.isArray(b) ? 1 : bindingUtil.compare(a, b);
|
4675
|
+
return a === b ? 0 : a ? b ? Array.isArray(a) ? Array.isArray(b) ? compareIntersections(a, b) : -1 : Array.isArray(b) ? 1 : bindingUtil.compare(a, b) : 1 : b ? -1 : 0;
|
4688
4676
|
}
|
4689
4677
|
function compareIntersections(a, b) {
|
4690
4678
|
const len = a.length;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { types as t } from "@marko/compiler";
|
2
|
-
import { type Many, type
|
2
|
+
import { type Many, type Opt, Sorted } from "./optional";
|
3
3
|
import { type Section } from "./sections";
|
4
4
|
declare const kIsInvoked: unique symbol;
|
5
5
|
export declare const kBranchSerializeReason: unique symbol;
|
@@ -74,7 +74,7 @@ export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody |
|
|
74
74
|
export declare function trackHoistedReference(referencePath: t.NodePath<t.Identifier>, binding: Binding): void;
|
75
75
|
export declare function setReferencesScope(path: t.NodePath<any>): void;
|
76
76
|
export declare function mergeReferences<T extends t.Node>(section: Section, target: T, nodes: (t.Node | undefined)[]): NonNullable<T["extra"]>;
|
77
|
-
export declare function compareReferences(a:
|
77
|
+
export declare function compareReferences(a: ReferencedBindings, b: ReferencedBindings): number;
|
78
78
|
export declare function finalizeReferences(): void;
|
79
79
|
export declare const intersectionMeta: WeakMap<Intersection, {
|
80
80
|
id: number;
|