Skip to content

Commit a27cdee

Browse files
committed
missed some
1 parent 7c97a85 commit a27cdee

File tree

4 files changed

+18
-60
lines changed

4 files changed

+18
-60
lines changed

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -311,43 +311,3 @@ export function create_derived_block_argument(node, context) {
311311
export function create_derived(state, arg) {
312312
return b.call(state.analysis.runes ? '$.derived' : '$.derived_safe_equal', arg);
313313
}
314-
315-
/**
316-
* Whether a variable can be referenced directly from template string.
317-
* @param {import('#compiler').Binding | undefined} binding
318-
* @returns {boolean}
319-
*/
320-
export function can_inline_variable(binding) {
321-
return (
322-
!!binding &&
323-
// in a `<script module>` block
324-
!binding.scope.parent &&
325-
// to prevent the need for escaping
326-
binding.initial?.type === 'Literal'
327-
);
328-
}
329-
330-
/**
331-
* @param {(AST.Text | AST.ExpressionTag) | (AST.Text | AST.ExpressionTag)[]} node_or_nodes
332-
* @param {import('./types.js').ComponentClientTransformState} state
333-
*/
334-
export function is_inlinable_expression(node_or_nodes, state) {
335-
let nodes = Array.isArray(node_or_nodes) ? node_or_nodes : [node_or_nodes];
336-
let has_expression_tag = false;
337-
for (let value of nodes) {
338-
if (value.type === 'ExpressionTag') {
339-
if (value.expression.type === 'Identifier') {
340-
const binding = state.scope
341-
.owner(value.expression.name)
342-
?.declarations.get(value.expression.name);
343-
if (!can_inline_variable(binding)) {
344-
return false;
345-
}
346-
} else {
347-
return false;
348-
}
349-
has_expression_tag = true;
350-
}
351-
}
352-
return has_expression_tag;
353-
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { is_event_attribute, is_text_attribute } from '../../../../utils/ast.js'
1616
import * as b from '../../../../utils/builders.js';
1717
import { is_custom_element_node } from '../../../nodes.js';
1818
import { clean_nodes, determine_namespace_for_children } from '../../utils.js';
19-
import { build_getter, create_derived, is_inlinable_expression } from '../utils.js';
19+
import { build_getter, create_derived } from '../utils.js';
2020
import {
2121
get_attribute_name,
2222
build_attribute_value,
@@ -577,10 +577,6 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
577577
);
578578
}
579579

580-
const inlinable_expression =
581-
attribute.value === true
582-
? false // not an expression
583-
: is_inlinable_expression(attribute.value, context.state);
584580
if (attribute.metadata.expression.has_state) {
585581
if (has_call) {
586582
state.init.push(build_update(update));
@@ -589,11 +585,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
589585
}
590586
return true;
591587
} else {
592-
if (inlinable_expression) {
593-
context.state.template.push(` ${name}="`, value, '"');
594-
} else {
595-
state.init.push(update);
596-
}
588+
state.init.push(update);
597589
return false;
598590
}
599591
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { cannot_be_set_statically } from '../../../../../../utils.js';
55
import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
66
import * as b from '../../../../../utils/builders.js';
7-
import { is_inlinable_expression } from '../../utils.js';
87
import { build_template_literal, build_update } from './utils.js';
98

109
/**
@@ -155,13 +154,7 @@ function is_static_element(node, state) {
155154
return false;
156155
}
157156

158-
if (
159-
attribute.value !== true &&
160-
!is_text_attribute(attribute) &&
161-
// If the attribute is not a text attribute but is inlinable we will directly inline it in the
162-
// the template so before returning false we need to check that the attribute is not inlinable
163-
!is_inlinable_expression(attribute.value, state)
164-
) {
157+
if (attribute.value !== true && !is_text_attribute(attribute)) {
165158
return false;
166159
}
167160
}

packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@ const __DECLARED_ASSET_0__ = "__VITE_ASSET__2AM7_y_a__ 1440w, __VITE_ASSET__2AM7
55
const __DECLARED_ASSET_1__ = "__VITE_ASSET__2AM7_y_c__ 1440w, __VITE_ASSET__2AM7_y_d__ 960w";
66
const __DECLARED_ASSET_2__ = "__VITE_ASSET__2AM7_y_e__ 1440w, __VITE_ASSET__2AM7_y_f__ 960w";
77
const __DECLARED_ASSET_3__ = "__VITE_ASSET__2AM7_y_g__";
8-
var root = $.template(`<picture><source srcset="${__DECLARED_ASSET_0__}" type="image/avif"> <source srcset="${__DECLARED_ASSET_1__}" type="image/webp"> <source srcset="${__DECLARED_ASSET_2__}" type="image/png"> <img src="${__DECLARED_ASSET_3__}" alt="production test" width="1440" height="1440"></picture>`);
8+
var root = $.template(`<picture><source type="image/avif"> <source type="image/webp"> <source type="image/png"> <img alt="production test" width="1440" height="1440"></picture>`);
99

1010
export default function Inline_module_vars($$anchor) {
1111
var picture = root();
12+
var source = $.child(picture);
1213

13-
$.next(6);
14+
$.set_attribute(source, "srcset", __DECLARED_ASSET_0__);
15+
16+
var source_1 = $.sibling(source, 2);
17+
18+
$.set_attribute(source_1, "srcset", __DECLARED_ASSET_1__);
19+
20+
var source_2 = $.sibling(source_1, 2);
21+
22+
$.set_attribute(source_2, "srcset", __DECLARED_ASSET_2__);
23+
24+
var img = $.sibling(source_2, 2);
25+
26+
$.set_attribute(img, "src", __DECLARED_ASSET_3__);
1427
$.reset(picture);
1528
$.append($$anchor, picture);
1629
}

0 commit comments

Comments
 (0)