From 88e2146701668bd4cd9f8052eb0e050488dcef3b Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 6 May 2022 10:59:24 -0700 Subject: [PATCH] use ternary --- src/runtime/internal/ssr.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index 416267fa03..ecffc82fa4 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -72,12 +72,6 @@ export function merge_ssr_styles(style_attribute, style_directive) { const ATTR_REGEX = /[&"]/g; const CONTENT_REGEX = /[&<]/g; -const escapes = { - '"': '"', - '&': '&', - '<': '<' -}; - export function escape(html: string, is_attr = false) { if (typeof html !== 'string') return html; @@ -87,11 +81,12 @@ export function escape(html: string, is_attr = false) { let escaped = ''; let last = 0; - while (pattern.test(html)) { - const i = pattern.lastIndex - 1; - escaped += html.slice(last, i) + escapes[html[i]]; - last = i + 1; - } + while (pattern.test(html)) { + const i = pattern.lastIndex - 1; + const ch = html[i]; + escaped += html.slice(last, i) + (ch === '&' ? '&' : (ch === '"' ? '"' : '<')); + last = i + 1; + } return escaped + html.slice(last); }