refactor: rename _to_text to _escape_text

This commit is contained in:
dpiercey 2025-12-04 09:47:24 -07:00 committed by Dylan Piercey
parent 3de60b9c82
commit 66ccfd8e8f
10 changed files with 16 additions and 11 deletions

View File

@ -0,0 +1,5 @@
---
"@marko/runtime-tags": patch
---
Rename \_to_text helper to \_escape_text on the server.

View File

@ -2,7 +2,7 @@ import * as _ from "@marko/runtime-tags/debug/html";
export default _._template("__tests__/template.marko", input => {
const $scope0_id = _._scope_id();
let count = 0;
_._html(`<div><button>${_._escape(count)}${_._el_resume($scope0_id, "#text/1")}</button>${_._el_resume($scope0_id, "#button/0")}<!--${_._to_text(count)} + ${_._to_text(count)} = ${_._to_text(count + count)}-->${_._el_resume($scope0_id, "#comment/2")}</div>`);
_._html(`<div><button>${_._escape(count)}${_._el_resume($scope0_id, "#text/1")}</button>${_._el_resume($scope0_id, "#button/0")}<!--${_._escape_text(count)} + ${_._escape_text(count)} = ${_._escape_text(count + count)}-->${_._el_resume($scope0_id, "#comment/2")}</div>`);
_._script($scope0_id, "__tests__/template.marko_0_count");
_._scope($scope0_id, {
count

View File

@ -2,7 +2,7 @@ import * as _ from "@marko/runtime-tags/debug/html";
export default _._template("__tests__/template.marko", input => {
const $scope0_id = _._scope_id();
let value = "before";
_._html(`<textarea>${_._to_text(value)}</textarea>${_._el_resume($scope0_id, "#textarea/0")}<button>update</button>${_._el_resume($scope0_id, "#button/1")}`);
_._html(`<textarea>${_._escape_text(value)}</textarea>${_._el_resume($scope0_id, "#textarea/0")}<button>update</button>${_._el_resume($scope0_id, "#button/1")}`);
_._script($scope0_id, "__tests__/template.marko_0");
_._scope($scope0_id, {}, "__tests__/template.marko", 0);
_._resume_branch($scope0_id);

View File

@ -2,7 +2,7 @@ import * as _ from "@marko/runtime-tags/debug/html";
export default _._template("__tests__/template.marko", input => {
const $scope0_id = _._scope_id();
let count = 0;
_._html(`<title>Count is ${_._to_text(count)}</title>${_._el_resume($scope0_id, "#title/0")}<button>+</button>${_._el_resume($scope0_id, "#button/1")}<div></div>${_._el_resume($scope0_id, "#div/2")}`);
_._html(`<title>Count is ${_._escape_text(count)}</title>${_._el_resume($scope0_id, "#title/0")}<button>+</button>${_._el_resume($scope0_id, "#button/1")}<div></div>${_._el_resume($scope0_id, "#div/2")}`);
_._script($scope0_id, "__tests__/template.marko_0_count");
_._scope($scope0_id, {
count

View File

@ -1,5 +1,5 @@
import * as _ from "@marko/runtime-tags/debug/html";
export default _._template("__tests__/template.marko", input => {
const $scope0_id = _._scope_id();
_._html(`<textarea>${_._to_text("hello")}</textarea>`);
_._html(`<textarea>${_._escape_text("hello")}</textarea>`);
});

View File

@ -27,7 +27,7 @@ export {
_escape,
_escape_script,
_escape_style,
_to_text,
_escape_text,
_unescaped,
} from "./html/content";
export { _content, _content_resume, _dynamic_tag } from "./html/dynamic-tag";

View File

@ -7,7 +7,7 @@ import {
styleValue,
} from "../common/helpers";
import { type Accessor, AccessorPrefix, ControlledType } from "../common/types";
import { _to_text } from "./content";
import { _escape_text } from "./content";
import {
_attr_content,
_html,
@ -78,7 +78,7 @@ export function _attr_textarea_value(
);
}
return _to_text(value);
return _escape_text(value);
}
export function _attr_input_value(

View File

@ -10,7 +10,7 @@ export function _escape(val: unknown) {
return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "&zwj;";
}
export function _to_text(val: unknown) {
export function _escape_text(val: unknown) {
return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
}

View File

@ -110,7 +110,7 @@ export default {
if (t.isMarkoText(child)) {
write`${child.value}`;
} else if (t.isMarkoPlaceholder(child)) {
write`${callRuntime("_to_text", child.value)}`;
write`${callRuntime("_escape_text", child.value)}`;
}
}
} else {

View File

@ -314,7 +314,7 @@ export default {
valueChange,
);
} else if (value) {
writeAtStartOfBody = callRuntime("_to_text", value);
writeAtStartOfBody = callRuntime("_escape_text", value);
}
}
@ -483,7 +483,7 @@ export default {
if (t.isMarkoText(child)) {
write`${child.value}`;
} else if (t.isMarkoPlaceholder(child)) {
write`${callRuntime("_to_text", child.value)}`;
write`${callRuntime("_escape_text", child.value)}`;
}
}
} else {