-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: consider static attributes that are inlined in the template #14249
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
Changes from 2 commits
f21a6b0
805327c
3928ce9
31dee50
3a45986
ad95a09
6c7cded
88b1115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'svelte': patch | ||
| --- | ||
|
|
||
| fix: consider static attributes that are inlined in the template |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| /** @import { ComponentContext } from '../../types' */ | ||
| import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js'; | ||
| import * as b from '../../../../../utils/builders.js'; | ||
| import { can_inline_variable, is_inlinable_expression } from '../../utils.js'; | ||
| import { build_template_literal, build_update } from './utils.js'; | ||
|
|
||
| /** | ||
|
|
@@ -97,7 +98,7 @@ export function process_children(nodes, initial, is_element, { visit, state }) { | |
|
|
||
| let child_state = state; | ||
|
|
||
| if (is_static_element(node)) { | ||
| if (is_static_element(node, state)) { | ||
| skipped += 1; | ||
| } else if (node.type === 'EachBlock' && nodes.length === 1 && is_element) { | ||
| node.metadata.is_controlled = true; | ||
|
|
@@ -124,8 +125,9 @@ export function process_children(nodes, initial, is_element, { visit, state }) { | |
|
|
||
| /** | ||
| * @param {SvelteNode} node | ||
| * @param {ComponentContext["state"]} state | ||
| */ | ||
| function is_static_element(node) { | ||
| function is_static_element(node, state) { | ||
| if (node.type !== 'RegularElement') return false; | ||
| if (node.fragment.metadata.dynamic) return false; | ||
|
|
||
|
|
@@ -139,7 +141,12 @@ function is_static_element(node) { | |
| } | ||
|
|
||
| if (attribute.value !== true && !is_text_attribute(attribute)) { | ||
| return false; | ||
| // if it's not a text attribute but it's an inlinable expression | ||
| // we will inline it in the template so we can still consider it static | ||
| return is_inlinable_expression( | ||
|
||
| Array.isArray(attribute.value) ? attribute.value : [attribute.value], | ||
| state | ||
| ); | ||
| } | ||
|
|
||
| if (attribute.name === 'autofocus' || attribute.name === 'muted') { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.