diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 71af6e342bafe..52574ae5bf615 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2197,25 +2197,7 @@ module ts { } else if (hasSpreadElement) { let unionOfElements = getUnionType(elementTypes); - if (languageVersion >= ScriptTarget.ES6) { - // If the user has something like: - // - // function fun(...[a, ...b]) { } - // - // Normally, in ES6, the implied type of an array binding pattern with a rest element is - // an iterable. However, there is a requirement in our type system that all rest - // parameters be array types. To satisfy this, we have an exception to the rule that - // says the type of an array binding pattern with a rest element is an array type - // if it is *itself* in a rest parameter. It will still be compatible with a spreaded - // iterable argument, but within the function it will be an array. - let parent = pattern.parent; - let isRestParameter = parent.kind === SyntaxKind.Parameter && - pattern === (parent).name && - (parent).dotDotDotToken !== undefined; - return isRestParameter ? createArrayType(unionOfElements) : createIterableType(unionOfElements); - } - - return createArrayType(unionOfElements); + return languageVersion >= ScriptTarget.ES6 ? createIterableType(unionOfElements) : createArrayType(unionOfElements); } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. @@ -6035,14 +6017,38 @@ module ts { } let hasSpreadElement = false; let elementTypes: Type[] = []; + let inDestructuringPattern = isAssignmentTarget(node); for (let e of elements) { - let type = checkExpression(e, contextualMapper); - elementTypes.push(type); + if (inDestructuringPattern && e.kind === SyntaxKind.SpreadElementExpression) { + // Given the following situation: + // var c: {}; + // [...c] = ["", 0]; + // + // c is represented in the tree as a spread element in an array literal. + // But c really functions as a rest element, and its purpose is to provide + // a contextual type for the right hand side of the assignment. Therefore, + // instead of calling checkExpression on "...c", which will give an error + // if c is not iterable/array-like, we need to act as if we are trying to + // get the contextual element type from it. So we do something similar to + // getContextualTypeForElementExpression, which will crucially not error + // if there is no index type / iterated type. + let restArrayType = checkExpression((e).expression, contextualMapper); + let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) || + (languageVersion >= ScriptTarget.ES6 ? checkIteratedType(restArrayType, /*expressionForError*/ undefined) : undefined); + + if (restElementType) { + elementTypes.push(restElementType); + } + } + else { + let type = checkExpression(e, contextualMapper); + elementTypes.push(type); + } hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; } if (!hasSpreadElement) { let contextualType = getContextualType(node); - if (contextualType && contextualTypeIsTupleLikeType(contextualType) || isAssignmentTarget(node)) { + if (contextualType && contextualTypeIsTupleLikeType(contextualType) || inDestructuringPattern) { return createTupleType(elementTypes); } } @@ -7633,7 +7639,7 @@ module ts { // This elementType will be used if the specific property corresponding to this index is not // present (aka the tuple element property). This call also checks that the parentType is in // fact an iterable or array (depending on target language). - let elementType = checkIteratedTypeOrElementType(sourceType, node, /*allowStringInput*/ false); + let elementType = checkIteratedTypeOrElementType(sourceType, node, /*allowStringInput*/ false) || unknownType; let elements = node.elements; for (let i = 0; i < elements.length; i++) { let e = elements[i]; @@ -7657,11 +7663,17 @@ module ts { } } else { - if (i === elements.length - 1) { - checkReferenceAssignment((e).expression, createArrayType(elementType), contextualMapper); + if (i < elements.length - 1) { + error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } else { - error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + let restExpression = (e).expression; + if (restExpression.kind === SyntaxKind.BinaryExpression && (restExpression).operatorToken.kind === SyntaxKind.EqualsToken) { + error((restExpression).operatorToken, Diagnostics.A_rest_element_cannot_have_an_initializer); + } + else { + checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper); + } } } } @@ -8121,10 +8133,11 @@ module ts { if (node.questionToken && isBindingPattern(node.name) && func.body) { error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } - if (node.dotDotDotToken) { - if (!isArrayType(getTypeOfSymbol(node.symbol))) { - error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type); - } + + // Only check rest parameter type if it's not a binding pattern. Since binding patterns are + // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. + if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { + error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } @@ -9427,6 +9440,10 @@ module ts { } function checkIteratedTypeOrElementType(inputType: Type, errorNode: Node, allowStringInput: boolean): Type { + if (inputType.flags & TypeFlags.Any) { + return inputType; + } + if (languageVersion >= ScriptTarget.ES6) { return checkIteratedType(inputType, errorNode) || anyType; } @@ -12270,6 +12287,10 @@ module ts { return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); } + if (isBindingPattern(parameter.name)) { + return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); + } + if (parameter.questionToken) { return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_rest_parameter_cannot_be_optional); } @@ -12756,6 +12777,11 @@ module ts { if (node !== elements[elements.length - 1]) { return grammarErrorOnNode(node, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } + + if (node.name.kind === SyntaxKind.ArrayBindingPattern || node.name.kind === SyntaxKind.ObjectBindingPattern) { + return grammarErrorOnNode(node.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); + } + if (node.initializer) { // Error on equals token which immediate precedes the initializer return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0271ac731053e..851b90f61c89b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -363,6 +363,7 @@ module ts { External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." }, An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." }, A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." }, + A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 063a0d50ef5cb..258f98357b773 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1439,6 +1439,10 @@ "category": "Error", "code": 2500 }, + "A rest element cannot contain a binding pattern.": { + "category": "Error", + "code": 2501 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 82916c3c9ae2e..ed447ab1dd4f0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1589,23 +1589,40 @@ var __param = this.__param || function(index, decorator) { return function (targ return result; } - function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression { + function createPropertyAccessExpression(expression: Expression, name: Identifier): PropertyAccessExpression { let result = createSynthesizedNode(SyntaxKind.PropertyAccessExpression); - result.expression = expression; + result.expression = parenthesizeForAccess(expression); result.dotToken = createSynthesizedNode(SyntaxKind.DotToken); result.name = name; return result; - } + } - function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression { + function createElementAccessExpression(expression: Expression, argumentExpression: Expression): ElementAccessExpression { let result = createSynthesizedNode(SyntaxKind.ElementAccessExpression); - result.expression = expression; + result.expression = parenthesizeForAccess(expression); result.argumentExpression = argumentExpression; return result; } + function parenthesizeForAccess(expr: Expression): LeftHandSideExpression { + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary + // to parenthesize the expression before a dot. The known exceptions are: + // + // NewExpression: + // new C.x -> not the same as (new C).x + // NumberLiteral + // 1.x -> not the same as (1).x + // + if (isLeftHandSideExpression(expr) && expr.kind !== SyntaxKind.NewExpression && expr.kind !== SyntaxKind.NumericLiteral) { + return expr; + } + let node = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); + node.expression = expr; + return node; + } + function emitComputedPropertyName(node: ComputedPropertyName) { write("["); emitExpressionForPropertyName(node); @@ -2276,7 +2293,7 @@ var __param = this.__param || function(index, decorator) { return function (targ if (node.initializer.kind === SyntaxKind.ArrayLiteralExpression || node.initializer.kind === SyntaxKind.ObjectLiteralExpression) { // This is a destructuring pattern, so call emitDestructuring instead of emit. Calling emit will not work, because it will cause // the BinaryExpression to be passed in instead of the expression statement, which will cause emitDestructuring to crash. - emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined, /*locationForCheckingExistingName*/ node); + emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined); } else { emitNodeWithoutSourceMap(assignmentExpression); @@ -2480,16 +2497,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } } - /** - * If the root has a chance of being a synthesized node, callers should also pass a value for - * lowestNonSynthesizedAncestor. This should be an ancestor of root, it should not be synthesized, - * and there should not be a lower ancestor that introduces a scope. This node will be used as the - * location for ensuring that temporary names are unique. - */ - function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, - isAssignmentExpressionStatement: boolean, - value?: Expression, - lowestNonSynthesizedAncestor?: Node) { + function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, isAssignmentExpressionStatement: boolean, value?: Expression) { let emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so // temporary variables in an exported declaration need to have real declarations elsewhere @@ -2520,9 +2528,6 @@ var __param = this.__param || function(index, decorator) { return function (targ function ensureIdentifier(expr: Expression): Expression { if (expr.kind !== SyntaxKind.Identifier) { - // In case the root is a synthesized node, we need to pass lowestNonSynthesizedAncestor - // as the location for determining uniqueness of the variable we are about to - // generate. let identifier = createTempVariable(TempFlags.Auto); if (!isDeclaration) { recordTempDeclaration(identifier); @@ -2561,27 +2566,22 @@ var __param = this.__param || function(index, decorator) { return function (targ return node; } - function parenthesizeForAccess(expr: Expression): LeftHandSideExpression { - if (expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { - return expr; - } - let node = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); - node.expression = expr; - return node; - } - - function createPropertyAccess(object: Expression, propName: Identifier): Expression { + function createPropertyAccessForDestructuringProperty(object: Expression, propName: Identifier | LiteralExpression): Expression { if (propName.kind !== SyntaxKind.Identifier) { - return createElementAccess(object, propName); + return createElementAccessExpression(object, propName); } - return createPropertyAccessExpression(parenthesizeForAccess(object), propName); + + return createPropertyAccessExpression(object, propName); } - function createElementAccess(object: Expression, index: Expression): Expression { - let node = createSynthesizedNode(SyntaxKind.ElementAccessExpression); - node.expression = parenthesizeForAccess(object); - node.argumentExpression = index; - return node; + function createSliceCall(value: Expression, sliceIndex: number): CallExpression { + let call = createSynthesizedNode(SyntaxKind.CallExpression); + let sliceIdentifier = createSynthesizedNode(SyntaxKind.Identifier); + sliceIdentifier.text = "slice"; + call.expression = createPropertyAccessExpression(value, sliceIdentifier); + call.arguments = >createSynthesizedNodeArray(); + call.arguments[0] = createNumericLiteral(sliceIndex); + return call; } function emitObjectLiteralAssignment(target: ObjectLiteralExpression, value: Expression) { @@ -2594,8 +2594,8 @@ var __param = this.__param || function(index, decorator) { return function (targ for (let p of properties) { if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) { // TODO(andersh): Computed property support - let propName = ((p).name); - emitDestructuringAssignment((p).initializer || propName, createPropertyAccess(value, propName)); + let propName = ((p).name); + emitDestructuringAssignment((p).initializer || propName, createPropertyAccessForDestructuringProperty(value, propName)); } } } @@ -2611,14 +2611,10 @@ var __param = this.__param || function(index, decorator) { return function (targ let e = elements[i]; if (e.kind !== SyntaxKind.OmittedExpression) { if (e.kind !== SyntaxKind.SpreadElementExpression) { - emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); + emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment((e).expression, value); - write(".slice(" + i + ")"); - } + else if (i === elements.length - 1) { + emitDestructuringAssignment((e).expression, createSliceCall(value, i)); } } } @@ -2682,19 +2678,15 @@ var __param = this.__param || function(index, decorator) { return function (targ if (pattern.kind === SyntaxKind.ObjectBindingPattern) { // Rewrite element to a declaration with an initializer that fetches property let propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccess(value, propName)); + emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); } else if (element.kind !== SyntaxKind.OmittedExpression) { if (!element.dotDotDotToken) { // Rewrite element to a declaration that accesses array element at index i - emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); + emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment(element.name, value); - write(".slice(" + i + ")"); - } + else if (i === elements.length - 1) { + emitBindingElement(element, createSliceCall(value, i)); } } } @@ -2862,6 +2854,12 @@ var __param = this.__param || function(index, decorator) { return function (targ if (languageVersion < ScriptTarget.ES6) { let tempIndex = 0; forEach(node.parameters, p => { + // A rest parameter cannot have a binding pattern or an initializer, + // so let's just ignore it. + if (p.dotDotDotToken) { + return; + } + if (isBindingPattern(p.name)) { writeLine(); write("var "); @@ -2892,6 +2890,12 @@ var __param = this.__param || function(index, decorator) { return function (targ if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) { let restIndex = node.parameters.length - 1; let restParam = node.parameters[restIndex]; + + // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. + if (isBindingPattern(restParam.name)) { + return; + } + let tempName = createTempVariable(TempFlags._i).text; writeLine(); emitLeadingComments(restParam); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2530e3586629e..0a7347ea1ffb0 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1165,6 +1165,13 @@ module ts { return node; } + export function createSynthesizedNodeArray(): NodeArray { + var array = >[]; + array.pos = -1; + array.end = -1; + return array; + } + export function createDiagnosticCollection(): DiagnosticCollection { let nonFileDiagnostics: Diagnostic[] = []; let fileDiagnostics: Map = {}; @@ -1904,4 +1911,4 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN); } -} \ No newline at end of file +} diff --git a/tests/baselines/reference/arrayAssignmentPatternWithAny.js b/tests/baselines/reference/arrayAssignmentPatternWithAny.js new file mode 100644 index 0000000000000..c81b5f1f38d8b --- /dev/null +++ b/tests/baselines/reference/arrayAssignmentPatternWithAny.js @@ -0,0 +1,9 @@ +//// [arrayAssignmentPatternWithAny.ts] +var a: any; +var x: string; +[x] = a; + +//// [arrayAssignmentPatternWithAny.js] +var a; +var x; +x = a[0]; diff --git a/tests/baselines/reference/arrayAssignmentPatternWithAny.symbols b/tests/baselines/reference/arrayAssignmentPatternWithAny.symbols new file mode 100644 index 0000000000000..a55febc142289 --- /dev/null +++ b/tests/baselines/reference/arrayAssignmentPatternWithAny.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/arrayAssignmentPatternWithAny.ts === +var a: any; +>a : Symbol(a, Decl(arrayAssignmentPatternWithAny.ts, 0, 3)) + +var x: string; +>x : Symbol(x, Decl(arrayAssignmentPatternWithAny.ts, 1, 3)) + +[x] = a; +>x : Symbol(x, Decl(arrayAssignmentPatternWithAny.ts, 1, 3)) +>a : Symbol(a, Decl(arrayAssignmentPatternWithAny.ts, 0, 3)) + diff --git a/tests/baselines/reference/arrayAssignmentPatternWithAny.types b/tests/baselines/reference/arrayAssignmentPatternWithAny.types new file mode 100644 index 0000000000000..452fc0737a1ec --- /dev/null +++ b/tests/baselines/reference/arrayAssignmentPatternWithAny.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/es6/destructuring/arrayAssignmentPatternWithAny.ts === +var a: any; +>a : any + +var x: string; +>x : string + +[x] = a; +>[x] = a : any +>[x] : [string] +>x : string +>a : any + diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index a8a57090fb8b6..cf747b44b3e94 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -14,7 +14,6 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(3 tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,9): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,1): error TS2461: Type 'any' is not an array type. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(42,36): error TS1034: 'super' must be followed by an argument list or member access. @@ -39,7 +38,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6 tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression. -==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== +==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (38 errors) ==== // expected error for all the LHS of assignments var value; @@ -110,8 +109,6 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 // array literals ['', ''] = value; - ~~~~~~~~ -!!! error TS2461: Type 'any' is not an array type. ~~ !!! error TS2364: Invalid left-hand side of assignment expression. ~~ diff --git a/tests/baselines/reference/assignmentRestElementWithErrorSourceType.errors.txt b/tests/baselines/reference/assignmentRestElementWithErrorSourceType.errors.txt new file mode 100644 index 0000000000000..080aca5a7ac30 --- /dev/null +++ b/tests/baselines/reference/assignmentRestElementWithErrorSourceType.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts(2,5): error TS2304: Cannot find name 'c'. +tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts(2,10): error TS2304: Cannot find name 'tupel'. + + +==== tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts (2 errors) ==== + var tuple: [string, number]; + [...c] = tupel; // intentionally misspelled + ~ +!!! error TS2304: Cannot find name 'c'. + ~~~~~ +!!! error TS2304: Cannot find name 'tupel'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentRestElementWithErrorSourceType.js b/tests/baselines/reference/assignmentRestElementWithErrorSourceType.js new file mode 100644 index 0000000000000..0a1109a14f762 --- /dev/null +++ b/tests/baselines/reference/assignmentRestElementWithErrorSourceType.js @@ -0,0 +1,7 @@ +//// [assignmentRestElementWithErrorSourceType.ts] +var tuple: [string, number]; +[...c] = tupel; // intentionally misspelled + +//// [assignmentRestElementWithErrorSourceType.js] +var tuple; +c = tupel.slice(0); // intentionally misspelled diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js index 088bb4e849f20..9a9be8c69da32 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -11,7 +11,7 @@ var [x3, y3, z3] = a; // emit x3, y3, z3 //// [declarationEmitDestructuringArrayPattern1.js] var _a = [1, "hello"]; // Dont emit anything -var x = ([1, "hello"])[0]; // emit x: number +var x = [1, "hello"][0]; // emit x: number var _b = [1, "hello"], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string var _c = [0, 1, 2], z1 = _c[2]; // emit z1: number var a = [1, "hello"]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js index f19a4a840bf23..1bd07e7b974e8 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -10,14 +10,14 @@ var [x18, y18, ...a12] = [1, "hello", true]; var [x19, y19, z19, ...a13] = [1, "hello", true]; //// [declarationEmitDestructuringArrayPattern4.js] -var _a = [1, 2, 3], a5 = _a.slice(0); -var _b = [1, 2, 3], x14 = _b[0], a6 = _b.slice(1); -var _c = [1, 2, 3], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2); -var _d = [1, 2, 3], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3); -var _e = [1, "hello", true], a9 = _e.slice(0); -var _f = [1, "hello", true], x17 = _f[0], a10 = _f.slice(1); -var _g = [1, "hello", true], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2); -var _h = [1, "hello", true], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3); +var a5 = [1, 2, 3].slice(0); +var _a = [1, 2, 3], x14 = _a[0], a6 = _a.slice(1); +var _b = [1, 2, 3], x15 = _b[0], y15 = _b[1], a7 = _b.slice(2); +var _c = [1, 2, 3], x16 = _c[0], y16 = _c[1], z16 = _c[2], a8 = _c.slice(3); +var a9 = [1, "hello", true].slice(0); +var _d = [1, "hello", true], x17 = _d[0], a10 = _d.slice(1); +var _e = [1, "hello", true], x18 = _e[0], y18 = _e[1], a12 = _e.slice(2); +var _f = [1, "hello", true], x19 = _f[0], y19 = _f[1], z19 = _f[2], a13 = _f.slice(3); //// [declarationEmitDestructuringArrayPattern4.d.ts] diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js index d94da79ad9aa5..38b0a14af5c97 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js @@ -24,11 +24,11 @@ module m { //// [declarationEmitDestructuringObjectLiteralPattern.js] var _a = { x: 5, y: "hello" }; -var x4 = ({ x4: 5, y4: "hello" }).x4; -var y5 = ({ x5: 5, y5: "hello" }).y5; +var x4 = { x4: 5, y4: "hello" }.x4; +var y5 = { x5: 5, y5: "hello" }.y5; var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6; -var a1 = ({ x7: 5, y7: "hello" }).x7; -var b1 = ({ x8: 5, y8: "hello" }).y8; +var a1 = { x7: 5, y7: "hello" }.x7; +var b1 = { x8: 5, y8: "hello" }.y8; var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9; var _d = { a: 1, b: { a: "hello", b: { a: true } } }, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a; function f15() { diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js index 2c14e743039ca..264e56fe58c5c 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js @@ -10,11 +10,11 @@ var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; //// [declarationEmitDestructuringObjectLiteralPattern1.js] var _a = { x: 5, y: "hello" }; -var x4 = ({ x4: 5, y4: "hello" }).x4; -var y5 = ({ x5: 5, y5: "hello" }).y5; +var x4 = { x4: 5, y4: "hello" }.x4; +var y5 = { x5: 5, y5: "hello" }.y5; var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6; -var a1 = ({ x7: 5, y7: "hello" }).x7; -var b1 = ({ x8: 5, y8: "hello" }).y8; +var a1 = { x7: 5, y7: "hello" }.x7; +var b1 = { x8: 5, y8: "hello" }.y8; var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9; diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index 032f4cb0e633d..5c47756e7fe0c 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -183,7 +183,7 @@ function f21() { //// [declarationsAndAssignments.js] function f0() { var _a = [1, "hello"]; - var x = ([1, "hello"])[0]; + var x = [1, "hello"][0]; var _b = [1, "hello"], x = _b[0], y = _b[1]; var _c = [1, "hello"], x = _c[0], y = _c[1], z = _c[2]; // Error var _d = [0, 1, 2], z = _d[2]; @@ -201,13 +201,13 @@ function f1() { } function f2() { var _a = { x: 5, y: "hello" }; - var x = ({ x: 5, y: "hello" }).x; - var y = ({ x: 5, y: "hello" }).y; + var x = { x: 5, y: "hello" }.x; + var y = { x: 5, y: "hello" }.y; var _b = { x: 5, y: "hello" }, x = _b.x, y = _b.y; var x; var y; - var a = ({ x: 5, y: "hello" }).x; - var b = ({ x: 5, y: "hello" }).y; + var a = { x: 5, y: "hello" }.x; + var b = { x: 5, y: "hello" }.y; var _c = { x: 5, y: "hello" }, a = _c.x, b = _c.y; var a; var b; @@ -312,7 +312,7 @@ function f19() { _a = [1, 2], a = _a[0], b = _a[1]; _b = [b, a], a = _b[0], b = _b[1]; (_c = { b: b, a: a }, a = _c.a, b = _c.b, _c); - _d = ([[2, 3]])[0], _e = _d === void 0 ? [1, 2] : _d, a = _e[0], b = _e[1]; + _d = [[2, 3]][0], _e = _d === void 0 ? [1, 2] : _d, a = _e[0], b = _e[1]; var x = (_f = [1, 2], a = _f[0], b = _f[1], _f); var _a, _b, _c, _d, _e, _f; } @@ -321,28 +321,28 @@ function f20() { var x; var y; var z; - var _a = [1, 2, 3], a = _a.slice(0); - var _b = [1, 2, 3], x = _b[0], a = _b.slice(1); - var _c = [1, 2, 3], x = _c[0], y = _c[1], a = _c.slice(2); - var _d = [1, 2, 3], x = _d[0], y = _d[1], z = _d[2], a = _d.slice(3); - _e = [1, 2, 3], a = _e.slice(0); - _f = [1, 2, 3], x = _f[0], a = _f.slice(1); - _g = [1, 2, 3], x = _g[0], y = _g[1], a = _g.slice(2); - _h = [1, 2, 3], x = _h[0], y = _h[1], z = _h[2], a = _h.slice(3); - var _e, _f, _g, _h; + var a = [1, 2, 3].slice(0); + var _a = [1, 2, 3], x = _a[0], a = _a.slice(1); + var _b = [1, 2, 3], x = _b[0], y = _b[1], a = _b.slice(2); + var _c = [1, 2, 3], x = _c[0], y = _c[1], z = _c[2], a = _c.slice(3); + a = [1, 2, 3].slice(0); + _d = [1, 2, 3], x = _d[0], a = _d.slice(1); + _e = [1, 2, 3], x = _e[0], y = _e[1], a = _e.slice(2); + _f = [1, 2, 3], x = _f[0], y = _f[1], z = _f[2], a = _f.slice(3); + var _d, _e, _f; } function f21() { var a; var x; var y; var z; - var _a = [1, "hello", true], a = _a.slice(0); - var _b = [1, "hello", true], x = _b[0], a = _b.slice(1); - var _c = [1, "hello", true], x = _c[0], y = _c[1], a = _c.slice(2); - var _d = [1, "hello", true], x = _d[0], y = _d[1], z = _d[2], a = _d.slice(3); - _e = [1, "hello", true], a = _e.slice(0); - _f = [1, "hello", true], x = _f[0], a = _f.slice(1); - _g = [1, "hello", true], x = _g[0], y = _g[1], a = _g.slice(2); - _h = [1, "hello", true], x = _h[0], y = _h[1], z = _h[2], a = _h.slice(3); - var _e, _f, _g, _h; + var a = [1, "hello", true].slice(0); + var _a = [1, "hello", true], x = _a[0], a = _a.slice(1); + var _b = [1, "hello", true], x = _b[0], y = _b[1], a = _b.slice(2); + var _c = [1, "hello", true], x = _c[0], y = _c[1], z = _c[2], a = _c.slice(3); + a = [1, "hello", true].slice(0); + _d = [1, "hello", true], x = _d[0], a = _d.slice(1); + _e = [1, "hello", true], x = _e[0], y = _e[1], a = _e.slice(2); + _f = [1, "hello", true], x = _f[0], y = _f[1], z = _f[2], a = _f.slice(3); + var _d, _e, _f; } diff --git a/tests/baselines/reference/destructuringWithNewExpression.js b/tests/baselines/reference/destructuringWithNewExpression.js new file mode 100644 index 0000000000000..310129674b167 --- /dev/null +++ b/tests/baselines/reference/destructuringWithNewExpression.js @@ -0,0 +1,15 @@ +//// [destructuringWithNewExpression.ts] +class C { + x = 0; +} + +var { x } = new C; + +//// [destructuringWithNewExpression.js] +var C = (function () { + function C() { + this.x = 0; + } + return C; +})(); +var x = (new C).x; diff --git a/tests/baselines/reference/destructuringWithNewExpression.symbols b/tests/baselines/reference/destructuringWithNewExpression.symbols new file mode 100644 index 0000000000000..c7dce46848575 --- /dev/null +++ b/tests/baselines/reference/destructuringWithNewExpression.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/destructuringWithNewExpression.ts === +class C { +>C : Symbol(C, Decl(destructuringWithNewExpression.ts, 0, 0)) + + x = 0; +>x : Symbol(x, Decl(destructuringWithNewExpression.ts, 0, 9)) +} + +var { x } = new C; +>x : Symbol(x, Decl(destructuringWithNewExpression.ts, 4, 5)) +>C : Symbol(C, Decl(destructuringWithNewExpression.ts, 0, 0)) + diff --git a/tests/baselines/reference/destructuringWithNewExpression.types b/tests/baselines/reference/destructuringWithNewExpression.types new file mode 100644 index 0000000000000..1d36746a44dfe --- /dev/null +++ b/tests/baselines/reference/destructuringWithNewExpression.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/destructuringWithNewExpression.ts === +class C { +>C : C + + x = 0; +>x : number +>0 : number +} + +var { x } = new C; +>x : number +>new C : C +>C : typeof C + diff --git a/tests/baselines/reference/destructuringWithNumberLiteral.js b/tests/baselines/reference/destructuringWithNumberLiteral.js new file mode 100644 index 0000000000000..8804b850cc39a --- /dev/null +++ b/tests/baselines/reference/destructuringWithNumberLiteral.js @@ -0,0 +1,5 @@ +//// [destructuringWithNumberLiteral.ts] +var { toExponential } = 0; + +//// [destructuringWithNumberLiteral.js] +var toExponential = (0).toExponential; diff --git a/tests/baselines/reference/destructuringWithNumberLiteral.symbols b/tests/baselines/reference/destructuringWithNumberLiteral.symbols new file mode 100644 index 0000000000000..6190dc1505224 --- /dev/null +++ b/tests/baselines/reference/destructuringWithNumberLiteral.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/destructuringWithNumberLiteral.ts === +var { toExponential } = 0; +>toExponential : Symbol(toExponential, Decl(destructuringWithNumberLiteral.ts, 0, 5)) + diff --git a/tests/baselines/reference/destructuringWithNumberLiteral.types b/tests/baselines/reference/destructuringWithNumberLiteral.types new file mode 100644 index 0000000000000..7fe902c622efc --- /dev/null +++ b/tests/baselines/reference/destructuringWithNumberLiteral.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/destructuringWithNumberLiteral.ts === +var { toExponential } = 0; +>toExponential : (fractionDigits?: number) => string +>0 : number + diff --git a/tests/baselines/reference/downlevelLetConst12.js b/tests/baselines/reference/downlevelLetConst12.js index 6437d17accb3e..bd0ab2fb46f7f 100644 --- a/tests/baselines/reference/downlevelLetConst12.js +++ b/tests/baselines/reference/downlevelLetConst12.js @@ -16,7 +16,7 @@ const {a: baz4} = { a: 1 }; // top level let\const should not be renamed var foo; var bar = 1; -var baz = ([])[0]; -var baz2 = ({ a: 1 }).a; -var baz3 = ([])[0]; -var baz4 = ({ a: 1 }).a; +var baz = [][0]; +var baz2 = { a: 1 }.a; +var baz3 = [][0]; +var baz4 = { a: 1 }.a; diff --git a/tests/baselines/reference/downlevelLetConst13.js b/tests/baselines/reference/downlevelLetConst13.js index 8324d697e95fd..b6baf85080027 100644 --- a/tests/baselines/reference/downlevelLetConst13.js +++ b/tests/baselines/reference/downlevelLetConst13.js @@ -24,16 +24,16 @@ export module M { // exported let\const bindings should not be renamed exports.foo = 10; exports.bar = "123"; -exports.bar1 = ([1])[0]; -exports.bar2 = ([2])[0]; -exports.bar3 = ({ a: 1 }).a; -exports.bar4 = ({ a: 1 }).a; +exports.bar1 = [1][0]; +exports.bar2 = [2][0]; +exports.bar3 = { a: 1 }.a; +exports.bar4 = { a: 1 }.a; var M; (function (M) { M.baz = 100; M.baz2 = true; - M.bar5 = ([1])[0]; - M.bar6 = ([2])[0]; - M.bar7 = ({ a: 1 }).a; - M.bar8 = ({ a: 1 }).a; + M.bar5 = [1][0]; + M.bar6 = [2][0]; + M.bar7 = { a: 1 }.a; + M.bar8 = { a: 1 }.a; })(M = exports.M || (exports.M = {})); diff --git a/tests/baselines/reference/downlevelLetConst14.js b/tests/baselines/reference/downlevelLetConst14.js index d45cf10d3a75f..cddfb9672171d 100644 --- a/tests/baselines/reference/downlevelLetConst14.js +++ b/tests/baselines/reference/downlevelLetConst14.js @@ -61,13 +61,13 @@ var z0, z1, z2, z3; { var x_1 = 20; use(x_1); - var z0_1 = ([1])[0]; + var z0_1 = [1][0]; use(z0_1); - var z1_1 = ([1])[0]; + var z1_1 = [1][0]; use(z1_1); - var z2_1 = ({ a: 1 }).a; + var z2_1 = { a: 1 }.a; use(z2_1); - var z3_1 = ({ a: 1 }).a; + var z3_1 = { a: 1 }.a; use(z3_1); } use(x); @@ -79,10 +79,10 @@ var z6; var y = true; { var y_1 = ""; - var z6_1 = ([true])[0]; + var z6_1 = [true][0]; { var y_2 = 1; - var z6_2 = ({ a: 1 }).a; + var z6_2 = { a: 1 }.a; use(y_2); use(z6_2); } @@ -95,10 +95,10 @@ var z = false; var z5 = 1; { var z_1 = ""; - var z5_1 = ([5])[0]; + var z5_1 = [5][0]; { var _z = 1; - var _z5 = ({ a: 1 }).a; + var _z5 = { a: 1 }.a; // try to step on generated name use(_z); } diff --git a/tests/baselines/reference/downlevelLetConst15.js b/tests/baselines/reference/downlevelLetConst15.js index 99522542d38c6..807f49bf84eba 100644 --- a/tests/baselines/reference/downlevelLetConst15.js +++ b/tests/baselines/reference/downlevelLetConst15.js @@ -61,13 +61,13 @@ var z0, z1, z2, z3; { var x_1 = 20; use(x_1); - var z0_1 = ([1])[0]; + var z0_1 = [1][0]; use(z0_1); - var z1_1 = ([{ a: 1 }])[0].a; + var z1_1 = [{ a: 1 }][0].a; use(z1_1); - var z2_1 = ({ a: 1 }).a; + var z2_1 = { a: 1 }.a; use(z2_1); - var z3_1 = ({ a: { b: 1 } }).a.b; + var z3_1 = { a: { b: 1 } }.a.b; use(z3_1); } use(x); @@ -79,10 +79,10 @@ var z6; var y = true; { var y_1 = ""; - var z6_1 = ([true])[0]; + var z6_1 = [true][0]; { var y_2 = 1; - var z6_2 = ({ a: 1 }).a; + var z6_2 = { a: 1 }.a; use(y_2); use(z6_2); } @@ -95,10 +95,10 @@ var z = false; var z5 = 1; { var z_1 = ""; - var z5_1 = ([5])[0]; + var z5_1 = [5][0]; { var _z = 1; - var _z5 = ({ a: 1 }).a; + var _z5 = { a: 1 }.a; // try to step on generated name use(_z); } diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js index 4765b50e0a19a..874fc12119128 100644 --- a/tests/baselines/reference/downlevelLetConst16.js +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -238,18 +238,18 @@ use(z); function foo1() { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); } function foo2() { { var x_1 = 1; use(x_1); - var y_1 = ([1])[0]; + var y_1 = [1][0]; use(y_1); - var z_1 = ({ a: 1 }).a; + var z_1 = { a: 1 }.a; use(z_1); } use(x); @@ -260,18 +260,18 @@ var A = (function () { A.prototype.m1 = function () { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); }; A.prototype.m2 = function () { { var x_2 = 1; use(x_2); - var y_2 = ([1])[0]; + var y_2 = [1][0]; use(y_2); - var z_2 = ({ a: 1 }).a; + var z_2 = { a: 1 }.a; use(z_2); } use(x); @@ -284,18 +284,18 @@ var B = (function () { B.prototype.m1 = function () { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); }; B.prototype.m2 = function () { { var x_3 = 1; use(x_3); - var y_3 = ([1])[0]; + var y_3 = [1][0]; use(y_3); - var z_3 = ({ a: 1 }).a; + var z_3 = { a: 1 }.a; use(z_3); } use(x); @@ -305,18 +305,18 @@ var B = (function () { function bar1() { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); } function bar2() { { var x_4 = 1; use(x_4); - var y_4 = ([1])[0]; + var y_4 = [1][0]; use(y_4); - var z_4 = ({ a: 1 }).a; + var z_4 = { a: 1 }.a; use(z_4); } use(x); @@ -325,9 +325,9 @@ var M1; (function (M1) { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); })(M1 || (M1 = {})); var M2; @@ -335,9 +335,9 @@ var M2; { var x_5 = 1; use(x_5); - var y_5 = ([1])[0]; + var y_5 = [1][0]; use(y_5); - var z_5 = ({ a: 1 }).a; + var z_5 = { a: 1 }.a; use(z_5); } use(x); @@ -346,9 +346,9 @@ var M3; (function (M3) { var x = 1; use(x); - var y = ([1])[0]; + var y = [1][0]; use(y); - var z = ({ a: 1 }).a; + var z = { a: 1 }.a; use(z); })(M3 || (M3 = {})); var M4; @@ -356,9 +356,9 @@ var M4; { var x_6 = 1; use(x_6); - var y_6 = ([1])[0]; + var y_6 = [1][0]; use(y_6); - var z_6 = ({ a: 1 }).a; + var z_6 = { a: 1 }.a; use(z_6); } use(x); @@ -369,10 +369,10 @@ function foo3() { for (var x_7 = void 0;;) { use(x_7); } - for (var y_7 = ([])[0];;) { + for (var y_7 = [][0];;) { use(y_7); } - for (var z_7 = ({ a: 1 }).a;;) { + for (var z_7 = { a: 1 }.a;;) { use(z_7); } use(x); @@ -381,10 +381,10 @@ function foo4() { for (var x_8 = 1;;) { use(x_8); } - for (var y_8 = ([])[0];;) { + for (var y_8 = [][0];;) { use(y_8); } - for (var z_8 = ({ a: 1 }).a;;) { + for (var z_8 = { a: 1 }.a;;) { use(z_8); } use(x); diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js index 428a085ca568a..e746b24a066c0 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js @@ -24,7 +24,6 @@ return 103; }); (function () { - if (arg === void 0) { arg = []; } var arg = []; for (var _i = 0; _i < arguments.length; _i++) { arg[_i - 0] = arguments[_i]; diff --git a/tests/baselines/reference/for-of49.errors.txt b/tests/baselines/reference/for-of49.errors.txt index d5bc314e678f9..aaf29f5bfe3eb 100644 --- a/tests/baselines/reference/for-of49.errors.txt +++ b/tests/baselines/reference/for-of49.errors.txt @@ -1,12 +1,14 @@ -tests/cases/conformance/es6/for-ofStatements/for-of49.ts(3,13): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es6/for-ofStatements/for-of49.ts(3,14): error TS2322: Type 'string | boolean' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. ==== tests/cases/conformance/es6/for-ofStatements/for-of49.ts (1 errors) ==== var k: string, v: boolean; var map = new Map([["", true]]); for ([k, ...[v]] of map) { - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2322: Type 'string | boolean' is not assignable to type 'boolean'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. k; v; } \ No newline at end of file diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.js b/tests/baselines/reference/initializePropertiesWithRenamedLet.js index d4f985bea5644..d53fed8c0f738 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.js +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.js @@ -25,8 +25,8 @@ if (true) { } var x, y, z; if (true) { - var x_1 = ({ x: 0 }).x; - var y_1 = ({ y: 0 }).y; + var x_1 = { x: 0 }.x; + var y_1 = { y: 0 }.y; var z_1; (_a = { z: 0 }, z_1 = _a.z, _a); (_b = { z: 0 }, z_1 = _b.z, _b); diff --git a/tests/baselines/reference/iterableArrayPattern14.errors.txt b/tests/baselines/reference/iterableArrayPattern14.errors.txt new file mode 100644 index 0000000000000..a14ddc45022a3 --- /dev/null +++ b/tests/baselines/reference/iterableArrayPattern14.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts (1 errors) ==== + function fun(...[a, ...b]) { } + ~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + fun(new FooIterator); + class Bar { x } + class Foo extends Bar { y } + class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern14.symbols b/tests/baselines/reference/iterableArrayPattern14.symbols deleted file mode 100644 index 6fbf26014d0a0..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern14.symbols +++ /dev/null @@ -1,45 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts === -function fun(...[a, ...b]) { } ->fun : Symbol(fun, Decl(iterableArrayPattern14.ts, 0, 0)) ->a : Symbol(a, Decl(iterableArrayPattern14.ts, 0, 17)) ->b : Symbol(b, Decl(iterableArrayPattern14.ts, 0, 19)) - -fun(new FooIterator); ->fun : Symbol(fun, Decl(iterableArrayPattern14.ts, 0, 0)) ->FooIterator : Symbol(FooIterator, Decl(iterableArrayPattern14.ts, 3, 27)) - -class Bar { x } ->Bar : Symbol(Bar, Decl(iterableArrayPattern14.ts, 1, 21)) ->x : Symbol(x, Decl(iterableArrayPattern14.ts, 2, 11)) - -class Foo extends Bar { y } ->Foo : Symbol(Foo, Decl(iterableArrayPattern14.ts, 2, 15)) ->Bar : Symbol(Bar, Decl(iterableArrayPattern14.ts, 1, 21)) ->y : Symbol(y, Decl(iterableArrayPattern14.ts, 3, 23)) - -class FooIterator { ->FooIterator : Symbol(FooIterator, Decl(iterableArrayPattern14.ts, 3, 27)) - - next() { ->next : Symbol(next, Decl(iterableArrayPattern14.ts, 4, 19)) - - return { - value: new Foo, ->value : Symbol(value, Decl(iterableArrayPattern14.ts, 6, 16)) ->Foo : Symbol(Foo, Decl(iterableArrayPattern14.ts, 2, 15)) - - done: false ->done : Symbol(done, Decl(iterableArrayPattern14.ts, 7, 27)) - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1262, 11)) ->iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) - - return this; ->this : Symbol(FooIterator, Decl(iterableArrayPattern14.ts, 3, 27)) - } -} diff --git a/tests/baselines/reference/iterableArrayPattern14.types b/tests/baselines/reference/iterableArrayPattern14.types deleted file mode 100644 index 110e185cea890..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern14.types +++ /dev/null @@ -1,51 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts === -function fun(...[a, ...b]) { } ->fun : (...[a, ...b]: any[]) => void ->a : any ->b : any[] - -fun(new FooIterator); ->fun(new FooIterator) : void ->fun : (...[a, ...b]: any[]) => void ->new FooIterator : FooIterator ->FooIterator : typeof FooIterator - -class Bar { x } ->Bar : Bar ->x : any - -class Foo extends Bar { y } ->Foo : Foo ->Bar : Bar ->y : any - -class FooIterator { ->FooIterator : FooIterator - - next() { ->next : () => { value: Foo; done: boolean; } - - return { ->{ value: new Foo, done: false } : { value: Foo; done: boolean; } - - value: new Foo, ->value : Foo ->new Foo : Foo ->Foo : typeof Foo - - done: false ->done : boolean ->false : boolean - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : symbol ->Symbol : SymbolConstructor ->iterator : symbol - - return this; ->this : FooIterator - } -} diff --git a/tests/baselines/reference/iterableArrayPattern15.errors.txt b/tests/baselines/reference/iterableArrayPattern15.errors.txt new file mode 100644 index 0000000000000..bb2d1eb096d7a --- /dev/null +++ b/tests/baselines/reference/iterableArrayPattern15.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts (1 errors) ==== + function fun(...[a, b]: Bar[]) { } + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + fun(...new FooIterator); + class Bar { x } + class Foo extends Bar { y } + class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern15.symbols b/tests/baselines/reference/iterableArrayPattern15.symbols deleted file mode 100644 index c0624ef10b38c..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern15.symbols +++ /dev/null @@ -1,46 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts === -function fun(...[a, b]: Bar[]) { } ->fun : Symbol(fun, Decl(iterableArrayPattern15.ts, 0, 0)) ->a : Symbol(a, Decl(iterableArrayPattern15.ts, 0, 17)) ->b : Symbol(b, Decl(iterableArrayPattern15.ts, 0, 19)) ->Bar : Symbol(Bar, Decl(iterableArrayPattern15.ts, 1, 24)) - -fun(...new FooIterator); ->fun : Symbol(fun, Decl(iterableArrayPattern15.ts, 0, 0)) ->FooIterator : Symbol(FooIterator, Decl(iterableArrayPattern15.ts, 3, 27)) - -class Bar { x } ->Bar : Symbol(Bar, Decl(iterableArrayPattern15.ts, 1, 24)) ->x : Symbol(x, Decl(iterableArrayPattern15.ts, 2, 11)) - -class Foo extends Bar { y } ->Foo : Symbol(Foo, Decl(iterableArrayPattern15.ts, 2, 15)) ->Bar : Symbol(Bar, Decl(iterableArrayPattern15.ts, 1, 24)) ->y : Symbol(y, Decl(iterableArrayPattern15.ts, 3, 23)) - -class FooIterator { ->FooIterator : Symbol(FooIterator, Decl(iterableArrayPattern15.ts, 3, 27)) - - next() { ->next : Symbol(next, Decl(iterableArrayPattern15.ts, 4, 19)) - - return { - value: new Foo, ->value : Symbol(value, Decl(iterableArrayPattern15.ts, 6, 16)) ->Foo : Symbol(Foo, Decl(iterableArrayPattern15.ts, 2, 15)) - - done: false ->done : Symbol(done, Decl(iterableArrayPattern15.ts, 7, 27)) - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1262, 11)) ->iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) - - return this; ->this : Symbol(FooIterator, Decl(iterableArrayPattern15.ts, 3, 27)) - } -} diff --git a/tests/baselines/reference/iterableArrayPattern15.types b/tests/baselines/reference/iterableArrayPattern15.types deleted file mode 100644 index 6475c2c30de9f..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern15.types +++ /dev/null @@ -1,53 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts === -function fun(...[a, b]: Bar[]) { } ->fun : (...[a, b]: Bar[]) => void ->a : Bar ->b : Bar ->Bar : Bar - -fun(...new FooIterator); ->fun(...new FooIterator) : void ->fun : (...[a, b]: Bar[]) => void ->...new FooIterator : Foo ->new FooIterator : FooIterator ->FooIterator : typeof FooIterator - -class Bar { x } ->Bar : Bar ->x : any - -class Foo extends Bar { y } ->Foo : Foo ->Bar : Bar ->y : any - -class FooIterator { ->FooIterator : FooIterator - - next() { ->next : () => { value: Foo; done: boolean; } - - return { ->{ value: new Foo, done: false } : { value: Foo; done: boolean; } - - value: new Foo, ->value : Foo ->new Foo : Foo ->Foo : typeof Foo - - done: false ->done : boolean ->false : boolean - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : symbol ->Symbol : SymbolConstructor ->iterator : symbol - - return this; ->this : FooIterator - } -} diff --git a/tests/baselines/reference/iterableArrayPattern16.errors.txt b/tests/baselines/reference/iterableArrayPattern16.errors.txt index 42236140be78a..e03d0a799daf5 100644 --- a/tests/baselines/reference/iterableArrayPattern16.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern16.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'. Property '0' is missing in type 'FooIterator'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (2 errors) ==== function fun(...[a, b]: [Bar, Bar][]) { } + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. fun(...new FooIteratorIterator); ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'. diff --git a/tests/baselines/reference/iterableArrayPattern17.errors.txt b/tests/baselines/reference/iterableArrayPattern17.errors.txt index 306b00ea99067..3cc04fadd11b2 100644 --- a/tests/baselines/reference/iterableArrayPattern17.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern17.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'. Property 'x' is missing in type 'FooIterator'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (2 errors) ==== function fun(...[a, b]: Bar[]) { } + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. fun(new FooIterator); ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'. diff --git a/tests/baselines/reference/iterableArrayPattern20.errors.txt b/tests/baselines/reference/iterableArrayPattern20.errors.txt new file mode 100644 index 0000000000000..4451a814bd5b4 --- /dev/null +++ b/tests/baselines/reference/iterableArrayPattern20.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts (1 errors) ==== + function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + fun(...new FooArrayIterator); + class Bar { x } + class Foo extends Bar { y } + class FooArrayIterator { + next() { + return { + value: [new Foo], + done: false + }; + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern20.symbols b/tests/baselines/reference/iterableArrayPattern20.symbols deleted file mode 100644 index 80587a99322c8..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern20.symbols +++ /dev/null @@ -1,48 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts === -function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { } ->fun : Symbol(fun, Decl(iterableArrayPattern20.ts, 0, 0)) ->a : Symbol(a, Decl(iterableArrayPattern20.ts, 0, 18)) ->Foo : Symbol(Foo, Decl(iterableArrayPattern20.ts, 2, 15)) ->b : Symbol(b, Decl(iterableArrayPattern20.ts, 0, 31)) ->Foo : Symbol(Foo, Decl(iterableArrayPattern20.ts, 2, 15)) ->Bar : Symbol(Bar, Decl(iterableArrayPattern20.ts, 1, 29)) - -fun(...new FooArrayIterator); ->fun : Symbol(fun, Decl(iterableArrayPattern20.ts, 0, 0)) ->FooArrayIterator : Symbol(FooArrayIterator, Decl(iterableArrayPattern20.ts, 3, 27)) - -class Bar { x } ->Bar : Symbol(Bar, Decl(iterableArrayPattern20.ts, 1, 29)) ->x : Symbol(x, Decl(iterableArrayPattern20.ts, 2, 11)) - -class Foo extends Bar { y } ->Foo : Symbol(Foo, Decl(iterableArrayPattern20.ts, 2, 15)) ->Bar : Symbol(Bar, Decl(iterableArrayPattern20.ts, 1, 29)) ->y : Symbol(y, Decl(iterableArrayPattern20.ts, 3, 23)) - -class FooArrayIterator { ->FooArrayIterator : Symbol(FooArrayIterator, Decl(iterableArrayPattern20.ts, 3, 27)) - - next() { ->next : Symbol(next, Decl(iterableArrayPattern20.ts, 4, 24)) - - return { - value: [new Foo], ->value : Symbol(value, Decl(iterableArrayPattern20.ts, 6, 16)) ->Foo : Symbol(Foo, Decl(iterableArrayPattern20.ts, 2, 15)) - - done: false ->done : Symbol(done, Decl(iterableArrayPattern20.ts, 7, 29)) - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1262, 11)) ->iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) - - return this; ->this : Symbol(FooArrayIterator, Decl(iterableArrayPattern20.ts, 3, 27)) - } -} diff --git a/tests/baselines/reference/iterableArrayPattern20.types b/tests/baselines/reference/iterableArrayPattern20.types deleted file mode 100644 index b7bd26377a980..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern20.types +++ /dev/null @@ -1,59 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts === -function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { } ->fun : (...[[a = new Foo], b = [new Foo]]: Bar[][]) => void ->a : Bar ->new Foo : Foo ->Foo : typeof Foo ->b : Bar[] ->[new Foo] : Foo[] ->new Foo : Foo ->Foo : typeof Foo ->Bar : Bar - -fun(...new FooArrayIterator); ->fun(...new FooArrayIterator) : void ->fun : (...[[a = new Foo], b = [new Foo]]: Bar[][]) => void ->...new FooArrayIterator : Foo[] ->new FooArrayIterator : FooArrayIterator ->FooArrayIterator : typeof FooArrayIterator - -class Bar { x } ->Bar : Bar ->x : any - -class Foo extends Bar { y } ->Foo : Foo ->Bar : Bar ->y : any - -class FooArrayIterator { ->FooArrayIterator : FooArrayIterator - - next() { ->next : () => { value: Foo[]; done: boolean; } - - return { ->{ value: [new Foo], done: false } : { value: Foo[]; done: boolean; } - - value: [new Foo], ->value : Foo[] ->[new Foo] : Foo[] ->new Foo : Foo ->Foo : typeof Foo - - done: false ->done : boolean ->false : boolean - - }; - } - - [Symbol.iterator]() { ->Symbol.iterator : symbol ->Symbol : SymbolConstructor ->iterator : symbol - - return this; ->this : FooArrayIterator - } -} diff --git a/tests/baselines/reference/iterableArrayPattern25.errors.txt b/tests/baselines/reference/iterableArrayPattern25.errors.txt index cc901523b55d8..07f46c0d49ee8 100644 --- a/tests/baselines/reference/iterableArrayPattern25.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern25.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,30): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. ==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { } - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern26.errors.txt b/tests/baselines/reference/iterableArrayPattern26.errors.txt index 9fb3e6880398f..a5eff0afb0df0 100644 --- a/tests/baselines/reference/iterableArrayPattern26.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern26.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(2,21): error TS2345: Argument of type 'Map' is not assignable to parameter of type '[string, number]'. Property '0' is missing in type 'Map'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (2 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'Map' is not assignable to parameter of type '[string, number]'. diff --git a/tests/baselines/reference/iterableArrayPattern27.errors.txt b/tests/baselines/reference/iterableArrayPattern27.errors.txt new file mode 100644 index 0000000000000..99914ddc50815 --- /dev/null +++ b/tests/baselines/reference/iterableArrayPattern27.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts (1 errors) ==== + function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern27.symbols b/tests/baselines/reference/iterableArrayPattern27.symbols deleted file mode 100644 index 0f5e8b7094b63..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern27.symbols +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts === -function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } ->takeFirstTwoEntries : Symbol(takeFirstTwoEntries, Decl(iterableArrayPattern27.ts, 0, 0)) ->k1 : Symbol(k1, Decl(iterableArrayPattern27.ts, 0, 34)) ->v1 : Symbol(v1, Decl(iterableArrayPattern27.ts, 0, 37)) ->k2 : Symbol(k2, Decl(iterableArrayPattern27.ts, 0, 44)) ->v2 : Symbol(v2, Decl(iterableArrayPattern27.ts, 0, 47)) - -takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])); ->takeFirstTwoEntries : Symbol(takeFirstTwoEntries, Decl(iterableArrayPattern27.ts, 0, 0)) ->Map : Symbol(Map, Decl(lib.d.ts, 1837, 1), Decl(lib.d.ts, 1859, 11)) - diff --git a/tests/baselines/reference/iterableArrayPattern27.types b/tests/baselines/reference/iterableArrayPattern27.types deleted file mode 100644 index d6f87590326de..0000000000000 --- a/tests/baselines/reference/iterableArrayPattern27.types +++ /dev/null @@ -1,22 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts === -function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } ->takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [string, number][]) => void ->k1 : string ->v1 : number ->k2 : string ->v2 : number - -takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])); ->takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])) : void ->takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [string, number][]) => void ->...new Map([["", 0], ["hello", 1]]) : [string, number] ->new Map([["", 0], ["hello", 1]]) : Map ->Map : MapConstructor ->[["", 0], ["hello", 1]] : [string, number][] ->["", 0] : [string, number] ->"" : string ->0 : number ->["hello", 1] : [string, number] ->"hello" : string ->1 : number - diff --git a/tests/baselines/reference/iterableArrayPattern28.errors.txt b/tests/baselines/reference/iterableArrayPattern28.errors.txt index 0190dd939e8e0..986dfe1d9a243 100644 --- a/tests/baselines/reference/iterableArrayPattern28.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern28.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,28): error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'boolean'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (2 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(...new Map([["", 0], ["hello", true]])); ~~~ !!! error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly. diff --git a/tests/baselines/reference/iterableArrayPattern29.errors.txt b/tests/baselines/reference/iterableArrayPattern29.errors.txt index 632854ae952f3..b34d0317d5768 100644 --- a/tests/baselines/reference/iterableArrayPattern29.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern29.errors.txt @@ -1,10 +1,13 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(2,21): error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'. Types of property '1' are incompatible. Type 'boolean' is not assignable to type 'number'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (2 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(...new Map([["", true], ["hello", true]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'. diff --git a/tests/baselines/reference/letInNonStrictMode.js b/tests/baselines/reference/letInNonStrictMode.js index 8a431535ae2cf..8e4920cc22035 100644 --- a/tests/baselines/reference/letInNonStrictMode.js +++ b/tests/baselines/reference/letInNonStrictMode.js @@ -3,5 +3,5 @@ let [x] = [1]; let {a: y} = {a: 1}; //// [letInNonStrictMode.js] -var x = ([1])[0]; -var y = ({ a: 1 }).a; +var x = [1][0]; +var y = { a: 1 }.a; diff --git a/tests/baselines/reference/nonIterableRestElement1.js b/tests/baselines/reference/nonIterableRestElement1.js new file mode 100644 index 0000000000000..6852ad503cfbd --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement1.js @@ -0,0 +1,7 @@ +//// [nonIterableRestElement1.ts] +var c = {}; +[...c] = ["", 0]; + +//// [nonIterableRestElement1.js] +var c = {}; +c = ["", 0].slice(0); diff --git a/tests/baselines/reference/nonIterableRestElement1.symbols b/tests/baselines/reference/nonIterableRestElement1.symbols new file mode 100644 index 0000000000000..352d0c87da45b --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement1.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts === +var c = {}; +>c : Symbol(c, Decl(nonIterableRestElement1.ts, 0, 3)) + +[...c] = ["", 0]; +>c : Symbol(c, Decl(nonIterableRestElement1.ts, 0, 3)) + diff --git a/tests/baselines/reference/nonIterableRestElement1.types b/tests/baselines/reference/nonIterableRestElement1.types new file mode 100644 index 0000000000000..4973b67d4ae0b --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement1.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts === +var c = {}; +>c : {} +>{} : {} + +[...c] = ["", 0]; +>[...c] = ["", 0] : (string | number)[] +>[...c] : {}[] +>...c : any +>c : {} +>["", 0] : (string | number)[] +>"" : string +>0 : number + diff --git a/tests/baselines/reference/nonIterableRestElement2.js b/tests/baselines/reference/nonIterableRestElement2.js new file mode 100644 index 0000000000000..edeef32e188d4 --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement2.js @@ -0,0 +1,7 @@ +//// [nonIterableRestElement2.ts] +var c = {}; +[...c] = ["", 0]; + +//// [nonIterableRestElement2.js] +var c = {}; +[...c] = ["", 0]; diff --git a/tests/baselines/reference/nonIterableRestElement2.symbols b/tests/baselines/reference/nonIterableRestElement2.symbols new file mode 100644 index 0000000000000..766524a408ba2 --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement2.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts === +var c = {}; +>c : Symbol(c, Decl(nonIterableRestElement2.ts, 0, 3)) + +[...c] = ["", 0]; +>c : Symbol(c, Decl(nonIterableRestElement2.ts, 0, 3)) + diff --git a/tests/baselines/reference/nonIterableRestElement2.types b/tests/baselines/reference/nonIterableRestElement2.types new file mode 100644 index 0000000000000..e6d84d5297e6b --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement2.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts === +var c = {}; +>c : {} +>{} : {} + +[...c] = ["", 0]; +>[...c] = ["", 0] : (string | number)[] +>[...c] : {}[] +>...c : any +>c : {} +>["", 0] : (string | number)[] +>"" : string +>0 : number + diff --git a/tests/baselines/reference/nonIterableRestElement3.errors.txt b/tests/baselines/reference/nonIterableRestElement3.errors.txt new file mode 100644 index 0000000000000..2c44aba661e14 --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement3.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts(2,5): error TS2322: Type '(string | number)[]' is not assignable to type '{ bogus: number; }'. + Property 'bogus' is missing in type '(string | number)[]'. + + +==== tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts (1 errors) ==== + var c = { bogus: 0 }; + [...c] = ["", 0]; + ~ +!!! error TS2322: Type '(string | number)[]' is not assignable to type '{ bogus: number; }'. +!!! error TS2322: Property 'bogus' is missing in type '(string | number)[]'. \ No newline at end of file diff --git a/tests/baselines/reference/nonIterableRestElement3.js b/tests/baselines/reference/nonIterableRestElement3.js new file mode 100644 index 0000000000000..0f7edfe98f4d1 --- /dev/null +++ b/tests/baselines/reference/nonIterableRestElement3.js @@ -0,0 +1,7 @@ +//// [nonIterableRestElement3.ts] +var c = { bogus: 0 }; +[...c] = ["", 0]; + +//// [nonIterableRestElement3.js] +var c = { bogus: 0 }; +c = ["", 0].slice(0); diff --git a/tests/baselines/reference/parserParameterList10.js b/tests/baselines/reference/parserParameterList10.js index 4f85dec801c64..7a4e8132868d5 100644 --- a/tests/baselines/reference/parserParameterList10.js +++ b/tests/baselines/reference/parserParameterList10.js @@ -8,7 +8,6 @@ var C = (function () { function C() { } C.prototype.foo = function () { - if (bar === void 0) { bar = 0; } var bar = []; for (var _i = 0; _i < arguments.length; _i++) { bar[_i - 0] = arguments[_i]; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern1.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern1.errors.txt new file mode 100644 index 0000000000000..2e1046c9317f5 --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern1.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts(2,9): error TS2322: Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts (2 errors) ==== + var a: string, b: number; + [...[a, b = 0]] = ["", 1]; + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithAssignmentPattern1.js b/tests/baselines/reference/restElementWithAssignmentPattern1.js new file mode 100644 index 0000000000000..34574022868ac --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern1.js @@ -0,0 +1,7 @@ +//// [restElementWithAssignmentPattern1.ts] +var a: string, b: number; +[...[a, b = 0]] = ["", 1]; + +//// [restElementWithAssignmentPattern1.js] +var a, b; +[...[a, b = 0]] = ["", 1]; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern2.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern2.errors.txt new file mode 100644 index 0000000000000..f9b11b5694cab --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts(2,10): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts(2,18): error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. + + +==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts (2 errors) ==== + var a: string, b: number; + [...{ 0: a = "", b }] = ["", 1]; + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithAssignmentPattern2.js b/tests/baselines/reference/restElementWithAssignmentPattern2.js new file mode 100644 index 0000000000000..66c4428ea41d8 --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern2.js @@ -0,0 +1,7 @@ +//// [restElementWithAssignmentPattern2.ts] +var a: string, b: number; +[...{ 0: a = "", b }] = ["", 1]; + +//// [restElementWithAssignmentPattern2.js] +var a, b; +[...{ 0: a = "", b }] = ["", 1]; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt new file mode 100644 index 0000000000000..6906bdde36f5c --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,9): error TS2322: Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts (2 errors) ==== + var a: string, b: number; + var tuple: [string, number] = ["", 1]; + [...[a, b = 0]] = tuple; + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithAssignmentPattern3.js b/tests/baselines/reference/restElementWithAssignmentPattern3.js new file mode 100644 index 0000000000000..1ca504fbd6dab --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern3.js @@ -0,0 +1,10 @@ +//// [restElementWithAssignmentPattern3.ts] +var a: string, b: number; +var tuple: [string, number] = ["", 1]; +[...[a, b = 0]] = tuple; + +//// [restElementWithAssignmentPattern3.js] +var a, b; +var tuple = ["", 1]; +_a = tuple.slice(0), a = _a[0], _b = _a[1], b = _b === void 0 ? 0 : _b; +var _a, _b; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt new file mode 100644 index 0000000000000..258d091523930 --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,10): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,18): error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. + + +==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts (2 errors) ==== + var a: string, b: number; + var tuple: [string, number] = ["", 1]; + [...{ 0: a = "", b }] = tuple; + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithAssignmentPattern4.js b/tests/baselines/reference/restElementWithAssignmentPattern4.js new file mode 100644 index 0000000000000..b47a2adea0119 --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern4.js @@ -0,0 +1,10 @@ +//// [restElementWithAssignmentPattern4.ts] +var a: string, b: number; +var tuple: [string, number] = ["", 1]; +[...{ 0: a = "", b }] = tuple; + +//// [restElementWithAssignmentPattern4.js] +var a, b; +var tuple = ["", 1]; +_a = tuple.slice(0), _b = _a[0], a = _b === void 0 ? "" : _b, b = _a.b; +var _a, _b; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern5.js b/tests/baselines/reference/restElementWithAssignmentPattern5.js new file mode 100644 index 0000000000000..e0985d54b1c9e --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern5.js @@ -0,0 +1,8 @@ +//// [restElementWithAssignmentPattern5.ts] +var s: string, s2: string; +[...[s, s2]] = ["", ""]; + +//// [restElementWithAssignmentPattern5.js] +var s, s2; +_a = ["", ""].slice(0), s = _a[0], s2 = _a[1]; +var _a; diff --git a/tests/baselines/reference/restElementWithAssignmentPattern5.symbols b/tests/baselines/reference/restElementWithAssignmentPattern5.symbols new file mode 100644 index 0000000000000..947c37e4f7cab --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern5.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts === +var s: string, s2: string; +>s : Symbol(s, Decl(restElementWithAssignmentPattern5.ts, 0, 3)) +>s2 : Symbol(s2, Decl(restElementWithAssignmentPattern5.ts, 0, 14)) + +[...[s, s2]] = ["", ""]; +>s : Symbol(s, Decl(restElementWithAssignmentPattern5.ts, 0, 3)) +>s2 : Symbol(s2, Decl(restElementWithAssignmentPattern5.ts, 0, 14)) + diff --git a/tests/baselines/reference/restElementWithAssignmentPattern5.types b/tests/baselines/reference/restElementWithAssignmentPattern5.types new file mode 100644 index 0000000000000..e3934c3119721 --- /dev/null +++ b/tests/baselines/reference/restElementWithAssignmentPattern5.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts === +var s: string, s2: string; +>s : string +>s2 : string + +[...[s, s2]] = ["", ""]; +>[...[s, s2]] = ["", ""] : string[] +>[...[s, s2]] : string[] +>...[s, s2] : string +>[s, s2] : string[] +>s : string +>s2 : string +>["", ""] : string[] +>"" : string +>"" : string + diff --git a/tests/baselines/reference/restElementWithBindingPattern.errors.txt b/tests/baselines/reference/restElementWithBindingPattern.errors.txt new file mode 100644 index 0000000000000..671b722db7309 --- /dev/null +++ b/tests/baselines/reference/restElementWithBindingPattern.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts(1,9): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts (1 errors) ==== + var [...[a, b]] = [0, 1]; + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithBindingPattern.js b/tests/baselines/reference/restElementWithBindingPattern.js new file mode 100644 index 0000000000000..fbdb4bdb3a71e --- /dev/null +++ b/tests/baselines/reference/restElementWithBindingPattern.js @@ -0,0 +1,5 @@ +//// [restElementWithBindingPattern.ts] +var [...[a, b]] = [0, 1]; + +//// [restElementWithBindingPattern.js] +var _a = [0, 1].slice(0), a = _a[0], b = _a[1]; diff --git a/tests/baselines/reference/restElementWithBindingPattern2.errors.txt b/tests/baselines/reference/restElementWithBindingPattern2.errors.txt new file mode 100644 index 0000000000000..9645a028a4ebf --- /dev/null +++ b/tests/baselines/reference/restElementWithBindingPattern2.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,9): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,16): error TS2459: Type 'number[]' has no property 'b' and no string index signature. + + +==== tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts (2 errors) ==== + var [...{0: a, b }] = [0, 1]; + ~~~~~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + ~ +!!! error TS2459: Type 'number[]' has no property 'b' and no string index signature. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithBindingPattern2.js b/tests/baselines/reference/restElementWithBindingPattern2.js new file mode 100644 index 0000000000000..bb8ebcf7d36dd --- /dev/null +++ b/tests/baselines/reference/restElementWithBindingPattern2.js @@ -0,0 +1,5 @@ +//// [restElementWithBindingPattern2.ts] +var [...{0: a, b }] = [0, 1]; + +//// [restElementWithBindingPattern2.js] +var _a = [0, 1].slice(0), a = _a[0], b = _a.b; diff --git a/tests/baselines/reference/restElementWithInitializer1.js b/tests/baselines/reference/restElementWithInitializer1.js index 26df58e3cf3fa..b0d35cdf47fd8 100644 --- a/tests/baselines/reference/restElementWithInitializer1.js +++ b/tests/baselines/reference/restElementWithInitializer1.js @@ -5,4 +5,4 @@ var [...x = a] = a; // Error, rest element cannot have initializer //// [restElementWithInitializer1.js] var a; -var x = a.slice(0); // Error, rest element cannot have initializer +var _a = a.slice(0), x = _a === void 0 ? a : _a; // Error, rest element cannot have initializer diff --git a/tests/baselines/reference/restElementWithInitializer2.errors.txt b/tests/baselines/reference/restElementWithInitializer2.errors.txt index 9c4e95e396388..43fbfcfcd2d0a 100644 --- a/tests/baselines/reference/restElementWithInitializer2.errors.txt +++ b/tests/baselines/reference/restElementWithInitializer2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts(3,5): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts(3,7): error TS1186: A rest element cannot have an initializer. ==== tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts (1 errors) ==== var a: number[]; var x: number[]; [...x = a] = a; // Error, rest element cannot have initializer - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS1186: A rest element cannot have an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithInitializer2.js b/tests/baselines/reference/restElementWithInitializer2.js index 8874f6a83d0a7..09ec76bdfb4d5 100644 --- a/tests/baselines/reference/restElementWithInitializer2.js +++ b/tests/baselines/reference/restElementWithInitializer2.js @@ -7,4 +7,5 @@ var x: number[]; //// [restElementWithInitializer2.js] var a; var x; -x = a = a.slice(0); // Error, rest element cannot have initializer +_a = a.slice(0), x = _a === void 0 ? a : _a; // Error, rest element cannot have initializer +var _a; diff --git a/tests/baselines/reference/restElementWithNullInitializer.js b/tests/baselines/reference/restElementWithNullInitializer.js index 9f326602fb837..ac378b0905bb5 100644 --- a/tests/baselines/reference/restElementWithNullInitializer.js +++ b/tests/baselines/reference/restElementWithNullInitializer.js @@ -14,14 +14,14 @@ function foo4([...r] = []) { //// [restElementWithNullInitializer.js] function foo1(_a) { - var _b = _a === void 0 ? null : _a, r = _b.slice(0); + var r = (_a === void 0 ? null : _a).slice(0); } function foo2(_a) { - var _b = _a === void 0 ? undefined : _a, r = _b.slice(0); + var r = (_a === void 0 ? undefined : _a).slice(0); } function foo3(_a) { - var _b = _a === void 0 ? {} : _a, r = _b.slice(0); + var r = (_a === void 0 ? {} : _a).slice(0); } function foo4(_a) { - var _b = _a === void 0 ? [] : _a, r = _b.slice(0); + var r = (_a === void 0 ? [] : _a).slice(0); } diff --git a/tests/baselines/reference/restParamAsOptional.js b/tests/baselines/reference/restParamAsOptional.js index 59aea1cc9c4f3..eb224b84c33b1 100644 --- a/tests/baselines/reference/restParamAsOptional.js +++ b/tests/baselines/reference/restParamAsOptional.js @@ -10,7 +10,6 @@ function f() { } } function f2() { - if (x === void 0) { x = []; } var x = []; for (var _i = 0; _i < arguments.length; _i++) { x[_i - 0] = arguments[_i]; diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt new file mode 100644 index 0000000000000..7194159a220e3 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/restParameterWithBindingPattern1.ts(1,15): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/compiler/restParameterWithBindingPattern1.ts (1 errors) ==== + function a(...{a, b}) { } + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.js b/tests/baselines/reference/restParameterWithBindingPattern1.js new file mode 100644 index 0000000000000..9fb45768afe33 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern1.js @@ -0,0 +1,5 @@ +//// [restParameterWithBindingPattern1.ts] +function a(...{a, b}) { } + +//// [restParameterWithBindingPattern1.js] +function a() { } diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt new file mode 100644 index 0000000000000..e69e1c2ba78a6 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/restParameterWithBindingPattern2.ts(1,15): error TS2501: A rest element cannot contain a binding pattern. + + +==== tests/cases/compiler/restParameterWithBindingPattern2.ts (1 errors) ==== + function a(...[a, b]) { } + ~~~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.js b/tests/baselines/reference/restParameterWithBindingPattern2.js new file mode 100644 index 0000000000000..5c97769acbbb3 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern2.js @@ -0,0 +1,5 @@ +//// [restParameterWithBindingPattern2.ts] +function a(...[a, b]) { } + +//// [restParameterWithBindingPattern2.js] +function a() { } diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js index b3c44600d1d1b..e1cae9c73fee7 100644 --- a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js @@ -15,9 +15,9 @@ if (true) { var x_1; if (true) { var x = 0; // Error - var _a = ({ x: 0 }).x, x = _a === void 0 ? 0 : _a; // Error - var _b = ({ x: 0 }).x, x = _b === void 0 ? 0 : _b; // Error - var x = ({ x: 0 }).x; // Error - var x = ({ x: 0 }).x; // Error + var _a = { x: 0 }.x, x = _a === void 0 ? 0 : _a; // Error + var _b = { x: 0 }.x, x = _b === void 0 ? 0 : _b; // Error + var x = { x: 0 }.x; // Error + var x = { x: 0 }.x; // Error } } diff --git a/tests/baselines/reference/strictModeReservedWordInDestructuring.js b/tests/baselines/reference/strictModeReservedWordInDestructuring.js index 1fe5a9f71d68a..e7675e6babfc9 100644 --- a/tests/baselines/reference/strictModeReservedWordInDestructuring.js +++ b/tests/baselines/reference/strictModeReservedWordInDestructuring.js @@ -8,8 +8,8 @@ var {public, protected} = { public: 1, protected: 2 }; //// [strictModeReservedWordInDestructuring.js] "use strict"; -var public = ([1])[0]; -var public = ({ x: 1 }).x; -var private = ([["hello"]])[0][0]; +var public = [1][0]; +var public = { x: 1 }.x; +var private = [["hello"]][0][0]; var _a = { y: { s: 1 }, z: { o: { p: 'h' } } }, static = _a.y.s, package = _a.z.o.p; var _b = { public: 1, protected: 2 }, public = _b.public, protected = _b.protected; diff --git a/tests/baselines/reference/strictModeUseContextualKeyword.js b/tests/baselines/reference/strictModeUseContextualKeyword.js index e5be28e9b71f5..33ceae360311d 100644 --- a/tests/baselines/reference/strictModeUseContextualKeyword.js +++ b/tests/baselines/reference/strictModeUseContextualKeyword.js @@ -27,5 +27,5 @@ function F() { function as() { } } function H() { - var as = ({ as: 1 }).as; + var as = { as: 1 }.as; } diff --git a/tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts b/tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts new file mode 100644 index 0000000000000..21b437be48ec1 --- /dev/null +++ b/tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts @@ -0,0 +1,2 @@ +var tuple: [string, number]; +[...c] = tupel; // intentionally misspelled \ No newline at end of file diff --git a/tests/cases/compiler/destructuringWithNewExpression.ts b/tests/cases/compiler/destructuringWithNewExpression.ts new file mode 100644 index 0000000000000..782fef2b54dbc --- /dev/null +++ b/tests/cases/compiler/destructuringWithNewExpression.ts @@ -0,0 +1,5 @@ +class C { + x = 0; +} + +var { x } = new C; \ No newline at end of file diff --git a/tests/cases/compiler/destructuringWithNumberLiteral.ts b/tests/cases/compiler/destructuringWithNumberLiteral.ts new file mode 100644 index 0000000000000..b0371c7c51020 --- /dev/null +++ b/tests/cases/compiler/destructuringWithNumberLiteral.ts @@ -0,0 +1 @@ +var { toExponential } = 0; \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern1.ts b/tests/cases/compiler/restParameterWithBindingPattern1.ts new file mode 100644 index 0000000000000..1004b0478440a --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern1.ts @@ -0,0 +1 @@ +function a(...{a, b}) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern2.ts b/tests/cases/compiler/restParameterWithBindingPattern2.ts new file mode 100644 index 0000000000000..85076703b7963 --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern2.ts @@ -0,0 +1 @@ +function a(...[a, b]) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/arrayAssignmentPatternWithAny.ts b/tests/cases/conformance/es6/destructuring/arrayAssignmentPatternWithAny.ts new file mode 100644 index 0000000000000..9ca6bd77eb7fa --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/arrayAssignmentPatternWithAny.ts @@ -0,0 +1,3 @@ +var a: any; +var x: string; +[x] = a; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts b/tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts new file mode 100644 index 0000000000000..3923e7e538eab --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts @@ -0,0 +1,2 @@ +var c = {}; +[...c] = ["", 0]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts b/tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts new file mode 100644 index 0000000000000..2bede0e7f579c --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var c = {}; +[...c] = ["", 0]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts b/tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts new file mode 100644 index 0000000000000..cffac92ebf4a2 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts @@ -0,0 +1,2 @@ +var c = { bogus: 0 }; +[...c] = ["", 0]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts new file mode 100644 index 0000000000000..51fb8ef4a7790 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern1.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var a: string, b: number; +[...[a, b = 0]] = ["", 1]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts new file mode 100644 index 0000000000000..db2defa95d779 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var a: string, b: number; +[...{ 0: a = "", b }] = ["", 1]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts new file mode 100644 index 0000000000000..839711498c289 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts @@ -0,0 +1,3 @@ +var a: string, b: number; +var tuple: [string, number] = ["", 1]; +[...[a, b = 0]] = tuple; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts new file mode 100644 index 0000000000000..5b1ad000529eb --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts @@ -0,0 +1,3 @@ +var a: string, b: number; +var tuple: [string, number] = ["", 1]; +[...{ 0: a = "", b }] = tuple; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts new file mode 100644 index 0000000000000..b7656f99fd653 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts @@ -0,0 +1,2 @@ +var s: string, s2: string; +[...[s, s2]] = ["", ""]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts b/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts new file mode 100644 index 0000000000000..960445aa10d69 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts @@ -0,0 +1 @@ +var [...[a, b]] = [0, 1]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts b/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts new file mode 100644 index 0000000000000..3861d20cf9f33 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts @@ -0,0 +1 @@ +var [...{0: a, b }] = [0, 1]; \ No newline at end of file