diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 90bc9feff33ac40bb8b80cd0ed5f480184376b4a..7831998020f47034a2b2dea11590bcf4fd7da30a 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 0000000000000000000000000000000000000000..1191247b6d9a206f6ba3d8ac79e26d041dd86941 --- /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 0000000000000000000000000000000000000000..16c9b266bac51fd63eca2325249e8a944e52fcb1 --- /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