Skip to content

Commit 8e0b091

Browse files
ajafffrbuckton
authored andcommitted
es2018: visit other binding elements when transforming object destructuring with rest (#35872)
* es2018: visit other binding elements when transforming object destructuring with rest fixes: #35771 * more tests
1 parent 7c05e1a commit 8e0b091

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ namespace ts {
325325
&& !(element.transformFlags & (TransformFlags.ContainsRestOrSpread | TransformFlags.ContainsObjectRestOrSpread))
326326
&& !(getTargetOfBindingOrAssignmentElement(element)!.transformFlags & (TransformFlags.ContainsRestOrSpread | TransformFlags.ContainsObjectRestOrSpread))
327327
&& !isComputedPropertyName(propertyName)) {
328-
bindingElements = append(bindingElements, element);
328+
bindingElements = append(bindingElements, visitNode(element, flattenContext.visitor));
329329
}
330330
else {
331331
if (bindingElements) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [objectRestSpread.ts]
2+
let obj = {};
3+
4+
({...obj});
5+
let {
6+
prop = { ...obj },
7+
more = { ...obj } = { ...obj },
8+
['' + 'other']: other = { ...obj },
9+
yetAnother: {nested: { ['nested' + 'prop']: nestedProp = { ...obj }, ...nestedRest } = { ...obj }} = { ...obj },
10+
fn = async function*() {},
11+
...props
12+
} = {} as any;
13+
14+
({
15+
prop = { ...obj },
16+
['' + 'other']: other = { ...obj },
17+
...props
18+
} = {} as any)
19+
20+
function test({
21+
prop = { ...obj },
22+
...props
23+
}) {}
24+
25+
//// [objectRestSpread.js]
26+
var __rest = (this && this.__rest) || function (s, e) {
27+
var t = {};
28+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
29+
t[p] = s[p];
30+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
31+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
32+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
33+
t[p[i]] = s[p[i]];
34+
}
35+
return t;
36+
};
37+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
38+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
39+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
40+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
41+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
42+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
43+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
44+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
45+
function fulfill(value) { resume("next", value); }
46+
function reject(value) { resume("throw", value); }
47+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
48+
};
49+
var _a, _b, _c, _d;
50+
let obj = {};
51+
(Object.assign({}, obj));
52+
let _e = {}, { prop = Object.assign({}, obj), more = _a = Object.assign({}, obj), obj = __rest(_a, []), _a } = _e, _f = '' + 'other', _g = _e[_f], other = _g === void 0 ? Object.assign({}, obj) : _g, _h = _e.yetAnother, _j = (_h === void 0 ? Object.assign({}, obj) : _h).nested, _k = _j === void 0 ? Object.assign({}, obj) : _j, _l = 'nested' + 'prop', _m = _k[_l], nestedProp = _m === void 0 ? Object.assign({}, obj) : _m, nestedRest = __rest(_k, [typeof _l === "symbol" ? _l : _l + ""]), { fn = function () { return __asyncGenerator(this, arguments, function* () { }); } } = _e, props = __rest(_e, ["prop", "more", typeof _f === "symbol" ? _f : _f + "", "yetAnother", "fn"]);
53+
(_b = {}, { prop = Object.assign({}, obj) } = _b, _c = '' + 'other', _d = _b[_c], other = _d === void 0 ? Object.assign({}, obj) : _d, props = __rest(_b, ["prop", typeof _c === "symbol" ? _c : _c + ""]));
54+
function test(_a) { var { prop = Object.assign({}, obj) } = _a, props = __rest(_a, ["prop"]); }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @target: es2017
2+
// @lib: es2018
3+
// @noTypesAndSymbols: true
4+
let obj = {};
5+
6+
({...obj});
7+
let {
8+
prop = { ...obj },
9+
more = { ...obj } = { ...obj },
10+
['' + 'other']: other = { ...obj },
11+
yetAnother: {nested: { ['nested' + 'prop']: nestedProp = { ...obj }, ...nestedRest } = { ...obj }} = { ...obj },
12+
fn = async function*() {},
13+
...props
14+
} = {} as any;
15+
16+
({
17+
prop = { ...obj },
18+
['' + 'other']: other = { ...obj },
19+
...props
20+
} = {} as any)
21+
22+
function test({
23+
prop = { ...obj },
24+
...props
25+
}) {}

0 commit comments

Comments
 (0)