diff --git a/.gitignore b/.gitignore index f487ea6dd29ba..f28b2ffd329ce 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ tests/services/baselines/local/* tests/baselines/prototyping/local/* tests/baselines/rwc/* tests/baselines/test262/* +tests/baselines/reference/projectOutput/* tests/baselines/local/projectOutput/* tests/services/baselines/prototyping/local/* tests/services/browser/typescriptServices.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3201434da5839..020226439b720 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6599,7 +6599,7 @@ module ts { result.splice(spliceIndex, 0, signature); } } - + function getSpreadArgumentIndex(args: Expression[]): number { for (let i = 0; i < args.length; i++) { if (args[i].kind === SyntaxKind.SpreadElementExpression) { @@ -7121,10 +7121,10 @@ module ts { } function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature { - if (node.arguments && languageVersion < ScriptTarget.ES6) { + if (node.arguments && languageVersion < ScriptTarget.ES5) { let spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } @@ -7142,7 +7142,7 @@ module ts { // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate - // signatures for overload resolution.The result type of the function call becomes + // signatures for overload resolution. The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); if (expressionType === unknownType) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 32dc590eeecff..2a8527168464a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -334,7 +334,7 @@ module ts { The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a3dfd62d34e75..cf1645b140724 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1324,7 +1324,7 @@ "category": "Error", "code": 2471 }, - "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.": { + "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher.": { "category": "Error", "code": 2472 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c9d23ec5ceebf..f474926b33959 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1366,16 +1366,16 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return true; } - function emitListWithSpread(elements: Expression[], alwaysCopy: boolean, multiLine: boolean, trailingComma: boolean) { + function emitListWithSpread(elements: Expression[], needsUniqueCopy: boolean, multiLine: boolean, trailingComma: boolean, useConcat: boolean) { let pos = 0; let group = 0; let length = elements.length; while (pos < length) { // Emit using the pattern .concat(, , ...) - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } let e = elements[pos]; @@ -1383,7 +1383,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { e = (e).expression; emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== SyntaxKind.ArrayLiteralExpression) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== SyntaxKind.ArrayLiteralExpression) { write(".slice()"); } } @@ -1406,7 +1406,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { group++; } if (group > 1) { - write(")"); + if(useConcat) { + write(")"); + } } } @@ -1425,8 +1427,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("]"); } else { - emitListWithSpread(elements, /*alwaysCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, - /*trailingComma*/ elements.hasTrailingComma); + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); } } @@ -1850,7 +1852,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("void 0"); } write(", "); - emitListWithSpread(node.arguments, /*alwaysCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); write(")"); } @@ -1886,11 +1888,44 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitNewExpression(node: NewExpression) { write("new "); - emit(node.expression); - if (node.arguments) { + + // Spread operator logic can be supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var arguments = [1, 2, 3, 4, 5]; + // new Array(...arguments); + // + // Could be transpiled into ES5: + // + // var arguments = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(arguments))); + // + // `[void 0]` is the first argument which represents `thisArg` to the bind method above. + // And `thisArg` will be set to the return value of the constructor when instantiated + // with the new operator — regardless of any value we set `thisArg` to. Thus, we set it + // to an undefined, `void 0`. + if (languageVersion === ScriptTarget.ES5 && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); - emitCommaList(node.arguments); - write(")"); + let target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } diff --git a/tests/baselines/reference/callWithSpread.errors.txt b/tests/baselines/reference/callWithSpread.errors.txt deleted file mode 100644 index a28d4c8b1a176..0000000000000 --- a/tests/baselines/reference/callWithSpread.errors.txt +++ /dev/null @@ -1,59 +0,0 @@ -tests/cases/conformance/expressions/functionCalls/callWithSpread.ts(52,21): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts (1 errors) ==== - interface X { - foo(x: number, y: number, ...z: string[]); - } - - function foo(x: number, y: number, ...z: string[]) { - } - - var a: string[]; - var z: number[]; - var obj: X; - var xa: X[]; - - foo(1, 2, "abc"); - foo(1, 2, ...a); - foo(1, 2, ...a, "abc"); - - obj.foo(1, 2, "abc"); - obj.foo(1, 2, ...a); - obj.foo(1, 2, ...a, "abc"); - - (obj.foo)(1, 2, "abc"); - (obj.foo)(1, 2, ...a); - (obj.foo)(1, 2, ...a, "abc"); - - xa[1].foo(1, 2, "abc"); - xa[1].foo(1, 2, ...a); - xa[1].foo(1, 2, ...a, "abc"); - - (xa[1].foo)(...[1, 2, "abc"]); - - class C { - constructor(x: number, y: number, ...z: string[]) { - this.foo(x, y); - this.foo(x, y, ...z); - } - foo(x: number, y: number, ...z: string[]) { - } - } - - class D extends C { - constructor() { - super(1, 2); - super(1, 2, ...a); - } - foo() { - super.foo(1, 2); - super.foo(1, 2, ...a); - } - } - - // Only supported in when target is ES6 - var c = new C(1, 2, ...a); - ~~~~ -!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. - \ No newline at end of file diff --git a/tests/baselines/reference/callWithSpread.js b/tests/baselines/reference/callWithSpread.js index c9cd5d2adce65..d21b4879daabf 100644 --- a/tests/baselines/reference/callWithSpread.js +++ b/tests/baselines/reference/callWithSpread.js @@ -48,9 +48,6 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); //// [callWithSpread.js] @@ -112,6 +109,4 @@ var D = (function (_super) { }; return D; })(C); -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); var _a, _b, _c; diff --git a/tests/baselines/reference/callWithSpread.symbols b/tests/baselines/reference/callWithSpread.symbols new file mode 100644 index 0000000000000..c5ac7fe66b2f9 --- /dev/null +++ b/tests/baselines/reference/callWithSpread.symbols @@ -0,0 +1,159 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts === +interface X { +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + + foo(x: number, y: number, ...z: string[]); +>foo : Symbol(foo, Decl(callWithSpread.ts, 0, 13)) +>x : Symbol(x, Decl(callWithSpread.ts, 1, 8)) +>y : Symbol(y, Decl(callWithSpread.ts, 1, 18)) +>z : Symbol(z, Decl(callWithSpread.ts, 1, 29)) +} + +function foo(x: number, y: number, ...z: string[]) { +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>x : Symbol(x, Decl(callWithSpread.ts, 4, 13)) +>y : Symbol(y, Decl(callWithSpread.ts, 4, 23)) +>z : Symbol(z, Decl(callWithSpread.ts, 4, 34)) +} + +var a: string[]; +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +var z: number[]; +>z : Symbol(z, Decl(callWithSpread.ts, 8, 3)) + +var obj: X; +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + +var xa: X[]; +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + +foo(1, 2, "abc"); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) + +foo(1, 2, ...a); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +foo(1, 2, ...a, "abc"); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +obj.foo(1, 2, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +obj.foo(1, 2, ...a); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +obj.foo(1, 2, ...a, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(obj.foo)(1, 2, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +(obj.foo)(1, 2, ...a); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(obj.foo)(1, 2, ...a, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +xa[1].foo(1, 2, "abc"); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +xa[1].foo(1, 2, ...a); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +xa[1].foo(1, 2, ...a, "abc"); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(xa[1].foo)(...[1, 2, "abc"]); +>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + constructor(x: number, y: number, ...z: string[]) { +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) + + this.foo(x, y); +>this.foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) + + this.foo(x, y, ...z); +>this.foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) + } + foo(x: number, y: number, ...z: string[]) { +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 35, 8)) +>y : Symbol(y, Decl(callWithSpread.ts, 35, 18)) +>z : Symbol(z, Decl(callWithSpread.ts, 35, 29)) + } +} + +class D extends C { +>D : Symbol(D, Decl(callWithSpread.ts, 37, 1)) +>C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + constructor() { + super(1, 2); +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + super(1, 2, ...a); +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + } + foo() { +>foo : Symbol(foo, Decl(callWithSpread.ts, 43, 5)) + + super.foo(1, 2); +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) + + super.foo(1, 2, ...a); +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + } +} + diff --git a/tests/baselines/reference/callWithSpread.types b/tests/baselines/reference/callWithSpread.types new file mode 100644 index 0000000000000..f7097727204ff --- /dev/null +++ b/tests/baselines/reference/callWithSpread.types @@ -0,0 +1,247 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts === +interface X { +>X : X + + foo(x: number, y: number, ...z: string[]); +>foo : (x: number, y: number, ...z: string[]) => any +>x : number +>y : number +>z : string[] +} + +function foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +var a: string[]; +>a : string[] + +var z: number[]; +>z : number[] + +var obj: X; +>obj : X +>X : X + +var xa: X[]; +>xa : X[] +>X : X + +foo(1, 2, "abc"); +>foo(1, 2, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"abc" : string + +foo(1, 2, ...a); +>foo(1, 2, ...a) : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +foo(1, 2, ...a, "abc"); +>foo(1, 2, ...a, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +obj.foo(1, 2, "abc"); +>obj.foo(1, 2, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +obj.foo(1, 2, ...a); +>obj.foo(1, 2, ...a) : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +obj.foo(1, 2, ...a, "abc"); +>obj.foo(1, 2, ...a, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +(obj.foo)(1, 2, "abc"); +>(obj.foo)(1, 2, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +(obj.foo)(1, 2, ...a); +>(obj.foo)(1, 2, ...a) : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +(obj.foo)(1, 2, ...a, "abc"); +>(obj.foo)(1, 2, ...a, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +xa[1].foo(1, 2, "abc"); +>xa[1].foo(1, 2, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +xa[1].foo(1, 2, ...a); +>xa[1].foo(1, 2, ...a) : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +xa[1].foo(1, 2, ...a, "abc"); +>xa[1].foo(1, 2, ...a, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +(xa[1].foo)(...[1, 2, "abc"]); +>(xa[1].foo)(...[1, 2, "abc"]) : any +>(xa[1].foo) : Function +>xa[1].foo : Function +>Function : Function +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>...[1, 2, "abc"] : string | number +>[1, 2, "abc"] : (string | number)[] +>1 : number +>2 : number +>"abc" : string + +class C { +>C : C + + constructor(x: number, y: number, ...z: string[]) { +>x : number +>y : number +>z : string[] + + this.foo(x, y); +>this.foo(x, y) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number + + this.foo(x, y, ...z); +>this.foo(x, y, ...z) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>...z : string +>z : string[] + } + foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] + } +} + +class D extends C { +>D : D +>C : C + + constructor() { + super(1, 2); +>super(1, 2) : void +>super : typeof C +>1 : number +>2 : number + + super(1, 2, ...a); +>super(1, 2, ...a) : void +>super : typeof C +>1 : number +>2 : number +>...a : string +>a : string[] + } + foo() { +>foo : () => void + + super.foo(1, 2); +>super.foo(1, 2) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number + + super.foo(1, 2, ...a); +>super.foo(1, 2, ...a) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + } +} + diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js index d6a915f5f36f2..11fa8d6edcdc5 100644 --- a/tests/baselines/reference/callWithSpreadES6.js +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -49,9 +49,6 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); //// [callWithSpreadES6.js] @@ -92,5 +89,3 @@ class D extends C { super.foo(1, 2, ...a); } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/callWithSpreadES6.symbols b/tests/baselines/reference/callWithSpreadES6.symbols index 94e0b94b002be..008488d0ce905 100644 --- a/tests/baselines/reference/callWithSpreadES6.symbols +++ b/tests/baselines/reference/callWithSpreadES6.symbols @@ -158,9 +158,3 @@ class D extends C { } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); ->c : Symbol(c, Decl(callWithSpreadES6.ts, 52, 3)) ->C : Symbol(C, Decl(callWithSpreadES6.ts, 29, 40)) ->a : Symbol(a, Decl(callWithSpreadES6.ts, 8, 3)) - diff --git a/tests/baselines/reference/callWithSpreadES6.types b/tests/baselines/reference/callWithSpreadES6.types index 71d3cf9b2df58..ba638207e8a28 100644 --- a/tests/baselines/reference/callWithSpreadES6.types +++ b/tests/baselines/reference/callWithSpreadES6.types @@ -246,13 +246,3 @@ class D extends C { } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); ->c : C ->new C(1, 2, ...a) : C ->C : typeof C ->1 : number ->2 : number ->...a : string ->a : string[] - diff --git a/tests/baselines/reference/newWithSpread.errors.txt b/tests/baselines/reference/newWithSpread.errors.txt new file mode 100644 index 0000000000000..293c7054e4c2f --- /dev/null +++ b/tests/baselines/reference/newWithSpread.errors.txt @@ -0,0 +1,178 @@ +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(37,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(38,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(41,8): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(42,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(46,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(47,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(51,15): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(52,15): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(56,17): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(57,17): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(61,18): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(62,18): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(66,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(67,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(71,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(72,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(76,20): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(77,20): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(81,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(82,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(86,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(87,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(91,27): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(92,27): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(96,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(97,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + +==== tests/cases/conformance/expressions/functionCalls/newWithSpread.ts (26 errors) ==== + + function f(x: number, y: number, ...z: string[]) { + } + + function f2(...x: string[]) { + } + + interface A { + f: { + new (x: number, y: number, ...z: string[]); + } + } + + class B { + constructor(x: number, y: number, ...z: string[]) {} + } + + interface C { + "a-b": typeof B; + } + + interface D { + 1: typeof B; + } + + var a: string[]; + var b: A; + var c: C; + var d: A[]; + var e: { [key: string]: A }; + var g: C[]; + var h: { [key: string]: C }; + var i: C[][]; + + // Basic expression + new f(1, 2, "string"); + new f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Multiple spreads arguments + new f2(...a, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1 ,2, ...a, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Call expression + new f(1, 2, "string")(); + new f(1, 2, ...a)(); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1, 2, ...a, "string")(); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Property access expression + new b.f(1, 2, "string"); + new b.f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new b.f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Parenthesised expression + new (b.f)(1, 2, "string"); + new (b.f)(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new (b.f)(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression + new d[1].f(1, 2, "string"); + new d[1].f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new d[1].f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a punctuated key + new e["a-b"].f(1, 2, "string"); + new e["a-b"].f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new e["a-b"].f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Basic expression + new B(1, 2, "string"); + new B(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new B(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Property access expression + new c["a-b"](1, 2, "string"); + new c["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new c["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Parenthesised expression + new (c["a-b"])(1, 2, "string"); + new (c["a-b"])(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new (c["a-b"])(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression + new g[1]["a-b"](1, 2, "string"); + new g[1]["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new g[1]["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a punctuated key + new h["a-b"]["a-b"](1, 2, "string"); + new h["a-b"]["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new h["a-b"]["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a number + new i["a-b"][1](1, 2, "string"); + new i["a-b"][1](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new i["a-b"][1](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/newWithSpread.js b/tests/baselines/reference/newWithSpread.js new file mode 100644 index 0000000000000..3161eb9f67e29 --- /dev/null +++ b/tests/baselines/reference/newWithSpread.js @@ -0,0 +1,180 @@ +//// [newWithSpread.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpread.js] +function f(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } +} +function f2() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +var B = (function () { + function B(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + } + return B; +})(); +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); +// Multiple spreads arguments +new f2(...a, ...a); +new f(1, 2, ...a, ...a); +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); diff --git a/tests/baselines/reference/newWithSpreadES5.js b/tests/baselines/reference/newWithSpreadES5.js new file mode 100644 index 0000000000000..f74702662731e --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.js @@ -0,0 +1,180 @@ +//// [newWithSpreadES5.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) {} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpreadES5.js] +function f(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } +} +function f2() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +var B = (function () { + function B(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + } + return B; +})(); +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new (f.bind.apply(f, [void 0].concat([1, 2], a)))(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, ["string"])))(); +// Multiple spreads arguments +new (f2.bind.apply(f2, [void 0].concat(a, a)))(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, a)))(); +// Call expression +new f(1, 2, "string")(); +new (f.bind.apply(f, [void 0].concat([1, 2], a)))()(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, ["string"])))()(); +// Property access expression +new b.f(1, 2, "string"); +new ((_a = b.f).bind.apply(_a, [void 0].concat([1, 2], a)))(); +new ((_b = b.f).bind.apply(_b, [void 0].concat([1, 2], a, ["string"])))(); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new ((_c = (b.f)).bind.apply(_c, [void 0].concat([1, 2], a)))(); +new ((_d = (b.f)).bind.apply(_d, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression +new d[1].f(1, 2, "string"); +new ((_e = d[1].f).bind.apply(_e, [void 0].concat([1, 2], a)))(); +new ((_f = d[1].f).bind.apply(_f, [void 0].concat([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].concat([1, 2], a)))(); +new ((_h = e["a-b"].f).bind.apply(_h, [void 0].concat([1, 2], a, ["string"])))(); +// Basic expression +new B(1, 2, "string"); +new (B.bind.apply(B, [void 0].concat([1, 2], a)))(); +new (B.bind.apply(B, [void 0].concat([1, 2], a, ["string"])))(); +// Property access expression +new c["a-b"](1, 2, "string"); +new ((_j = c["a-b"]).bind.apply(_j, [void 0].concat([1, 2], a)))(); +new ((_k = c["a-b"]).bind.apply(_k, [void 0].concat([1, 2], a, ["string"])))(); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new ((_l = (c["a-b"])).bind.apply(_l, [void 0].concat([1, 2], a)))(); +new ((_m = (c["a-b"])).bind.apply(_m, [void 0].concat([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].concat([1, 2], a)))(); +new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0].concat([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].concat([1, 2], a)))(); +new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0].concat([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].concat([1, 2], a)))(); +new ((_t = i["a-b"][1]).bind.apply(_t, [void 0].concat([1, 2], a, ["string"])))(); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; diff --git a/tests/baselines/reference/newWithSpreadES5.symbols b/tests/baselines/reference/newWithSpreadES5.symbols new file mode 100644 index 0000000000000..021674ef33758 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.symbols @@ -0,0 +1,273 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>x : Symbol(x, Decl(newWithSpreadES5.ts, 1, 11)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 1, 21)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 1, 32)) +} + +function f2(...x: string[]) {} +>f2 : Symbol(f2, Decl(newWithSpreadES5.ts, 2, 1)) +>x : Symbol(x, Decl(newWithSpreadES5.ts, 4, 12)) + +interface A { +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + + f: { +>f : Symbol(f, Decl(newWithSpreadES5.ts, 6, 13)) + + new (x: number, y: number, ...z: string[]); +>x : Symbol(x, Decl(newWithSpreadES5.ts, 8, 13)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 8, 23)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 8, 34)) + } +} + +class B { +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) + + constructor(x: number, y: number, ...z: string[]) {} +>x : Symbol(x, Decl(newWithSpreadES5.ts, 13, 16)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 13, 26)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 13, 37)) +} + +interface C { +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + + "a-b": typeof B; +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +} + +interface D { +>D : Symbol(D, Decl(newWithSpreadES5.ts, 18, 1)) + + 1: typeof B; +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +} + +var a: string[]; +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +var b: A; +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var c: C; +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var d: A[]; +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var e: { [key: string]: A }; +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>key : Symbol(key, Decl(newWithSpreadES5.ts, 28, 10)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var g: C[]; +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var h: { [key: string]: C }; +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>key : Symbol(key, Decl(newWithSpreadES5.ts, 30, 10)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var i: C[][]; +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +// Basic expression +new f(1, 2, "string"); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) + +new f(1, 2, ...a); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1, 2, ...a, "string"); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Multiple spreads arguments +new f2(...a, ...a); +>f2 : Symbol(f2, Decl(newWithSpreadES5.ts, 2, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1 ,2, ...a, ...a); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Call expression +new f(1, 2, "string")(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) + +new f(1, 2, ...a)(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1, 2, ...a, "string")(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Property access expression +new b.f(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new b.f(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new b.f(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new (b.f)(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new (b.f)(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression +new d[1].f(1, 2, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new d[1].f(1, 2, ...a); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new d[1].f(1, 2, ...a, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new e["a-b"].f(1, 2, ...a); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new e["a-b"].f(1, 2, ...a, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Basic expression +new B(1, 2, "string"); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) + +new B(1, 2, ...a); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new B(1, 2, ...a, "string"); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Property access expression +new c["a-b"](1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new c["a-b"](1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new c["a-b"](1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new (c["a-b"])(1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new (c["a-b"])(1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new g[1]["a-b"](1, 2, ...a); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new g[1]["a-b"](1, 2, ...a, "string"); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new h["a-b"]["a-b"](1, 2, ...a); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) + +new i["a-b"][1](1, 2, ...a); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new i["a-b"][1](1, 2, ...a, "string"); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + diff --git a/tests/baselines/reference/newWithSpreadES5.types b/tests/baselines/reference/newWithSpreadES5.types new file mode 100644 index 0000000000000..a2c83ed6372e0 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.types @@ -0,0 +1,494 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +function f2(...x: string[]) {} +>f2 : (...x: string[]) => void +>x : string[] + +interface A { +>A : A + + f: { +>f : new (x: number, y: number, ...z: string[]) => any + + new (x: number, y: number, ...z: string[]); +>x : number +>y : number +>z : string[] + } +} + +class B { +>B : B + + constructor(x: number, y: number, ...z: string[]) {} +>x : number +>y : number +>z : string[] +} + +interface C { +>C : C + + "a-b": typeof B; +>B : typeof B +} + +interface D { +>D : D + + 1: typeof B; +>B : typeof B +} + +var a: string[]; +>a : string[] + +var b: A; +>b : A +>A : A + +var c: C; +>c : C +>C : C + +var d: A[]; +>d : A[] +>A : A + +var e: { [key: string]: A }; +>e : { [key: string]: A; } +>key : string +>A : A + +var g: C[]; +>g : C[] +>C : C + +var h: { [key: string]: C }; +>h : { [key: string]: C; } +>key : string +>C : C + +var i: C[][]; +>i : C[][] +>C : C + +// Basic expression +new f(1, 2, "string"); +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a); +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string"); +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Multiple spreads arguments +new f2(...a, ...a); +>new f2(...a, ...a) : any +>f2 : (...x: string[]) => void +>...a : string +>a : string[] +>...a : string +>a : string[] + +new f(1 ,2, ...a, ...a); +>new f(1 ,2, ...a, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>...a : string +>a : string[] + +// Call expression +new f(1, 2, "string")(); +>new f(1, 2, "string")() : any +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a)(); +>new f(1, 2, ...a)() : any +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string")(); +>new f(1, 2, ...a, "string")() : any +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new b.f(1, 2, "string"); +>new b.f(1, 2, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new b.f(1, 2, ...a); +>new b.f(1, 2, ...a) : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new b.f(1, 2, ...a, "string"); +>new b.f(1, 2, ...a, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>new (b.f)(1, 2, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new (b.f)(1, 2, ...a); +>new (b.f)(1, 2, ...a) : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new (b.f)(1, 2, ...a, "string"); +>new (b.f)(1, 2, ...a, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new d[1].f(1, 2, "string"); +>new d[1].f(1, 2, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new d[1].f(1, 2, ...a); +>new d[1].f(1, 2, ...a) : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new d[1].f(1, 2, ...a, "string"); +>new d[1].f(1, 2, ...a, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>new e["a-b"].f(1, 2, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new e["a-b"].f(1, 2, ...a); +>new e["a-b"].f(1, 2, ...a) : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new e["a-b"].f(1, 2, ...a, "string"); +>new e["a-b"].f(1, 2, ...a, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Basic expression +new B(1, 2, "string"); +>new B(1, 2, "string") : B +>B : typeof B +>1 : number +>2 : number +>"string" : string + +new B(1, 2, ...a); +>new B(1, 2, ...a) : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] + +new B(1, 2, ...a, "string"); +>new B(1, 2, ...a, "string") : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new c["a-b"](1, 2, "string"); +>new c["a-b"](1, 2, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new c["a-b"](1, 2, ...a); +>new c["a-b"](1, 2, ...a) : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new c["a-b"](1, 2, ...a, "string"); +>new c["a-b"](1, 2, ...a, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>new (c["a-b"])(1, 2, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new (c["a-b"])(1, 2, ...a); +>new (c["a-b"])(1, 2, ...a) : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new (c["a-b"])(1, 2, ...a, "string"); +>new (c["a-b"])(1, 2, ...a, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>new g[1]["a-b"](1, 2, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new g[1]["a-b"](1, 2, ...a); +>new g[1]["a-b"](1, 2, ...a) : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new g[1]["a-b"](1, 2, ...a, "string"); +>new g[1]["a-b"](1, 2, ...a, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>new h["a-b"]["a-b"](1, 2, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new h["a-b"]["a-b"](1, 2, ...a); +>new h["a-b"]["a-b"](1, 2, ...a) : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>new h["a-b"]["a-b"](1, 2, ...a, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>new i["a-b"][1](1, 2, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>"string" : string + +new i["a-b"][1](1, 2, ...a); +>new i["a-b"][1](1, 2, ...a) : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] + +new i["a-b"][1](1, 2, ...a, "string"); +>new i["a-b"][1](1, 2, ...a, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + diff --git a/tests/baselines/reference/newWithSpreadES6.js b/tests/baselines/reference/newWithSpreadES6.js new file mode 100644 index 0000000000000..b712984f05ea9 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.js @@ -0,0 +1,167 @@ +//// [newWithSpreadES6.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpreadES6.js] +function f(x, y, ...z) { +} +function f2(...x) { +} +class B { + constructor(x, y, ...z) { + } +} +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); +// Multiple spreads arguments +new f2(...a, ...a); +new f(1, 2, ...a, ...a); +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); diff --git a/tests/baselines/reference/newWithSpreadES6.symbols b/tests/baselines/reference/newWithSpreadES6.symbols new file mode 100644 index 0000000000000..51a34ad73ef4f --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.symbols @@ -0,0 +1,274 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>x : Symbol(x, Decl(newWithSpreadES6.ts, 1, 11)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 1, 21)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 1, 32)) +} + +function f2(...x: string[]) { +>f2 : Symbol(f2, Decl(newWithSpreadES6.ts, 2, 1)) +>x : Symbol(x, Decl(newWithSpreadES6.ts, 4, 12)) +} + +interface A { +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + + f: { +>f : Symbol(f, Decl(newWithSpreadES6.ts, 7, 13)) + + new (x: number, y: number, ...z: string[]); +>x : Symbol(x, Decl(newWithSpreadES6.ts, 9, 13)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 9, 23)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 9, 34)) + } +} + +class B { +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) + + constructor(x: number, y: number, ...z: string[]) {} +>x : Symbol(x, Decl(newWithSpreadES6.ts, 14, 16)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 14, 26)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 14, 37)) +} + +interface C { +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + + "a-b": typeof B; +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +} + +interface D { +>D : Symbol(D, Decl(newWithSpreadES6.ts, 19, 1)) + + 1: typeof B; +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +} + +var a: string[]; +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +var b: A; +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var c: C; +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var d: A[]; +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var e: { [key: string]: A }; +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>key : Symbol(key, Decl(newWithSpreadES6.ts, 29, 10)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var g: C[]; +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var h: { [key: string]: C }; +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>key : Symbol(key, Decl(newWithSpreadES6.ts, 31, 10)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var i: C[][]; +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +// Basic expression +new f(1, 2, "string"); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) + +new f(1, 2, ...a); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1, 2, ...a, "string"); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Multiple spreads arguments +new f2(...a, ...a); +>f2 : Symbol(f2, Decl(newWithSpreadES6.ts, 2, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1 ,2, ...a, ...a); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Call expression +new f(1, 2, "string")(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) + +new f(1, 2, ...a)(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1, 2, ...a, "string")(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Property access expression +new b.f(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new b.f(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new b.f(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new (b.f)(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new (b.f)(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression +new d[1].f(1, 2, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new d[1].f(1, 2, ...a); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new d[1].f(1, 2, ...a, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new e["a-b"].f(1, 2, ...a); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new e["a-b"].f(1, 2, ...a, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Basic expression +new B(1, 2, "string"); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) + +new B(1, 2, ...a); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new B(1, 2, ...a, "string"); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Property access expression +new c["a-b"](1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new c["a-b"](1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new c["a-b"](1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new (c["a-b"])(1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new (c["a-b"])(1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new g[1]["a-b"](1, 2, ...a); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new g[1]["a-b"](1, 2, ...a, "string"); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new h["a-b"]["a-b"](1, 2, ...a); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) + +new i["a-b"][1](1, 2, ...a); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new i["a-b"][1](1, 2, ...a, "string"); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + diff --git a/tests/baselines/reference/newWithSpreadES6.types b/tests/baselines/reference/newWithSpreadES6.types new file mode 100644 index 0000000000000..52951729e3de4 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.types @@ -0,0 +1,495 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +function f2(...x: string[]) { +>f2 : (...x: string[]) => void +>x : string[] +} + +interface A { +>A : A + + f: { +>f : new (x: number, y: number, ...z: string[]) => any + + new (x: number, y: number, ...z: string[]); +>x : number +>y : number +>z : string[] + } +} + +class B { +>B : B + + constructor(x: number, y: number, ...z: string[]) {} +>x : number +>y : number +>z : string[] +} + +interface C { +>C : C + + "a-b": typeof B; +>B : typeof B +} + +interface D { +>D : D + + 1: typeof B; +>B : typeof B +} + +var a: string[]; +>a : string[] + +var b: A; +>b : A +>A : A + +var c: C; +>c : C +>C : C + +var d: A[]; +>d : A[] +>A : A + +var e: { [key: string]: A }; +>e : { [key: string]: A; } +>key : string +>A : A + +var g: C[]; +>g : C[] +>C : C + +var h: { [key: string]: C }; +>h : { [key: string]: C; } +>key : string +>C : C + +var i: C[][]; +>i : C[][] +>C : C + +// Basic expression +new f(1, 2, "string"); +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a); +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string"); +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Multiple spreads arguments +new f2(...a, ...a); +>new f2(...a, ...a) : any +>f2 : (...x: string[]) => void +>...a : string +>a : string[] +>...a : string +>a : string[] + +new f(1 ,2, ...a, ...a); +>new f(1 ,2, ...a, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>...a : string +>a : string[] + +// Call expression +new f(1, 2, "string")(); +>new f(1, 2, "string")() : any +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a)(); +>new f(1, 2, ...a)() : any +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string")(); +>new f(1, 2, ...a, "string")() : any +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new b.f(1, 2, "string"); +>new b.f(1, 2, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new b.f(1, 2, ...a); +>new b.f(1, 2, ...a) : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new b.f(1, 2, ...a, "string"); +>new b.f(1, 2, ...a, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>new (b.f)(1, 2, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new (b.f)(1, 2, ...a); +>new (b.f)(1, 2, ...a) : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new (b.f)(1, 2, ...a, "string"); +>new (b.f)(1, 2, ...a, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new d[1].f(1, 2, "string"); +>new d[1].f(1, 2, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new d[1].f(1, 2, ...a); +>new d[1].f(1, 2, ...a) : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new d[1].f(1, 2, ...a, "string"); +>new d[1].f(1, 2, ...a, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>new e["a-b"].f(1, 2, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new e["a-b"].f(1, 2, ...a); +>new e["a-b"].f(1, 2, ...a) : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new e["a-b"].f(1, 2, ...a, "string"); +>new e["a-b"].f(1, 2, ...a, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Basic expression +new B(1, 2, "string"); +>new B(1, 2, "string") : B +>B : typeof B +>1 : number +>2 : number +>"string" : string + +new B(1, 2, ...a); +>new B(1, 2, ...a) : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] + +new B(1, 2, ...a, "string"); +>new B(1, 2, ...a, "string") : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new c["a-b"](1, 2, "string"); +>new c["a-b"](1, 2, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new c["a-b"](1, 2, ...a); +>new c["a-b"](1, 2, ...a) : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new c["a-b"](1, 2, ...a, "string"); +>new c["a-b"](1, 2, ...a, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>new (c["a-b"])(1, 2, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new (c["a-b"])(1, 2, ...a); +>new (c["a-b"])(1, 2, ...a) : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new (c["a-b"])(1, 2, ...a, "string"); +>new (c["a-b"])(1, 2, ...a, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>new g[1]["a-b"](1, 2, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new g[1]["a-b"](1, 2, ...a); +>new g[1]["a-b"](1, 2, ...a) : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new g[1]["a-b"](1, 2, ...a, "string"); +>new g[1]["a-b"](1, 2, ...a, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>new h["a-b"]["a-b"](1, 2, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new h["a-b"]["a-b"](1, 2, ...a); +>new h["a-b"]["a-b"](1, 2, ...a) : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>new h["a-b"]["a-b"](1, 2, ...a, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>new i["a-b"][1](1, 2, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>"string" : string + +new i["a-b"][1](1, 2, ...a); +>new i["a-b"][1](1, 2, ...a) : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] + +new i["a-b"][1](1, 2, ...a, "string"); +>new i["a-b"][1](1, 2, ...a, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts index 9acba00697a20..245028db3d425 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts @@ -47,6 +47,3 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts index 2f7d16ba368a0..accb6df135d25 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts @@ -49,6 +49,3 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts new file mode 100644 index 0000000000000..d17919a703625 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts @@ -0,0 +1,97 @@ + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts new file mode 100644 index 0000000000000..25ef34446699c --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts @@ -0,0 +1,97 @@ +//@target: ES5 + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) {} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts new file mode 100644 index 0000000000000..0068b6cf80e41 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts @@ -0,0 +1,98 @@ +//@target: ES6 + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file