From 66ccfd8e8f4ea277fb504464afca79b7ee6245d4 Mon Sep 17 00:00:00 2001 From: dpiercey Date: Thu, 4 Dec 2025 09:47:24 -0700 Subject: [PATCH] refactor: rename _to_text to _escape_text --- .changeset/dirty-cloths-rest.md | 5 +++++ .../__snapshots__/html.expected/template.js | 2 +- .../__snapshots__/html.expected/template.js | 2 +- .../title-counter/__snapshots__/html.expected/template.js | 2 +- .../__snapshots__/html.expected/template.js | 2 +- packages/runtime-tags/src/html.ts | 2 +- packages/runtime-tags/src/html/attrs.ts | 4 ++-- packages/runtime-tags/src/html/content.ts | 2 +- packages/runtime-tags/src/translator/core/html-comment.ts | 2 +- .../runtime-tags/src/translator/visitors/tag/native-tag.ts | 4 ++-- 10 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 .changeset/dirty-cloths-rest.md diff --git a/.changeset/dirty-cloths-rest.md b/.changeset/dirty-cloths-rest.md new file mode 100644 index 000000000..170ce471c --- /dev/null +++ b/.changeset/dirty-cloths-rest.md @@ -0,0 +1,5 @@ +--- +"@marko/runtime-tags": patch +--- + +Rename \_to_text helper to \_escape_text on the server. diff --git a/packages/runtime-tags/src/__tests__/fixtures/html-comment-counter/__snapshots__/html.expected/template.js b/packages/runtime-tags/src/__tests__/fixtures/html-comment-counter/__snapshots__/html.expected/template.js index 9652ee05e..8a2e35c67 100644 --- a/packages/runtime-tags/src/__tests__/fixtures/html-comment-counter/__snapshots__/html.expected/template.js +++ b/packages/runtime-tags/src/__tests__/fixtures/html-comment-counter/__snapshots__/html.expected/template.js @@ -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(`
${_._el_resume($scope0_id, "#button/0")}${_._el_resume($scope0_id, "#comment/2")}
`); + _._html(`
${_._el_resume($scope0_id, "#button/0")}${_._el_resume($scope0_id, "#comment/2")}
`); _._script($scope0_id, "__tests__/template.marko_0_count"); _._scope($scope0_id, { count diff --git a/packages/runtime-tags/src/__tests__/fixtures/textarea-dynamic-text/__snapshots__/html.expected/template.js b/packages/runtime-tags/src/__tests__/fixtures/textarea-dynamic-text/__snapshots__/html.expected/template.js index 99f32138a..fa12d2710 100644 --- a/packages/runtime-tags/src/__tests__/fixtures/textarea-dynamic-text/__snapshots__/html.expected/template.js +++ b/packages/runtime-tags/src/__tests__/fixtures/textarea-dynamic-text/__snapshots__/html.expected/template.js @@ -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(`${_._el_resume($scope0_id, "#textarea/0")}${_._el_resume($scope0_id, "#button/1")}`); + _._html(`${_._el_resume($scope0_id, "#textarea/0")}${_._el_resume($scope0_id, "#button/1")}`); _._script($scope0_id, "__tests__/template.marko_0"); _._scope($scope0_id, {}, "__tests__/template.marko", 0); _._resume_branch($scope0_id); diff --git a/packages/runtime-tags/src/__tests__/fixtures/title-counter/__snapshots__/html.expected/template.js b/packages/runtime-tags/src/__tests__/fixtures/title-counter/__snapshots__/html.expected/template.js index 3ebe9a134..23e8a6ecd 100644 --- a/packages/runtime-tags/src/__tests__/fixtures/title-counter/__snapshots__/html.expected/template.js +++ b/packages/runtime-tags/src/__tests__/fixtures/title-counter/__snapshots__/html.expected/template.js @@ -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(`Count is ${_._to_text(count)}${_._el_resume($scope0_id, "#title/0")}${_._el_resume($scope0_id, "#button/1")}
${_._el_resume($scope0_id, "#div/2")}`); + _._html(`Count is ${_._escape_text(count)}${_._el_resume($scope0_id, "#title/0")}${_._el_resume($scope0_id, "#button/1")}
${_._el_resume($scope0_id, "#div/2")}`); _._script($scope0_id, "__tests__/template.marko_0_count"); _._scope($scope0_id, { count diff --git a/packages/runtime-tags/src/__tests__/fixtures/uncontrolled-textarea-value/__snapshots__/html.expected/template.js b/packages/runtime-tags/src/__tests__/fixtures/uncontrolled-textarea-value/__snapshots__/html.expected/template.js index f1e826b15..a5b1ab777 100644 --- a/packages/runtime-tags/src/__tests__/fixtures/uncontrolled-textarea-value/__snapshots__/html.expected/template.js +++ b/packages/runtime-tags/src/__tests__/fixtures/uncontrolled-textarea-value/__snapshots__/html.expected/template.js @@ -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(``); + _._html(``); }); \ No newline at end of file diff --git a/packages/runtime-tags/src/html.ts b/packages/runtime-tags/src/html.ts index 509fcd56a..e3529a69b 100644 --- a/packages/runtime-tags/src/html.ts +++ b/packages/runtime-tags/src/html.ts @@ -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"; diff --git a/packages/runtime-tags/src/html/attrs.ts b/packages/runtime-tags/src/html/attrs.ts index 693917947..25220993a 100644 --- a/packages/runtime-tags/src/html/attrs.ts +++ b/packages/runtime-tags/src/html/attrs.ts @@ -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( diff --git a/packages/runtime-tags/src/html/content.ts b/packages/runtime-tags/src/html/content.ts index 65ddd2cdf..4a93a7c68 100644 --- a/packages/runtime-tags/src/html/content.ts +++ b/packages/runtime-tags/src/html/content.ts @@ -10,7 +10,7 @@ export function _escape(val: unknown) { return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "‍"; } -export function _to_text(val: unknown) { +export function _escape_text(val: unknown) { return val ? escapeXMLStr(val + "") : val === 0 ? "0" : ""; } diff --git a/packages/runtime-tags/src/translator/core/html-comment.ts b/packages/runtime-tags/src/translator/core/html-comment.ts index b272b40b1..108a4d739 100644 --- a/packages/runtime-tags/src/translator/core/html-comment.ts +++ b/packages/runtime-tags/src/translator/core/html-comment.ts @@ -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 { diff --git a/packages/runtime-tags/src/translator/visitors/tag/native-tag.ts b/packages/runtime-tags/src/translator/visitors/tag/native-tag.ts index 199313acf..2f48aa161 100644 --- a/packages/runtime-tags/src/translator/visitors/tag/native-tag.ts +++ b/packages/runtime-tags/src/translator/visitors/tag/native-tag.ts @@ -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 {