You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/src/compiler/compile/utils/stringify.ts

29 lines
586 B

export function string_literal(data: string) {
return {
type: 'Literal',
value: data
};
}
export function escape(data: string, { only_escape_at_symbol = false } = {}) {
return data.replace(only_escape_at_symbol ? /@+/g : /(@+|#+)/g, (match: string) => {
return match + match[0];
});
}
const escaped = {
'"': '"',
"'": ''',
'&': '&',
'<': '&lt;',
'>': '&gt;',
};
export function escape_html(html) {
return String(html).replace(/["'&<>]/g, match => escaped[match]);
}
export function escape_template(str) {
return str.replace(/(\${|`|\\)/g, '\\$1');
}