Closed
Description
TypeScript Version: 3.2.1
Search Terms:
Code
// @target: ES6
function test(
x = class {
[y] = 1
},
y: 'foo',
) {}
Expected behavior:
Calling test(undefined, "foo")
executes without an error.
Actual behavior:
Runtime error ReferenceError: _b is not defined
.
The helper variables _a
and _b
are declared inside the function body, but parameter initializers cannot reference declarations in the function body. I guess this could be fixed by wrapping the emit of the class expression in an IIFE.
"use strict";
function test(x = (_b = class {
constructor() {
this[_a] = 1;
}
},
_a = y,
_b), y) { var _a, _b; }
Note: The same code downleveled to ES5 works as expected as the parameter initializer is emitted inside the function body.
Playground Link: https://agentcooper.github.io/typescript-play/?target=2#code/GYVwdgxgLglg9mABFApgZygCgFCL4gD0QF5EIAbAQzTUQG9d8mBtATwF0TEBGRvAXwA0fRKwBciAOTA4cScICU9ftiA
Related Issues: