boolean argument

pull/5701/head
Rich Harris 5 years ago
parent 57bb045cd1
commit 29d4695fc7

@ -9,7 +9,7 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
// handle special case — `class={possiblyUndefined}` with scoped CSS // handle special case — `class={possiblyUndefined}` with scoped CSS
if (attribute.chunks.length === 2 && (attribute.chunks[1] as Text).synthetic) { if (attribute.chunks.length === 2 && (attribute.chunks[1] as Text).synthetic) {
const value = (attribute.chunks[0] as Expression).node; const value = (attribute.chunks[0] as Expression).node;
return x`@escape(@null_to_empty(${value}), 1) + "${(attribute.chunks[1] as Text).data}"`; return x`@escape(@null_to_empty(${value}), true) + "${(attribute.chunks[1] as Text).data}"`;
} }
return get_attribute_value(attribute); return get_attribute_value(attribute);
@ -22,7 +22,7 @@ export function get_attribute_value(attribute: Attribute): ESTreeExpression {
.map((chunk) => { .map((chunk) => {
return chunk.type === 'Text' return chunk.type === 'Text'
? string_literal(chunk.data.replace(/"/g, '"')) as ESTreeExpression ? string_literal(chunk.data.replace(/"/g, '"')) as ESTreeExpression
: x`@escape(${chunk.node}, 1)`; : x`@escape(${chunk.node}, true)`;
}) })
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`); .reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
} }

@ -41,10 +41,10 @@ const escapes = {
'<': '&lt' '<': '&lt'
}; };
export function escape(html: string, attr: 0 | 1 = 0) { export function escape(html: string, is_attr = false) {
if (typeof html !== 'string') return html; if (typeof html !== 'string') return html;
const pattern = attr ? ATTR_REGEX : CONTENT_REGEX; const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
pattern.lastIndex = 0; pattern.lastIndex = 0;
let escaped = ''; let escaped = '';

Loading…
Cancel
Save