From c791da77dcec864804c02d398b1bbc98c885f5f2 Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Sun, 5 Sep 2021 13:18:38 +0800 Subject: [PATCH] (fix) reacitve declare destructuring with alias --- packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts | 3 +++ .../reactive-declare-destructuring/expected.tsx | 13 +++++++++++++ .../reactive-declare-destructuring/input.svelte | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte diff --git a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts index 5bc607438..3cddb0494 100644 --- a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts +++ b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts @@ -87,6 +87,9 @@ export function extractIdentifiers( } else if (ts.isShorthandPropertyAssignment(child)) { // in ts Ast { a = 1 } and { a } are both ShorthandPropertyAssignment extractIdentifiers(child.name, identifiers); + } else if (ts.isPropertyAssignment(child)) { + // { a: b } + extractIdentifiers(child.initializer, identifiers); } }); } else if (ts.isArrayLiteralExpression(node)) { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx new file mode 100644 index 000000000..110af63ac --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/expected.tsx @@ -0,0 +1,13 @@ +/// +<>;function render() { + +let { a } = __sveltets_1_invalidate(() => ({ a: '' })); +let { b: d } = __sveltets_1_invalidate(() => ({ b: '' })); +let { c: { length } } = __sveltets_1_invalidate(() => ({ c: '' })); +let { ...e } = __sveltets_1_invalidate(() => ({ f: ''})); +; +() => (<>); +return { props: {}, slots: {}, getters: {}, events: {} }} + +export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) { +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte new file mode 100644 index 000000000..736461015 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/reactive-declare-destructuring/input.svelte @@ -0,0 +1,6 @@ +