marko 6.3.25 → 6.3.26

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.
@@ -1906,7 +1906,8 @@ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, seriali
1906
1906
  return _textarea_value(value);
1907
1907
  }
1908
1908
  function _textarea_value(value) {
1909
- return _escape(normalizeStrAttrValue(value));
1909
+ const escaped = _escape(normalizeStrAttrValue(value));
1910
+ return escaped[0] === "\n" || escaped[0] === "\r" ? "\n" + escaped : escaped;
1910
1911
  }
1911
1912
  function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1912
1913
  if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
@@ -3484,7 +3485,14 @@ function replaceAssignedNode(node) {
3484
3485
  switch (node.left.type) {
3485
3486
  case "Identifier": {
3486
3487
  const { extra } = node.left;
3487
- return isAssignedBindingExtra(extra) && getBuildAssignment(extra)?.(extra.section, node.operator === "=" ? node.right : _marko_compiler.types.binaryExpression(node.operator.slice(0, -1), createScopeReadExpression(extra.assignment, extra.section), node.right)) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
3488
+ if (isAssignedBindingExtra(extra)) {
3489
+ const { operator } = node;
3490
+ const shortCircuits = operator === "||=" || operator === "&&=" || operator === "??=";
3491
+ const readAssigned = () => createScopeReadExpression(extra.assignment, extra.section);
3492
+ const builtAssignment = getBuildAssignment(extra)?.(extra.section, operator === "=" || shortCircuits ? node.right : _marko_compiler.types.binaryExpression(operator.slice(0, -1), readAssigned(), node.right));
3493
+ if (builtAssignment) return shortCircuits ? _marko_compiler.types.logicalExpression(operator.slice(0, -1), readAssigned(), builtAssignment) : builtAssignment;
3494
+ }
3495
+ return extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
3488
3496
  }
3489
3497
  case "ArrayPattern":
3490
3498
  case "ObjectPattern": {
@@ -4298,8 +4306,8 @@ function translateAttrs(tag, propTree = true, skip, statements = [], contentKey
4298
4306
  else {
4299
4307
  const translatedAttrTag = translateAttrs(child, getKnownFromPropTree(propTree, attrTagMeta.name), void 0, statements, contentKey);
4300
4308
  const prevProp = attrTagMeta.repeated ? findObjectProperty(attrTagMeta.name, contentProperties) : void 0;
4301
- if (prevProp) prevProp.value = callRuntime("attrTags", prevProp.value, propsToExpression(translatedAttrTag.properties));
4302
- else contentProperties.push(toObjectProperty(attrTagMeta.name, callRuntime("attrTag", propsToExpression(translatedAttrTag.properties))));
4309
+ if (prevProp) prevProp.value = callRuntime("attrTags", prevProp.value, _marko_compiler.types.objectExpression(translatedAttrTag.properties));
4310
+ else contentProperties.push(toObjectProperty(attrTagMeta.name, callRuntime("attrTag", _marko_compiler.types.objectExpression(translatedAttrTag.properties))));
4303
4311
  }
4304
4312
  } else i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, propTree, contentKey);
4305
4313
  }
@@ -4339,8 +4347,8 @@ function addDynamicAttrTagStatements(attrTags, index, attrTagLookup, statements,
4339
4347
  const attrTagExport = getKnownFromPropTree(propTree, attrTagMeta.name);
4340
4348
  if (attrTagExport && attrTagMeta.dynamic) {
4341
4349
  const translatedAttrTag = translateAttrs(tag, attrTagExport, void 0, statements, contentKey);
4342
- if (attrTagMeta.repeated) statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTags", getAttrTagIdentifier(attrTagMeta), propsToExpression(translatedAttrTag.properties)))));
4343
- else statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTag", propsToExpression(translatedAttrTag.properties)))));
4350
+ if (attrTagMeta.repeated) statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTags", getAttrTagIdentifier(attrTagMeta), _marko_compiler.types.objectExpression(translatedAttrTag.properties)))));
4351
+ else statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTag", _marko_compiler.types.objectExpression(translatedAttrTag.properties)))));
4344
4352
  }
4345
4353
  } else switch (getTagName(tag)) {
4346
4354
  case "if": return translateIfAttrTag(attrTags, index, attrTagLookup, statements, propTree, contentKey);
@@ -4348,6 +4356,8 @@ function addDynamicAttrTagStatements(attrTags, index, attrTagLookup, statements,
4348
4356
  }
4349
4357
  return index;
4350
4358
  }
4359
+ /** Unwraps a lone spread to the spread argument itself, so the result may alias
4360
+ * a caller binding; anything the runtime writes to needs its own object. */
4351
4361
  function propsToExpression(props) {
4352
4362
  return props.length === 1 && _marko_compiler.types.isSpreadElement(props[0]) ? props[0].argument : _marko_compiler.types.objectExpression(props);
4353
4363
  }
@@ -4761,7 +4771,7 @@ var native_tag_default = {
4761
4771
  const canHaveAttrContent = !(isTextOnly || isOpenOnly || hasChildren || staticContentAttr);
4762
4772
  const name = tag.get("name");
4763
4773
  const staticName = name.isStringLiteral() ? name.node.value : void 0;
4764
- const controllable = controllableClaimFor(staticName);
4774
+ const controllable = !staticControllable && controllableClaimFor(staticName);
4765
4775
  if (skipExpression) addStatement("render", tagSection, tagExtra.referencedBindings, _marko_compiler.types.expressionStatement(callRuntime(canHaveAttrContent ? "_attrs_partial_content" : "_attrs_partial", scopeIdentifier, visitAccessor, spreadExpression, skipExpression, controllable && importRuntime(controllable))));
4766
4776
  else addStatement("render", tagSection, tagExtra.referencedBindings, _marko_compiler.types.expressionStatement(callRuntime(canHaveAttrContent ? "_attrs_content" : "_attrs", scopeIdentifier, visitAccessor, spreadExpression, controllable && importRuntime(controllable))));
4767
4777
  enableControllable(controllableScriptLatchFor(staticName));
@@ -5174,8 +5184,9 @@ function isDynamicControllable(controllable) {
5174
5184
  function buildUndefined$1() {
5175
5185
  return _marko_compiler.types.unaryExpression("void", _marko_compiler.types.numericLiteral(0));
5176
5186
  }
5177
- /** How a statically named tag claims its controlled attrs during render;
5178
- * nothing for the many tags that control nothing. */
5187
+ /** How a spread claims its controlled attrs during render; nothing for the many
5188
+ * tags that control nothing, and nothing when a static attr owns the
5189
+ * controllable, since then the spread must leave the slots it wrote alone. */
5179
5190
  function controllableClaimFor(tagName) {
5180
5191
  switch (tagName) {
5181
5192
  case "input": return "_controllable_input";
@@ -6298,6 +6309,7 @@ function applyAttrObject(tag, propTree, tagInputIdentifier, info) {
6298
6309
  let translatedProps = propsToExpression(translatedAttrs.properties);
6299
6310
  if (translatedAttrs.statements.length) addStatement("render", info.tagSection, referencedBindings, translatedAttrs.statements);
6300
6311
  if ((0, _marko_compiler_babel_utils.isAttributeTag)(tag)) {
6312
+ translatedProps = _marko_compiler.types.objectExpression(translatedAttrs.properties);
6301
6313
  const attrTagName = getTagName(tag);
6302
6314
  const parentTag = tag.parentPath;
6303
6315
  if (analyzeAttributeTags(parentTag)?.[attrTagName]?.repeated) {
@@ -6313,7 +6325,8 @@ function applyAttrObject(tag, propTree, tagInputIdentifier, info) {
6313
6325
  addStatement("render", info.tagSection, referencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(tagInputIdentifier, [createScopeReadExpression(info.childScopeBinding, info.tagSection), translatedProps])), void 0, true);
6314
6326
  }
6315
6327
  function translateAttrTag(tag, attrTagMeta, info, statements) {
6316
- let translatedProps = propsToExpression(translateAttrs(tag, true, void 0, statements).properties);
6328
+ const translatedAttrs = translateAttrs(tag, true, void 0, statements);
6329
+ let translatedProps = _marko_compiler.types.objectExpression(translatedAttrs.properties);
6317
6330
  const attrTagName = getTagName(tag);
6318
6331
  const parentTag = tag.parentPath;
6319
6332
  if (attrTagMeta.repeated) {
@@ -8022,17 +8035,17 @@ var define_default = {
8022
8035
  let allDirectReferences = true;
8023
8036
  for (const ref of babelBinding.referencePaths) if (ref.parent.type === "MarkoTag" && ref.parent.name === ref.node) hasDirectReferences = true;
8024
8037
  else allDirectReferences = false;
8025
- if (hasDirectReferences) {
8038
+ if (allDirectReferences) {
8026
8039
  const bodySection = getSectionForBody(tag.get("body"));
8027
8040
  if (bodySection) {
8028
- const signal = getSignal(bodySection, void 0);
8029
- signal.build = () => {
8030
- if (signalHasStatements(signal)) return callRuntime("_child_setup", getSignalFn(signal));
8031
- };
8032
- if (allDirectReferences) {
8033
- tag.remove();
8034
- return;
8041
+ if (hasDirectReferences) {
8042
+ const signal = getSignal(bodySection, void 0);
8043
+ signal.build = () => {
8044
+ if (signalHasStatements(signal)) return callRuntime("_child_setup", getSignalFn(signal));
8045
+ };
8035
8046
  }
8047
+ tag.remove();
8048
+ return;
8036
8049
  }
8037
8050
  }
8038
8051
  }
@@ -8077,7 +8090,9 @@ var effect_default = {
8077
8090
  var export_default = {
8078
8091
  parse(tag) {
8079
8092
  const { node } = tag;
8080
- tag.replaceWith((0, _marko_compiler_babel_utils.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]);
8093
+ const statements = (0, _marko_compiler_babel_utils.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end);
8094
+ if (statements.length > 1) throw tag.hub.buildError(statements[1], "The `<export>` tag takes a single export statement.");
8095
+ tag.replaceWith(statements[0]);
8081
8096
  },
8082
8097
  parseOptions: {
8083
8098
  statement: true,
@@ -8242,7 +8257,9 @@ var id_default = {
8242
8257
  var import_default = {
8243
8258
  parse(tag) {
8244
8259
  const { node } = tag;
8245
- tag.replaceWith((0, _marko_compiler_babel_utils.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]);
8260
+ const statements = (0, _marko_compiler_babel_utils.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end);
8261
+ if (statements.length > 1) throw tag.hub.buildError(statements[1], "The [`<import>` tag](https://markojs.com/docs/syntax/#importing-external-files) takes a single import statement.");
8262
+ tag.replaceWith(statements[0]);
8246
8263
  },
8247
8264
  parseOptions: {
8248
8265
  statement: true,
@@ -9685,12 +9702,13 @@ const kDOMBinding = Symbol("dynamic tag dom binding");
9685
9702
  const kChildOffsetScopeBinding = Symbol("custom tag scope offset");
9686
9703
  const importedDynamicTagResume = /* @__PURE__ */ new WeakSet();
9687
9704
  const [getCompatRegistrations] = createProgramState(() => /* @__PURE__ */ new Set());
9705
+ const [getCompatBoundaryCalls] = createProgramState(() => /* @__PURE__ */ new Map());
9688
9706
  function pushCompatRegistration(key, statement) {
9689
9707
  const keys = getCompatRegistrations();
9690
- if (!keys.has(key)) {
9691
- keys.add(key);
9692
- (0, _marko_compiler_babel_utils.getProgram)().node.body.push(statement);
9693
- }
9708
+ if (keys.has(key)) return false;
9709
+ keys.add(key);
9710
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(statement);
9711
+ return true;
9694
9712
  }
9695
9713
  var dynamic_tag_default = {
9696
9714
  analyze: { enter(tag) {
@@ -9772,11 +9790,19 @@ var dynamic_tag_default = {
9772
9790
  if (_marko_compiler.types.isStringLiteral(tagExpression)) tagExpression = (0, _marko_compiler_babel_utils.importDefault)(tag.hub.file, getTagRelativePath(tag), tagExpression.value);
9773
9791
  if (classTagTemplate) {
9774
9792
  const preserveBoundary = !tagsSerializeReason && (classHydration === "descendant" || classHydration === "self" && !!classFile?.metadata.marko.hasComponentBrowser);
9775
- if (isOutputHTML() ? serializeReason || classHydration : serializeReason) pushCompatRegistration(classFile.metadata.marko.id, isOutputHTML() ? _marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"), [
9776
- _marko_compiler.types.stringLiteral(classFile.metadata.marko.id),
9793
+ const classId = classFile.metadata.marko.id;
9794
+ const registration = isOutputHTML() ? _marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"), [
9795
+ _marko_compiler.types.stringLiteral(classId),
9777
9796
  _marko_compiler.types.identifier(tagExpression.name),
9778
9797
  ...preserveBoundary ? [_marko_compiler.types.stringLiteral("preserve")] : []
9779
- ]))], true) : _marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.stringLiteral(classFile.metadata.marko.id), _marko_compiler.types.identifier(tagExpression.name))));
9798
+ ]) : void 0;
9799
+ if (isOutputHTML() ? serializeReason || classHydration : serializeReason) {
9800
+ if (pushCompatRegistration(classId, registration ? _marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(registration)], true) : _marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.stringLiteral(classId), _marko_compiler.types.identifier(tagExpression.name)))) && registration) getCompatBoundaryCalls().set(classId, registration);
9801
+ }
9802
+ if (!preserveBoundary) {
9803
+ const emitted = getCompatBoundaryCalls().get(classId);
9804
+ if (emitted) emitted.arguments.length = 2;
9805
+ }
9780
9806
  } else {
9781
9807
  const rendererName = tagExpression.name;
9782
9808
  pushCompatRegistration(rendererName, _marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("??=", _marko_compiler.types.memberExpression(_marko_compiler.types.identifier(rendererName), _marko_compiler.types.identifier("_")), _marko_compiler.types.identifier(rendererName)))], true));
@@ -9977,7 +10003,7 @@ var text_default = {
9977
10003
  function buildAggregateError(file, rootMsg, ...paths) {
9978
10004
  const err = /* @__PURE__ */ new SyntaxError();
9979
10005
  const fileName = path.default.relative(_marko_compiler_modules.cwd, file.opts.filename);
9980
- const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$10]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$10)}:\x1b[0m\n${getFrame(file, path$10)}`).join("\n\n")}`;
10006
+ const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$12]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$12)}:\x1b[0m\n${getFrame(file, path$12)}`).join("\n\n")}`;
9981
10007
  if (!("MARKO_DEBUG" in process.env)) err.stack = finalMsg;
9982
10008
  Object.defineProperty(err, "message", {
9983
10009
  get() {
@@ -10094,9 +10120,11 @@ function getFeatureTypeFromCoreTagName(tagName) {
10094
10120
  case "macro":
10095
10121
  case "module-code":
10096
10122
  case "while": return Class;
10123
+ case "attrs":
10097
10124
  case "const":
10098
10125
  case "debug":
10099
10126
  case "define":
10127
+ case "effect":
10100
10128
  case "id":
10101
10129
  case "let":
10102
10130
  case "lifecycle":
@@ -10249,11 +10277,15 @@ function mergeTagDef(def5, def6) {
10249
10277
  }
10250
10278
  function mergeObjects(a, b, cb) {
10251
10279
  const merged = {};
10280
+ const assign = (key, aValue, bValue) => {
10281
+ const value = cb(key, aValue, bValue);
10282
+ if (value !== void 0) merged[key] = value;
10283
+ };
10252
10284
  if (a) if (b) {
10253
- for (const key in a) merged[key] = cb(key, a[key], b[key]);
10254
- for (const key in b) if (!(key in a)) merged[key] = cb(key, void 0, b[key]);
10255
- } else for (const key in a) merged[key] = cb(key, a[key], void 0);
10256
- else if (b) for (const key in b) merged[key] = cb(key, void 0, b[key]);
10285
+ for (const key in a) assign(key, a[key], b[key]);
10286
+ for (const key in b) if (!(key in a)) assign(key, void 0, b[key]);
10287
+ } else for (const key in a) assign(key, a[key], void 0);
10288
+ else if (b) for (const key in b) assign(key, void 0, b[key]);
10257
10289
  return merged;
10258
10290
  }
10259
10291
  function normalizeTagDef(tagDef) {
@@ -10279,8 +10311,34 @@ function normalizeVisitor(visitor) {
10279
10311
  return visitor?.default ?? visitor;
10280
10312
  }
10281
10313
  function normalizeVisit(visitor) {
10314
+ if (Array.isArray(visitor)) {
10315
+ let merged;
10316
+ for (const entry of visitor) merged = sequenceVisit(merged, normalizeVisit(entry));
10317
+ return merged;
10318
+ }
10282
10319
  return typeof visitor === "function" ? visitor : normalizeVisitor(visitor);
10283
10320
  }
10321
+ function sequenceVisit(first, second) {
10322
+ if (!first || !second) return first || second;
10323
+ const enterFirst = getVisitorEnter(first);
10324
+ const enterSecond = getVisitorEnter(second);
10325
+ const enter = (enterFirst || enterSecond) && function enter(path$10, state) {
10326
+ const { node } = path$10;
10327
+ enterFirst?.call(this, path$10, state);
10328
+ if (path$10.node === node) enterSecond?.call(this, path$10, state);
10329
+ };
10330
+ const exitFirst = getVisitorExit(first);
10331
+ const exitSecond = getVisitorExit(second);
10332
+ const exit = (exitFirst || exitSecond) && function exit(path$11, state) {
10333
+ const { node } = path$11;
10334
+ exitFirst?.call(this, path$11, state);
10335
+ if (path$11.node === node) exitSecond?.call(this, path$11, state);
10336
+ };
10337
+ return exit ? enter ? {
10338
+ enter,
10339
+ exit
10340
+ } : { exit } : enter;
10341
+ }
10284
10342
  function getVisitorEnter(visit) {
10285
10343
  return typeof visit === "function" ? visit : visit?.enter;
10286
10344
  }
@@ -10,5 +10,7 @@ export declare function getTranslatedBodyContentProperty(props: t.ObjectExpressi
10
10
  value: t.Expression;
11
11
  }) | undefined;
12
12
  export declare function addDynamicAttrTagStatements(attrTags: t.NodePath<t.MarkoTag["attributeTags"][number]>[], index: number, attrTagLookup: AttrTagLookup, statements: t.Statement[], propTree: BindingPropTree | true, contentKey?: ContentKey): number;
13
+ /** Unwraps a lone spread to the spread argument itself, so the result may alias
14
+ * a caller binding; anything the runtime writes to needs its own object. */
13
15
  export declare function propsToExpression(props: t.ObjectExpression["properties"]): t.Expression;
14
16
  export {};
@@ -21,8 +21,9 @@ declare const _default: {
21
21
  };
22
22
  };
23
23
  export default _default;
24
- /** How a statically named tag claims its controlled attrs during render;
25
- * nothing for the many tags that control nothing. */
24
+ /** How a spread claims its controlled attrs during render; nothing for the many
25
+ * tags that control nothing, and nothing when a static attr owns the
26
+ * controllable, since then the spread must leave the slots it wrote alone. */
26
27
  export declare function controllableClaimFor(tagName: string | undefined): "_controllable_input" | "_controllable_open" | "_controllable_select" | "_controllable_textarea" | undefined;
27
28
  /** The resume-pass latch for a tag: `_attrs_script` resolves the control kind
28
29
  * at run time, and a run-time tag name can be any of them. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.3.25",
3
+ "version": "6.3.26",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -48,14 +48,14 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@marko/compiler": "^5.41.9",
51
+ "@marko/compiler": "^5.41.10",
52
52
  "csstype": "^3.2.3",
53
53
  "fastest-levenshtein": "^1.0.16",
54
54
  "magic-string": "^0.30.21"
55
55
  },
56
56
  "devDependencies": {
57
- "marko": "5.39.29",
58
- "@marko/runtime-tags": "npm:marko@6.3.25"
57
+ "marko": "5.39.30",
58
+ "@marko/runtime-tags": "npm:marko@6.3.26"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"