diff --git a/.changeset/serious-spiders-bake.md b/.changeset/serious-spiders-bake.md new file mode 100644 index 0000000000..b1f9d84a3f --- /dev/null +++ b/.changeset/serious-spiders-bake.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly update dynamic member expressions diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js index 635f939c75..042c467df1 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js @@ -126,16 +126,11 @@ export function Identifier(node, context) { } } - if (!can_inline && context.state.expression) { - context.state.expression.can_inline = false; - } + if (!can_inline) { + if (context.state.expression) { + context.state.expression.can_inline = false; + } - /** - * if the identifier is part of an expression tag of an attribute we want to check if it's inlinable - * before marking the subtree as dynamic. This is because if it's inlinable it will be inlined in the template - * directly making the whole thing actually static. - */ - if (!can_inline || !context.path.find((node) => node.type === 'Attribute')) { mark_subtree_dynamic(context.path); } } diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/MemberExpression.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/MemberExpression.js index adcc2da422..88adecbd35 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/MemberExpression.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/MemberExpression.js @@ -4,6 +4,7 @@ import * as e from '../../../errors.js'; import * as w from '../../../warnings.js'; import { object } from '../../../utils/ast.js'; import { is_pure, is_safe_identifier } from './shared/utils.js'; +import { mark_subtree_dynamic } from './shared/fragment.js'; /** * @param {MemberExpression} node @@ -20,6 +21,8 @@ export function MemberExpression(node, context) { if (context.state.expression && !is_pure(node, context)) { context.state.expression.has_state = true; context.state.expression.can_inline = false; + + mark_subtree_dynamic(context.path); } if (!is_safe_identifier(node, context.state.scope)) { diff --git a/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/_config.js b/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/_config.js new file mode 100644 index 0000000000..c229f97e07 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `
+ import { sprites } from './sprites.js' + + +
+ +
diff --git a/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/sprites.js b/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/sprites.js new file mode 100644 index 0000000000..055fdbd59a --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/inline-expressions-3/sprites.js @@ -0,0 +1,3 @@ +export const sprites = { + a: 'test' +}; diff --git a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js b/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js index 75e632239e..4622624424 100644 --- a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js @@ -11,7 +11,7 @@ var root = $.template(`