marko
Version:
Optimized runtime for Marko templates.
1,508 lines • 405 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
//#endregion
let package_json = require("../../package.json");
let _marko_compiler = require("@marko/compiler");
let _marko_compiler_babel_utils = require("@marko/compiler/babel-utils");
let _marko_compiler_config = require("@marko/compiler/config");
let node_path = require("node:path");
node_path = __toESM(node_path);
let path = require("path");
path = __toESM(path);
let magic_string = require("magic-string");
magic_string = __toESM(magic_string);
let fastest_levenshtein = require("fastest-levenshtein");
let _marko_compiler_internal_babel = require("@marko/compiler/internal/babel");
let _marko_compiler_modules = require("@marko/compiler/modules");
_marko_compiler_modules = __toESM(_marko_compiler_modules);
//#region src/translator/util/runtime-info.ts
var runtime_info_default = {
name: package_json.name,
taglibId: "marko-core"
};
//#endregion
//#region src/translator/util/assert.ts
function assertNoSpreadAttrs(tag) {
for (const attr of tag.get("attributes")) if (attr.isMarkoSpreadAttribute()) {
const tagName = tag.get("name").node.value;
throw attr.buildCodeFrameError(`The [\`<${tagName}>\`](https://markojs.com/docs/reference/core-tag#${tagName}) tag does not support \`...spread\` attributes.`);
}
}
function assertNoBodyContent(tag) {
if (tag.node.body.body.length) {
const tagName = tag.get("name");
const tagNameLiteral = tagName.node.value;
throw tagName.buildCodeFrameError(`The [\`<${tagNameLiteral}>\`](https://markojs.com/docs/reference/core-tag#${tagNameLiteral}) tag does not support body content.`);
}
}
//#endregion
//#region src/translator/core/attrs.ts
var attrs_default = {
migrate: [(tag) => {
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
(0, _marko_compiler_babel_utils.assertNoAttributes)(tag);
assertNoBodyContent(tag);
(0, _marko_compiler_babel_utils.assertNoAttributeTags)(tag);
(0, _marko_compiler_babel_utils.diagnosticDeprecate)(tag, {
label: "The `attrs` tag is deprecated, prefer destructuring `input` via the `const` tag.",
fix() {
const tagVar = tag.node.var;
if (tagVar && !(tagVar.type === "Identifier" && tagVar.name === "input")) {
const constTag = _marko_compiler.types.markoTag(_marko_compiler.types.stringLiteral("const"), [_marko_compiler.types.markoAttribute("value", _marko_compiler.types.identifier("input"))], _marko_compiler.types.markoTagBody([]));
constTag.var = tagVar;
tag.replaceWith(constTag);
} else tag.remove();
}
});
}],
attributes: {},
autocomplete: [{
displayText: "attrs/{ ... }",
description: "Use to receive the attributes passed into this template.",
snippet: "attrs/{ $1 }$2"
}]
};
//#endregion
//#region src/common/accessor.debug.ts
let AccessorPrefix$1 = /* @__PURE__ */ function(AccessorPrefix) {
AccessorPrefix["BranchScopes"] = "BranchScopes:";
AccessorPrefix["ClosureScopes"] = "ClosureScopes:";
AccessorPrefix["ClosureSignalIndex"] = "ClosureSignalIndex:";
AccessorPrefix["ConditionalRenderer"] = "ConditionalRenderer:";
AccessorPrefix["ControlledHandler"] = "ControlledHandler:";
AccessorPrefix["ControlledType"] = "ControlledType:";
AccessorPrefix["ControlledValue"] = "ControlledValue:";
AccessorPrefix["DynamicHTMLLastChild"] = "DynamicHTMLLastChild:";
AccessorPrefix["EventAttributes"] = "EventAttributes:";
AccessorPrefix["Getter"] = "Getter:";
AccessorPrefix["Lifecycle"] = "Lifecycle:";
AccessorPrefix["Promise"] = "Promise:";
AccessorPrefix["TagVariableChange"] = "TagVariableChange:";
return AccessorPrefix;
}({});
let AccessorProp$1 = /* @__PURE__ */ function(AccessorProp) {
AccessorProp["Global"] = "$global";
AccessorProp["Owner"] = "_";
AccessorProp["AbortControllers"] = "#AbortControllers";
AccessorProp["AbortScopes"] = "#AbortScopes";
AccessorProp["AwaitCounter"] = "#AwaitCounter";
AccessorProp["BranchAccessor"] = "#BranchAccessor";
AccessorProp["BranchScopes"] = "#BranchScopes";
AccessorProp["CatchContent"] = "#CatchContent";
AccessorProp["ClosestBranch"] = "#ClosestBranch";
AccessorProp["ClosestBranchId"] = "#ClosestBranchId";
AccessorProp["Gen"] = "#Gen";
AccessorProp["DetachedAwait"] = "#DetachedAwait";
AccessorProp["EndNode"] = "#EndNode";
AccessorProp["Id"] = "#Id";
AccessorProp["Load"] = "#Load";
AccessorProp["LoopKey"] = "#LoopKey";
AccessorProp["ParentBranch"] = "#ParentBranch";
AccessorProp["PendingEffects"] = "#PendingEffects";
AccessorProp["PendingRenders"] = "#PendingRenders";
AccessorProp["PendingScopes"] = "#PendingScopes";
AccessorProp["PlaceholderBranch"] = "#PlaceholderBranch";
AccessorProp["PlaceholderContent"] = "#PlaceholderContent";
AccessorProp["Renderer"] = "#Renderer";
AccessorProp["StartNode"] = "#StartNode";
AccessorProp["TagVariable"] = "#TagVariable";
AccessorProp["TagVariableChange"] = "#TagVariableChange";
return AccessorProp;
}({});
//#endregion
//#region src/translator/util/evaluate.ts
function evaluate(value) {
let { extra } = value;
if (!extra) extra = value.extra = {};
if (extra.confident === void 0) {
const computed = (0, _marko_compiler_babel_utils.computeNode)(value);
if (computed) {
extra.computed = computed.value;
extra.confident = true;
extra.nullable = computed.value == null;
} else {
extra.computed = void 0;
extra.confident = false;
extra.nullable = isNullableExpr(value);
}
}
return extra;
}
function isNullableExpr(expr) {
switch (expr.type) {
case "ArrayExpression":
case "ArrowFunctionExpression":
case "BigIntLiteral":
case "BinaryExpression":
case "BooleanLiteral":
case "ClassExpression":
case "FunctionExpression":
case "NewExpression":
case "NumericLiteral":
case "ObjectExpression":
case "RegExpLiteral":
case "StringLiteral":
case "TemplateLiteral":
case "UpdateExpression": return false;
case "AssignmentExpression": switch (expr.operator) {
case "=": return isNullableExpr(expr.right);
case "*=":
case "/=":
case "%=":
case "+=":
case "-=":
case "<<=":
case ">>=":
case ">>>=":
case "&=":
case "^=":
case "|=":
case "**=": return false;
case "||=":
case "??=": return isNullableExpr(expr.right) || isNullableExpr(expr.left);
case "&&=": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
default: return true;
}
case "AwaitExpression": return isNullableExpr(expr.argument);
case "ConditionalExpression": return isNullableExpr(expr.consequent) || isNullableExpr(expr.alternate);
case "LogicalExpression": switch (expr.operator) {
case "||":
case "??": return isNullableExpr(expr.right) || isNullableExpr(expr.left);
case "&&": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
default: return true;
}
case "ParenthesizedExpression": return isNullableExpr(expr.expression);
case "SequenceExpression": return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
case "UnaryExpression": return expr.operator === "void";
default: return true;
}
}
//#endregion
//#region src/common/helpers.ts
const htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
const userAttrNameReg = /^[^a-z_$]|[^a-z0-9._:-]/i;
function stringifyClassObject(name, value) {
return value ? name : "";
}
function stringifyStyleObject(name, value) {
return value || value === 0 ? name + ":" + value : "";
}
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
let str = "";
let sep = "";
let part;
if (val) if (typeof val !== "object") str += val;
else if (Array.isArray(val)) for (const v of val) {
part = toDelimitedString(v, delimiter, stringify);
if (part) {
str += sep + part;
sep = delimiter;
}
}
else for (const name in val) {
part = stringify(name, val[name]);
if (part) {
str += sep + part;
sep = delimiter;
}
}
return str;
};
function isEventHandler(name) {
return /^on[A-Z-]/.test(name);
}
function getEventHandlerName(name) {
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
}
function isVoid(value) {
return value == null || value === false;
}
function isNotVoid(value) {
return value != null && value !== false;
}
function normalizeDynamicRenderer(value) {
if (value) {
if (typeof value === "string") return value;
const normalized = value.content || value.default || value;
if ("id" in normalized) return normalized;
}
}
const decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36);
//#endregion
//#region src/html/serializer.ts
const K_SCOPE_ID = Symbol("Scope ID");
const kTouchedIterator = Symbol.for("marko.touchedIterator");
const { hasOwnProperty: hasOwnProperty$1 } = {};
const Generator = (function* () {})().constructor;
const AsyncGenerator = (async function* () {})().constructor;
patchIteratorNext(Generator.prototype);
patchIteratorNext(AsyncGenerator.prototype);
(() => {
const KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
for (const name of Object.getOwnPropertyNames(Symbol)) {
const symbol = Symbol[name];
if (typeof symbol === "symbol") KNOWN_SYMBOLS.set(symbol, "Symbol." + name);
}
return KNOWN_SYMBOLS;
})();
new Map([
[AggregateError, "AggregateError"],
[Array, "Array"],
[Array.from, "Array.from"],
[Array.isArray, "Array.isArray"],
[Array.of, "Array.of"],
[ArrayBuffer, "ArrayBuffer"],
[ArrayBuffer.isView, "ArrayBuffer.isView"],
[Atomics.add, "Atomics.add"],
[Atomics.and, "Atomics.and"],
[Atomics.compareExchange, "Atomics.compareExchange"],
[Atomics.exchange, "Atomics.exchange"],
[Atomics.isLockFree, "Atomics.isLockFree"],
[Atomics.load, "Atomics.load"],
[Atomics.notify, "Atomics.notify"],
[Atomics.or, "Atomics.or"],
[Atomics.store, "Atomics.store"],
[Atomics.sub, "Atomics.sub"],
[Atomics.wait, "Atomics.wait"],
[BigInt, "BigInt"],
[BigInt.asIntN, "BigInt.asIntN"],
[BigInt.asUintN, "BigInt.asUintN"],
[BigInt64Array, "BigInt64Array"],
[BigInt64Array.from, "BigInt64Array.from"],
[BigInt64Array.of, "BigInt64Array.of"],
[BigUint64Array, "BigUint64Array"],
[BigUint64Array.from, "BigUint64Array.from"],
[BigUint64Array.of, "BigUint64Array.of"],
[Boolean, "Boolean"],
[console.assert, "console.assert"],
[console.clear, "console.clear"],
[console.count, "console.count"],
[console.countReset, "console.countReset"],
[console.debug, "console.debug"],
[console.dir, "console.dir"],
[console.dirxml, "console.dirxml"],
[console.error, "console.error"],
[console.group, "console.group"],
[console.groupCollapsed, "console.groupCollapsed"],
[console.groupEnd, "console.groupEnd"],
[console.info, "console.info"],
[console.log, "console.log"],
[console.table, "console.table"],
[console.time, "console.time"],
[console.timeEnd, "console.timeEnd"],
[console.timeLog, "console.timeLog"],
[console.timeStamp, "console.timeStamp"],
[console.trace, "console.trace"],
[console.warn, "console.warn"],
[DataView, "DataView"],
[Date, "Date"],
[Date.now, "Date.now"],
[Date.parse, "Date.parse"],
[Date.UTC, "Date.UTC"],
[decodeURI, "decodeURI"],
[decodeURIComponent, "decodeURIComponent"],
[encodeURI, "encodeURI"],
[encodeURIComponent, "encodeURIComponent"],
[Error, "Error"],
[EvalError, "EvalError"],
[Float32Array, "Float32Array"],
[Float32Array.from, "Float32Array.from"],
[Float32Array.of, "Float32Array.of"],
[Float64Array, "Float64Array"],
[Float64Array.from, "Float64Array.from"],
[Float64Array.of, "Float64Array.of"],
[Function, "Function"],
[globalThis.atob, "atob"],
[globalThis.btoa, "btoa"],
[globalThis.clearImmediate, "clearImmediate"],
[globalThis.clearInterval, "clearInterval"],
[globalThis.clearTimeout, "clearTimeout"],
[globalThis.crypto?.getRandomValues, "crypto.getRandomValues"],
[globalThis.crypto?.randomUUID, "crypto.randomUUID"],
[globalThis.fetch, "fetch"],
[globalThis.performance?.now, "performance.now"],
[globalThis.queueMicrotask, "queueMicrotask"],
[globalThis.setImmediate, "setImmediate"],
[globalThis.setInterval, "setInterval"],
[globalThis.setTimeout, "setTimeout"],
[globalThis.structuredClone, "structuredClone"],
[globalThis.URL, "URL"],
[globalThis.URLSearchParams, "URLSearchParams"],
[globalThis.WritableStream, "WritableStream"],
[Int16Array, "Int16Array"],
[Int16Array.from, "Int16Array.from"],
[Int16Array.of, "Int16Array.of"],
[Int32Array, "Int32Array"],
[Int32Array.from, "Int32Array.from"],
[Int32Array.of, "Int32Array.of"],
[Int8Array, "Int8Array"],
[Int8Array.from, "Int8Array.from"],
[Int8Array.of, "Int8Array.of"],
[Intl.Collator, "Intl.Collator"],
[Intl.DateTimeFormat, "Intl.DateTimeFormat"],
[Intl.DisplayNames, "Intl.DisplayNames"],
[Intl.getCanonicalLocales, "Intl.getCanonicalLocales"],
[Intl.ListFormat, "Intl.ListFormat"],
[Intl.Locale, "Intl.Locale"],
[Intl.NumberFormat, "Intl.NumberFormat"],
[Intl.PluralRules, "Intl.PluralRules"],
[Intl.RelativeTimeFormat, "Intl.RelativeTimeFormat"],
[Intl.Segmenter, "Intl.Segmenter"],
[Intl.supportedValuesOf, "Intl.supportedValuesOf"],
[isFinite, "isFinite"],
[isNaN, "isNaN"],
[JSON.parse, "JSON.parse"],
[JSON.stringify, "JSON.stringify"],
[Map, "Map"],
[Map.groupBy, "Map.groupBy"],
[Math.abs, "Math.abs"],
[Math.acos, "Math.acos"],
[Math.acosh, "Math.acosh"],
[Math.asin, "Math.asin"],
[Math.asinh, "Math.asinh"],
[Math.atan, "Math.atan"],
[Math.atan2, "Math.atan2"],
[Math.atanh, "Math.atanh"],
[Math.cbrt, "Math.cbrt"],
[Math.ceil, "Math.ceil"],
[Math.clz32, "Math.clz32"],
[Math.cos, "Math.cos"],
[Math.cosh, "Math.cosh"],
[Math.exp, "Math.exp"],
[Math.expm1, "Math.expm1"],
[Math.floor, "Math.floor"],
[Math.fround, "Math.fround"],
[Math.hypot, "Math.hypot"],
[Math.imul, "Math.imul"],
[Math.log, "Math.log"],
[Math.log10, "Math.log10"],
[Math.log1p, "Math.log1p"],
[Math.log2, "Math.log2"],
[Math.max, "Math.max"],
[Math.min, "Math.min"],
[Math.pow, "Math.pow"],
[Math.random, "Math.random"],
[Math.round, "Math.round"],
[Math.sign, "Math.sign"],
[Math.sin, "Math.sin"],
[Math.sinh, "Math.sinh"],
[Math.sqrt, "Math.sqrt"],
[Math.tan, "Math.tan"],
[Math.tanh, "Math.tanh"],
[Math.trunc, "Math.trunc"],
[Number, "Number"],
[Number.isFinite, "Number.isFinite"],
[Number.isInteger, "Number.isInteger"],
[Number.isNaN, "Number.isNaN"],
[Number.isSafeInteger, "Number.isSafeInteger"],
[Number.parseFloat, "Number.parseFloat"],
[Number.parseInt, "Number.parseInt"],
[Object, "Object"],
[Object.assign, "Object.assign"],
[Object.create, "Object.create"],
[Object.defineProperties, "Object.defineProperties"],
[Object.defineProperty, "Object.defineProperty"],
[Object.entries, "Object.entries"],
[Object.freeze, "Object.freeze"],
[Object.fromEntries, "Object.fromEntries"],
[Object.getOwnPropertyDescriptor, "Object.getOwnPropertyDescriptor"],
[Object.getOwnPropertyDescriptors, "Object.getOwnPropertyDescriptors"],
[Object.getOwnPropertyNames, "Object.getOwnPropertyNames"],
[Object.getOwnPropertySymbols, "Object.getOwnPropertySymbols"],
[Object.getPrototypeOf, "Object.getPrototypeOf"],
[Object.is, "Object.is"],
[Object.isExtensible, "Object.isExtensible"],
[Object.isFrozen, "Object.isFrozen"],
[Object.isSealed, "Object.isSealed"],
[Object.keys, "Object.keys"],
[Object.preventExtensions, "Object.preventExtensions"],
[Object.seal, "Object.seal"],
[Object.setPrototypeOf, "Object.setPrototypeOf"],
[Object.values, "Object.values"],
[parseFloat, "parseFloat"],
[parseInt, "parseInt"],
[Promise, "Promise"],
[Proxy, "Proxy"],
[RangeError, "RangeError"],
[ReferenceError, "ReferenceError"],
[Reflect.apply, "Reflect.apply"],
[Reflect.construct, "Reflect.construct"],
[Reflect.defineProperty, "Reflect.defineProperty"],
[Reflect.deleteProperty, "Reflect.deleteProperty"],
[Reflect.get, "Reflect.get"],
[Reflect.getOwnPropertyDescriptor, "Reflect.getOwnPropertyDescriptor"],
[Reflect.getPrototypeOf, "Reflect.getPrototypeOf"],
[Reflect.has, "Reflect.has"],
[Reflect.isExtensible, "Reflect.isExtensible"],
[Reflect.ownKeys, "Reflect.ownKeys"],
[Reflect.preventExtensions, "Reflect.preventExtensions"],
[Reflect.set, "Reflect.set"],
[Reflect.setPrototypeOf, "Reflect.setPrototypeOf"],
[RegExp, "RegExp"],
[Set, "Set"],
[String, "String"],
[String.fromCharCode, "String.fromCharCode"],
[String.fromCodePoint, "String.fromCodePoint"],
[String.raw, "String.raw"],
[Symbol, "Symbol"],
[Symbol.for, "Symbol.for"],
[SyntaxError, "SyntaxError"],
[TypeError, "TypeError"],
[Uint16Array, "Uint16Array"],
[Uint16Array.from, "Uint16Array.from"],
[Uint16Array.of, "Uint16Array.of"],
[Uint32Array, "Uint32Array"],
[Uint32Array.from, "Uint32Array.from"],
[Uint32Array.of, "Uint32Array.of"],
[Uint8Array, "Uint8Array"],
[Uint8Array.from, "Uint8Array.from"],
[Uint8Array.of, "Uint8Array.of"],
[Uint8ClampedArray, "Uint8ClampedArray"],
[Uint8ClampedArray.from, "Uint8ClampedArray.from"],
[Uint8ClampedArray.of, "Uint8ClampedArray.of"],
[URIError, "URIError"],
[WeakMap, "WeakMap"],
[WeakSet, "WeakSet"]
]);
new Map([
[Atomics, "Atomics"],
[console, "console"],
[globalThis, "globalThis"],
[globalThis.crypto, "crypto"],
[Intl, "Intl"],
[JSON, "JSON"],
[Math, "Math"],
[Reflect, "Reflect"]
]);
function toAccess(accessor) {
const start = accessor[0];
return start === "\"" || start >= "0" && start <= "9" ? "[" + accessor + "]" : "." + accessor;
}
function patchIteratorNext(proto) {
if (proto.next[kTouchedIterator]) return;
const { next } = proto;
proto.next = function(value) {
this[kTouchedIterator] = 1;
return next.call(this, value);
};
proto.next[kTouchedIterator] = true;
}
//#endregion
//#region src/translator/util/get-compile-stage.ts
function isTranslate() {
return getCompileStage() === "translate";
}
function getCompileStage() {
return (0, _marko_compiler_babel_utils.getFile)().___compileStage;
}
//#endregion
//#region src/translator/util/traverse.ts
const skip = Symbol("skip");
function traverseReplace(container, key, enter, state) {
const node = container[key];
if (node) if (Array.isArray(node)) for (let i = node.length; i--;) traverseReplace(node, i, enter, state);
else {
const keys = _marko_compiler.types.VISITOR_KEYS[node.type];
for (let i = keys.length; i--;) traverseReplace(node, keys[i], enter, state);
const replacement = enter(node, state);
if (replacement) container[key] = replacement;
}
}
function traverseContains(node, check) {
if (node) if (Array.isArray(node)) {
for (const item of node) if (traverseContains(item, check)) return true;
} else {
switch (check(node)) {
case true: return true;
case skip: return false;
}
for (const key of _marko_compiler.types.VISITOR_KEYS[node.type]) if (traverseContains(node[key], check)) return true;
}
return false;
}
function traverse(visit, node, parent, grandParent) {
if (node) {
if (Array.isArray(node)) for (const item of node) traverse(visit, item, parent, grandParent);
else if (visit(node, parent, grandParent) !== skip) for (const key of _marko_compiler.types.VISITOR_KEYS[node.type]) traverse(visit, node[key], node, parent);
}
}
//#endregion
//#region src/translator/util/generate-uid.ts
const countsForFile = /* @__PURE__ */ new WeakMap();
function generateUid(name = "") {
const file = (0, _marko_compiler_babel_utils.getFile)();
let counts = countsForFile.get(file);
if (!counts) {
const { cache } = file.markoOpts;
const { filename } = file.opts;
const cacheKey = `uid-counts:${filename}`;
counts = cache.get(cacheKey);
if (counts) {
if (isTranslate()) counts = new Map(counts);
} else {
counts = getInitialCounts(file);
if (!isTranslate()) cache.set(cacheKey, counts);
}
countsForFile.set(file, counts);
}
name = name.replace(/^[^a-z$_]|[^a-z$_0-9]/gi, "") || "temp";
name = /^\$?(.*?)\d*$/.exec(name)?.[1] || name;
const i = (counts.get(name) || 0) + 1;
const uniqueName = `$${i > 1 ? name + i : name}`;
counts.set(name, i);
return uniqueName;
}
function generateUidIdentifier(name) {
return _marko_compiler.types.identifier(generateUid(name));
}
const sharedUIDsForFile = /* @__PURE__ */ new WeakMap();
function getSharedUid(name, section) {
const file = (0, _marko_compiler_babel_utils.getFile)();
let sharedUIDs = sharedUIDsForFile.get(file);
if (!sharedUIDs) {
const { cache } = file.markoOpts;
const { filename } = file.opts;
let cacheKey = `uid-shared:${filename}`;
if (section) cacheKey += `:${section.id}`;
sharedUIDs = cache.get(cacheKey);
if (sharedUIDs) {
if (isTranslate()) sharedUIDs = new Map(sharedUIDs);
} else {
sharedUIDs = /* @__PURE__ */ new Map();
if (!isTranslate()) cache.set(cacheKey, sharedUIDs);
}
sharedUIDsForFile.set(file, sharedUIDs);
}
const nameKey = section ? `${section.id}:${name}` : name;
let uniqueName = sharedUIDs.get(nameKey);
if (!uniqueName) {
uniqueName = generateUid(name);
sharedUIDs.set(nameKey, uniqueName);
}
return uniqueName;
}
function usedSharedUid(name) {
return !!sharedUIDsForFile.get((0, _marko_compiler_babel_utils.getFile)())?.has(name);
}
function getInitialCounts(file) {
const counts = /* @__PURE__ */ new Map();
const program = file.path;
const countName = (name) => {
const match = /^\$(.*?)([1-9]\d*)?$/.exec(name);
if (match) {
const name = match[1];
const count = match[2] ? +match[2] + 1 : 1;
counts.set(name, Math.max(counts.get(name) || 0, count));
}
};
for (const name in program.scope.globals) countName(name);
traverse((node, parent, grandParent) => {
if (node.type === "Identifier" && _marko_compiler.types.isBinding(node, parent, grandParent)) countName(node.name);
}, program.node);
return counts;
}
//#endregion
//#region src/translator/util/get-parent-tag.ts
function getParentTag(tag) {
const parent = tag.parent.type === "MarkoTagBody" ? tag.parentPath.parentPath : tag.parentPath;
if (parent.type === "MarkoTag") return parent;
}
function getAttributeTagParent(tag) {
let cur = tag;
while ((0, _marko_compiler_babel_utils.isAttributeTag)(cur) || (0, _marko_compiler_babel_utils.isTransparentTag)(cur)) cur = getParentTag(cur);
return cur;
}
//#endregion
//#region src/translator/util/get-root.ts
function getMarkoRoot(path) {
let curPath = path;
do
curPath = curPath.parentPath;
while (curPath && !isMarko(curPath));
return curPath;
}
function getExprRoot(path) {
let curPath = path;
while (!isMarko(curPath.parentPath)) curPath = curPath.parentPath;
return curPath;
}
function getFnRoot(path) {
let curPath = path;
let fnPath;
while (!isMarko(curPath)) {
if (isFunction(curPath)) fnPath = curPath;
else switch (curPath.type) {
case "OptionalCallExpression":
case "CallExpression":
case "NewExpression":
fnPath = void 0;
break;
}
const parentPath = curPath.parentPath;
if (parentPath) curPath = parentPath;
else break;
}
return fnPath;
}
function getFnParent(path) {
let curPath = path;
while (!isMarko(curPath)) {
if (isFunction(curPath)) return curPath;
const parentPath = curPath.parentPath;
if (parentPath) curPath = parentPath;
else break;
}
}
function getDeclarationRoot(path) {
let curPath = path;
let declPath;
while (!isMarko(curPath)) {
if (isFunctionOrVariableDeclaration(curPath)) declPath = curPath;
const parentPath = curPath.parentPath;
if (parentPath) curPath = parentPath;
else break;
}
return declPath;
}
function isMarko(path) {
switch (path.type) {
case "MarkoTag":
case "MarkoTagBody":
case "MarkoAttribute":
case "MarkoSpreadAttribute":
case "MarkoPlaceholder":
case "MarkoScriptlet":
case "ExportNamedDeclaration":
case "ExportDefaultDeclaration": return true;
default: return false;
}
}
function isFunction(path) {
switch (path.type) {
case "FunctionDeclaration": return !path.node.declare;
case "FunctionExpression":
case "ArrowFunctionExpression":
case "ObjectMethod": return true;
default: return false;
}
}
function isFunctionOrVariableDeclaration(path) {
switch (path.type) {
case "FunctionDeclaration": return !path.node.declare;
case "VariableDeclaration": return true;
default: return false;
}
}
//#endregion
//#region src/translator/util/get-tag-name.ts
function getTagName(tag) {
switch (tag.node.name.type) {
case "StringLiteral": return tag.node.name.value;
case "TemplateLiteral":
if (tag.node.name.quasis.length === 1) return tag.node.name.quasis[0].value.raw;
break;
}
}
//#endregion
//#region src/translator/util/is-core-tag.ts
const { taglibId } = runtime_info_default;
const htmlTaglibId = "marko-html";
function isCoreTag(tag) {
if (tag.isMarkoTag()) {
const tagDef = (0, _marko_compiler_babel_utils.getTagDef)(tag);
if (tagDef) switch (tagDef.taglibId) {
case taglibId: return true;
case htmlTaglibId:
switch (tagDef.name) {
case "script":
case "style": return true;
}
break;
}
}
return false;
}
function isCoreTagName(tag, name) {
return isCoreTag(tag) && getTagName(tag) === name;
}
function isConditionTag(tag) {
if (isCoreTag(tag)) switch (getTagName(tag)) {
case "if":
case "else-if":
case "else": return true;
}
return false;
}
function isControlFlowTag(tag) {
if (isCoreTag(tag)) switch (getTagName(tag)) {
case "if":
case "else-if":
case "else":
case "for":
case "await":
case "try": return true;
}
return false;
}
//#endregion
//#region src/translator/util/is-invoked-function.ts
function isInvokedFunction(expr) {
let curPath = expr;
while (curPath) {
const { parent, node } = curPath;
switch (parent.type) {
case "OptionalCallExpression":
case "CallExpression": return parent.callee === node;
case "TSNonNullExpression":
curPath = curPath.parentPath;
break;
default: return false;
}
}
return false;
}
//#endregion
//#region src/translator/util/optional.ts
var Sorted = class {
compare;
constructor(compare) {
this.compare = compare;
}
add(data, item) {
return data !== void 0 ? Array.isArray(data) ? addSorted(this.compare, data, item) : joinRepeatable(this.compare, data, item) : item;
}
union(a, b) {
if (a !== void 0) {
if (Array.isArray(a)) {
if (b !== void 0) if (Array.isArray(b)) return unionSortedRepeatable(this.compare, a, b);
else return addSorted(this.compare, a, b);
return a;
}
if (b !== void 0) {
if (Array.isArray(b)) return addSorted(this.compare, b, a);
return joinRepeatable(this.compare, b, a);
}
return a;
}
return b;
}
find(data, item) {
if (data !== void 0) {
if (Array.isArray(data)) return findSorted(this.compare, data, item);
else if (this.compare(data, item) === 0) return data;
}
}
has(data, item) {
return this.findIndex(data, item) !== -1;
}
findIndex(data, item) {
if (data !== void 0) {
if (Array.isArray(data)) return findIndexSorted(this.compare, data, item);
else if (this.compare(data, item) === 0) return 0;
}
return -1;
}
groupBy(data, cb) {
const group = /* @__PURE__ */ new Map();
if (data !== void 0) if (Array.isArray(data)) for (const item of data) {
const key = cb(item);
group.set(key, this.union(group.get(key), item));
}
else group.set(cb(data), data);
return group;
}
isSuperset(superset, subset) {
if (subset === void 0) return true;
if (!Array.isArray(subset)) return this.findIndex(superset, subset) !== -1;
if (!Array.isArray(superset)) return false;
const subLen = subset.length;
const supLen = superset.length;
if (subLen > supLen) return false;
for (let i = subLen; i--;) {
const found = findIndexSorted(this.compare, superset, subset[i]);
if (found === -1 || supLen - found <= i) return false;
}
return true;
}
};
function push(data, item) {
if (data !== void 0) {
if (Array.isArray(data)) {
data.push(item);
return data;
}
return [data, item];
}
return item;
}
function concat(a, b) {
if (a !== void 0) {
if (b !== void 0) if (Array.isArray(a)) return a.concat(b);
else if (Array.isArray(b)) return [a, ...b];
else return [a, b];
return a;
}
return b;
}
function filter(data, cb) {
if (data !== void 0) {
if (Array.isArray(data)) {
const len = data.length;
let result;
let i = 0;
while (i < len) {
let item = data[i++];
if (cb(item)) {
result = item;
while (i < len) {
item = data[i++];
if (cb(item)) {
result = [result, item];
while (i < len) {
item = data[i++];
if (cb(item)) result.push(item);
}
return result;
}
}
return result;
}
}
return result;
}
if (cb(data)) return data;
}
}
function forEach(data, cb) {
if (data !== void 0) if (Array.isArray(data)) {
let i = 0;
for (const item of data) cb(item, i++);
} else cb(data, 0);
}
function fromIter(data) {
let one;
let many;
for (const item of data) if (many) many.push(item);
else if (one) many = [one, item];
else one = item;
return many || one;
}
function* toIter(data) {
if (data !== void 0) if (Array.isArray(data)) yield* data;
else yield data;
}
function includes(data, item) {
return data !== void 0 ? Array.isArray(data) ? data.includes(item) : data === item : false;
}
function find(data, cb) {
if (data !== void 0) {
if (Array.isArray(data)) return data.find(cb);
if (cb(data, 0)) return data;
}
}
function some(data, cb) {
return data !== void 0 ? Array.isArray(data) ? data.some(cb) : !!cb(data, 0) : false;
}
function toArray(data, cb) {
return data !== void 0 ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
}
function mapToString(data, sep, cb) {
if (data !== void 0) {
if (Array.isArray(data)) {
let str = "";
let curSep = "";
for (let i = 0; i < data.length; i++) {
str += curSep + cb(data[i], i);
curSep = sep;
}
return str;
}
return cb(data, 0);
}
return "";
}
function findSorted(compare, data, item) {
let max = data.length;
let pos = 0;
while (pos < max) {
const mid = pos + max >>> 1;
const cur = data[mid];
const compareResult = compare(cur, item);
if (compareResult === 0) return cur;
if (compareResult > 0) max = mid;
else pos = mid + 1;
}
}
function findIndexSorted(compare, data, item) {
let max = data.length;
let pos = 0;
while (pos < max) {
const mid = pos + max >>> 1;
const compareResult = compare(data[mid], item);
if (compareResult === 0) return mid;
if (compareResult > 0) max = mid;
else pos = mid + 1;
}
return -1;
}
function addSorted(compare, data, item) {
const len = data.length;
let max = len;
let pos = 0;
while (pos < max) {
const mid = pos + max >>> 1;
const compareResult = compare(data[mid], item);
if (compareResult === 0) return data;
if (compareResult > 0) max = mid;
else pos = mid + 1;
}
const result = new Array(len + 1);
for (let i = 0; i < pos; i++) result[i] = data[i];
let cur = item;
while (pos < len) {
const next = cur;
cur = data[pos];
result[pos++] = next;
}
result[len] = cur;
return result;
}
function unionSortedRepeatable(compare, a, b) {
const aLen = a.length;
const bLen = b.length;
const result = [];
let aIndex = 0;
let bIndex = 0;
let same = true;
while (aIndex < aLen && bIndex < bLen) {
const aValue = a[aIndex];
const bValue = b[bIndex];
const delta = compare(aValue, bValue);
if (delta === 0) {
aIndex++;
bIndex++;
result.push(aValue);
} else if (delta < 0) {
same = false;
aIndex++;
result.push(aValue);
} else {
same = false;
bIndex++;
result.push(bValue);
}
}
if (same && aLen === bLen) return a;
while (aIndex < aLen) result.push(a[aIndex++]);
while (bIndex < bLen) result.push(b[bIndex++]);
return result;
}
function joinRepeatable(compare, a, b) {
const compareResult = compare(a, b);
return compareResult === 0 ? a : compareResult < 0 ? [a, b] : [b, a];
}
//#endregion
//#region src/common/accessor.ts
let AccessorPrefix = /* @__PURE__ */ function(AccessorPrefix) {
AccessorPrefix["BranchScopes"] = "A";
AccessorPrefix["ClosureScopes"] = "B";
AccessorPrefix["ClosureSignalIndex"] = "C";
AccessorPrefix["ConditionalRenderer"] = "D";
AccessorPrefix["ControlledHandler"] = "E";
AccessorPrefix["ControlledType"] = "F";
AccessorPrefix["ControlledValue"] = "G";
AccessorPrefix["DynamicHTMLLastChild"] = "H";
AccessorPrefix["EventAttributes"] = "I";
AccessorPrefix["Getter"] = "J";
AccessorPrefix["Lifecycle"] = "K";
AccessorPrefix["Promise"] = "L";
AccessorPrefix["TagVariableChange"] = "M";
return AccessorPrefix;
}({});
let AccessorProp = /* @__PURE__ */ function(AccessorProp) {
AccessorProp["Global"] = "$";
AccessorProp["Owner"] = "_";
AccessorProp["AbortControllers"] = "A";
AccessorProp["AbortScopes"] = "B";
AccessorProp["AwaitCounter"] = "O";
AccessorProp["BranchAccessor"] = "C";
AccessorProp["BranchScopes"] = "D";
AccessorProp["CatchContent"] = "E";
AccessorProp["ClosestBranch"] = "F";
AccessorProp["ClosestBranchId"] = "G";
AccessorProp["Gen"] = "H";
AccessorProp["DetachedAwait"] = "V";
AccessorProp["EndNode"] = "K";
AccessorProp["Id"] = "L";
AccessorProp["Load"] = "X";
AccessorProp["LoopKey"] = "M";
AccessorProp["ParentBranch"] = "N";
AccessorProp["PendingEffects"] = "J";
AccessorProp["PendingRenders"] = "W";
AccessorProp["PendingScopes"] = "Y";
AccessorProp["PlaceholderBranch"] = "P";
AccessorProp["PlaceholderContent"] = "Q";
AccessorProp["Renderer"] = "R";
AccessorProp["StartNode"] = "S";
AccessorProp["TagVariable"] = "T";
AccessorProp["TagVariableChange"] = "U";
return AccessorProp;
}({});
//#endregion
//#region src/translator/util/marko-config.ts
function isOutputHTML() {
return getMarkoOpts().output === "html";
}
function isOutputDOM() {
return getMarkoOpts().output === "dom";
}
function getMarkoOpts() {
return (0, _marko_compiler_babel_utils.getFile)().markoOpts;
}
function isOptimize() {
return getMarkoOpts().optimize;
}
function getReadyId(file = (0, _marko_compiler_babel_utils.getFile)()) {
const { markoOpts } = file;
if (!markoOpts.linkAssets) return void 0;
return (markoOpts.optimize ? "_" : "ready:") + (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, file.opts.filename);
}
//#endregion
//#region src/translator/util/get-accessor-char.ts
function getAccessorPrefix() {
return isOptimize() ? AccessorPrefix : AccessorPrefix$1;
}
function getAccessorProp() {
return isOptimize() ? AccessorProp : AccessorProp$1;
}
//#endregion
//#region src/translator/util/serialize-reasons.ts
const scopeExprsBySection = /* @__PURE__ */ new WeakMap();
const propExprsBySection = /* @__PURE__ */ new WeakMap();
const serializePropsByBinding = /* @__PURE__ */ new WeakMap();
const serializePropByModifier = {};
function isSameReason(a, b) {
return a === b || (a && b ? a !== true && b !== true && compareSources(a, b) === 0 : false);
}
function isForceSerialized(section, prop, prefix) {
return true === (prop ? section.serializeReasons.get(getPropKey(section, prop, prefix)) : section.serializeReason);
}
function addSerializeReason(section, reason, prop, prefix) {
if (reason) if (prop) {
const key = getPropKey(section, prop, prefix);
const curReason = section.serializeReasons.get(key);
if (curReason !== true) if (reason === true) forcePropSerialize(section, key);
else {
const newReason = mergeSerializeReasons(curReason, reason);
if (curReason !== newReason) setPropSerializeReason(section, key, newReason);
}
} else {
const curReason = section.serializeReason;
if (curReason !== true) if (reason === true) forceSerialize(section);
else {
const newReason = mergeSerializeReasons(curReason, reason);
if (curReason !== newReason) setSerializeReason(section, newReason);
}
}
}
function addSerializeExpr(section, expr, prop, prefix) {
if (expr) {
if (prop) {
const key = getPropKey(section, prop, prefix);
if (section.serializeReasons.get(key) !== true) if (expr === true) forcePropSerialize(section, key);
else {
let curExpr;
let curExprs = propExprsBySection.get(section);
if (curExprs) curExpr = curExprs.get(key);
else {
curExprs = /* @__PURE__ */ new Map();
propExprsBySection.set(section, curExprs);
}
curExprs.set(key, curExpr ? concat(curExpr, expr) : expr);
}
} else if (section.serializeReason !== true) if (expr === true) forceSerialize(section);
else {
const curExpr = scopeExprsBySection.get(section);
scopeExprsBySection.set(section, curExpr ? concat(curExpr, expr) : expr);
}
}
}
function addOwnerSerializeReason(from, to, reason) {
if (reason) {
let cur = from;
while (cur !== to && cur.parent) {
addSerializeReason(cur, reason, getAccessorProp().Owner);
cur = cur.parent;
}
}
}
function isReasonDynamic(reason) {
return !!reason && reason !== true && !reason.state;
}
function getSerializeReason(section, prop, prefix) {
if (prop) return section.serializeReasons.get(getPropKey(section, prop, prefix));
else return section.serializeReason;
}
function getSerializeSourcesForExpr(expr) {
if (isReferencedExtra(expr)) return getSerializeSourcesForRef(expr.referencedBindings);
}
function getSerializeSourcesForExprs(exprs) {
if (exprs) if (exprs === true) return exprs;
else if (Array.isArray(exprs)) {
let allSources;
for (const expr of exprs) allSources = mergeSources(allSources, getSerializeSourcesForExpr(expr));
return allSources;
} else return getSerializeSourcesForExpr(exprs);
}
function getSerializeSourcesForRef(ref) {
if (ref) {
let allSources;
if (Array.isArray(ref)) {
for (const { sources } of ref) allSources = mergeSources(allSources, sources);
return allSources;
} else return ref.sources;
}
}
function mergeSerializeReasons(a, b) {
if (a === true || b === true) return true;
return mergeSources(a, b);
}
function applySerializeExprs(section) {
const propExprs = propExprsBySection.get(section);
if (propExprs) {
propExprsBySection.delete(section);
for (const [key, exprs] of propExprs) {
const exprReason = getSerializeSourcesForExprs(exprs);
if (exprReason) {
const curReason = section.serializeReasons.get(key);
const newReason = mergeSerializeReasons(curReason, exprReason);
if (curReason !== newReason) setPropSerializeReason(section, key, newReason);
}
}
}
const scopeExprs = scopeExprsBySection.get(section);
if (scopeExprs) {
const exprReason = getSerializeSourcesForExprs(scopeExprs);
scopeExprsBySection.delete(section);
if (exprReason) {
const curReason = section.serializeReason;
const newReason = mergeSerializeReasons(curReason, exprReason);
if (curReason !== newReason) setSerializeReason(section, newReason);
}
}
}
function finalizeSerializeReason(section) {
const curReason = section.serializeReason;
let newReason = curReason;
if (newReason !== true) {
for (const propReason of section.serializeReasons.values()) {
if (propReason === true) {
newReason = true;
break;
}
newReason = mergeSources(newReason, propReason);
}
if (newReason && curReason !== newReason) setSerializeReason(section, newReason);
}
}
function getPropKey(section, prop, prefix) {
if (isStrOrSym(prop)) {
const keys = serializePropByModifier[prop] ||= /* @__PURE__ */ new WeakMap();
let key = keys.get(section);
if (!key) keys.set(section, key = Symbol(typeof prop === "symbol" ? `Symbol(${prop.description})` : prop));
if (prefix) throw new Error("Cannot have a scope property reason with a prefix.");
return key;
} else {
const keys = prefix ? serializePropByModifier[prefix] ||= /* @__PURE__ */ new WeakMap() : serializePropsByBinding;
const binding = getCanonicalBinding(prop);
let key = keys.get(binding);
if (!key) keys.set(binding, key = Symbol((prefix ? typeof prefix === "symbol" ? `Symbol(${prefix.description})` : prefix : "") + binding.name));
return key;
}
}
function forceSerialize(section) {
scopeExprsBySection.delete(section);
setSerializeReason(section, true);
}
function forcePropSerialize(section, key) {
setPropSerializeReason(section, key, true);
propExprsBySection.get(section)?.delete(key);
}
function isStrOrSym(v) {
switch (typeof v) {
case "string":
case "symbol": return true;
default: return false;
}
}
function setSerializeReason(section, reason) {
section.serializeReason = reason;
}
function setPropSerializeReason(section, key, reason) {
section.serializeReasons.set(key, reason);
}
//#endregion
//#region src/translator/util/state.ts
function createProgramState(init) {
const map = /* @__PURE__ */ new WeakMap();
return [() => {
let state = map.get((0, _marko_compiler_babel_utils.getProgram)());
if (!state) map.set((0, _marko_compiler_babel_utils.getProgram)(), state = init());
return state;
}, (value) => {
map.set((0, _marko_compiler_babel_utils.getProgram)(), value);
}];
}
function createSectionState(key, init) {
return [(section) => {
const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
return arrayOfSectionData[section.id] ??= init && init(section);
}, (section, value) => {
const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
arrayOfSectionData[section.id] = value;
}];
}
//#endregion
//#region src/translator/util/tag-name-type.ts
const MARKO_FILE_REG = /^<.*>$|\.marko$/;
function analyzeTagNameType(tag, allowDynamic) {
const extra = tag.node.extra ??= {};
if (extra.tagNameType === void 0) {
const name = tag.get("name");
if (name.isStringLiteral()) {
extra.tagNameType = name.node.value[0] === "@" ? 3 : (0, _marko_compiler_babel_utils.isNativeTag)(tag) ? 0 : 1;
extra.tagNameNullable = extra.tagNameDynamic = false;
} else if (name.isTemplateLiteral() && name.node.quasis.length === 1) {
extra.tagNameType = 0;
extra.tagNameNullable = extra.tagNameDynamic = false;
} else if (name.isIdentifier()) {
analyzeExpressionTagName(name, extra);
extra.tagNameDynamic = !extra.tagNameImported;
} else {
analyzeExpressionTagName(name, extra);
extra.tagNameDynamic = true;
}
if (!extra.tagNameDynamic && extra.tagNameType === 1 && !isCoreTag(tag)) {
const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
if ((0, _marko_compiler_babel_utils.getTagDef)(tag)?.renderer || childFile?.ast.program.extra.featureType === "class") {
extra.tagNameType = 2;
extra.tagNameDynamic = true;
extra.featureType = "class";
((0, _marko_compiler_babel_utils.getProgram)().node.extra ??= {}).needsCompat = true;
} else if (!childFile) {
extra.tagNameType = 2;
extra.tagNameDynamic = true;
}
}
}
return !allowDynamic && extra.tagNameDynamic ? 2 : extra.tagNameType;
}
function analyzeExpressionTagName(name, extra) {
const pending = [name];
let path;
let type;
let nullable = false;
let tagNameImported;
let tagNameLoad;
while ((path = pending.pop()) && type !== 2) if (path.isConditionalExpression()) {
pending.push(path.get("consequent"));
if (path.node.alternate) pending.push(path.get("alternate"));
} else if (path.isLogicalExpression()) {
if (path.node.operator === "||") pending.push(path.get("left"));
else nullable = true;
pending.push(path.get("right"));
} else if (path.isAssignmentExpression()) pending.push(path.get("right"));
else if (path.isBinaryExpression()) type = path.node.operator !== "+" || type === void 0 || type === 0 ? 0 : 2;
else if (path.isStringLiteral() || path.isTemplateLiteral()) type = type === void 0 || type === 0 ? 0 : 2;
else if (path.isNullLiteral()) nullable = true;
else if (path.isIdentifier()) {
if (path.node.name === "undefined") {
nullable = true;
continue;
}
const binding = path.scope.getBinding(path.node.name);
if (!binding) {
type = 2;
continue;
}
if (binding.kind === "module") {
const decl = binding.path.parent;
if (MARKO_FILE_REG.test(decl.source.value) && decl.specifiers.some((it) => _marko_compiler.types.isImportDefaultSpecifier(it))) {
const resolvedImport = decl.extra?.tagImport || decl.source.value;
if (type === void 0) {
type = 1;
tagNameImported = resolvedImport;
tagNameLoad = decl.extra?.loadImport;
} else if (type === 0) {
type = 2;
tagNameImported = void 0;
} else if (tagNameImported !== resolvedImport) tagNameImported = void 0;
} else type = 2;
continue;
}
const bindingTag = binding.path;
if (bindingTag.isMarkoTag() && binding.kind === "local") {
const bindingTagName = bindingTag.get("name").node.value;
if (bindingTagName === "const") {
pending.push(bindingTag.get("attributes")[0].get("value"));
continue;
}
if (bindingTagName === "let") {
type = 2;
continue;
}
continue;
}
type = 2;
} else type = 2;
extra.tagNameType = type ?? 2;
extra.tagNameNullable = nullable;
if (type === 1 && tagNameImported) {
extra.tagNameImported = tagNameImported;
extra.tagNameLoad = tagNameLoad;
}
}
//#endregion
//#region src/translator/util/sections.ts
const sectionUtil = new Sorted(function compareSections(a, b) {
return a.id - b.id;
});
function startSection(path) {
const extra = path.node.extra ??= {};
let section = extra.section;
if (!section && (path.type === "Program" || path.get("body").length)) {
const parentTag = path.parentPath?.isMarkoTag() ? path.parentPath : void 0;
const parentSection = path.parentPath ? getOrCreateSection(path.parentPath) : void 0;
const sectionName = parentTag ? generateUid((isCoreTagName(parentTag, "define") && _marko_compiler.types.isIdentifier(parentTag.node.var) ? parentTag.node.var.name : parentTag.get("name").toString()) + "_content") : "";
const programExtra = path.hub.file.path.node.extra ??= {};
const sections = programExtra.sections ??= [];
section = extra.section = {
id: sections.length,
name: sectionName,
loc: parentTag?.node.name.loc || void 0,
depth: parentSection ? parentSection.depth + 1 : 0,
parent: parentSection,
sectionAccessor: void 0,
params: void 0,
referencedLocalClosures: void 0,
referencedClosures: void 0,
referencedHoists: void 0,
bindings: void 0,
hoisted: void 0,
hoistedTo: void 0,
isHoistThrough: void 0,
serializeReason: void 0,
serializeReasons: /* @__PURE__ */ new Map(),
paramReasonGroups: void 0,
returnValueExpr: void 0,
returnSerializeReason: void 0,
content: getContentInfo(path),
upstreamExpression: void 0,
downstreamBinding: void 0,
hasAbortSignal: false,
readsOwner: false,
isBranch: false
};
sections.push(section);
}
return section;
}
function getOrCreateSection(path) {
let cur = path;
while (true) {
if (cur.type === "Program" || cur.type === "MarkoTagBody" && !cur.node.attributeTags && !isNativeNode(cur.parentPath)) return startSection(cur);
cur = cur.parentPath;
}
}
function getSectionForBody(body) {
return body.node.extra?.section;
}
function getSection(path) {
let section;
let currentPath = path;
while ((section = currentPath.node.extra?.section) === void 0) currentPath = currentPath.parentPath;
return section;
}
const [getScopeIdIdentifier] = createSectionState("scopeIdIdentifier", (section) => generateUidIdentifier(`scope${section.id}_id`));
const [getSectionParentIsOwner, setSectionParentIsOwner] = createSectionState("parentIsOwner", () => false);
const [getBranchRendererArgs, setBranchRendererArgs] = createSectionState("rendererExpression");
function forEachSection(fn) {
const { sections } = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
sections?.forEach(fn);
}
function forEachSectionReverse(fn) {
const { sections } = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
for (let i = sections.length; i--;) fn(sections[i]);
}
function getContentInfo(path) {
const body = path.get("body");
const contentInfo = {
startType: null,
endType: null,
singleChild: true
};
for (let endIndex = body.length; endIndex--;) {
const endType = getNodeContentType(body[endIndex], "endType", contentInfo);
if (endType !== null) {
contentInfo.endType = endType;
if (endType === 1) contentInfo.singleChild = false;
for (let startIndex = 0; startIndex < endIndex; startIndex++) {
const startType = getNodeContentType(body[startIndex], "startType");
if (startType !== null) {
contentInfo.startType = startType;
contentInfo.singleChild = false;
return contentInfo;
}
}
contentInfo.startType = getNodeContentType(body[endIndex], "startType");
return contentInfo;
}
}
return null;
}
function getNodeContentType(path, extraMember, contentInfo) {
switch (path.type) {
case "MarkoText": return 4;
case "MarkoPlaceholder": return 2;
case "MarkoScriptlet":
case "MarkoComment":
case "ImportDeclaration":
case "ExportAllDeclaration":
case "ExportNamedDeclaration":
case "ExportDefaultDeclaration": return null;
case "MarkoTag": {
const tag = path;
if (isCoreTag(tag)) switch (tag.node.name.value) {
case "html-comment": return 0;
case "html-script":
case "html-style": return 3;
case "for":
case "if":
case "await":
case "try": return 1;
default: return null;
}
else if ((0, _marko_compiler_babel_utils.isNativeTag)(tag)) return 3;
else if ((0, _marko_compiler_bab