From aa8395858930f36aad80e063443a5626ca416640 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Wed, 9 Aug 2023 14:38:09 +0800 Subject: [PATCH] Fix compiling computed key in propertyExpression Issue: I7RQ1Y Signed-off-by: gavin1012_hw Change-Id: I0e064598a1b784c13423f6e1de8a075ed3ea72b5 --- es2panda/compiler/base/destructuring.cpp | 2 +- .../computed-property-name-expected.txt | 2 ++ .../computed-property-name.js | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 es2panda/test/compiler/js/language/computed-property-names/computed-property-name-expected.txt create mode 100644 es2panda/test/compiler/js/language/computed-property-names/computed-property-name.js diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 90bc9feff3..7831998020 100644 --- a/es2panda/compiler/base/destructuring.cpp +++ b/es2panda/compiler/base/destructuring.cpp @@ -144,7 +144,7 @@ static void GenObjectProperty(PandaGen *pg, const ir::ObjectExpression *object, LReference lref = LReference::CreateLRef(pg, target, object->IsDeclaration()); // load obj property from rhs, return undefined if no corresponding property exists - if (key->IsIdentifier()) { + if (key->IsIdentifier() && !propExpr->IsComputed()) { pg->LoadObjByName(element, value, key->AsIdentifier()->Name()); } else { key->Compile(pg); diff --git a/es2panda/test/compiler/js/language/computed-property-names/computed-property-name-expected.txt b/es2panda/test/compiler/js/language/computed-property-names/computed-property-name-expected.txt new file mode 100644 index 0000000000..1191247b6d --- /dev/null +++ b/es2panda/test/compiler/js/language/computed-property-names/computed-property-name-expected.txt @@ -0,0 +1,2 @@ +1 +2 diff --git a/es2panda/test/compiler/js/language/computed-property-names/computed-property-name.js b/es2panda/test/compiler/js/language/computed-property-names/computed-property-name.js new file mode 100644 index 0000000000..16c9b266ba --- /dev/null +++ b/es2panda/test/compiler/js/language/computed-property-names/computed-property-name.js @@ -0,0 +1,15 @@ +const a = "hello" +const a2 = "test" + +let b = { + [a]: 1, + [a2]: 2 +} + +const { + [a] : c, + [a2]: d +} = b; + +print(c); +print(d); \ No newline at end of file -- Gitee