Add __spreadArrays helper (#31166)

This commit is contained in:
Ron Buckton 2019-06-11 14:15:57 -07:00 committed by GitHub
parent ad322a561a
commit 375487ec60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 465 additions and 240 deletions

View file

@ -19080,8 +19080,8 @@ namespace ts {
}
function checkSpreadExpression(node: SpreadElement, checkMode?: CheckMode): Type {
if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.SpreadIncludes);
if (languageVersion < ScriptTarget.ES2015) {
checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? ExternalEmitHelpers.SpreadIncludes : ExternalEmitHelpers.SpreadArrays);
}
const arrayOrIterableType = checkExpression(node.expression, checkMode);
@ -31104,6 +31104,7 @@ namespace ts {
case ExternalEmitHelpers.Values: return "__values";
case ExternalEmitHelpers.Read: return "__read";
case ExternalEmitHelpers.Spread: return "__spread";
case ExternalEmitHelpers.SpreadArrays: return "__spreadArrays";
case ExternalEmitHelpers.Await: return "__await";
case ExternalEmitHelpers.AsyncGenerator: return "__asyncGenerator";
case ExternalEmitHelpers.AsyncDelegator: return "__asyncDelegator";

View file

@ -2657,6 +2657,7 @@ namespace ts {
valuesHelper,
readHelper,
spreadHelper,
spreadArraysHelper,
restHelper,
decorateHelper,
metadataHelper,
@ -3693,6 +3694,31 @@ namespace ts {
);
}
export const spreadArraysHelper: UnscopedEmitHelper = {
name: "typescript:spreadArrays",
scoped: false,
text: `
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};`
};
export function createSpreadArraysHelper(context: TransformationContext, argumentList: ReadonlyArray<Expression>, location?: TextRange) {
context.requestEmitHelper(spreadArraysHelper);
return setTextRange(
createCall(
getHelperName("__spreadArrays"),
/*typeArguments*/ undefined,
argumentList
),
location
);
}
// Utilities
export function createForOfBindingStatement(node: ForInitializer, boundValue: Expression): Statement {

View file

@ -3819,8 +3819,11 @@ namespace ts {
// [source]
// [a, ...b, c]
//
// [output (downlevelIteration)]
// __spread([a], b, [c])
//
// [output]
// [a].concat(b, [c])
// __spreadArrays([a], b, [c])
// Map spans of spread expressions into their expressions and spans of other
// expressions into an array literal.
@ -3834,10 +3837,7 @@ namespace ts {
if (compilerOptions.downlevelIteration) {
if (segments.length === 1) {
const firstSegment = segments[0];
if (isCallExpression(firstSegment)
&& isIdentifier(firstSegment.expression)
&& (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName)
&& firstSegment.expression.escapedText === "___spread") {
if (isCallToHelper(firstSegment, "___spread" as __String)) {
return segments[0];
}
}
@ -3846,17 +3846,33 @@ namespace ts {
}
else {
if (segments.length === 1) {
const firstElement = elements[0];
return needsUniqueCopy && isSpreadElement(firstElement) && firstElement.expression.kind !== SyntaxKind.ArrayLiteralExpression
? createArraySlice(segments[0])
: segments[0];
const firstSegment = segments[0];
if (!needsUniqueCopy
|| isPackedArrayLiteral(firstSegment)
|| isCallToHelper(firstSegment, "___spreadArrays" as __String)) {
return segments[0];
}
}
// Rewrite using the pattern <segment0>.concat(<segment1>, <segment2>, ...)
return createArrayConcat(segments.shift()!, segments);
return createSpreadArraysHelper(context, segments);
}
}
function isPackedElement(node: Expression) {
return !isOmittedExpression(node);
}
function isPackedArrayLiteral(node: Expression) {
return isArrayLiteralExpression(node) && every(node.elements, isPackedElement);
}
function isCallToHelper(firstSegment: Expression, helperName: __String) {
return isCallExpression(firstSegment)
&& isIdentifier(firstSegment.expression)
&& (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName)
&& firstSegment.expression.escapedText === helperName;
}
function partitionSpread(node: Expression) {
return isSpreadElement(node)
? visitSpanOfSpreads

View file

@ -5339,12 +5339,13 @@ namespace ts {
Values = 1 << 8, // __values (used by ES2015 for..of and yield* transformations)
Read = 1 << 9, // __read (used by ES2015 iterator destructuring transformation)
Spread = 1 << 10, // __spread (used by ES2015 array spread and argument list spread transformations)
Await = 1 << 11, // __await (used by ES2017 async generator transformation)
AsyncGenerator = 1 << 12, // __asyncGenerator (used by ES2017 async generator transformation)
AsyncDelegator = 1 << 13, // __asyncDelegator (used by ES2017 async generator yield* transformation)
AsyncValues = 1 << 14, // __asyncValues (used by ES2017 for..await..of transformation)
ExportStar = 1 << 15, // __exportStar (used by CommonJS/AMD/UMD module transformation)
MakeTemplateObject = 1 << 16, // __makeTemplateObject (used for constructing template string array objects)
SpreadArrays = 1 << 11, // __spreadArrays (used by ES2015 array spread and argument list spread transformations)
Await = 1 << 12, // __await (used by ES2017 async generator transformation)
AsyncGenerator = 1 << 13, // __asyncGenerator (used by ES2017 async generator transformation)
AsyncDelegator = 1 << 14, // __asyncDelegator (used by ES2017 async generator yield* transformation)
AsyncValues = 1 << 15, // __asyncValues (used by ES2017 for..await..of transformation)
ExportStar = 1 << 16, // __exportStar (used by CommonJS/AMD/UMD module transformation)
MakeTemplateObject = 1 << 17, // __makeTemplateObject (used for constructing template string array objects)
FirstEmitHelper = Extends,
LastEmitHelper = MakeTemplateObject,

View file

@ -19,6 +19,13 @@ baz(["string", 1, true, ...array]); // Error
foo(o); // Error because x has an array type namely (string|number)[]
//// [argumentExpressionContextualTyping.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// In a typed function call, argument expressions are contextually typed by their corresponding parameter types.
function foo(_a) {
var _b = _a.x, a = _b[0], b = _b[1], _c = _a.y, c = _c.c, d = _c.d, e = _c.e;
@ -36,5 +43,5 @@ var tuple = ["string", 1, true];
baz(tuple);
baz(["string", 1, true]);
baz(array); // Error
baz(["string", 1, true].concat(array)); // Error
baz(__spreadArrays(["string", 1, true], array)); // Error
foo(o); // Error because x has an array type namely (string|number)[]

View file

@ -16,6 +16,13 @@ var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error
//// [arrayLiteralExpressionContextualTyping.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by
// the type of the property with the numeric name N in the contextual type, if any, or otherwise
// the numeric index type of the contextual type, if any.
@ -26,6 +33,6 @@ var tup1 = [1, 2, 3, "string"];
var tup2 = [1, 2, 3, "string"]; // Error
// In a contextually typed array literal expression containing one or more spread elements,
// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any.
var spr = [1, 2, 3].concat(array);
var spr1 = [1, 2, 3].concat(tup);
var spr2 = [1, 2, 3].concat(tup); // Error
var spr = __spreadArrays([1, 2, 3], array);
var spr1 = __spreadArrays([1, 2, 3], tup);
var spr2 = __spreadArrays([1, 2, 3], tup); // Error

View file

@ -24,20 +24,27 @@ function f2() {
//// [arrayLiteralSpread.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function f0() {
var a = [1, 2, 3];
var a1 = a.slice();
var a2 = [1].concat(a);
var a3 = [1, 2].concat(a);
var a4 = a.concat([1]);
var a5 = a.concat([1, 2]);
var a6 = [1, 2].concat(a, [1, 2]);
var a7 = [1].concat(a, [2], a);
var a8 = a.concat(a, a);
var a1 = __spreadArrays(a);
var a2 = __spreadArrays([1], a);
var a3 = __spreadArrays([1, 2], a);
var a4 = __spreadArrays(a, [1]);
var a5 = __spreadArrays(a, [1, 2]);
var a6 = __spreadArrays([1, 2], a, [1, 2]);
var a7 = __spreadArrays([1], a, [2], a);
var a8 = __spreadArrays(a, a, a);
}
function f1() {
var a = [1, 2, 3];
var b = ["hello"].concat(a, [true]);
var b = __spreadArrays(["hello"], a, [true]);
var b;
}
function f2() {

View file

@ -62,14 +62,21 @@ var d9 = [[...temp1], ...["hello"]];
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4];
var a1 = ["hello", "world"];
var a2 = [, , ].concat(a0, ["hello"]);
var a3 = [, ].concat(a0);
var a2 = __spreadArrays([, , ], a0, ["hello"]);
var a3 = __spreadArrays([, ], a0);
var a4 = [function () { return 1; },];
var a5 = a0.concat([,]);
var a5 = __spreadArrays(a0, [,]);
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
@ -92,13 +99,13 @@ var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];
var d0 = [1, true].concat(temp); // has type (string|number|boolean)[]
var d1 = temp.slice(); // has type string[]
var d2 = temp1.slice();
var d3 = temp1.slice();
var d4 = temp.concat(temp1);
var d5 = temp3.slice();
var d6 = temp4.slice();
var d7 = temp1.slice();
var d8 = [temp1.slice()];
var d9 = [temp1.slice()].concat(["hello"]);
var d0 = __spreadArrays([1, true], temp); // has type (string|number|boolean)[]
var d1 = __spreadArrays(temp); // has type string[]
var d2 = __spreadArrays(temp1);
var d3 = __spreadArrays(temp1);
var d4 = __spreadArrays(temp, temp1);
var d5 = __spreadArrays(temp3);
var d6 = __spreadArrays(temp4);
var d7 = __spreadArrays(temp1);
var d8 = [__spreadArrays(temp1)];
var d9 = __spreadArrays([__spreadArrays(temp1)], ["hello"]);

View file

@ -40,6 +40,13 @@ var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
@ -55,6 +62,6 @@ var _a = [1, 2, "string", true], b1 = _a[0], b2 = _a[1];
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var c0 = temp2.slice(); // Error
var c1 = temp1.slice(); // Error cannot assign number[] to [number, number, number]
var c2 = temp1.concat(temp); // Error cannot assign (number|string)[] to number[]
var c0 = __spreadArrays(temp2); // Error
var c1 = __spreadArrays(temp1); // Error cannot assign number[] to [number, number, number]
var c2 = __spreadArrays(temp1, temp); // Error cannot assign (number|string)[] to number[]

View file

@ -12,10 +12,17 @@ withRest();
withRest(...n);
//// [callOverload.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var n;
fn(1); // no error
fn(1, 2, 3, 4);
takeTwo(1, 2, 3, 4);
withRest.apply(void 0, ['a'].concat(n)); // no error
withRest.apply(void 0, __spreadArrays(['a'], n)); // no error
withRest();
withRest.apply(void 0, n);

View file

@ -72,6 +72,13 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var _a, _b, _c, _d, _e, _f, _g;
function foo(x, y) {
var z = [];
@ -84,23 +91,23 @@ var z;
var obj;
var xa;
foo(1, 2, "abc");
foo.apply(void 0, [1, 2].concat(a));
foo.apply(void 0, [1, 2].concat(a, ["abc"]));
foo.apply(void 0, __spreadArrays([1, 2], a));
foo.apply(void 0, __spreadArrays([1, 2], a, ["abc"]));
obj.foo(1, 2, "abc");
obj.foo.apply(obj, [1, 2].concat(a));
obj.foo.apply(obj, [1, 2].concat(a, ["abc"]));
obj.foo.apply(obj, [1, 2].concat(a)).foo(1, 2, "abc");
(_a = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_a, [1, 2].concat(a));
(_b = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_b, [1, 2].concat(a, ["abc"]));
obj.foo.apply(obj, __spreadArrays([1, 2], a));
obj.foo.apply(obj, __spreadArrays([1, 2], a, ["abc"]));
obj.foo.apply(obj, __spreadArrays([1, 2], a)).foo(1, 2, "abc");
(_a = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_a, __spreadArrays([1, 2], a));
(_b = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_b, __spreadArrays([1, 2], a, ["abc"]));
(obj.foo)(1, 2, "abc");
obj.foo.apply(obj, [1, 2].concat(a));
obj.foo.apply(obj, [1, 2].concat(a, ["abc"]));
(obj.foo.apply(obj, [1, 2].concat(a)).foo)(1, 2, "abc");
(_c = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_c, [1, 2].concat(a));
(_d = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_d, [1, 2].concat(a, ["abc"]));
obj.foo.apply(obj, __spreadArrays([1, 2], a));
obj.foo.apply(obj, __spreadArrays([1, 2], a, ["abc"]));
(obj.foo.apply(obj, __spreadArrays([1, 2], a)).foo)(1, 2, "abc");
(_c = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_c, __spreadArrays([1, 2], a));
(_d = obj.foo.apply(obj, __spreadArrays([1, 2], a))).foo.apply(_d, __spreadArrays([1, 2], a, ["abc"]));
xa[1].foo(1, 2, "abc");
(_e = xa[1]).foo.apply(_e, [1, 2].concat(a));
(_f = xa[1]).foo.apply(_f, [1, 2].concat(a, ["abc"]));
(_e = xa[1]).foo.apply(_e, __spreadArrays([1, 2], a));
(_f = xa[1]).foo.apply(_f, __spreadArrays([1, 2], a, ["abc"]));
(_g = xa[1]).foo.apply(_g, [1, 2, "abc"]);
var C = /** @class */ (function () {
function C(x, y) {
@ -109,7 +116,7 @@ var C = /** @class */ (function () {
z[_i - 2] = arguments[_i];
}
this.foo(x, y);
this.foo.apply(this, [x, y].concat(z));
this.foo.apply(this, __spreadArrays([x, y], z));
}
C.prototype.foo = function (x, y) {
var z = [];
@ -123,12 +130,12 @@ var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
var _this = _super.call(this, 1, 2) || this;
_this = _super.apply(this, [1, 2].concat(a)) || this;
_this = _super.apply(this, __spreadArrays([1, 2], a)) || this;
return _this;
}
D.prototype.foo = function () {
_super.prototype.foo.call(this, 1, 2);
_super.prototype.foo.apply(this, [1, 2].concat(a));
_super.prototype.foo.apply(this, __spreadArrays([1, 2], a));
};
return D;
}(C));

View file

@ -38,24 +38,31 @@ prefix2("g", ...ns);
//// [callWithSpread2.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// good
all.apply(void 0, ns);
weird.apply(void 0, ns);
weird.apply(void 0, mixed);
weird.apply(void 0, tuple);
prefix.apply(void 0, ["a"].concat(ns));
rest.apply(void 0, ["d"].concat(ns));
prefix.apply(void 0, __spreadArrays(["a"], ns));
rest.apply(void 0, __spreadArrays(["d"], ns));
// extra arguments
normal.apply(void 0, ["g"].concat(ns));
normal.apply(void 0, __spreadArrays(["g"], ns));
thunk.apply(void 0, ns);
// bad
all.apply(void 0, mixed);
all.apply(void 0, tuple);
prefix.apply(void 0, ["b"].concat(mixed));
prefix.apply(void 0, ["c"].concat(tuple));
rest.apply(void 0, ["e"].concat(mixed));
rest.apply(void 0, ["f"].concat(tuple));
prefix.apply(void 0, __spreadArrays(["b"], mixed));
prefix.apply(void 0, __spreadArrays(["c"], tuple));
rest.apply(void 0, __spreadArrays(["e"], mixed));
rest.apply(void 0, __spreadArrays(["f"], tuple));
prefix.apply(void 0, ns); // required parameters are required
prefix.apply(void 0, mixed);
prefix.apply(void 0, tuple);
prefix2.apply(void 0, ["g"].concat(ns));
prefix2.apply(void 0, __spreadArrays(["g"], ns));

View file

@ -11,9 +11,16 @@ takeTwo(...t2, 'a'); // error on 'a'
takeTwo(...t3); // error on ...t3
//// [callWithSpread3.js]
takeTwo.apply(void 0, ['a'].concat(t2)); // error on ...t2
takeTwo.apply(void 0, ['a', 'b', 'c'].concat(t2)); // error on 'c' and ...t2
takeTwo.apply(void 0, ['a', 'b'].concat(t2, ['c'])); // error on ...t2 and 'c'
takeTwo.apply(void 0, ['a', 'b', 'c'].concat(t2, ['d'])); // error on 'c', ...t2 and 'd'
takeTwo.apply(void 0, t2.concat(['a'])); // error on 'a'
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
takeTwo.apply(void 0, __spreadArrays(['a'], t2)); // error on ...t2
takeTwo.apply(void 0, __spreadArrays(['a', 'b', 'c'], t2)); // error on 'c' and ...t2
takeTwo.apply(void 0, __spreadArrays(['a', 'b'], t2, ['c'])); // error on ...t2 and 'c'
takeTwo.apply(void 0, __spreadArrays(['a', 'b', 'c'], t2, ['d'])); // error on 'c', ...t2 and 'd'
takeTwo.apply(void 0, __spreadArrays(t2, ['a'])); // error on 'a'
takeTwo.apply(void 0, t3); // error on ...t3

View file

@ -70,6 +70,13 @@ var [c14, c15, c16] = [1, 2, "string"];
* AssignmentRestElement:
* ... LeftHandSideExpression
*/
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
// An expression of type S is considered assignable to an assignment target V if one of the following is true
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
@ -88,7 +95,7 @@ var _e = foo(), b6 = _e[0], b7 = _e[1];
var b8 = foo().slice(0);
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
var temp = [1, 2, 3];
var _f = temp.slice(), c0 = _f[0], c1 = _f[1];
var _f = __spreadArrays(temp), c0 = _f[0], c1 = _f[1];
var c2 = [][0];
var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0];
var _h = [[1], true], c5 = _h[0][0], c6 = _h[1];

View file

@ -35,6 +35,13 @@ function foo(idx: number): F {
var [c4, c5, c6] = foo(1); // Error
//// [destructuringArrayBindingPatternAndAssignment2.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
// S is the type Any, or
var _a = [], a0 = _a[0][0], a1 = _a[1][0][0]; // Error
@ -50,8 +57,8 @@ var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 =
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
var temp = [1, 2, 3];
var _e = temp.slice(), c0 = _e[0], c1 = _e[1]; // Error
var _f = temp.slice(), c2 = _f[0], c3 = _f[1]; // Error
var _e = __spreadArrays(temp), c0 = _e[0], c1 = _e[1]; // Error
var _f = __spreadArrays(temp), c2 = _f[0], c3 = _f[1]; // Error
function foo(idx) {
return {
2: true

View file

@ -42,6 +42,13 @@ var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] }
//// [destructuringVariableDeclaration1ES5.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2;
@ -66,7 +73,7 @@ var _m = [1, "string"], d1 = _m[0], d2 = _m[1];
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true];
var _o = [1, "string"].concat(temp1), d3 = _o[0], d4 = _o[1];
var _o = __spreadArrays([1, "string"], temp1), d3 = _o[0], d4 = _o[1];
// Combining both forms of destructuring,
var _p = { e: [1, 2, { b1: 4, b4: 0 }] }.e, e1 = _p[0], e2 = _p[1], _q = _p[2], e3 = _q === void 0 ? { b1: 1000, b4: 200 } : _q;
var _r = { f: [1, 2, { f3: 4, f5: 0 }] }.f, f1 = _r[0], f2 = _r[1], _s = _r[2], f4 = _s.f3, f5 = _s.f5;

View file

@ -67,7 +67,7 @@ function arrayLiteral2() {
switch (_a.label) {
case 0: return [4 /*yield*/, y];
case 1:
x = (_a.sent()).concat([z]);
x = __spreadArrays.apply(void 0, [(_a.sent()), [z]]);
return [2 /*return*/];
}
});
@ -75,14 +75,14 @@ function arrayLiteral2() {
}
function arrayLiteral3() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b = (_a = y).concat;
_a = [y];
return [4 /*yield*/, z];
case 1:
x = _b.apply(_a, [[_c.sent()]]);
x = __spreadArrays.apply(void 0, _a.concat([[_b.sent()]]));
return [2 /*return*/];
}
});
@ -94,7 +94,7 @@ function arrayLiteral4() {
switch (_a.label) {
case 0: return [4 /*yield*/, y];
case 1:
x = [_a.sent()].concat(z);
x = __spreadArrays.apply(void 0, [[_a.sent()], z]);
return [2 /*return*/];
}
});
@ -102,14 +102,14 @@ function arrayLiteral4() {
}
function arrayLiteral5() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b = (_a = [y]).concat;
_a = [[y]];
return [4 /*yield*/, z];
case 1:
x = _b.apply(_a, [(_c.sent())]);
x = __spreadArrays.apply(void 0, _a.concat([(_b.sent())]));
return [2 /*return*/];
}
});

View file

@ -146,7 +146,7 @@ function callExpression4() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, x.apply(void 0, y.concat([z]))];
case 0: return [4 /*yield*/, x.apply(void 0, __spreadArrays(y, [z]))];
case 1:
_a.sent();
return [2 /*return*/];
@ -160,7 +160,7 @@ function callExpression5() {
switch (_a.label) {
case 0: return [4 /*yield*/, x];
case 1:
(_a.sent()).apply(void 0, y.concat([z]));
(_a.sent()).apply(void 0, __spreadArrays(y, [z]));
return [2 /*return*/];
}
});
@ -176,7 +176,7 @@ function callExpression6() {
_c = [void 0];
return [4 /*yield*/, y];
case 1:
_b.apply(_a, _c.concat([(_d.sent()).concat([z])]));
_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [(_d.sent()), [z]])]));
return [2 /*return*/];
}
});
@ -184,16 +184,16 @@ function callExpression6() {
}
function callExpression7() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = x).apply;
_c = [void 0];
_e = (_d = y).concat;
_d = [y];
return [4 /*yield*/, z];
case 1:
_b.apply(_a, _c.concat([_e.apply(_d, [[_f.sent()]])]));
_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([[_e.sent()]]))]));
return [2 /*return*/];
}
});
@ -209,7 +209,7 @@ function callExpression8() {
_c = [void 0];
return [4 /*yield*/, y];
case 1:
_b.apply(_a, _c.concat([[_d.sent()].concat(z)]));
_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [[_d.sent()], z])]));
return [2 /*return*/];
}
});
@ -217,16 +217,16 @@ function callExpression8() {
}
function callExpression9() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = x).apply;
_c = [void 0];
_e = (_d = [y]).concat;
_d = [[y]];
return [4 /*yield*/, z];
case 1:
_b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent())])]));
_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent())]))]));
return [2 /*return*/];
}
});

View file

@ -145,7 +145,7 @@ function newExpression4() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new (x.bind.apply(x, [void 0].concat(y, [z])))()];
case 0: return [4 /*yield*/, new (x.bind.apply(x, __spreadArrays([void 0], y, [z])))()];
case 1:
_a.sent();
return [2 /*return*/];
@ -160,7 +160,7 @@ function newExpression5() {
switch (_b.label) {
case 0: return [4 /*yield*/, x];
case 1:
new ((_a = (_b.sent())).bind.apply(_a, [void 0].concat(y, [z])))();
new ((_a = (_b.sent())).bind.apply(_a, __spreadArrays([void 0], y, [z])))();
return [2 /*return*/];
}
});
@ -168,16 +168,16 @@ function newExpression5() {
}
function newExpression6() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = x.bind).apply;
_c = [x];
_e = (_d = [void 0]).concat;
_d = [[void 0]];
return [4 /*yield*/, y];
case 1:
new (_b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent()), [z]])])))();
new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent()), [z]]))])))();
return [2 /*return*/];
}
});
@ -185,17 +185,16 @@ function newExpression6() {
}
function newExpression7() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, _f;
return __generator(this, function (_g) {
switch (_g.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = x.bind).apply;
_c = [x];
_e = (_d = [void 0]).concat;
_f = [y];
_d = [[void 0], y];
return [4 /*yield*/, z];
case 1:
new (_b.apply(_a, _c.concat([_e.apply(_d, _f.concat([[_g.sent()]]))])))();
new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([[_e.sent()]]))])))();
return [2 /*return*/];
}
});
@ -212,7 +211,7 @@ function newExpression8() {
_d = [void 0];
return [4 /*yield*/, y];
case 1:
new (_b.apply(_a, _c.concat([_d.concat([_e.sent()]).concat(z)])))();
new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, [_d.concat([_e.sent()]), z])])))();
return [2 /*return*/];
}
});
@ -220,16 +219,16 @@ function newExpression8() {
}
function newExpression9() {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_b = (_a = x.bind).apply;
_c = [x];
_e = (_d = [void 0, y]).concat;
_d = [[void 0, y]];
return [4 /*yield*/, z];
case 1:
new (_b.apply(_a, _c.concat([_e.apply(_d, [(_f.sent())])])))();
new (_b.apply(_a, _c.concat([__spreadArrays.apply(void 0, _d.concat([(_e.sent())]))])))();
return [2 /*return*/];
}
});

View file

@ -167,53 +167,60 @@ ff1 = ff4; // Error
//// [genericRestParameters1.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
f1 = f2;
f2 = f1;
f1(42, "hello", true);
f1(t3[0], t3[1], t3[2]);
f1.apply(void 0, t3);
f1.apply(void 0, [42].concat(t2));
f1.apply(void 0, [42, "hello"].concat(t1));
f1.apply(void 0, [42, "hello", true].concat(t0));
f1.apply(void 0, __spreadArrays([42], t2));
f1.apply(void 0, __spreadArrays([42, "hello"], t1));
f1.apply(void 0, __spreadArrays([42, "hello", true], t0));
f1(ns[0], ns[1], true);
f1.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last
f1.apply(void 0, __spreadArrays(ns, [true])); // Error, tuple spread only expanded when last
f2(42, "hello", true);
f2(t3[0], t3[1], t3[2]);
f2.apply(void 0, t3);
f2.apply(void 0, [42].concat(t2));
f2.apply(void 0, [42, "hello"].concat(t1));
f2.apply(void 0, [42, "hello", true].concat(t0));
f2.apply(void 0, __spreadArrays([42], t2));
f2.apply(void 0, __spreadArrays([42, "hello"], t1));
f2.apply(void 0, __spreadArrays([42, "hello", true], t0));
f2(ns[0], ns[1], true);
f2.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last
f2.apply(void 0, __spreadArrays(ns, [true])); // Error, tuple spread only expanded when last
var x10 = f10(42, "hello", true); // [number, string, boolean]
var x11 = f10(42, "hello"); // [number, string]
var x12 = f10(42); // [number]
var x13 = f10(); // []
var x14 = f10.apply(void 0, t3); // [number, string, boolean]
var x15 = f10.apply(void 0, [42].concat(t2)); // [number, string, boolean]
var x16 = f10.apply(void 0, [42, "hello"].concat(t1)); // [number, string, boolean]
var x17 = f10.apply(void 0, [42, "hello", true].concat(t0)); // [number, string, boolean]
var x18 = f10.apply(void 0, ns.concat([true])); // (string | number | boolean)[]
var x15 = f10.apply(void 0, __spreadArrays([42], t2)); // [number, string, boolean]
var x16 = f10.apply(void 0, __spreadArrays([42, "hello"], t1)); // [number, string, boolean]
var x17 = f10.apply(void 0, __spreadArrays([42, "hello", true], t0)); // [number, string, boolean]
var x18 = f10.apply(void 0, __spreadArrays(ns, [true])); // (string | number | boolean)[]
function g10(u, v) {
var x1 = f10.apply(void 0, u); // U
var x2 = f10.apply(void 0, v); // V
var x3 = f10.apply(void 0, [1].concat(u)); // [number, ...string[]]
var x4 = f10.apply(void 0, u.concat(v)); // (string | number)[]
var x3 = f10.apply(void 0, __spreadArrays([1], u)); // [number, ...string[]]
var x4 = f10.apply(void 0, __spreadArrays(u, v)); // (string | number)[]
}
var z10 = f11(42, "hello", true); // [42, "hello", true]
var z11 = f11(42, "hello"); // [42, "hello"]
var z12 = f11(42); // [42]
var z13 = f11(); // []
var z14 = f11.apply(void 0, t3); // [number, string, boolean]
var z15 = f11.apply(void 0, [42].concat(t2)); // [42, string, boolean]
var z16 = f11.apply(void 0, [42, "hello"].concat(t1)); // [42, "hello", boolean]
var z17 = f11.apply(void 0, [42, "hello", true].concat(t0)); // [42, "hello", true]
var z18 = f11.apply(void 0, ns.concat([true])); // (string | number | true)[]
var z15 = f11.apply(void 0, __spreadArrays([42], t2)); // [42, string, boolean]
var z16 = f11.apply(void 0, __spreadArrays([42, "hello"], t1)); // [42, "hello", boolean]
var z17 = f11.apply(void 0, __spreadArrays([42, "hello", true], t0)); // [42, "hello", true]
var z18 = f11.apply(void 0, __spreadArrays(ns, [true])); // (string | number | true)[]
function g11(u, v) {
var x1 = f11.apply(void 0, u); // U
var x2 = f11.apply(void 0, v); // V
var x3 = f11.apply(void 0, [1].concat(u)); // [1, ...string[]]
var x4 = f11.apply(void 0, u.concat(v)); // (string | number)[]
var x3 = f11.apply(void 0, __spreadArrays([1], u)); // [1, ...string[]]
var x4 = f11.apply(void 0, __spreadArrays(u, v)); // (string | number)[]
}
function call(f) {
var args = [];
@ -239,7 +246,7 @@ function bind(f, x) {
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
return f.apply(void 0, [x].concat(rest));
return f.apply(void 0, __spreadArrays([x], rest));
};
}
var f21 = bind(f20, 42); // (y: string, z: boolean) => string[]

View file

@ -81,46 +81,53 @@ type T12 = P1<(x: number, y: number) => void>;
//// [genericRestParameters2.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
f10(42, "hello");
f10(42, "hello", true);
f10(42, "hello", true, false);
f10(t1[0], t1[1], t1[2], t1[3]);
f10.apply(void 0, t1);
f10.apply(void 0, [42].concat(t2));
f10.apply(void 0, [42, "hello"].concat(t3));
f10.apply(void 0, [42, "hello", true].concat(t4));
f10.apply(void 0, [42, "hello", true].concat(t4, [false], t3));
f10.apply(void 0, __spreadArrays([42], t2));
f10.apply(void 0, __spreadArrays([42, "hello"], t3));
f10.apply(void 0, __spreadArrays([42, "hello", true], t4));
f10.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3));
f11(42, "hello");
f11(42, "hello", true);
f11(42, "hello", true, false);
f11(t1[0], t1[1], t1[2], t1[3]);
f11.apply(void 0, t1);
f11.apply(void 0, [42].concat(t2));
f11.apply(void 0, [42, "hello"].concat(t3));
f11.apply(void 0, [42, "hello", true].concat(t4));
f11.apply(void 0, [42, "hello", true].concat(t4, [false], t3));
f11.apply(void 0, __spreadArrays([42], t2));
f11.apply(void 0, __spreadArrays([42, "hello"], t3));
f11.apply(void 0, __spreadArrays([42, "hello", true], t4));
f11.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3));
f12(42, "hello");
f12(42, "hello", true);
f12(42, "hello", true, false);
f12(t1[0], t1[1], t1[2], t1[3]);
f12.apply(void 0, t1);
f12.apply(void 0, [42].concat(t2));
f12.apply(void 0, [42, "hello"].concat(t3));
f12.apply(void 0, [42, "hello", true].concat(t4));
f12.apply(void 0, [42, "hello", true].concat(t4, [false], t3));
f12.apply(void 0, __spreadArrays([42], t2));
f12.apply(void 0, __spreadArrays([42, "hello"], t3));
f12.apply(void 0, __spreadArrays([42, "hello", true], t4));
f12.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3));
f13(42, "hello");
f13(42, "hello", true);
f13(42, "hello", true, false);
f13(t1[0], t1[1], t1[2], t1[3]);
f13.apply(void 0, t1);
f13.apply(void 0, [42].concat(t2));
f13.apply(void 0, [42, "hello"].concat(t3));
f13.apply(void 0, [42, "hello", true].concat(t4));
f13.apply(void 0, [42, "hello", true].concat(t4, [false], t3));
f13.apply(void 0, __spreadArrays([42], t2));
f13.apply(void 0, __spreadArrays([42, "hello"], t3));
f13.apply(void 0, __spreadArrays([42, "hello", true], t4));
f13.apply(void 0, __spreadArrays([42, "hello", true], t4, [false], t3));
f20.apply(void 0, t1);
f20.apply(void 0, [42].concat(t2));
f20.apply(void 0, [42, "hello"].concat(t3));
f20.apply(void 0, [42, "hello"].concat(t2, [true]));
f20.apply(void 0, __spreadArrays([42], t2));
f20.apply(void 0, __spreadArrays([42, "hello"], t3));
f20.apply(void 0, __spreadArrays([42, "hello"], t2, [true]));
//// [genericRestParameters2.d.ts]

View file

@ -56,9 +56,16 @@ hmm("what"); // no error? A = [] | [number, string] ?
//// [genericRestParameters3.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
f1("foo", "abc");
f1("foo", 10, true);
f1.apply(void 0, ["foo"].concat(tt));
f1.apply(void 0, __spreadArrays(["foo"], tt));
f1("foo", 10); // Error
f1("foo"); // Error
f2 = f1;

View file

@ -672,6 +672,13 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var Shape = /** @class */ (function () {
function Shape() {
}
@ -951,7 +958,7 @@ function f1(thing) {
var x1 = path(thing, 'a'); // { x: number, y: string }
var x2 = path(thing, 'a', 'y'); // string
var x3 = path(thing, 'b'); // boolean
var x4 = path.apply(void 0, [thing].concat(['a', 'x'])); // any
var x4 = path.apply(void 0, __spreadArrays([thing], ['a', 'x'])); // any
}
// Repro from comment in #12114
var assignTo2 = function (object, key1, key2) {

View file

@ -62,6 +62,13 @@ function f5() {
}
//// [literalFreshnessPropagationOnNarrowing.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function f1() {
var b = true;
var obj = { b: b };
@ -83,7 +90,7 @@ function f2() {
// Desired: OK
// 3.0: Error
// 3.1: OK
var a5 = (Array.isArray(elOrA) ? elOrA : [elOrA]).slice();
var a5 = __spreadArrays(Array.isArray(elOrA) ? elOrA : [elOrA]);
}
function f3() {
var x = 'x';

View file

@ -97,6 +97,13 @@ new i["a-b"][1](1, 2, ...a);
new i["a-b"][1](1, 2, ...a, "string");
//// [newWithSpread.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
function f(x, y) {
var z = [];
@ -129,52 +136,52 @@ var h;
var i;
// Basic expression
new f(1, 2, "string");
new (f.bind.apply(f, [void 0, 1, 2].concat(a)))();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Multiple spreads arguments
new (f2.bind.apply(f2, [void 0].concat(a, a)))();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, a)))();
new (f2.bind.apply(f2, __spreadArrays([void 0], a, a)))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, a)))();
// Call expression
new f(1, 2, "string")();
new (f.bind.apply(f, [void 0, 1, 2].concat(a)))()();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))()();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))()();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))()();
// Property access expression
new b.f(1, 2, "string");
new ((_a = b.f).bind.apply(_a, [void 0, 1, 2].concat(a)))();
new ((_b = b.f).bind.apply(_b, [void 0, 1, 2].concat(a, ["string"])))();
new ((_a = b.f).bind.apply(_a, __spreadArrays([void 0, 1, 2], a)))();
new ((_b = b.f).bind.apply(_b, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Parenthesised expression
new (b.f)(1, 2, "string");
new ((_c = (b.f)).bind.apply(_c, [void 0, 1, 2].concat(a)))();
new ((_d = (b.f)).bind.apply(_d, [void 0, 1, 2].concat(a, ["string"])))();
new ((_c = (b.f)).bind.apply(_c, __spreadArrays([void 0, 1, 2], a)))();
new ((_d = (b.f)).bind.apply(_d, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression
new d[1].f(1, 2, "string");
new ((_e = d[1].f).bind.apply(_e, [void 0, 1, 2].concat(a)))();
new ((_f = d[1].f).bind.apply(_f, [void 0, 1, 2].concat(a, ["string"])))();
new ((_e = d[1].f).bind.apply(_e, __spreadArrays([void 0, 1, 2], a)))();
new ((_f = d[1].f).bind.apply(_f, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a punctuated key
new e["a-b"].f(1, 2, "string");
new ((_g = e["a-b"].f).bind.apply(_g, [void 0, 1, 2].concat(a)))();
new ((_h = e["a-b"].f).bind.apply(_h, [void 0, 1, 2].concat(a, ["string"])))();
new ((_g = e["a-b"].f).bind.apply(_g, __spreadArrays([void 0, 1, 2], a)))();
new ((_h = e["a-b"].f).bind.apply(_h, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Basic expression
new B(1, 2, "string");
new (B.bind.apply(B, [void 0, 1, 2].concat(a)))();
new (B.bind.apply(B, [void 0, 1, 2].concat(a, ["string"])))();
new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a)))();
new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Property access expression
new c["a-b"](1, 2, "string");
new ((_j = c["a-b"]).bind.apply(_j, [void 0, 1, 2].concat(a)))();
new ((_k = c["a-b"]).bind.apply(_k, [void 0, 1, 2].concat(a, ["string"])))();
new ((_j = c["a-b"]).bind.apply(_j, __spreadArrays([void 0, 1, 2], a)))();
new ((_k = c["a-b"]).bind.apply(_k, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Parenthesised expression
new (c["a-b"])(1, 2, "string");
new ((_l = (c["a-b"])).bind.apply(_l, [void 0, 1, 2].concat(a)))();
new ((_m = (c["a-b"])).bind.apply(_m, [void 0, 1, 2].concat(a, ["string"])))();
new ((_l = (c["a-b"])).bind.apply(_l, __spreadArrays([void 0, 1, 2], a)))();
new ((_m = (c["a-b"])).bind.apply(_m, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression
new g[1]["a-b"](1, 2, "string");
new ((_o = g[1]["a-b"]).bind.apply(_o, [void 0, 1, 2].concat(a)))();
new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0, 1, 2].concat(a, ["string"])))();
new ((_o = g[1]["a-b"]).bind.apply(_o, __spreadArrays([void 0, 1, 2], a)))();
new ((_p = g[1]["a-b"]).bind.apply(_p, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a punctuated key
new h["a-b"]["a-b"](1, 2, "string");
new ((_q = h["a-b"]["a-b"]).bind.apply(_q, [void 0, 1, 2].concat(a)))();
new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0, 1, 2].concat(a, ["string"])))();
new ((_q = h["a-b"]["a-b"]).bind.apply(_q, __spreadArrays([void 0, 1, 2], a)))();
new ((_r = h["a-b"]["a-b"]).bind.apply(_r, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a number
new i["a-b"][1](1, 2, "string");
new ((_s = i["a-b"][1]).bind.apply(_s, [void 0, 1, 2].concat(a)))();
new ((_t = i["a-b"][1]).bind.apply(_t, [void 0, 1, 2].concat(a, ["string"])))();
new ((_s = i["a-b"][1]).bind.apply(_s, __spreadArrays([void 0, 1, 2], a)))();
new ((_t = i["a-b"][1]).bind.apply(_t, __spreadArrays([void 0, 1, 2], a, ["string"])))();

View file

@ -96,6 +96,13 @@ new i["a-b"][1](1, 2, ...a);
new i["a-b"][1](1, 2, ...a, "string");
//// [newWithSpreadES5.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
function f(x, y) {
var z = [];
@ -128,52 +135,52 @@ var h;
var i;
// Basic expression
new f(1, 2, "string");
new (f.bind.apply(f, [void 0, 1, 2].concat(a)))();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Multiple spreads arguments
new (f2.bind.apply(f2, [void 0].concat(a, a)))();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, a)))();
new (f2.bind.apply(f2, __spreadArrays([void 0], a, a)))();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, a)))();
// Call expression
new f(1, 2, "string")();
new (f.bind.apply(f, [void 0, 1, 2].concat(a)))()();
new (f.bind.apply(f, [void 0, 1, 2].concat(a, ["string"])))()();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a)))()();
new (f.bind.apply(f, __spreadArrays([void 0, 1, 2], a, ["string"])))()();
// Property access expression
new b.f(1, 2, "string");
new ((_a = b.f).bind.apply(_a, [void 0, 1, 2].concat(a)))();
new ((_b = b.f).bind.apply(_b, [void 0, 1, 2].concat(a, ["string"])))();
new ((_a = b.f).bind.apply(_a, __spreadArrays([void 0, 1, 2], a)))();
new ((_b = b.f).bind.apply(_b, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Parenthesised expression
new (b.f)(1, 2, "string");
new ((_c = (b.f)).bind.apply(_c, [void 0, 1, 2].concat(a)))();
new ((_d = (b.f)).bind.apply(_d, [void 0, 1, 2].concat(a, ["string"])))();
new ((_c = (b.f)).bind.apply(_c, __spreadArrays([void 0, 1, 2], a)))();
new ((_d = (b.f)).bind.apply(_d, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression
new d[1].f(1, 2, "string");
new ((_e = d[1].f).bind.apply(_e, [void 0, 1, 2].concat(a)))();
new ((_f = d[1].f).bind.apply(_f, [void 0, 1, 2].concat(a, ["string"])))();
new ((_e = d[1].f).bind.apply(_e, __spreadArrays([void 0, 1, 2], a)))();
new ((_f = d[1].f).bind.apply(_f, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a punctuated key
new e["a-b"].f(1, 2, "string");
new ((_g = e["a-b"].f).bind.apply(_g, [void 0, 1, 2].concat(a)))();
new ((_h = e["a-b"].f).bind.apply(_h, [void 0, 1, 2].concat(a, ["string"])))();
new ((_g = e["a-b"].f).bind.apply(_g, __spreadArrays([void 0, 1, 2], a)))();
new ((_h = e["a-b"].f).bind.apply(_h, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Basic expression
new B(1, 2, "string");
new (B.bind.apply(B, [void 0, 1, 2].concat(a)))();
new (B.bind.apply(B, [void 0, 1, 2].concat(a, ["string"])))();
new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a)))();
new (B.bind.apply(B, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Property access expression
new c["a-b"](1, 2, "string");
new ((_j = c["a-b"]).bind.apply(_j, [void 0, 1, 2].concat(a)))();
new ((_k = c["a-b"]).bind.apply(_k, [void 0, 1, 2].concat(a, ["string"])))();
new ((_j = c["a-b"]).bind.apply(_j, __spreadArrays([void 0, 1, 2], a)))();
new ((_k = c["a-b"]).bind.apply(_k, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Parenthesised expression
new (c["a-b"])(1, 2, "string");
new ((_l = (c["a-b"])).bind.apply(_l, [void 0, 1, 2].concat(a)))();
new ((_m = (c["a-b"])).bind.apply(_m, [void 0, 1, 2].concat(a, ["string"])))();
new ((_l = (c["a-b"])).bind.apply(_l, __spreadArrays([void 0, 1, 2], a)))();
new ((_m = (c["a-b"])).bind.apply(_m, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression
new g[1]["a-b"](1, 2, "string");
new ((_o = g[1]["a-b"]).bind.apply(_o, [void 0, 1, 2].concat(a)))();
new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0, 1, 2].concat(a, ["string"])))();
new ((_o = g[1]["a-b"]).bind.apply(_o, __spreadArrays([void 0, 1, 2], a)))();
new ((_p = g[1]["a-b"]).bind.apply(_p, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a punctuated key
new h["a-b"]["a-b"](1, 2, "string");
new ((_q = h["a-b"]["a-b"]).bind.apply(_q, [void 0, 1, 2].concat(a)))();
new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0, 1, 2].concat(a, ["string"])))();
new ((_q = h["a-b"]["a-b"]).bind.apply(_q, __spreadArrays([void 0, 1, 2], a)))();
new ((_r = h["a-b"]["a-b"]).bind.apply(_r, __spreadArrays([void 0, 1, 2], a, ["string"])))();
// Element access expression with a number
new i["a-b"][1](1, 2, "string");
new ((_s = i["a-b"][1]).bind.apply(_s, [void 0, 1, 2].concat(a)))();
new ((_t = i["a-b"][1]).bind.apply(_t, [void 0, 1, 2].concat(a, ["string"])))();
new ((_s = i["a-b"][1]).bind.apply(_s, __spreadArrays([void 0, 1, 2], a)))();
new ((_t = i["a-b"][1]).bind.apply(_t, __spreadArrays([void 0, 1, 2], a, ["string"])))();

View file

@ -8,11 +8,18 @@ export function f() {
//// [noCrashOnNoLib.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
exports.__esModule = true;
function f() {
var e;
while (true) {
e = (e || []).slice();
e = __spreadArrays((e || []));
}
}
exports.f = f;

View file

@ -29,6 +29,13 @@ function f4(...args: readonly string[]) {
//// [readonlyRestParameters.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function f0(a, b) {
f0(a, b);
f1(a, b);
@ -41,7 +48,7 @@ function f1() {
}
f0.apply(void 0, args); // Error
f1('abc', 'def');
f1.apply(void 0, ['abc'].concat(args));
f1.apply(void 0, __spreadArrays(['abc'], args));
f1.apply(void 0, args);
}
function f2() {
@ -51,10 +58,10 @@ function f2() {
}
f0.apply(void 0, args);
f1('abc', 'def');
f1.apply(void 0, ['abc'].concat(args));
f1.apply(void 0, __spreadArrays(['abc'], args));
f1.apply(void 0, args);
f2('abc', 'def');
f2.apply(void 0, ['abc'].concat(args)); // Error
f2.apply(void 0, __spreadArrays(['abc'], args)); // Error
f2.apply(void 0, args);
}
function f4() {

View file

@ -101,6 +101,13 @@ const funcUnionTupleRest: TupleUnionFunc = (...params) => {
//// [restTuplesFromContextualTypes.js]
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
(function (a, b, c) { }).apply(void 0, t1);
(function () {
var x = [];
@ -201,31 +208,31 @@ f2(function (a, b, c) {
x[_i - 3] = arguments[_i];
}
});
(function (a, b, c) { }).apply(void 0, [1].concat(t3));
(function (a, b, c) { }).apply(void 0, __spreadArrays([1], t3));
(function () {
var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
x[_i] = arguments[_i];
}
}).apply(void 0, [1].concat(t3));
}).apply(void 0, __spreadArrays([1], t3));
(function (a) {
var x = [];
for (var _i = 1; _i < arguments.length; _i++) {
x[_i - 1] = arguments[_i];
}
}).apply(void 0, [1].concat(t3));
}).apply(void 0, __spreadArrays([1], t3));
(function (a, b) {
var x = [];
for (var _i = 2; _i < arguments.length; _i++) {
x[_i - 2] = arguments[_i];
}
}).apply(void 0, [1].concat(t3));
}).apply(void 0, __spreadArrays([1], t3));
(function (a, b, c) {
var x = [];
for (var _i = 3; _i < arguments.length; _i++) {
x[_i - 3] = arguments[_i];
}
}).apply(void 0, [1].concat(t3));
}).apply(void 0, __spreadArrays([1], t3));
f3(function (a, b, c) { });
f3(function () {
var x = [];
@ -263,13 +270,13 @@ function f4(t) {
for (var _i = 1; _i < arguments.length; _i++) {
x[_i - 1] = arguments[_i];
}
}).apply(void 0, [1].concat(t));
}).apply(void 0, __spreadArrays([1], t));
(function (a) {
var x = [];
for (var _i = 1; _i < arguments.length; _i++) {
x[_i - 1] = arguments[_i];
}
}).apply(void 0, [1, 2].concat(t));
}).apply(void 0, __spreadArrays([1, 2], t));
function f(cb) { }
f(function () {
var x = [];

View file

@ -6,8 +6,15 @@ for (const subcomponent of [1, 2, 3]) {
//// [selfReferencingSpreadInLoop.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var additional = [];
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var subcomponent = _a[_i];
additional = additional.concat([subcomponent]);
additional = __spreadArrays(additional, [subcomponent]);
}

View file

@ -8,4 +8,11 @@ declare let foo2: Foo;
foo1 = [...Array.isArray(foo2) ? foo2 : [foo2]];
//// [spreadBooleanRespectsFreshness.js]
foo1 = (Array.isArray(foo2) ? foo2 : [foo2]).slice();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
foo1 = __spreadArrays(Array.isArray(foo2) ? foo2 : [foo2]);

View file

@ -41,6 +41,13 @@ var whitespace3 = <div>
//// [file.jsx]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var p;
var selfClosed1 = <div />;
var selfClosed2 = <div x="1"/>;
@ -60,10 +67,10 @@ var SomeClass = /** @class */ (function () {
SomeClass.prototype.f = function () {
var _this = this;
var rewrites1 = <div>{function () { return _this; }}</div>;
var rewrites2 = <div>{[p].concat(p, [p])}</div>;
var rewrites2 = <div>{__spreadArrays([p], p, [p])}</div>;
var rewrites3 = <div>{{ p: p }}</div>;
var rewrites4 = <div a={function () { return _this; }}></div>;
var rewrites5 = <div a={[p].concat(p, [p])}></div>;
var rewrites5 = <div a={__spreadArrays([p], p, [p])}></div>;
var rewrites6 = <div a={{ p: p }}></div>;
};
return SomeClass;

View file

@ -42,6 +42,13 @@ var whitespace3 = <div>
//// [file.js]
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var p;
var selfClosed1 = React.createElement("div", null);
var selfClosed2 = React.createElement("div", { x: "1" });
@ -61,10 +68,10 @@ var SomeClass = /** @class */ (function () {
SomeClass.prototype.f = function () {
var _this = this;
var rewrites1 = React.createElement("div", null, function () { return _this; });
var rewrites2 = React.createElement("div", null, [p].concat(p, [p]));
var rewrites2 = React.createElement("div", null, __spreadArrays([p], p, [p]));
var rewrites3 = React.createElement("div", null, { p: p });
var rewrites4 = React.createElement("div", { a: function () { return _this; } });
var rewrites5 = React.createElement("div", { a: [p].concat(p, [p]) });
var rewrites5 = React.createElement("div", { a: __spreadArrays([p], p, [p]) });
var rewrites6 = React.createElement("div", { a: { p: p } });
};
return SomeClass;