Skip to content

fix: style shorthand not referencing variables #12392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-pots-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: mark variables in shorthand style directives as referenced
13 changes: 12 additions & 1 deletion packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,18 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {

TransitionDirective: SvelteDirective,
AnimateDirective: SvelteDirective,
UseDirective: SvelteDirective
UseDirective: SvelteDirective,
// using it's own function instead of `SvelteDirective` because
// StyleDirective doesn't have expressions and are generally already
// handled by `Identifier`. This is the special case for the shorthand
// eg <button style:height /> where the variable has the same name of
// the css property
StyleDirective(node, { path, state, next }) {
if (node.value === true) {
state.scope.reference(b.id(node.name), path);
}
next();
}

// TODO others
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let height;
</script>

<button style:height></button>
Loading