add test, do some drive-by tidying

pull/11971/head
Rich Harris 2 years ago
parent 49da40b31d
commit 3bea72be36

@ -269,23 +269,27 @@ export function add_styles(style_object) {
*/
export function merge_styles(style_attribute, style_directive) {
/** @type {Record<string, string>} */
const style_object = {};
for (const individual_style of (style_attribute ?? '').split(';')) {
const colon_index = individual_style.indexOf(':');
const name = individual_style.slice(0, colon_index).trim();
const value = individual_style.slice(colon_index + 1).trim();
if (!name) continue;
style_object[name] = value;
var merged = {};
if (style_attribute) {
for (var individual_style of style_attribute.split(';')) {
var colon_index = individual_style.indexOf(':');
var name = individual_style.slice(0, colon_index).trim();
var value = individual_style.slice(colon_index + 1).trim();
if (name) merged[name] = value;
}
}
for (const name in style_directive) {
const value = style_directive[name];
for (var name in style_directive) {
var value = style_directive[name];
if (value) {
style_object[name] = value;
merged[name] = value;
} else {
delete style_object[name];
delete merged[name];
}
}
return style_object;
return merged;
}
/**

@ -0,0 +1,7 @@
import { ok, test } from '../../test';
export default test({
html: `
<p style="color: red;">red</p>
`
});
Loading…
Cancel
Save