8000 Faster SSR by Rich-Harris · Pull Request #5701 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content

Faster SSR #5701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
restore String conversion
  • Loading branch information
benmccann committed May 6, 2022
commit b32049bfdf40089e341c2fa2c8a200545488a59c
12 changes: 6 additions & 6 deletions src/runtime/internal/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ const CONTENT_REGEX = /[&<]/g;
* Note: this method is performance sensitive and has been optimized
* https://github.com/sveltejs/svelte/pull/5701
*/
export function escape(html: string, is_attr = false) {
if (typeof html !== 'string') return html;
export function escape(value: unknown, is_attr = false) {
const str = String(value);

const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
pattern.lastIndex = 0;

let escaped = '';
let last = 0;

while (pattern.test(html)) {
while (pattern.test(str)) {
const i = pattern.lastIndex - 1;
const ch = html[i];
escaped += html.substring(last, i) + (ch === '&' ? '&amp;' : (ch === '"' ? '&quot;' : '&lt;'));
const ch = str[i];
escaped += str.substring(last, i) + (ch === '&' ? '&amp;' : (ch === '"' ? '&quot;' : '&lt;'));
last = i + 1;
}

return escaped + html.substring(last);
return escaped + str.substring(last);
}

export function escape_attribute_value(value) {
Expand Down
0