Skip to content

Commit 63a7a37

Browse files
authored
Merge pull request #3432 from sveltejs/gh-1830
bail out of style tag optimisation when appropriate
2 parents e5e41c7 + d720f0b commit 63a7a37

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/compiler/compile/render_dom/wrappers/Element/StyleAttribute.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ function get_style_value(chunks: Array<Text | Expression>) {
110110
let in_url = false;
111111
let quote_mark = null;
112112
let escaped = false;
113+
let closed = false;
113114

114-
while (chunks.length) {
115+
while (chunks.length && !closed) {
115116
const chunk = chunks.shift();
116117

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
html: `
3+
<p style="opacity: 0.5; color: red">color: red</p>
4+
`,
5+
6+
test({ assert, component, target, window }) {
7+
const p = target.querySelector('p');
8+
9+
let styles = window.getComputedStyle(p);
10+
assert.equal(styles.opacity, '0.5');
11+
assert.equal(styles.color, 'red');
12+
13+
component.styles = 'font-size: 20px';
14+
15+
styles = window.getComputedStyle(p);
16+
assert.equal(styles.opacity, '0.5');
17+
assert.equal(styles.color, '');
18+
assert.equal(styles.fontSize, '20px');
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let styles = `color: red`;
3+
</script>
4+
5+
<p style="opacity: 0.5; {styles}">{styles}</p>

0 commit comments

Comments
 (0)