Skip to content

Commit 38c3f67

Browse files
authored
Visit destructuring computed names (microsoft#18052)
1 parent 69a8504 commit 38c3f67

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ namespace ts {
409409
*/
410410
function createDestructuringPropertyAccess(flattenContext: FlattenContext, value: Expression, propertyName: PropertyName): LeftHandSideExpression {
411411
if (isComputedPropertyName(propertyName)) {
412-
const argumentExpression = ensureIdentifier(flattenContext, propertyName.expression, /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
412+
const argumentExpression = ensureIdentifier(flattenContext, visitNode(propertyName.expression, flattenContext.visitor), /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
413413
return createElementAccess(value, argumentExpression);
414414
}
415415
else if (isStringOrNumericLiteral(propertyName)) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [computerPropertiesInES5ShouldBeTransformed.ts]
2+
const b = ({ [`key`]: renamed }) => renamed;
3+
4+
//// [computerPropertiesInES5ShouldBeTransformed.js]
5+
var b = function (_a) {
6+
var _b = "key", renamed = _a[_b];
7+
return renamed;
8+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/computerPropertiesInES5ShouldBeTransformed.ts ===
2+
const b = ({ [`key`]: renamed }) => renamed;
3+
>b : Symbol(b, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 5))
4+
>renamed : Symbol(renamed, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 12))
5+
>renamed : Symbol(renamed, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 12))
6+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/computerPropertiesInES5ShouldBeTransformed.ts ===
2+
const b = ({ [`key`]: renamed }) => renamed;
3+
>b : ({ [`key`]: renamed }: {}) => any
4+
>({ [`key`]: renamed }) => renamed : ({ [`key`]: renamed }: {}) => any
5+
>`key` : "key"
6+
>renamed : any
7+
>renamed : any
8+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @target: es5
2+
const b = ({ [`key`]: renamed }) => renamed;

0 commit comments

Comments
 (0)