From 5dffe715d356b5f50c45467204565491d1daef12 Mon Sep 17 00:00:00 2001 From: Nguyen Tran <88808276+ngtr6788@users.noreply.github.com> Date: Wed, 27 Dec 2023 05:44:03 -0500 Subject: [PATCH] fix: issue with assiging prop values as defaults of other props (#9985) * Fix issue on assiging prop values as defaults of other props * Prettier * Add changeset --- .changeset/itchy-kings-deliver.md | 5 +++++ .../3-transform/client/visitors/javascript-runes.js | 3 +++ .../samples/assign-prop-to-prop/Test.svelte | 9 +++++++++ .../runtime-runes/samples/assign-prop-to-prop/_config.js | 5 +++++ .../samples/assign-prop-to-prop/main.svelte | 5 +++++ 5 files changed, 27 insertions(+) create mode 100644 .changeset/itchy-kings-deliver.md create mode 100644 packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/Test.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/main.svelte diff --git a/.changeset/itchy-kings-deliver.md b/.changeset/itchy-kings-deliver.md new file mode 100644 index 0000000000..1a188b77f3 --- /dev/null +++ b/.changeset/itchy-kings-deliver.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +Fix issue with assigning prop values as defaults of other props diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js index 41ce98de49..e4de622649 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js @@ -195,6 +195,9 @@ export const javascript_visitors_runes = { id = property.value.left; initial = property.value.right; } + initial = initial + ? /** @type {import('estree').Expression} */ (visit(initial)) + : undefined; assert.equal(id.type, 'Identifier'); diff --git a/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/Test.svelte b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/Test.svelte new file mode 100644 index 0000000000..0bf0649b9e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/Test.svelte @@ -0,0 +1,9 @@ + + +

{a}

+

{b}

+

{c}

+

{d}

\ No newline at end of file diff --git a/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/_config.js b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/_config.js new file mode 100644 index 0000000000..f68a56cfbc --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `

5

5

25

65

` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/main.svelte b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/main.svelte new file mode 100644 index 0000000000..0ff0ef524e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/assign-prop-to-prop/main.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file