diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 8543a56d18..6c069525ef 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -21,17 +21,17 @@ interface Processed { dependencies?: string[]; } -function parse_attribute_value(value: string) { - return /^['"]/.test(value) ? - value.slice(1, -1) : - value; -} - function parse_attributes(str: string) { const attrs = {}; str.split(/\s+/).filter(Boolean).forEach(attr => { - const [name, value] = attr.split('='); - attrs[name] = value ? parse_attribute_value(value) : true; + const p = attr.indexOf('='); + if (p === -1) { + attrs[attr] = true; + } else { + attrs[attr.slice(0, p)] = `'"`.includes(attr[p + 1]) ? + attr.slice(p + 2, -1) : + attr.slice(p + 1); + } }); return attrs; } diff --git a/test/preprocess/samples/attributes-with-equals/_config.js b/test/preprocess/samples/attributes-with-equals/_config.js new file mode 100644 index 0000000000..bee4928b1f --- /dev/null +++ b/test/preprocess/samples/attributes-with-equals/_config.js @@ -0,0 +1,5 @@ +export default { + preprocess: { + style: ({ attributes }) => attributes.foo && attributes.foo.includes('=') ? { code: '' } : null + } +}; diff --git a/test/preprocess/samples/attributes-with-equals/input.svelte b/test/preprocess/samples/attributes-with-equals/input.svelte new file mode 100644 index 0000000000..4e88284a29 --- /dev/null +++ b/test/preprocess/samples/attributes-with-equals/input.svelte @@ -0,0 +1,3 @@ + diff --git a/test/preprocess/samples/attributes-with-equals/output.svelte b/test/preprocess/samples/attributes-with-equals/output.svelte new file mode 100644 index 0000000000..c194ab682d --- /dev/null +++ b/test/preprocess/samples/attributes-with-equals/output.svelte @@ -0,0 +1 @@ +