marko 6.0.0-next.3.70 → 6.0.0-next.3.72
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/common/types.d.ts +5 -5
- package/dist/debug/dom.js +96 -91
- package/dist/debug/dom.mjs +96 -91
- package/dist/debug/html.js +4 -3
- package/dist/debug/html.mjs +4 -3
- package/dist/dom/control-flow.d.ts +1 -1
- package/dist/dom/queue.d.ts +1 -1
- package/dist/dom/resume.d.ts +1 -1
- package/dist/dom/schedule.d.ts +0 -1
- package/dist/dom.js +106 -99
- package/dist/dom.mjs +106 -99
- package/dist/html.js +4 -3
- package/dist/html.mjs +4 -3
- package/dist/translator/index.js +63 -72
- package/dist/translator/util/signals.d.ts +0 -1
- package/index.d.ts +22 -14
- package/package.json +1 -1
package/dist/translator/index.js
CHANGED
@@ -1849,7 +1849,7 @@ function flushInto(path5) {
|
|
1849
1849
|
const target = path5.isProgram() ? path5 : path5.get("body");
|
1850
1850
|
const expr = consumeHTML(target);
|
1851
1851
|
if (expr) {
|
1852
|
-
target.
|
1852
|
+
target.node.body.push(expr);
|
1853
1853
|
}
|
1854
1854
|
}
|
1855
1855
|
function getSectionMeta(section) {
|
@@ -2394,7 +2394,7 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
|
|
2394
2394
|
if (isOutputHTML()) {
|
2395
2395
|
return signal;
|
2396
2396
|
} else if (!referencedBindings) {
|
2397
|
-
signal.build = () => getSignalFn(signal
|
2397
|
+
signal.build = () => getSignalFn(signal);
|
2398
2398
|
} else if (Array.isArray(referencedBindings)) {
|
2399
2399
|
subscribe(referencedBindings, signal);
|
2400
2400
|
signal.build = () => {
|
@@ -2402,21 +2402,14 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
|
|
2402
2402
|
return callRuntime(
|
2403
2403
|
"intersection",
|
2404
2404
|
import_compiler18.types.numericLiteral(id),
|
2405
|
-
getSignalFn(
|
2406
|
-
signal,
|
2407
|
-
[scopeIdentifier],
|
2408
|
-
signal.renderReferencedBindings
|
2409
|
-
),
|
2405
|
+
getSignalFn(signal),
|
2410
2406
|
scopeOffset || referencedBindings.length > 2 ? import_compiler18.types.numericLiteral(referencedBindings.length - 1) : void 0,
|
2411
2407
|
scopeOffset && getScopeAccessorLiteral(scopeOffset)
|
2412
2408
|
);
|
2413
2409
|
};
|
2414
2410
|
} else if (referencedBindings.section !== section && bindingUtil.find(section.referencedClosures, referencedBindings)) {
|
2415
2411
|
signal.build = () => {
|
2416
|
-
const render = getSignalFn(signal
|
2417
|
-
scopeIdentifier,
|
2418
|
-
import_compiler18.types.identifier(referencedBindings.name)
|
2419
|
-
]);
|
2412
|
+
const render = getSignalFn(signal);
|
2420
2413
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
2421
2414
|
return !closureSignalBuilder || isDynamicClosure(section, referencedBindings) ? callRuntime(
|
2422
2415
|
"dynamicClosureRead",
|
@@ -2436,10 +2429,7 @@ function initValue(binding, runtimeHelper = "value") {
|
|
2436
2429
|
const section = binding.section;
|
2437
2430
|
const signal = getSignal(section, binding);
|
2438
2431
|
signal.build = () => {
|
2439
|
-
const fn = getSignalFn(signal
|
2440
|
-
scopeIdentifier,
|
2441
|
-
import_compiler18.types.identifier(binding.name)
|
2442
|
-
]);
|
2432
|
+
const fn = getSignalFn(signal);
|
2443
2433
|
const isParamBinding = !binding.upstreamAlias && (binding.type === 3 /* param */ || binding.type === 2 /* input */);
|
2444
2434
|
const isNakedAlias = binding.upstreamAlias && !binding.property;
|
2445
2435
|
const needsGuard = !isNakedAlias && (binding.downstreamExpressions.size || fn.body.body.length > 0);
|
@@ -2464,19 +2454,30 @@ function initValue(binding, runtimeHelper = "value") {
|
|
2464
2454
|
}
|
2465
2455
|
return signal;
|
2466
2456
|
}
|
2467
|
-
function getSignalFn(signal
|
2457
|
+
function getSignalFn(signal) {
|
2468
2458
|
const section = signal.section;
|
2469
2459
|
const binding = signal.referencedBindings;
|
2470
|
-
const
|
2471
|
-
const
|
2472
|
-
|
2460
|
+
const params = [scopeIdentifier];
|
2461
|
+
const isIntersection = Array.isArray(binding);
|
2462
|
+
const isBinding = binding && !isIntersection;
|
2463
|
+
const isValue = isBinding && binding.section === section;
|
2464
|
+
if (isBinding && (signal.renderReferencedBindings || binding.aliases.size || binding.propertyAliases.size)) {
|
2465
|
+
const valueParam = import_compiler18.types.identifier(binding.name);
|
2466
|
+
if (binding.loc) {
|
2467
|
+
valueParam.loc = binding.loc;
|
2468
|
+
valueParam.start = binding.loc.start.index;
|
2469
|
+
valueParam.end = binding.loc.end.index;
|
2470
|
+
}
|
2471
|
+
params.push(valueParam);
|
2472
|
+
}
|
2473
|
+
if (isValue) {
|
2473
2474
|
for (const alias of binding.aliases) {
|
2474
2475
|
const aliasSignal = getSignal(alias.section, alias);
|
2475
2476
|
signal.render.push(
|
2476
2477
|
import_compiler18.types.expressionStatement(
|
2477
2478
|
import_compiler18.types.callExpression(aliasSignal.identifier, [
|
2478
|
-
|
2479
|
-
|
2479
|
+
scopeIdentifier,
|
2480
|
+
import_compiler18.types.identifier(binding.name),
|
2480
2481
|
...getTranslatedExtraArgs(aliasSignal)
|
2481
2482
|
])
|
2482
2483
|
)
|
@@ -2487,8 +2488,12 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2487
2488
|
signal.render.push(
|
2488
2489
|
import_compiler18.types.expressionStatement(
|
2489
2490
|
import_compiler18.types.callExpression(aliasSignal.identifier, [
|
2490
|
-
|
2491
|
-
toMemberExpression(
|
2491
|
+
scopeIdentifier,
|
2492
|
+
toMemberExpression(
|
2493
|
+
import_compiler18.types.identifier(binding.name),
|
2494
|
+
key,
|
2495
|
+
binding.nullable
|
2496
|
+
),
|
2492
2497
|
...getTranslatedExtraArgs(aliasSignal)
|
2493
2498
|
])
|
2494
2499
|
)
|
@@ -2508,10 +2513,10 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2508
2513
|
}
|
2509
2514
|
forEach(signal.intersection, (intersection) => {
|
2510
2515
|
signal.render.push(
|
2511
|
-
import_compiler18.types.expressionStatement(import_compiler18.types.callExpression(intersection, [
|
2516
|
+
import_compiler18.types.expressionStatement(import_compiler18.types.callExpression(intersection, [scopeIdentifier]))
|
2512
2517
|
);
|
2513
2518
|
});
|
2514
|
-
if (
|
2519
|
+
if (isValue) {
|
2515
2520
|
let dynamicClosureArgs;
|
2516
2521
|
let dynamicClosureSignalIdentifier;
|
2517
2522
|
forEach(binding.closureSections, (closureSection) => {
|
@@ -2525,7 +2530,7 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2525
2530
|
signal.render.push(
|
2526
2531
|
import_compiler18.types.expressionStatement(
|
2527
2532
|
import_compiler18.types.callExpression(dynamicClosureSignalIdentifier, [
|
2528
|
-
|
2533
|
+
scopeIdentifier
|
2529
2534
|
])
|
2530
2535
|
)
|
2531
2536
|
);
|
@@ -2537,7 +2542,7 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2537
2542
|
signal.render.push(
|
2538
2543
|
import_compiler18.types.expressionStatement(
|
2539
2544
|
import_compiler18.types.callExpression(getSignal(closureSection, binding).identifier, [
|
2540
|
-
|
2545
|
+
scopeIdentifier
|
2541
2546
|
])
|
2542
2547
|
)
|
2543
2548
|
);
|
@@ -2559,16 +2564,16 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2559
2564
|
const effectIdentifier = import_compiler18.types.identifier(`${signal.identifier.name}_effect`);
|
2560
2565
|
signal.render.push(
|
2561
2566
|
import_compiler18.types.expressionStatement(
|
2562
|
-
import_compiler18.types.callExpression(effectIdentifier, [
|
2567
|
+
import_compiler18.types.callExpression(effectIdentifier, [scopeIdentifier])
|
2563
2568
|
)
|
2564
2569
|
);
|
2565
2570
|
}
|
2566
|
-
if (
|
2571
|
+
if (isIntersection && signal.renderReferencedBindings) {
|
2567
2572
|
signal.render.unshift(
|
2568
2573
|
import_compiler18.types.variableDeclaration("const", [
|
2569
2574
|
import_compiler18.types.variableDeclarator(
|
2570
|
-
createScopeReadPattern(section,
|
2571
|
-
|
2575
|
+
createScopeReadPattern(section, signal.renderReferencedBindings),
|
2576
|
+
scopeIdentifier
|
2572
2577
|
)
|
2573
2578
|
])
|
2574
2579
|
);
|
@@ -2736,8 +2741,7 @@ function writeSignals(section) {
|
|
2736
2741
|
currentSection = parentSection;
|
2737
2742
|
}
|
2738
2743
|
const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
|
2739
|
-
currentProgramPath.
|
2740
|
-
"body",
|
2744
|
+
currentProgramPath.node.body.push(
|
2741
2745
|
import_compiler18.types.variableDeclaration("const", [
|
2742
2746
|
import_compiler18.types.variableDeclarator(
|
2743
2747
|
hoistIdentifier,
|
@@ -2824,7 +2828,7 @@ function writeSignals(section) {
|
|
2824
2828
|
signalStatements.push(import_compiler18.types.variableDeclaration("const", [effectDeclarator]));
|
2825
2829
|
}
|
2826
2830
|
signalStatements.push(signalDeclaration);
|
2827
|
-
currentProgramPath.
|
2831
|
+
currentProgramPath.node.body.push(...signalStatements);
|
2828
2832
|
}
|
2829
2833
|
}
|
2830
2834
|
function writeRegisteredFns() {
|
@@ -2878,9 +2882,7 @@ function writeRegisteredFns() {
|
|
2878
2882
|
)
|
2879
2883
|
);
|
2880
2884
|
}
|
2881
|
-
|
2882
|
-
stmt.skip();
|
2883
|
-
}
|
2885
|
+
currentProgramPath.node.body.push(...statements);
|
2884
2886
|
}
|
2885
2887
|
}
|
2886
2888
|
function toReturnedFunction(rawFn) {
|
@@ -2914,6 +2916,7 @@ function addHTMLEffectCall(section, referencedBindings) {
|
|
2914
2916
|
function writeHTMLResumeStatements(path5) {
|
2915
2917
|
const section = getSectionForBody(path5);
|
2916
2918
|
if (!section) return;
|
2919
|
+
const body = path5.node.body;
|
2917
2920
|
const allSignals = Array.from(getSignals(section).values());
|
2918
2921
|
const scopeIdIdentifier = getScopeIdIdentifier(section);
|
2919
2922
|
const serializeOwnersUntilBinding = (binding) => serializeOwners(section, binding.section);
|
@@ -3027,8 +3030,7 @@ function writeHTMLResumeStatements(path5) {
|
|
3027
3030
|
for (let i = allSignals.length; i--; ) {
|
3028
3031
|
if (allSignals[i].effect.length) {
|
3029
3032
|
const signalRefs = allSignals[i].referencedBindings;
|
3030
|
-
|
3031
|
-
"body",
|
3033
|
+
body.push(
|
3032
3034
|
import_compiler18.types.expressionStatement(
|
3033
3035
|
callRuntime(
|
3034
3036
|
"writeEffect",
|
@@ -3099,8 +3101,7 @@ function writeHTMLResumeStatements(path5) {
|
|
3099
3101
|
writeScopeArgs.push(import_compiler18.types.objectExpression(debugVars));
|
3100
3102
|
}
|
3101
3103
|
}
|
3102
|
-
|
3103
|
-
"body",
|
3104
|
+
body.push(
|
3104
3105
|
import_compiler18.types.expressionStatement(
|
3105
3106
|
writeScopeBuilder ? writeScopeBuilder(callRuntime("writeScope", ...writeScopeArgs)) : callRuntime("writeScope", ...writeScopeArgs)
|
3106
3107
|
)
|
@@ -3108,25 +3109,24 @@ function writeHTMLResumeStatements(path5) {
|
|
3108
3109
|
}
|
3109
3110
|
const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.referencedClosures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
|
3110
3111
|
if (resumeClosestBranch2) {
|
3111
|
-
|
3112
|
-
"body",
|
3112
|
+
body.push(
|
3113
3113
|
import_compiler18.types.expressionStatement(
|
3114
3114
|
callRuntime("resumeClosestBranch", scopeIdIdentifier)
|
3115
3115
|
)
|
3116
3116
|
);
|
3117
3117
|
}
|
3118
3118
|
const additionalStatements = getHTMLSectionStatements(section);
|
3119
|
-
if (
|
3120
|
-
|
3119
|
+
if (body.length || additionalStatements.length) {
|
3120
|
+
body.unshift(
|
3121
3121
|
import_compiler18.types.variableDeclaration("const", [
|
3122
3122
|
import_compiler18.types.variableDeclarator(scopeIdIdentifier, callRuntime("nextScopeId"))
|
3123
3123
|
]),
|
3124
3124
|
...additionalStatements
|
3125
|
-
|
3125
|
+
);
|
3126
3126
|
}
|
3127
3127
|
const returnIdentifier = getSectionReturnValueIdentifier(section);
|
3128
3128
|
if (returnIdentifier !== void 0) {
|
3129
|
-
|
3129
|
+
body.push(import_compiler18.types.returnStatement(returnIdentifier));
|
3130
3130
|
}
|
3131
3131
|
}
|
3132
3132
|
function serializeOwners(from, to) {
|
@@ -3487,15 +3487,16 @@ var html_default = {
|
|
3487
3487
|
contentId ? import_compiler20.types.identifier(contentId) : contentFn
|
3488
3488
|
)
|
3489
3489
|
);
|
3490
|
-
|
3491
|
-
|
3492
|
-
contentId ? [
|
3490
|
+
if (contentId) {
|
3491
|
+
program.node.body.push(
|
3493
3492
|
import_compiler20.types.variableDeclaration("const", [
|
3494
3493
|
import_compiler20.types.variableDeclarator(import_compiler20.types.identifier(contentId), contentFn)
|
3495
3494
|
]),
|
3496
3495
|
exportDefault
|
3497
|
-
|
3498
|
-
|
3496
|
+
);
|
3497
|
+
} else {
|
3498
|
+
program.node.body.push(exportDefault);
|
3499
|
+
}
|
3499
3500
|
}
|
3500
3501
|
}
|
3501
3502
|
};
|
@@ -5206,8 +5207,7 @@ var native_tag_default = {
|
|
5206
5207
|
getterFnIdentifier = currentProgramPath.scope.generateUidIdentifier(
|
5207
5208
|
`get_${varName}`
|
5208
5209
|
);
|
5209
|
-
currentProgramPath.
|
5210
|
-
"body",
|
5210
|
+
currentProgramPath.node.body.push(
|
5211
5211
|
import_compiler30.types.variableDeclaration("const", [
|
5212
5212
|
import_compiler30.types.variableDeclarator(
|
5213
5213
|
getterFnIdentifier,
|
@@ -6524,8 +6524,7 @@ var html_comment_default = {
|
|
6524
6524
|
getterFnIdentifier = currentProgramPath.scope.generateUidIdentifier(
|
6525
6525
|
`get_${varName}`
|
6526
6526
|
);
|
6527
|
-
currentProgramPath.
|
6528
|
-
"body",
|
6527
|
+
currentProgramPath.node.body.push(
|
6529
6528
|
import_compiler36.types.variableDeclaration("const", [
|
6530
6529
|
import_compiler36.types.variableDeclarator(
|
6531
6530
|
getterFnIdentifier,
|
@@ -6743,8 +6742,7 @@ var html_script_default = {
|
|
6743
6742
|
getterFnIdentifier = currentProgramPath.scope.generateUidIdentifier(
|
6744
6743
|
`get_${varName}`
|
6745
6744
|
);
|
6746
|
-
currentProgramPath.
|
6747
|
-
"body",
|
6745
|
+
currentProgramPath.node.body.push(
|
6748
6746
|
import_compiler37.types.variableDeclaration("const", [
|
6749
6747
|
import_compiler37.types.variableDeclarator(
|
6750
6748
|
getterFnIdentifier,
|
@@ -7129,8 +7127,7 @@ var html_style_default = {
|
|
7129
7127
|
getterFnIdentifier = currentProgramPath.scope.generateUidIdentifier(
|
7130
7128
|
`get_${varName}`
|
7131
7129
|
);
|
7132
|
-
currentProgramPath.
|
7133
|
-
"body",
|
7130
|
+
currentProgramPath.node.body.push(
|
7134
7131
|
import_compiler38.types.variableDeclaration("const", [
|
7135
7132
|
import_compiler38.types.variableDeclarator(
|
7136
7133
|
getterFnIdentifier,
|
@@ -8306,21 +8303,18 @@ var style_default = {
|
|
8306
8303
|
});
|
8307
8304
|
if (importPath) {
|
8308
8305
|
if (!node.var) {
|
8309
|
-
currentProgramPath.
|
8310
|
-
"body",
|
8306
|
+
currentProgramPath.node.body.push(
|
8311
8307
|
import_compiler48.types.importDeclaration([], import_compiler48.types.stringLiteral(importPath))
|
8312
8308
|
);
|
8313
8309
|
} else if (import_compiler48.types.isIdentifier(node.var)) {
|
8314
|
-
currentProgramPath.
|
8315
|
-
"body",
|
8310
|
+
currentProgramPath.node.body.push(
|
8316
8311
|
import_compiler48.types.importDeclaration(
|
8317
8312
|
[import_compiler48.types.importDefaultSpecifier(node.var)],
|
8318
8313
|
import_compiler48.types.stringLiteral(importPath)
|
8319
8314
|
)
|
8320
8315
|
);
|
8321
8316
|
} else {
|
8322
|
-
currentProgramPath.
|
8323
|
-
"body",
|
8317
|
+
currentProgramPath.node.body.push(
|
8324
8318
|
import_compiler48.types.variableDeclaration("const", [
|
8325
8319
|
import_compiler48.types.variableDeclarator(
|
8326
8320
|
node.var,
|
@@ -8455,8 +8449,7 @@ var try_default = {
|
|
8455
8449
|
translatedAttrs.statements
|
8456
8450
|
);
|
8457
8451
|
}
|
8458
|
-
currentProgramPath.
|
8459
|
-
"body",
|
8452
|
+
currentProgramPath.node.body.push(
|
8460
8453
|
import_compiler49.types.expressionStatement(callRuntime("enableCatch"))
|
8461
8454
|
);
|
8462
8455
|
addValue(
|
@@ -9655,8 +9648,7 @@ var dynamic_tag_default = {
|
|
9655
9648
|
}
|
9656
9649
|
if (isClassAPI) {
|
9657
9650
|
if (isOutputHTML()) {
|
9658
|
-
currentProgramPath.
|
9659
|
-
"body",
|
9651
|
+
currentProgramPath.node.body.push(
|
9660
9652
|
import_compiler55.types.markoScriptlet(
|
9661
9653
|
[
|
9662
9654
|
import_compiler55.types.expressionStatement(
|
@@ -9673,8 +9665,7 @@ var dynamic_tag_default = {
|
|
9673
9665
|
)
|
9674
9666
|
);
|
9675
9667
|
} else {
|
9676
|
-
currentProgramPath.
|
9677
|
-
"body",
|
9668
|
+
currentProgramPath.node.body.push(
|
9678
9669
|
import_compiler55.types.expressionStatement(
|
9679
9670
|
callRuntime(
|
9680
9671
|
"register",
|
@@ -39,7 +39,6 @@ export declare const getHTMLSectionStatements: (section: Section) => t.Statement
|
|
39
39
|
export declare function getHoistFunctionIdentifier(hoistedBinding: Binding): t.Identifier;
|
40
40
|
export declare function getSignal(section: Section, referencedBindings: ReferencedBindings, name?: string): Signal;
|
41
41
|
export declare function initValue(binding: Binding, runtimeHelper?: "value" | "state"): Signal;
|
42
|
-
export declare function getSignalFn(signal: Signal, params: Array<t.Identifier | t.Pattern>, referencedBindings?: ReferencedBindings): t.ArrowFunctionExpression;
|
43
42
|
export declare function getDestructureSignal(bindingIdentifiersByName: Record<string, t.Identifier> | t.Identifier[], destructurePattern: t.LVal): {
|
44
43
|
readonly identifier: t.Identifier;
|
45
44
|
build(canCallOnlyWhenDirty?: boolean): t.ArrowFunctionExpression;
|
package/index.d.ts
CHANGED
@@ -33,6 +33,24 @@ declare global {
|
|
33
33
|
$global?: Global;
|
34
34
|
};
|
35
35
|
|
36
|
+
/** The result of calling `template.render`. */
|
37
|
+
export type RenderedTemplate = Promise<string> &
|
38
|
+
AsyncIterable<string> & {
|
39
|
+
toReadable(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
40
|
+
pipe(stream: {
|
41
|
+
write(chunk: string): unknown;
|
42
|
+
end(): unknown;
|
43
|
+
flush?(): void;
|
44
|
+
}): void;
|
45
|
+
toString(): string;
|
46
|
+
};
|
47
|
+
|
48
|
+
/** The result of calling `template.mount`. */
|
49
|
+
export type MountedTemplate<Input = unknown> = {
|
50
|
+
update(input: Marko.TemplateInput<Input>): void;
|
51
|
+
destroy(): void;
|
52
|
+
};
|
53
|
+
|
36
54
|
/** Body content created by a template. */
|
37
55
|
export interface Body<
|
38
56
|
in Params extends readonly any[] = [],
|
@@ -68,26 +86,16 @@ declare global {
|
|
68
86
|
|
69
87
|
/** @marko-overload-start */
|
70
88
|
/** Render the template to a string. */
|
71
|
-
abstract render(
|
72
|
-
|
73
|
-
|
74
|
-
pipe(stream: {
|
75
|
-
write(chunk: string): unknown;
|
76
|
-
end(): unknown;
|
77
|
-
flush?(): void;
|
78
|
-
}): void;
|
79
|
-
toString(): string;
|
80
|
-
};
|
89
|
+
abstract render(
|
90
|
+
input: Marko.TemplateInput<Input>,
|
91
|
+
): Marko.RenderedTemplate;
|
81
92
|
|
82
93
|
/** Render and attach the template to a DOM node. */
|
83
94
|
abstract mount(
|
84
95
|
input: Marko.TemplateInput<Input>,
|
85
96
|
reference: Node,
|
86
97
|
position?: "afterbegin" | "afterend" | "beforebegin" | "beforeend",
|
87
|
-
):
|
88
|
-
update(input: Marko.TemplateInput<Input>): void;
|
89
|
-
destroy(): void;
|
90
|
-
};
|
98
|
+
): Marko.MountedTemplate<typeof input>;
|
91
99
|
/** @marko-overload-end */
|
92
100
|
}
|
93
101
|
|