@marko/runtime-tags 6.3.1 → 6.3.2

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.
@@ -220,8 +220,8 @@ function _escape(val) {
220
220
  assertValidTextValue(val);
221
221
  return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
222
222
  }
223
- const unsafeScriptReg = /<\/script/gi;
224
- const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C/script") : str;
223
+ const unsafeScriptReg = /<(\/?script|!--)/gi;
224
+ const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
225
225
  function _escape_script(val) {
226
226
  assertValidTextValue(val);
227
227
  return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
@@ -648,7 +648,7 @@ function writeAssigned(state) {
648
648
  } else state.buf.push("void 0");
649
649
  const valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
650
650
  if (mutation.value === void 0) {} else if (writeProp(state, mutation.value, null, "")) {
651
- const valueRef = state.refs.get(mutation.value);
651
+ const valueRef = typeof mutation.value === "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
652
652
  if (valueRef && !valueRef.id && valueRef.scopeId === void 0) {
653
653
  valueRef.id = mutation.valueId || nextRefAccess(state);
654
654
  state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex];
@@ -1161,7 +1161,7 @@ function writeReadableStream(state, val, ref) {
1161
1161
  }
1162
1162
  function writeGenerator(state, iter, ref) {
1163
1163
  if (iter[kTouchedIterator]) {
1164
- state.buf.push("(async function*(){}())");
1164
+ state.buf.push("(function*(){}())");
1165
1165
  return true;
1166
1166
  }
1167
1167
  let sep = "";
@@ -218,8 +218,8 @@ function _escape(val) {
218
218
  assertValidTextValue(val);
219
219
  return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
220
220
  }
221
- const unsafeScriptReg = /<\/script/gi;
222
- const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C/script") : str;
221
+ const unsafeScriptReg = /<(\/?script|!--)/gi;
222
+ const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
223
223
  function _escape_script(val) {
224
224
  assertValidTextValue(val);
225
225
  return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
@@ -646,7 +646,7 @@ function writeAssigned(state) {
646
646
  } else state.buf.push("void 0");
647
647
  const valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
648
648
  if (mutation.value === void 0) {} else if (writeProp(state, mutation.value, null, "")) {
649
- const valueRef = state.refs.get(mutation.value);
649
+ const valueRef = typeof mutation.value === "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
650
650
  if (valueRef && !valueRef.id && valueRef.scopeId === void 0) {
651
651
  valueRef.id = mutation.valueId || nextRefAccess(state);
652
652
  state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex];
@@ -1159,7 +1159,7 @@ function writeReadableStream(state, val, ref) {
1159
1159
  }
1160
1160
  function writeGenerator(state, iter, ref) {
1161
1161
  if (iter[kTouchedIterator]) {
1162
- state.buf.push("(async function*(){}())");
1162
+ state.buf.push("(function*(){}())");
1163
1163
  return true;
1164
1164
  }
1165
1165
  let sep = "";
package/dist/html.js CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
4
4
  else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
5
  else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
6
6
  return str;
7
- }, unsafeXMLReg = /[<&]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<\/script/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C/script") : str, unsafeStyleReg = /<\/style/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C/style") : str, unsafeCommentReg = />/g, escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = Symbol.for("marko.touchedIterator"), { hasOwnProperty: hasOwnProperty$1 } = {}, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
7
+ }, unsafeXMLReg = /[<&]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<(\/?script|!--)/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str, unsafeStyleReg = /<\/style/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C/style") : str, unsafeCommentReg = />/g, escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = Symbol.for("marko.touchedIterator"), { hasOwnProperty: hasOwnProperty$1 } = {}, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
8
8
  let KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
9
9
  for (let name of Object.getOwnPropertyNames(Symbol)) {
10
10
  let symbol = Symbol[name];
@@ -534,7 +534,7 @@ function writeAssigned(state) {
534
534
  } else state.buf.push("void 0");
535
535
  let valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
536
536
  if (mutation.value !== void 0) if (writeProp(state, mutation.value, null, "")) {
537
- let valueRef = state.refs.get(mutation.value);
537
+ let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
538
538
  valueRef && !valueRef.id && valueRef.scopeId === void 0 && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
539
539
  } else state.buf.push("void 0");
540
540
  state.buf.push(")");
@@ -819,7 +819,7 @@ function writeReadableStream(state, val, ref) {
819
819
  return state.buf.push("new ReadableStream({start(c){(async(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()]))=>{for(i of a)v=await i,i==l?c.close():c.enqueue(v)})(" + iterId + "={}).catch(e=>c.error(e))}})"), reader.read().then(onFulfilled, onRejected), boundary.startAsync(), !0;
820
820
  }
821
821
  function writeGenerator(state, iter, ref) {
822
- if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
822
+ if (iter[kTouchedIterator]) return state.buf.push("(function*(){}())"), !0;
823
823
  let sep = "";
824
824
  for (state.buf.push("(function*(){");;) {
825
825
  let { value, done } = iter.next();
package/dist/html.mjs CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
4
4
  else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
5
  else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
6
6
  return str;
7
- }, unsafeXMLReg = /[<&]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<\/script/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C/script") : str, unsafeStyleReg = /<\/style/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C/style") : str, unsafeCommentReg = />/g, escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = Symbol.for("marko.touchedIterator"), { hasOwnProperty: hasOwnProperty$1 } = {}, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
7
+ }, unsafeXMLReg = /[<&]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<(\/?script|!--)/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str, unsafeStyleReg = /<\/style/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C/style") : str, unsafeCommentReg = />/g, escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = Symbol.for("marko.touchedIterator"), { hasOwnProperty: hasOwnProperty$1 } = {}, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
8
8
  let KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
9
9
  for (let name of Object.getOwnPropertyNames(Symbol)) {
10
10
  let symbol = Symbol[name];
@@ -533,7 +533,7 @@ function writeAssigned(state) {
533
533
  } else state.buf.push("void 0");
534
534
  let valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
535
535
  if (mutation.value !== void 0) if (writeProp(state, mutation.value, null, "")) {
536
- let valueRef = state.refs.get(mutation.value);
536
+ let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
537
537
  valueRef && !valueRef.id && valueRef.scopeId === void 0 && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
538
538
  } else state.buf.push("void 0");
539
539
  state.buf.push(")");
@@ -818,7 +818,7 @@ function writeReadableStream(state, val, ref) {
818
818
  return state.buf.push("new ReadableStream({start(c){(async(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()]))=>{for(i of a)v=await i,i==l?c.close():c.enqueue(v)})(" + iterId + "={}).catch(e=>c.error(e))}})"), reader.read().then(onFulfilled, onRejected), boundary.startAsync(), !0;
819
819
  }
820
820
  function writeGenerator(state, iter, ref) {
821
- if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
821
+ if (iter[kTouchedIterator]) return state.buf.push("(function*(){}())"), !0;
822
822
  let sep = "";
823
823
  for (state.buf.push("(function*(){");;) {
824
824
  let { value, done } = iter.next();
@@ -1713,8 +1713,8 @@ const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg,
1713
1713
  function _escape(val) {
1714
1714
  return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
1715
1715
  }
1716
- const unsafeScriptReg = /<\/script/gi;
1717
- const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C/script") : str;
1716
+ const unsafeScriptReg = /<(\/?script|!--)/gi;
1717
+ const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
1718
1718
  function _escape_script(val) {
1719
1719
  return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
1720
1720
  }
@@ -4300,6 +4300,7 @@ var native_tag_default = {
4300
4300
  (0, _marko_compiler_babel_utils.getProgram)().node.extra.page ??= true;
4301
4301
  break;
4302
4302
  }
4303
+ if (tagName === "option") assertOptionInSelectWithValue(tag);
4303
4304
  const isTextOnly = isTextOnlyNativeTag(tag);
4304
4305
  const seen = {};
4305
4306
  const { attributes } = tag.node;
@@ -4796,6 +4797,31 @@ function getCanonicalTagName(tag) {
4796
4797
  default: return tagName;
4797
4798
  }
4798
4799
  }
4800
+ function assertOptionInSelectWithValue(tag) {
4801
+ let parent = tag.parentPath;
4802
+ while (parent) {
4803
+ if (parent.isMarkoTag()) {
4804
+ if (analyzeTagNameType(parent) === 0) {
4805
+ const parentName = getCanonicalTagName(parent);
4806
+ if (parentName === "select") {
4807
+ if (parent.node.attributes.some((attr) => _marko_compiler.types.isMarkoAttribute(attr) && (attr.name === "value" || attr.name === "valueChange"))) {
4808
+ let hasValue = false;
4809
+ const attributes = tag.get("attributes");
4810
+ for (let i = 0; i < attributes.length; i++) {
4811
+ const attr = attributes[i].node;
4812
+ if (!_marko_compiler.types.isMarkoAttribute(attr) || attr.name === "value") hasValue = true;
4813
+ else if (attr.name === "selected") throw attributes[i].buildCodeFrameError("The `selected` attribute is not supported on an `<option>` within a `<select>` that has a `value` attribute; include the option's `value` in the select's `value` instead.");
4814
+ }
4815
+ if (!hasValue) throw tag.buildCodeFrameError("An `<option>` within a `<select>` that has a `value` attribute must also have a `value` attribute.");
4816
+ }
4817
+ return;
4818
+ }
4819
+ if (parentName !== "optgroup") return;
4820
+ } else if (!isControlFlowTag(parent)) return;
4821
+ } else if (parent.isProgram()) return;
4822
+ parent = parent.parentPath;
4823
+ }
4824
+ }
4799
4825
  function getTextOnlyEscapeHelper(tagName) {
4800
4826
  switch (tagName) {
4801
4827
  case "script": return "_escape_script";
@@ -7772,6 +7798,7 @@ var export_default = {
7772
7798
  //#endregion
7773
7799
  //#region src/translator/core/html-comment.ts
7774
7800
  const kNodeBinding$1 = Symbol("comment tag binding");
7801
+ const escapeCommentText = (text) => text.replace(/>/g, "&gt;");
7775
7802
  var html_comment_default = {
7776
7803
  analyze(tag) {
7777
7804
  (0, _marko_compiler_babel_utils.assertNoArgs)(tag);
@@ -7809,11 +7836,11 @@ var html_comment_default = {
7809
7836
  const nodeBinding = tagExtra[kNodeBinding$1];
7810
7837
  const write = writeTo(tag);
7811
7838
  if (isOutputHTML()) {
7812
- for (const child of tag.node.body.body) if (_marko_compiler.types.isMarkoText(child)) write`${child.value}`;
7839
+ for (const child of tag.node.body.body) if (_marko_compiler.types.isMarkoText(child)) write`${escapeCommentText(child.value)}`;
7813
7840
  else if (_marko_compiler.types.isMarkoPlaceholder(child)) write`${callRuntime(child.escape ? "_escape_comment" : "_unescaped", child.value)}`;
7814
7841
  } else {
7815
7842
  const textLiteral = bodyToTextLiteral(tag.node.body);
7816
- if (_marko_compiler.types.isStringLiteral(textLiteral)) write`${textLiteral}`;
7843
+ if (_marko_compiler.types.isStringLiteral(textLiteral)) write`${escapeCommentText(textLiteral.value)}`;
7817
7844
  else addStatement("render", tagSection, tagExtra.referencedBindings, _marko_compiler.types.expressionStatement(callRuntime("_text", createScopeReadExpression(nodeBinding), textLiteral)));
7818
7845
  }
7819
7846
  exit(tag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/runtime-tags",
3
- "version": "6.3.1",
3
+ "version": "6.3.2",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",