Skip to content

Commit 1d76ccf

Browse files
fix: style shorthand not referencing variables (#12392)
* fix: style shorthand not referencing variables * Update .changeset/red-pots-pretend.md --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 898fe30 commit 1d76ccf

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

.changeset/red-pots-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: mark variables in shorthand style directives as referenced

packages/svelte/src/compiler/phases/scope.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,18 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
674674

675675
TransitionDirective: SvelteDirective,
676676
AnimateDirective: SvelteDirective,
677-
UseDirective: SvelteDirective
677+
UseDirective: SvelteDirective,
678+
// using it's own function instead of `SvelteDirective` because
679+
// StyleDirective doesn't have expressions and are generally already
680+
// handled by `Identifier`. This is the special case for the shorthand
681+
// eg <button style:height /> where the variable has the same name of
682+
// the css property
683+
StyleDirective(node, { path, state, next }) {
684+
if (node.value === true) {
685+
state.scope.reference(b.id(node.name), path);
686+
}
687+
next();
688+
}
678689

679690
// TODO others
680691
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let height;
3+
</script>
4+
5+
<button style:height></button>

0 commit comments

Comments
 (0)