-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]
|important
modifier for style directive (#7489)
* important modifier for style directive * docs * Exclude third param if false third param for set_style is optional * Remove unused test Runtime test doesn't work because of weird behaviour of computed style the puppeteer test should cover it * remove unnecessary test Co-authored-by: tanhauhau <lhtan93@gmail.com>
- Loading branch information
Showing
15 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/parser/samples/attribute-style-directive-modifiers/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div style:color|important={myColor}></div> |
50 changes: 50 additions & 0 deletions
50
test/parser/samples/attribute-style-directive-modifiers/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"html": { | ||
"start": 0, | ||
"end": 43, | ||
"type": "Fragment", | ||
"children": [ | ||
{ | ||
"start": 0, | ||
"end": 43, | ||
"type": "Element", | ||
"name": "div", | ||
"attributes": [ | ||
{ | ||
"start": 5, | ||
"end": 36, | ||
"type": "StyleDirective", | ||
"name": "color", | ||
"modifiers": [ | ||
"important" | ||
], | ||
"value": [ | ||
{ | ||
"start": 27, | ||
"end": 36, | ||
"type": "MustacheTag", | ||
"expression": { | ||
"type": "Identifier", | ||
"start": 28, | ||
"end": 35, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 28 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 35 | ||
} | ||
}, | ||
"name": "myColor" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"children": [] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"end": 26, | ||
"type": "StyleDirective", | ||
"name": "color", | ||
"modifiers": [], | ||
"value": [ | ||
{ | ||
"start": 17, | ||
|
22 changes: 22 additions & 0 deletions
22
test/runtime-puppeteer/samples/inline-style-directive-important/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default { | ||
html: ` | ||
<h1 class="svelte-szzkfu" style="background-color: red;">hello</h1> | ||
<h1 class="svelte-szzkfu" style="background-color: red !important;">hello</h1> | ||
`, | ||
|
||
ssrHtml: ` | ||
<h1 class="svelte-szzkfu" style="background-color: red;">hello</h1> | ||
<h1 class="svelte-szzkfu" style="background-color: red !important;">hello</h1> | ||
`, | ||
|
||
test({ assert, target, window, component }) { | ||
const h1s = target.querySelectorAll('h1'); | ||
|
||
assert.equal(window.getComputedStyle(h1s[0])['backgroundColor'], 'rgb(0, 0, 255)'); | ||
assert.equal(window.getComputedStyle(h1s[1])['backgroundColor'], 'rgb(255, 0, 0)'); | ||
|
||
component.color = 'yellow'; | ||
assert.equal(window.getComputedStyle(h1s[0])['backgroundColor'], 'rgb(0, 0, 255)'); | ||
assert.equal(window.getComputedStyle(h1s[1])['backgroundColor'], 'rgb(255, 255, 0)'); | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
test/runtime-puppeteer/samples/inline-style-directive-important/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
export let color = 'red' | ||
</script> | ||
|
||
<h1 style:background-color={color} >hello</h1> | ||
<h1 style:background-color|important="{color}">hello</h1> | ||
|
||
<style> | ||
h1 { | ||
background-color: blue !important; | ||
} | ||
</style> |
15 changes: 15 additions & 0 deletions
15
test/validator/samples/style-directive-modifiers-invalid/errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[{ | ||
"message": "Valid modifiers for style directives are: important", | ||
"code": "invalid-style-directive-modifier", | ||
"start": { | ||
"line": 1, | ||
"column": 8, | ||
"character": 8 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29, | ||
"character": 29 | ||
}, | ||
"pos": 8 | ||
}] |
1 change: 1 addition & 0 deletions
1
test/validator/samples/style-directive-modifiers-invalid/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button style:color|bad='red'></button> |