Skip to content

Commit 88e2146

Browse files
committed
use ternary
1 parent 30df740 commit 88e2146

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/runtime/internal/ssr.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ export function merge_ssr_styles(style_attribute, style_directive) {
7272
const ATTR_REGEX = /[&"]/g;
7373
const CONTENT_REGEX = /[&<]/g;
7474

75-
const escapes = {
76-
'"': '&quot;',
77-
'&': '&amp;',
78-
'<': '&lt'
79-
};
80-
8175
export function escape(html: string, is_attr = false) {
8276
if (typeof html !== 'string') return html;
8377

@@ -87,11 +81,12 @@ export function escape(html: string, is_attr = false) {
8781
let escaped = '';
8882
let last = 0;
8983

90-
while (pattern.test(html)) {
91-
const i = pattern.lastIndex - 1;
92-
escaped += html.slice(last, i) + escapes[html[i]];
93-
last = i + 1;
94-
}
84+
while (pattern.test(html)) {
85+
const i = pattern.lastIndex - 1;
86+
const ch = html[i];
87+
escaped += html.slice(last, i) + (ch === '&' ? '&amp;' : (ch === '"' ? '&quot;' : '&lt;'));
88+
last = i + 1;
89+
}
9590

9691
return escaped + html.slice(last);
9792
}

0 commit comments

Comments
 (0)