-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Faster SSR #5701
Changes from 3 commits
aa15e9a
e58d658
57bb045
29d4695
3a94f2a
bc4bda9
30df740
88e2146
1b0e836
61e180b
b32049b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,16 +32,31 @@ export function spread(args, classes_to_add) { | |
| return str; | ||
| } | ||
|
|
||
| export const escaped = { | ||
| const ATTR_REGEX = /[&"]/g; | ||
| const CONTENT_REGEX = /[&<]/g; | ||
|
|
||
| const escapes = { | ||
| '"': '"', | ||
| "'": ''', | ||
| '&': '&', | ||
| '<': '<', | ||
| '>': '>' | ||
| '<': '<' | ||
benmccann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export function escape(html) { | ||
| return String(html).replace(/["'&<>]/g, match => escaped[match]); | ||
| export function escape(html: string, attr: 0 | 1 = 0) { | ||
Rich-Harris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (typeof html !== 'string') return html; | ||
benmccann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const pattern = attr ? ATTR_REGEX : CONTENT_REGEX; | ||
| pattern.lastIndex = 0; | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| return escaped + html.slice(last); | ||
| } | ||
|
|
||
| export function each(items, fn) { | ||
|
|
@@ -129,7 +144,7 @@ export function create_ssr_component(fn) { | |
|
|
||
| export function add_attribute(name, value, boolean) { | ||
| if (value == null || (boolean && !value)) return ''; | ||
| return ` ${name}${value === true ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`; | ||
| return ` ${name}${value === true ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value, 1)) : `"${value}"`}`}`; | ||
Rich-Harris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export function add_classes(classes) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.