Skip to content

Commit

Permalink
bail out of style tag optimisation when appropriate - fixes #1830
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 20, 2019
1 parent 5149842 commit d720f0b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ function get_style_value(chunks: Array<Text | Expression>) {
let in_url = false;
let quote_mark = null;
let escaped = false;
let closed = false;

while (chunks.length) {
while (chunks.length && !closed) {
const chunk = chunks.shift();

if (chunk.type === 'Text') {
Expand All @@ -132,6 +133,7 @@ function get_style_value(chunks: Array<Text | Expression>) {
} else if (char === 'u' && chunk.data.slice(c, c + 4) === 'url(') {
in_url = true;
} else if (char === ';' && !in_url && !quote_mark) {
closed = true;
break;
}

Expand Down
20 changes: 20 additions & 0 deletions test/runtime/samples/inline-style-optimisation-bailout/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
html: `
<p style="opacity: 0.5; color: red">color: red</p>
`,

test({ assert, component, target, window }) {
const p = target.querySelector('p');

let styles = window.getComputedStyle(p);
assert.equal(styles.opacity, '0.5');
assert.equal(styles.color, 'red');

component.styles = 'font-size: 20px';

styles = window.getComputedStyle(p);
assert.equal(styles.opacity, '0.5');
assert.equal(styles.color, '');
assert.equal(styles.fontSize, '20px');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let styles = `color: red`;
</script>

<p style="opacity: 0.5; {styles}">{styles}</p>

0 comments on commit d720f0b

Please sign in to comment.