Visit destructuring computed names (#18052)

This commit is contained in:
Wesley Wigham 2017-08-25 15:10:47 -07:00 committed by GitHub
parent 69a8504d59
commit 38c3f67652
5 changed files with 25 additions and 1 deletions

View file

@ -409,7 +409,7 @@ namespace ts {
*/
function createDestructuringPropertyAccess(flattenContext: FlattenContext, value: Expression, propertyName: PropertyName): LeftHandSideExpression {
if (isComputedPropertyName(propertyName)) {
const argumentExpression = ensureIdentifier(flattenContext, propertyName.expression, /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
const argumentExpression = ensureIdentifier(flattenContext, visitNode(propertyName.expression, flattenContext.visitor), /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
return createElementAccess(value, argumentExpression);
}
else if (isStringOrNumericLiteral(propertyName)) {

View file

@ -0,0 +1,8 @@
//// [computerPropertiesInES5ShouldBeTransformed.ts]
const b = ({ [`key`]: renamed }) => renamed;
//// [computerPropertiesInES5ShouldBeTransformed.js]
var b = function (_a) {
var _b = "key", renamed = _a[_b];
return renamed;
};

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/computerPropertiesInES5ShouldBeTransformed.ts ===
const b = ({ [`key`]: renamed }) => renamed;
>b : Symbol(b, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 5))
>renamed : Symbol(renamed, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 12))
>renamed : Symbol(renamed, Decl(computerPropertiesInES5ShouldBeTransformed.ts, 0, 12))

View file

@ -0,0 +1,8 @@
=== tests/cases/compiler/computerPropertiesInES5ShouldBeTransformed.ts ===
const b = ({ [`key`]: renamed }) => renamed;
>b : ({ [`key`]: renamed }: {}) => any
>({ [`key`]: renamed }) => renamed : ({ [`key`]: renamed }: {}) => any
>`key` : "key"
>renamed : any
>renamed : any

View file

@ -0,0 +1,2 @@
// @target: es5
const b = ({ [`key`]: renamed }) => renamed;