marko 6.0.0-next.3.33 → 6.0.0-next.3.35
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
@@ -3114,7 +3114,9 @@ var program_default = {
|
|
3114
3114
|
currentProgramPath = program;
|
3115
3115
|
startSection(program);
|
3116
3116
|
trackParamsReferences(program, 2 /* input */);
|
3117
|
-
program.node.params[0]
|
3117
|
+
if (program.node.params[0]?.extra?.binding) {
|
3118
|
+
program.node.params[0].extra.binding.nullable = false;
|
3119
|
+
}
|
3118
3120
|
const { scope } = program;
|
3119
3121
|
(program.node.extra ??= {}).domExports = {
|
3120
3122
|
template: scope.generateUid("template_"),
|
@@ -3237,12 +3239,22 @@ function getExprRoot(path5) {
|
|
3237
3239
|
}
|
3238
3240
|
function getFnRoot(path5) {
|
3239
3241
|
let curPath = path5;
|
3242
|
+
let fnPath;
|
3240
3243
|
if (curPath.isProgram()) return;
|
3241
|
-
while (!
|
3242
|
-
if (
|
3244
|
+
while (!isMarko(curPath)) {
|
3245
|
+
if (isFunction(curPath)) {
|
3246
|
+
fnPath = curPath;
|
3247
|
+
} else {
|
3248
|
+
switch (curPath.type) {
|
3249
|
+
case "CallExpression":
|
3250
|
+
case "NewExpression":
|
3251
|
+
fnPath = void 0;
|
3252
|
+
break;
|
3253
|
+
}
|
3254
|
+
}
|
3243
3255
|
curPath = curPath.parentPath;
|
3244
3256
|
}
|
3245
|
-
return
|
3257
|
+
return fnPath;
|
3246
3258
|
}
|
3247
3259
|
function isMarko(path5) {
|
3248
3260
|
switch (path5.type) {
|
@@ -3257,10 +3269,13 @@ function isMarko(path5) {
|
|
3257
3269
|
return false;
|
3258
3270
|
}
|
3259
3271
|
}
|
3260
|
-
function
|
3272
|
+
function isFunction(path5) {
|
3261
3273
|
switch (path5.type) {
|
3274
|
+
case "FunctionDeclaration":
|
3275
|
+
return !path5.node.declare;
|
3262
3276
|
case "FunctionExpression":
|
3263
3277
|
case "ArrowFunctionExpression":
|
3278
|
+
case "ObjectMethod":
|
3264
3279
|
return true;
|
3265
3280
|
default:
|
3266
3281
|
return false;
|
@@ -3393,10 +3408,9 @@ function trackAssignment(assignment, binding) {
|
|
3393
3408
|
});
|
3394
3409
|
}
|
3395
3410
|
function setReferencesScope(path5) {
|
3396
|
-
|
3397
|
-
|
3411
|
+
const fnRoot = getFnRoot(path5);
|
3412
|
+
if (fnRoot) {
|
3398
3413
|
(fnRoot.node.extra ??= {}).referencesScope = true;
|
3399
|
-
fnRoot = getFnRoot(fnRoot.parentPath);
|
3400
3414
|
}
|
3401
3415
|
}
|
3402
3416
|
function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, upstreamExpression, property) {
|
@@ -4557,6 +4571,7 @@ var native_tag_default = {
|
|
4557
4571
|
);
|
4558
4572
|
}
|
4559
4573
|
}
|
4574
|
+
setForceResumeScope(section);
|
4560
4575
|
translateVar(
|
4561
4576
|
tag,
|
4562
4577
|
callRuntime(
|
@@ -7989,21 +8004,21 @@ var import_babel_utils37 = require("@marko/compiler/babel-utils");
|
|
7989
8004
|
var functionIdsBySection = /* @__PURE__ */ new WeakMap();
|
7990
8005
|
var function_default = {
|
7991
8006
|
analyze(fn) {
|
7992
|
-
|
7993
|
-
|
7994
|
-
|
7995
|
-
|
8007
|
+
if (fn !== getFnRoot(fn)) {
|
8008
|
+
return;
|
8009
|
+
}
|
8010
|
+
const markoRoot = getMarkoRoot(fn);
|
7996
8011
|
if (markoRoot && (markoRoot.isMarkoPlaceholder() || markoRoot.isMarkoScriptlet() && markoRoot.node.target === "server")) {
|
7997
8012
|
return;
|
7998
8013
|
}
|
8014
|
+
if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils37.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
|
8015
|
+
return;
|
8016
|
+
}
|
7999
8017
|
const { node } = fn;
|
8000
8018
|
const extra = node.extra ??= {};
|
8001
8019
|
const name2 = extra.name = fn.node.id?.name || (isMarkoAttribute(markoRoot) ? markoRoot.node.default ? import_compiler47.types.toIdentifier(
|
8002
8020
|
markoRoot.parentPath.has("var") ? markoRoot.parentPath.get("var") : markoRoot.parentPath.get("name")
|
8003
8021
|
) : markoRoot.node.name : import_compiler47.types.isVariableDeclarator(fn.parent) && import_compiler47.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : import_compiler47.types.isObjectMethod(node) && import_compiler47.types.isIdentifier(node.key) ? node.key.name : "anonymous");
|
8004
|
-
if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils37.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
|
8005
|
-
return;
|
8006
|
-
}
|
8007
8022
|
const {
|
8008
8023
|
markoOpts,
|
8009
8024
|
opts: { filename }
|
@@ -8029,18 +8044,6 @@ var function_default = {
|
|
8029
8044
|
);
|
8030
8045
|
}
|
8031
8046
|
};
|
8032
|
-
function isFunction(fn, isStatic2) {
|
8033
|
-
switch (fn.node.type) {
|
8034
|
-
case "FunctionDeclaration":
|
8035
|
-
return isStatic2 && !fn.node.declare;
|
8036
|
-
case "FunctionExpression":
|
8037
|
-
case "ArrowFunctionExpression":
|
8038
|
-
case "ObjectMethod":
|
8039
|
-
return true;
|
8040
|
-
default:
|
8041
|
-
return false;
|
8042
|
-
}
|
8043
|
-
}
|
8044
8047
|
function isMarkoAttribute(path5) {
|
8045
8048
|
return path5 ? path5.isMarkoAttribute() : false;
|
8046
8049
|
}
|
@@ -8370,6 +8373,7 @@ var import_compiler51 = require("@marko/compiler");
|
|
8370
8373
|
var import_babel_utils40 = require("@marko/compiler/babel-utils");
|
8371
8374
|
var import_path4 = __toESM(require("path"));
|
8372
8375
|
var kChildScopeBinding = Symbol("custom tag child scope");
|
8376
|
+
var kChildAttrExprs = Symbol("custom tag child attribute expressions");
|
8373
8377
|
var custom_tag_default = {
|
8374
8378
|
analyze: {
|
8375
8379
|
enter(tag) {
|
@@ -8398,12 +8402,14 @@ var custom_tag_default = {
|
|
8398
8402
|
void 0,
|
8399
8403
|
tagExtra
|
8400
8404
|
);
|
8405
|
+
tagExtra[kChildAttrExprs] = /* @__PURE__ */ new Set([tagExtra]);
|
8401
8406
|
const childFile = (0, import_babel_utils40.loadFileForTag)(tag);
|
8402
8407
|
if (childFile.opts.filename === tag.hub.file.opts.filename) {
|
8403
8408
|
mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
|
8404
8409
|
} else {
|
8405
8410
|
const childProgramExtra = childFile.ast.program.extra;
|
8406
8411
|
analyzeAttrs(
|
8412
|
+
tagExtra,
|
8407
8413
|
section,
|
8408
8414
|
tag,
|
8409
8415
|
childProgramExtra?.domExports.params?.props?.[0]
|
@@ -8442,40 +8448,51 @@ function translateHTML(tag) {
|
|
8442
8448
|
}
|
8443
8449
|
const tagVar = node.var;
|
8444
8450
|
const section = getSection(tag);
|
8445
|
-
const childScopeBinding = node.extra[kChildScopeBinding];
|
8446
|
-
const peekScopeId = tag.scope.generateUidIdentifier(childScopeBinding?.name);
|
8447
|
-
tag.insertBefore(
|
8448
|
-
import_compiler51.types.variableDeclaration("const", [
|
8449
|
-
import_compiler51.types.variableDeclarator(peekScopeId, callRuntime("peekNextScope"))
|
8450
|
-
])
|
8451
|
-
);
|
8452
|
-
getSerializedScopeProperties(section).set(
|
8453
|
-
getScopeAccessorLiteral(childScopeBinding),
|
8454
|
-
callRuntime("writeExistingScope", peekScopeId)
|
8455
|
-
);
|
8456
8451
|
const inputExport = (0, import_babel_utils40.loadFileForTag)(tag)?.ast.program.extra?.domExports?.params?.props?.[0];
|
8457
8452
|
const { properties, statements } = inputExport ? translateAttrs(tag, inputExport.props) : {
|
8458
8453
|
properties: [],
|
8459
8454
|
statements: []
|
8460
8455
|
};
|
8461
|
-
|
8462
|
-
|
8463
|
-
|
8464
|
-
|
8465
|
-
|
8466
|
-
|
8467
|
-
|
8468
|
-
|
8469
|
-
|
8470
|
-
|
8471
|
-
|
8472
|
-
|
8473
|
-
|
8456
|
+
let providesStatefulAttrs = false;
|
8457
|
+
for (const expr of tag.node.extra[kChildAttrExprs]) {
|
8458
|
+
if (isReferencedExtra(expr) && isStatefulReferences(expr.referencedBindings)) {
|
8459
|
+
providesStatefulAttrs = true;
|
8460
|
+
break;
|
8461
|
+
}
|
8462
|
+
}
|
8463
|
+
if (providesStatefulAttrs || tagVar) {
|
8464
|
+
const childScopeBinding = node.extra[kChildScopeBinding];
|
8465
|
+
const peekScopeId = tag.scope.generateUidIdentifier(
|
8466
|
+
childScopeBinding?.name
|
8467
|
+
);
|
8468
|
+
tag.insertBefore(
|
8469
|
+
import_compiler51.types.variableDeclaration("const", [
|
8470
|
+
import_compiler51.types.variableDeclarator(peekScopeId, callRuntime("peekNextScope"))
|
8471
|
+
])
|
8472
|
+
);
|
8473
|
+
getSerializedScopeProperties(section).set(
|
8474
|
+
getScopeAccessorLiteral(childScopeBinding),
|
8475
|
+
callRuntime("writeExistingScope", peekScopeId)
|
8476
|
+
);
|
8477
|
+
if (tagVar) {
|
8478
|
+
statements.push(
|
8479
|
+
import_compiler51.types.expressionStatement(
|
8480
|
+
callRuntime(
|
8481
|
+
"setTagVar",
|
8482
|
+
getScopeIdIdentifier(section),
|
8483
|
+
peekScopeId,
|
8484
|
+
import_compiler51.types.stringLiteral(
|
8485
|
+
getResumeRegisterId(
|
8486
|
+
section,
|
8487
|
+
node.var.extra?.binding,
|
8488
|
+
// TODO: node.var is not always an identifier.
|
8489
|
+
"var"
|
8490
|
+
)
|
8474
8491
|
)
|
8475
8492
|
)
|
8476
8493
|
)
|
8477
|
-
)
|
8478
|
-
|
8494
|
+
);
|
8495
|
+
}
|
8479
8496
|
}
|
8480
8497
|
if (node.extra.tagNameNullable) {
|
8481
8498
|
const contentProp = getTranslatedBodyContentProperty(properties);
|
@@ -8617,7 +8634,7 @@ function getTagRelativePath(tag) {
|
|
8617
8634
|
}
|
8618
8635
|
return relativePath;
|
8619
8636
|
}
|
8620
|
-
function analyzeAttrs(section, tag, templateExport) {
|
8637
|
+
function analyzeAttrs(rootTagExtra, section, tag, templateExport) {
|
8621
8638
|
if (!templateExport) {
|
8622
8639
|
dropReferences(getAllTagReferenceNodes(tag.node));
|
8623
8640
|
return;
|
@@ -8653,7 +8670,7 @@ function analyzeAttrs(section, tag, templateExport) {
|
|
8653
8670
|
const childAttrExports = templateExport.props[attrTagMeta.name];
|
8654
8671
|
if (childAttrExports) {
|
8655
8672
|
if (childAttrExports.props && !attrTagMeta.dynamic) {
|
8656
|
-
analyzeAttrs(section, child, childAttrExports);
|
8673
|
+
analyzeAttrs(rootTagExtra, section, child, childAttrExports);
|
8657
8674
|
} else {
|
8658
8675
|
analyzeDynamicChildGroup(attrTagMeta.group, child);
|
8659
8676
|
}
|
@@ -8677,8 +8694,12 @@ function analyzeAttrs(section, tag, templateExport) {
|
|
8677
8694
|
}
|
8678
8695
|
}
|
8679
8696
|
}
|
8680
|
-
for (const {
|
8681
|
-
|
8697
|
+
for (const {
|
8698
|
+
firstTag: { node },
|
8699
|
+
referenceNodes
|
8700
|
+
} of nodeReferencesByGroup.values()) {
|
8701
|
+
mergeReferences(section, node, referenceNodes);
|
8702
|
+
rootTagExtra[kChildAttrExprs].add(node.extra);
|
8682
8703
|
}
|
8683
8704
|
}
|
8684
8705
|
const { attributes } = tag.node;
|
@@ -8696,6 +8717,8 @@ function analyzeAttrs(section, tag, templateExport) {
|
|
8696
8717
|
spreadReferenceNodes.push(attr2.value);
|
8697
8718
|
} else if (import_compiler51.types.isMarkoSpreadAttribute(attr2)) {
|
8698
8719
|
spreadReferenceNodes = [attr2.value];
|
8720
|
+
} else {
|
8721
|
+
rootTagExtra[kChildAttrExprs].add(attr2.value.extra ??= {});
|
8699
8722
|
}
|
8700
8723
|
}
|
8701
8724
|
if (spreadReferenceNodes) {
|
@@ -2,6 +2,6 @@ import type { types as t } from "@marko/compiler";
|
|
2
2
|
type MarkoExprRootPath = t.NodePath<t.MarkoTag | t.MarkoTagBody | t.MarkoAttribute | t.MarkoSpreadAttribute | t.MarkoScriptlet | t.MarkoPlaceholder>;
|
3
3
|
export declare function getMarkoRoot(path: t.NodePath<t.Node>): MarkoExprRootPath | null;
|
4
4
|
export declare function getExprRoot(path: t.NodePath<t.Node>): t.NodePath<t.Node>;
|
5
|
-
export declare function getFnRoot(path: t.NodePath<t.Node>): t.NodePath<t.ArrowFunctionExpression | t.FunctionExpression> | undefined;
|
5
|
+
export declare function getFnRoot(path: t.NodePath<t.Node>): t.NodePath<t.ArrowFunctionExpression | t.FunctionExpression | t.ObjectMember> | undefined;
|
6
6
|
export declare function isMarko(path: t.NodePath<any>): path is MarkoExprRootPath;
|
7
7
|
export {};
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { types as t } from "@marko/compiler";
|
2
2
|
import { type Binding } from "../../util/references";
|
3
3
|
declare const kChildScopeBinding: unique symbol;
|
4
|
+
declare const kChildAttrExprs: unique symbol;
|
4
5
|
declare module "@marko/compiler/dist/types" {
|
5
6
|
interface MarkoTagExtra {
|
6
7
|
[kChildScopeBinding]?: Binding;
|
8
|
+
[kChildAttrExprs]?: Set<t.NodeExtra>;
|
7
9
|
}
|
8
10
|
}
|
9
11
|
declare const _default: {
|