From 372987e2314862a6f85a66f54daddf55c45becb6 Mon Sep 17 00:00:00 2001 From: shinyaigeek Date: Mon, 6 Sep 2021 23:33:51 +0900 Subject: [PATCH] [fix] handle AssignmentPattern with ObjectPattern in rewrite_identifier --- src/compiler/compile/Component.ts | 6 +++++- .../_config.js | 6 ++++++ .../main.svelte | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/destructured-assignment-pattern-with-object-pattern/_config.js create mode 100644 test/runtime/samples/destructured-assignment-pattern-with-object-pattern/main.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 5c83d1f346ad..202e14fd9813 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1044,7 +1044,11 @@ export default class Component { break; case 'AssignmentPattern': - param.left = get_new_name(param.left); + if (param.left.type === 'Identifier') { + param.left = get_new_name(param.left); + } else { + rename_identifiers(param.left); + } break; } } diff --git a/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/_config.js b/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/_config.js new file mode 100644 index 000000000000..75025e461407 --- /dev/null +++ b/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/_config.js @@ -0,0 +1,6 @@ +export default { + html: ` +
hello undefined
+
hello bar2
+ ` +}; diff --git a/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/main.svelte b/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/main.svelte new file mode 100644 index 000000000000..b71b25bd6750 --- /dev/null +++ b/test/runtime/samples/destructured-assignment-pattern-with-object-pattern/main.svelte @@ -0,0 +1,11 @@ + + +
hello {bar}
+
hello {bar2}