Skip to content

Commit b9fa06f

Browse files
committed
Address PR commennts
Update baselines with smaller emit as part of that.
1 parent 7c72f3d commit b9fa06f

File tree

8 files changed

+12
-21
lines changed

8 files changed

+12
-21
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11193,9 +11193,8 @@ namespace ts {
1119311193
let hasComputedStringProperty = false;
1119411194
let hasComputedNumberProperty = false;
1119511195

11196-
let i = 0;
1119711196
let offset = 0;
11198-
for (i = 0; i < node.properties.length; i++) {
11197+
for (let i = 0; i < node.properties.length; i++) {
1119911198
const memberDecl = node.properties[i];
1120011199
let member = memberDecl.symbol;
1120111200
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
4545
const restHelper = `
4646
var __rest = (this && this.__rest) || function (s, e) {
4747
var t = {};
48-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
48+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4949
t[p] = s[p];
5050
return t;
5151
};`;

src/compiler/transformers/destructuring.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ namespace ts {
326326
// Assignment for bindingTarget = value.propName should highlight whole property, hence use p as source map node
327327
const propAccess = createDestructuringPropertyAccess(value, propName);
328328
if (isComputedPropertyName(propName)) {
329-
(computedTempVariables = computedTempVariables || []).push((propAccess as ElementAccessExpression).argumentExpression);
329+
computedTempVariables = append(computedTempVariables, (propAccess as ElementAccessExpression).argumentExpression);
330330
}
331331
emitDestructuringAssignment(bindingTarget, propAccess, p);
332332
}
@@ -428,18 +428,11 @@ namespace ts {
428428
}
429429
if (isComputedPropertyName(getPropertyName(element))) {
430430
// get the temp name and put that in there instead, like `_tmp + ""`
431-
const stringifiedTemp = <StringLiteral>createSynthesizedNode(SyntaxKind.StringLiteral);
432-
stringifiedTemp.pos = location.pos;
433-
stringifiedTemp.end = location.end;
434-
stringifiedTemp.text = "";
435-
propertyNames.push(createBinary(computedTempVariables.shift(), SyntaxKind.PlusToken, stringifiedTemp));
431+
propertyNames.push(createBinary(computedTempVariables.shift(), SyntaxKind.PlusToken, createLiteral("")));
436432
}
437433
else {
438-
const str = <StringLiteral>createSynthesizedNode(SyntaxKind.StringLiteral);
439-
str.pos = location.pos;
440-
str.end = location.end;
441-
str.text = getTextOfPropertyName(getPropertyName(element));
442-
propertyNames.push(str);
434+
const propName = getTextOfPropertyName(getPropertyName(element));
435+
propertyNames.push(createLiteral(propName, location));
443436
}
444437
}
445438
const args = createSynthesizedNodeArray([value, createArrayLiteral(propertyNames, location)]);
@@ -569,11 +562,10 @@ namespace ts {
569562
bindingElements = [];
570563
}
571564
// Rewrite element to a declaration with an initializer that fetches property
572-
// TODO: Probably save the result of createDestructuringPropertyAccess if propName is a computed property
573565
const propName = element.propertyName || <Identifier>element.name;
574566
const propAccess = createDestructuringPropertyAccess(value, propName);
575567
if (isComputedPropertyName(propName)) {
576-
(computedTempVariables = computedTempVariables || []).push((propAccess as ElementAccessExpression).argumentExpression);
568+
computedTempVariables = append(computedTempVariables, (propAccess as ElementAccessExpression).argumentExpression);
577569
}
578570
emitBindingElement(element, propAccess);
579571
}

tests/baselines/reference/objectRest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o;
4141
//// [objectRest.js]
4242
var __rest = (this && this.__rest) || function (s, e) {
4343
var t = {};
44-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
44+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4545
t[p] = s[p];
4646
return t;
4747
};

tests/baselines/reference/objectRestAssignment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit;
1717
//// [objectRestAssignment.js]
1818
var __rest = (this && this.__rest) || function (s, e) {
1919
var t = {};
20-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
20+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2121
t[p] = s[p];
2222
return t;
2323
};

tests/baselines/reference/objectRestForOf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
2525
};
2626
var __rest = (this && this.__rest) || function (s, e) {
2727
var t = {};
28-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
28+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2929
t[p] = s[p];
3030
return t;
3131
};

tests/baselines/reference/objectRestNegative.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let rest: { b: string }
1515
//// [objectRestNegative.js]
1616
var __rest = (this && this.__rest) || function (s, e) {
1717
var t = {};
18-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
18+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1919
t[p] = s[p];
2020
return t;
2121
};

tests/baselines/reference/objectRestParameter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo'
1111
//// [objectRestParameter.js]
1212
var __rest = (this && this.__rest) || function (s, e) {
1313
var t = {};
14-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) === -1)
14+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1515
t[p] = s[p];
1616
return t;
1717
};

0 commit comments

Comments
 (0)