Skip to content

Commit 73d6384

Browse files
committed
use attribute metadata
1 parent 056475f commit 73d6384

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression } from 'estree' */
22
/** @import { AST, DelegatedEvent, SvelteNode } from '#compiler' */
33
/** @import { Context } from '../types' */
4-
import { is_capture_event, is_delegated } from '../../../../utils.js';
4+
import { is_boolean_attribute, is_capture_event, is_delegated } from '../../../../utils.js';
55
import {
66
get_attribute_chunks,
77
get_attribute_expression,
@@ -16,9 +16,10 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
1616
export function Attribute(node, context) {
1717
context.next();
1818

19+
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
20+
1921
// special case
2022
if (node.name === 'value') {
21-
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
2223
if (parent.type === 'RegularElement' && parent.name === 'option') {
2324
mark_subtree_dynamic(context.path);
2425
}
@@ -28,6 +29,10 @@ export function Attribute(node, context) {
2829
mark_subtree_dynamic(context.path);
2930
}
3031

32+
if (parent.type === 'RegularElement' && is_boolean_attribute(node.name.toLowerCase())) {
33+
node.metadata.expression.can_inline = false;
34+
}
35+
3136
if (node.value !== true) {
3237
for (const chunk of get_attribute_chunks(node.value)) {
3338
if (chunk.type !== 'ExpressionTag') continue;
@@ -41,6 +46,7 @@ export function Attribute(node, context) {
4146

4247
node.metadata.expression.has_state ||= chunk.metadata.expression.has_state;
4348
node.metadata.expression.has_call ||= chunk.metadata.expression.has_call;
49+
node.metadata.expression.can_inline &&= chunk.metadata.expression.can_inline;
4450
}
4551

4652
if (is_event_attribute(node)) {

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { dev, is_ignored, locator } from '../../../../state.js';
1414
import { is_event_attribute, is_text_attribute } from '../../../../utils/ast.js';
1515
import * as b from '../../../../utils/builders.js';
1616
import { is_custom_element_node } from '../../../nodes.js';
17-
import { is_inlinable_attribute } from '../../../utils.js';
1817
import { clean_nodes, determine_namespace_for_children } from '../../utils.js';
1918
import { build_getter, create_derived } from '../utils.js';
2019
import {
@@ -593,7 +592,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
593592
// we need to special case textarea value because it's not an actual attribute
594593
const can_inline =
595594
(attribute.name !== 'value' || element.name !== 'textarea') &&
596-
is_inlinable_attribute(attribute);
595+
attribute.metadata.expression.can_inline;
597596

598597
if (can_inline) {
599598
/** @type {Literal | undefined} */

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { escape_html } from '../../../../../../escaping.js';
66
import { is_event_attribute } from '../../../../../utils/ast.js';
77
import * as b from '../../../../../utils/builders.js';
8-
import { is_inlinable_attribute } from '../../../../utils.js';
98
import { build_template_chunk, build_update } from './utils.js';
109

1110
/**
@@ -156,7 +155,7 @@ function is_static_element(node) {
156155
return false;
157156
}
158157

159-
if (!is_inlinable_attribute(attribute)) {
158+
if (!attribute.metadata.expression.can_inline) {
160159
return false;
161160
}
162161
}

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)