@@ -2,7 +2,9 @@ import { set_current_component, current_component } from './lifecycle.js';
22import { run_all , blank_object } from './utils.js' ;
33import { boolean_attributes } from '../../shared/boolean_attributes.js' ;
44import { ensure_array_like } from './each.js' ;
5+ import { escape } from '../../shared/utils/escape.js' ;
56export { is_void } from '../../shared/utils/names.js' ;
7+ export { escape } ;
68
79export const invalid_attribute_name_character =
810 / [ \s ' " > / = \u{FDD0} - \u{FDEF} \u{FFFE} \u{FFFF} \u{1FFFE} \u{1FFFF} \u{2FFFE} \u{2FFFF} \u{3FFFE} \u{3FFFF} \u{4FFFE} \u{4FFFF} \u{5FFFE} \u{5FFFF} \u{6FFFE} \u{6FFFF} \u{7FFFE} \u{7FFFF} \u{8FFFE} \u{8FFFF} \u{9FFFE} \u{9FFFF} \u{AFFFE} \u{AFFFF} \u{BFFFE} \u{BFFFF} \u{CFFFE} \u{CFFFF} \u{DFFFE} \u{DFFFF} \u{EFFFE} \u{EFFFF} \u{FFFFE} \u{FFFFF} \u{10FFFE} \u{10FFFF} ] / u;
@@ -67,30 +69,6 @@ export function merge_ssr_styles(style_attribute, style_directive) {
6769 return style_object ;
6870}
6971
70- const ATTR_REGEX = / [ & " ] / g;
71- const CONTENT_REGEX = / [ & < ] / g;
72-
73- /**
74- * Note: this method is performance sensitive and has been optimized
75- * https://github.com/sveltejs/svelte/pull/5701
76- * @param {unknown } value
77- * @returns {string }
78- */
79- export function escape ( value , is_attr = false ) {
80- const str = String ( value ) ;
81- const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX ;
82- pattern . lastIndex = 0 ;
83- let escaped = '' ;
84- let last = 0 ;
85- while ( pattern . test ( str ) ) {
86- const i = pattern . lastIndex - 1 ;
87- const ch = str [ i ] ;
88- escaped += str . substring ( last , i ) + ( ch === '&' ? '&' : ch === '"' ? '"' : '<' ) ;
89- last = i + 1 ;
90- }
91- return escaped + str . substring ( last ) ;
92- }
93-
9472export function escape_attribute_value ( value ) {
9573 // keep booleans, null, and undefined for the sake of `spread`
9674 const should_escape = typeof value === 'string' || ( value && typeof value === 'object' ) ;
0 commit comments