458e87824b
Fix #14026, where ES5 emit for a parameter with 1. a default value initialiser 2. an object binding pattern containing an object rest incorrectly emitted the destructuring for the object rest before the default value initialisation. This happened because, during emit, the ES next transform runs first, transforming object rest destructuring and marking it as part of the function prologue. Then the ES5 transform runs and transforms the default initialiser, also marking it as part of the prologue. Then the prologue is emitted in the order the statements were added. The fix is to not mark the object rest destructuring as part of the prologue. I'm not 100% sure that this is the right fix, but it fixes the bug as it stands today. Here's an example: ```ts function foobar({ bar={}, ...opts }: any = {}) { } ``` which should have the ES5 emit: ```js function foobar(_a) { if (_a === void 0) { _a = {}; } var _b = _a.bar, bar = _b === void 0 ? {} : _b, opts = __rest(_a, ["bar"]); } ```
21 lines
666 B
TypeScript
21 lines
666 B
TypeScript
// @target: es2015
|
|
function cloneAgain({ a, ...clone }: { a: number, b: string }): void {
|
|
}
|
|
|
|
declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
|
|
suddenly(({ x: a, ...rest }) => rest.y);
|
|
suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka);
|
|
|
|
class C {
|
|
m({ a, ...clone }: { a: number, b: string}): void {
|
|
// actually, never mind, don't clone
|
|
}
|
|
set p({ a, ...clone }: { a: number, b: string}) {
|
|
// actually, never mind, don't clone
|
|
}
|
|
}
|
|
function foobar({ bar={}, ...opts }: any = {}) {
|
|
}
|
|
foobar();
|
|
foobar({ baz: 'hello' });
|
|
foobar({ bar: { greeting: 'hello' } });
|