From e78478b76738326fa1b6927826496c165e927e25 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 12:34:29 -0700 Subject: [PATCH 01/17] More flexible rules when destructuring have literal initializers --- src/compiler/checker.ts | 53 +++++++++++++++++++++++++++++++++-------- src/compiler/types.ts | 4 ++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e624eb41d86a5..7c4a438664fdf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2318,8 +2318,8 @@ namespace ts { // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. type = getTypeOfPropertyOfType(parentType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || - getIndexTypeOfType(parentType, IndexKind.String); + isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || + getIndexTypeOfType(parentType, IndexKind.String); if (!type) { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); return unknownType; @@ -2456,7 +2456,6 @@ namespace ts { let unionOfElements = getUnionType(elementTypes); 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. return createTupleType(elementTypes); } @@ -6607,12 +6606,18 @@ namespace ts { } } if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); + return createImpliedType(getTypeFromBindingPattern(declaration.name)); } } return undefined; } + function createImpliedType(type: Type): Type { + var result = clone(type); + result.flags |= TypeFlags.ImpliedType; + return result; + } + function getContextualTypeForReturnExpression(node: Expression): Type { let func = getContainingFunction(node); if (func && !func.asteriskToken) { @@ -7005,9 +7010,6 @@ namespace ts { function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type { let elements = node.elements; - if (!elements.length) { - return createArrayType(undefinedType); - } let hasSpreadElement = false; let elementTypes: Type[] = []; let inDestructuringPattern = isAssignmentTarget(node); @@ -7039,12 +7041,24 @@ namespace ts { hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; } if (!hasSpreadElement) { + if (inDestructuringPattern && elementTypes.length) { + return createImpliedType(createTupleType(elementTypes)); + } let contextualType = getContextualType(node); - if (contextualType && contextualTypeIsTupleLikeType(contextualType) || inDestructuringPattern) { - return createTupleType(elementTypes); + let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; + if (contextualTupleLikeType) { + if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { + let contextualElementTypes = (contextualTupleLikeType).elementTypes; + for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { + elementTypes.push(contextualElementTypes[i]); + } + } + if (elementTypes.length) { + return createTupleType(elementTypes); + } } } - return createArrayType(getUnionType(elementTypes)); + return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType) } function isNumericName(name: DeclarationName): boolean { @@ -7131,6 +7145,14 @@ namespace ts { } typeFlags |= type.flags; let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); + // If object literal is contextually typed by the implied type of a binding pattern, and if the + // binding pattern specifies a default value for the property, make the property optional. + if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + let impliedProp = getPropertyOfType(contextualType, member.name); + if (impliedProp) { + prop.flags |= impliedProp.flags & SymbolFlags.Optional; + } + } prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) { @@ -7157,6 +7179,17 @@ namespace ts { propertiesArray.push(member); } + // If object literal is contextually typed by the implied type of a binding pattern, augment the result + // type with those properties for which the binding pattern specifies a default value. + if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + for (let prop of getPropertiesOfType(contextualType)) { + if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { + propertiesTable[prop.name] = prop; + propertiesArray.push(prop); + } + } + } + let stringIndexType = getIndexType(IndexKind.String); let numberIndexType = getIndexType(IndexKind.Number); let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e3952737..1313fb5b0311e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1795,6 +1795,7 @@ namespace ts { /* @internal */ ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 + ImpliedType = 0x02000000, // Type implied by object binding pattern /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1864,8 +1865,7 @@ namespace ts { } export interface TupleType extends ObjectType { - elementTypes: Type[]; // Element types - baseArrayType: TypeReference; // Array where T is best common type of element types + elementTypes: Type[]; // Element types } export interface UnionOrIntersectionType extends Type { From c436736e1e127d99f4c9213229e9d7265789ba4d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:15:43 -0700 Subject: [PATCH 02/17] Adding a few comments --- src/compiler/checker.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7c4a438664fdf..d4e68381f7b8c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7041,12 +7041,16 @@ namespace ts { hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; } if (!hasSpreadElement) { + // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such + // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { return createImpliedType(createTupleType(elementTypes)); } let contextualType = getContextualType(node); let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; if (contextualTupleLikeType) { + // If array literal is contextually typed by the implied type of a binding pattern, pad the resulting + // tuple type with elements from the binding tuple type to make the lengths equal. if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { let contextualElementTypes = (contextualTupleLikeType).elementTypes; for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { From f28e424d31cb06b141a81580122cb43495066e54 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:16:54 -0700 Subject: [PATCH 03/17] Adding tests --- .../destructuringWithLiteralInitializers.js | 117 +++++++++ ...structuringWithLiteralInitializers.symbols | 150 +++++++++++ ...destructuringWithLiteralInitializers.types | 235 ++++++++++++++++++ .../destructuringWithLiteralInitializers.ts | 51 ++++ 4 files changed, 553 insertions(+) create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.js create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.symbols create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.types create mode 100644 tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js new file mode 100644 index 0000000000000..c25216a55f860 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -0,0 +1,117 @@ +//// [destructuringWithLiteralInitializers.ts] +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]); + + +//// [destructuringWithLiteralInitializers.js] +// (arg: { x: any, y: any }) => void +function f1(_a) { + var x = _a.x, y = _a.y; +} +f1({ x: 1, y: 1 }); +function f2(_a) { + var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; +} +f2({ x: 1 }); +f2({ x: 1, y: 1 }); +// (arg: { x?: number, y?: number }) => void +function f3(_a) { + var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c; +} +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); +// (arg?: { x: number, y: number }) => void +function f4(_a) { + var _b = _a === void 0 ? { x: 0, y: 0 } : _a, x = _b.x, y = _b.y; +} +f4(); +f4({ x: 1, y: 1 }); +// (arg?: { x: number, y?: number }) => void +function f5(_a) { + var _b = _a === void 0 ? { x: 0 } : _a, x = _b.x, _c = _b.y, y = _c === void 0 ? 0 : _c; +} +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); +// (arg?: { x?: number, y?: number }) => void +function f6(_a) { + var _b = _a === void 0 ? {} : _a, _c = _b.x, x = _c === void 0 ? 0 : _c, _d = _b.y, y = _d === void 0 ? 0 : _d; +} +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); +// (arg: [any, any]) => void +function g1(_a) { + var x = _a[0], y = _a[1]; +} +g1([1, 1]); +// (arg: [number, number]) => void +function g2(_a) { + var _b = _a[0], x = _b === void 0 ? 0 : _b, _c = _a[1], y = _c === void 0 ? 0 : _c; +} +g2([1, 1]); +// (arg?: [any, any]) => void +function g3(_a) { + var _b = _a === void 0 ? [] : _a, x = _b[0], y = _b[1]; +} +g3(); +g3([1, 1]); +// (arg?: [number, number]) => void +function g4(_a) { + var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; +} +g4(); +g4([1, 1]); diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols new file mode 100644 index 0000000000000..992a9c3ace53b --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -0,0 +1,150 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 1, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 1, 16)) + +f1({ x: 1, y: 1 }); +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 2, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 2, 10)) + +function f2({ x, y = 0 }) { } +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 4, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 4, 16)) + +f2({ x: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 4)) + +f2({ x: 1, y: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 6, 10)) + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 9, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 9, 20)) + +f3({}); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) + +f3({ x: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 11, 4)) + +f3({ y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) + +f3({ x: 1, y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 10)) + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 24)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 30)) + +f4(); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) + +f4({ x: 1, y: 1 }); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 18, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 18, 10)) + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 21, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 28)) + +f5(); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) + +f5({ x: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 23, 4)) + +f5({ x: 1, y: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 24, 10)) + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 27, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 27, 20)) + +f6(); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({}); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({ x: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 30, 4)) + +f6({ y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) + +f6({ x: 1, y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 10)) + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 35, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 35, 15)) + +g1([1, 1]); +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 39, 19)) + +g2([1, 1]); +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 43, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 43, 15)) + +g3(); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +g3([1, 1]); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 15)) + +g4(); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + +g4([1, 1]); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types new file mode 100644 index 0000000000000..c0577cb995019 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -0,0 +1,235 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : ({ x, y }: { x: any; y: any; }) => void +>x : any +>y : any + +f1({ x: 1, y: 1 }); +>f1({ x: 1, y: 1 }) : void +>f1 : ({ x, y }: { x: any; y: any; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +function f2({ x, y = 0 }) { } +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>x : any +>y : number +>0 : number + +f2({ x: 1 }); +>f2({ x: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f2({ x: 1, y: 1 }); +>f2({ x: 1, y: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number + +f3({}); +>f3({}) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{} : {} + +f3({ x: 1 }); +>f3({ x: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f3({ y: 1 }); +>f3({ y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f3({ x: 1, y: 1 }); +>f3({ x: 1, y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>x : number +>y : number +>{ x: 0, y: 0 } : { x: number; y: number; } +>x : number +>0 : number +>y : number +>0 : number + +f4(); +>f4() : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void + +f4({ x: 1, y: 1 }); +>f4({ x: 1, y: 1 }) : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>x : number +>y : number +>0 : number +>{ x: 0 } : { x: number; y?: number; } +>x : number +>0 : number + +f5(); +>f5() : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void + +f5({ x: 1 }); +>f5({ x: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f5({ x: 1, y: 1 }); +>f5({ x: 1, y: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number +>{} : { x?: number; y?: number; } + +f6(); +>f6() : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void + +f6({}); +>f6({}) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{} : {} + +f6({ x: 1 }); +>f6({ x: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f6({ y: 1 }); +>f6({ y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f6({ x: 1, y: 1 }); +>f6({ x: 1, y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : ([x, y]: [any, any]) => void +>x : any +>y : any + +g1([1, 1]); +>g1([1, 1]) : void +>g1 : ([x, y]: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : ([x = 0, y = 0]: [number, number]) => void +>x : number +>0 : number +>y : number +>0 : number + +g2([1, 1]); +>g2([1, 1]) : void +>g2 : ([x = 0, y = 0]: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : ([x, y]?: [any, any]) => void +>x : any +>y : any +>[] : [any, any] + +g3(); +>g3() : void +>g3 : ([x, y]?: [any, any]) => void + +g3([1, 1]); +>g3([1, 1]) : void +>g3 : ([x, y]?: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : ([x, y]?: [number, number]) => void +>x : number +>y : number +>[0, 0] : [number, number] +>0 : number +>0 : number + +g4(); +>g4() : void +>g4 : ([x, y]?: [number, number]) => void + +g4([1, 1]); +>g4([1, 1]) : void +>g4 : ([x, y]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts new file mode 100644 index 0000000000000..8f6b77d95c9c8 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -0,0 +1,51 @@ +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]); From 66e3abaa12c8fab57d99c77807341f553907a7f5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:17:02 -0700 Subject: [PATCH 04/17] Accepting new baselines --- .../reference/arrowFunctionExpressions.types | 6 +++--- .../reference/declarationEmitDestructuring2.js | 4 ++-- ...declarationEmitDestructuringArrayPattern2.types | 2 +- .../declarationsAndAssignments.errors.txt | 14 ++++---------- ...uringArrayBindingPatternAndAssignment1ES5.types | 2 +- ...uringArrayBindingPatternAndAssignment1ES6.types | 2 +- ...ingArrayBindingPatternAndAssignment2.errors.txt | 8 +------- ...ringObjectBindingPatternAndAssignment1ES5.types | 2 +- ...ringObjectBindingPatternAndAssignment1ES6.types | 2 +- .../destructuringVariableDeclaration1ES5.types | 2 +- .../destructuringVariableDeclaration1ES6.types | 2 +- .../baselines/reference/downlevelLetConst12.types | 4 ++-- .../baselines/reference/emitArrowFunctionES6.types | 6 +++--- .../reference/nonIterableRestElement1.types | 2 +- .../reference/nonIterableRestElement2.types | 2 +- 15 files changed, 24 insertions(+), 36 deletions(-) diff --git a/tests/baselines/reference/arrowFunctionExpressions.types b/tests/baselines/reference/arrowFunctionExpressions.types index fc9fdb8a3bd30..6ac405e6d7e1f 100644 --- a/tests/baselines/reference/arrowFunctionExpressions.types +++ b/tests/baselines/reference/arrowFunctionExpressions.types @@ -100,12 +100,12 @@ var p8 = ({ a = 1 }) => { }; >1 : number var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; ->p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void ->({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void +>p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void +>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void >a : any >b : number >1 : number ->{ b: 1 } : { b: number; } +>{ b: 1 } : { b?: number; } >b : number >1 : number diff --git a/tests/baselines/reference/declarationEmitDestructuring2.js b/tests/baselines/reference/declarationEmitDestructuring2.js index eeabbf1ff372f..09980c5c9dd11 100644 --- a/tests/baselines/reference/declarationEmitDestructuring2.js +++ b/tests/baselines/reference/declarationEmitDestructuring2.js @@ -21,8 +21,8 @@ function h1(_a) { //// [declarationEmitDestructuring2.d.ts] declare function f({x, y: [a, b, c, d]}?: { - x: number; - y: [number, number, number, number]; + x?: number; + y?: [number, number, number, number]; }): void; declare function g([a, b, c, d]?: [number, number, number, number]): void; declare function h([a, [b], [[c]], {x, y: [a, b, c], z: {a1, b1}}]: [any, [any], [[any]], { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index eb028aacff4e2..5820449cde9b9 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -23,7 +23,7 @@ var [a11, b11, c11] = []; >a11 : any >b11 : any >c11 : any ->[] : undefined[] +>[] : [any, any, any] var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; >a2 : number diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 828083e768764..3e0666a96c030 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,7 +1,5 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2493: Tuple type '[number, string]' with length '2' cannot be assigned to tuple with length '3'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(6,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2459: Type '{}' has no property 'a' and no string index signature. @@ -18,15 +16,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (13 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (11 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; // Error - ~ -!!! error TS2493: Tuple type '[number, string]' with length '2' cannot be assigned to tuple with length '3'. var [,, z] = [0, 1, 2]; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. var x: number; var y: string; } @@ -86,10 +84,6 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array var [d, e, f] = [1]; // Error, [1] is a tuple - ~ -!!! error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. - ~ -!!! error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. } function f9() { diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index adff61e407ce4..9325fbf6b2d34 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -93,7 +93,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : undefined[] +>[] : [any] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 0a9e75a8aedfe..aaa56cde3bcf4 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -94,7 +94,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : undefined[] +>[] : [any] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index a2e5cb7e17c17..5244dd55ec6f4 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,3 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -13,14 +11,10 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (6 errors) ==== // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is the type Any, or var [[a0], [[a1]]] = [] // Error - ~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - ~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index f44adab359fed..476b5bee0cc5b 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -27,7 +27,7 @@ var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >{ b21: "string" } : { b21: string; } >b21 : string >"string" : string ->{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>{ b2: { b21: "world" } } : { b2?: { b21: string; }; } >b2 : { b21: string; } >{ b21: "world" } : { b21: string; } >b21 : string diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index 47d4474b63e38..7a7f631eddfcf 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -27,7 +27,7 @@ var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >{ b21: "string" } : { b21: string; } >b21 : string >"string" : string ->{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>{ b2: { b21: "world" } } : { b2?: { b21: string; }; } >b2 : { b21: string; } >{ b21: "world" } : { b21: string; } >b21 : string diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index a0630fee9951c..620ad90d41488 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -31,7 +31,7 @@ var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >{ b11: "string" } : { b11: string; } >b11 : string >"string" : string ->{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>{ b1: { b11: "world" } } : { b1?: { b11: string; }; } >b1 : { b11: string; } >{ b11: "world" } : { b11: string; } >b11 : string diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index f9faf519b0abb..a3004f87c8265 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -31,7 +31,7 @@ var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >{ b11: "string" } : { b11: string; } >b11 : string >"string" : string ->{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>{ b1: { b11: "world" } } : { b1?: { b11: string; }; } >b1 : { b11: string; } >{ b11: "world" } : { b11: string; } >b11 : string diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types index 51d3b8eb08610..85002abbe5e89 100644 --- a/tests/baselines/reference/downlevelLetConst12.types +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -13,7 +13,7 @@ const bar = 1; let [baz] = []; >baz : any ->[] : undefined[] +>[] : [any] let {a: baz2} = { a: 1 }; >a : any @@ -24,7 +24,7 @@ let {a: baz2} = { a: 1 }; const [baz3] = [] >baz3 : any ->[] : undefined[] +>[] : [any] const {a: baz4} = { a: 1 }; >a : any diff --git a/tests/baselines/reference/emitArrowFunctionES6.types b/tests/baselines/reference/emitArrowFunctionES6.types index e2ad176fd7dcb..cc48cecd96a9f 100644 --- a/tests/baselines/reference/emitArrowFunctionES6.types +++ b/tests/baselines/reference/emitArrowFunctionES6.types @@ -87,12 +87,12 @@ var p8 = ({ a = 1 }) => { }; >1 : number var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; ->p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void ->({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void +>p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void +>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void >a : any >b : number >1 : number ->{ b: 1 } : { b: number; } +>{ b: 1 } : { b?: number; } >b : number >1 : number diff --git a/tests/baselines/reference/nonIterableRestElement1.types b/tests/baselines/reference/nonIterableRestElement1.types index 4973b67d4ae0b..a15fe5afd38cb 100644 --- a/tests/baselines/reference/nonIterableRestElement1.types +++ b/tests/baselines/reference/nonIterableRestElement1.types @@ -5,7 +5,7 @@ var c = {}; [...c] = ["", 0]; >[...c] = ["", 0] : (string | number)[] ->[...c] : {}[] +>[...c] : undefined[] >...c : any >c : {} >["", 0] : (string | number)[] diff --git a/tests/baselines/reference/nonIterableRestElement2.types b/tests/baselines/reference/nonIterableRestElement2.types index e6d84d5297e6b..c39a592d2e68d 100644 --- a/tests/baselines/reference/nonIterableRestElement2.types +++ b/tests/baselines/reference/nonIterableRestElement2.types @@ -5,7 +5,7 @@ var c = {}; [...c] = ["", 0]; >[...c] = ["", 0] : (string | number)[] ->[...c] : {}[] +>[...c] : undefined[] >...c : any >c : {} >["", 0] : (string | number)[] From dc8ad6eb5e34980fca18de037d65f2f1924e444e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 13:17:33 -0700 Subject: [PATCH 05/17] Store binding pattern in contextual type --- src/compiler/checker.ts | 86 ++++++++++++++++++++++------------------- src/compiler/types.ts | 10 +++-- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d4e68381f7b8c..e08d30ca9b960 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2406,7 +2406,7 @@ namespace ts { // If the declaration specifies a binding pattern, use the type implied by the binding pattern if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); + return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false); } // No type specified and nothing can be inferred @@ -2421,13 +2421,13 @@ namespace ts { return getWidenedType(checkExpressionCached(element.initializer)); } if (isBindingPattern(element.name)) { - return getTypeFromBindingPattern(element.name); + return getTypeFromBindingPattern(element.name, /*includePatternInType*/ false); } return anyType; } // Return the type implied by an object binding pattern - function getTypeFromObjectBindingPattern(pattern: BindingPattern): Type { + function getTypeFromObjectBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type { let members: SymbolTable = {}; forEach(pattern.elements, e => { let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0); @@ -2436,28 +2436,27 @@ namespace ts { symbol.type = getTypeFromBindingElement(e); members[symbol.name] = symbol; }); - return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); + let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); + if (includePatternInType) { + result.pattern = pattern; + } + return result; } // Return the type implied by an array binding pattern - function getTypeFromArrayBindingPattern(pattern: BindingPattern): Type { - let hasSpreadElement: boolean = false; - let elementTypes: Type[] = []; - forEach(pattern.elements, e => { - elementTypes.push(e.kind === SyntaxKind.OmittedExpression || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); - if (e.dotDotDotToken) { - hasSpreadElement = true; - } - }); - if (!elementTypes.length) { + function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type { + let elements = pattern.elements; + if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) { return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType; } - else if (hasSpreadElement) { - let unionOfElements = getUnionType(elementTypes); - 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. - return createTupleType(elementTypes); + let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e)); + let result = createTupleType(elementTypes); + if (includePatternInType) { + result = clone(result); + result.pattern = pattern; + } + return result; } // Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself @@ -2467,10 +2466,10 @@ namespace ts { // used as the contextual type of an initializer associated with the binding pattern. Also, for a destructuring // parameter with no type annotation or initializer, the type implied by the binding pattern becomes the type of // the parameter. - function getTypeFromBindingPattern(pattern: BindingPattern): Type { + function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean): Type { return pattern.kind === SyntaxKind.ObjectBindingPattern - ? getTypeFromObjectBindingPattern(pattern) - : getTypeFromArrayBindingPattern(pattern); + ? getTypeFromObjectBindingPattern(pattern, includePatternInType) + : getTypeFromArrayBindingPattern(pattern, includePatternInType); } // Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type @@ -6606,18 +6605,12 @@ namespace ts { } } if (isBindingPattern(declaration.name)) { - return createImpliedType(getTypeFromBindingPattern(declaration.name)); + return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true); } } return undefined; } - function createImpliedType(type: Type): Type { - var result = clone(type); - result.flags |= TypeFlags.ImpliedType; - return result; - } - function getContextualTypeForReturnExpression(node: Expression): Type { let func = getContainingFunction(node); if (func && !func.asteriskToken) { @@ -7044,17 +7037,28 @@ namespace ts { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { - return createImpliedType(createTupleType(elementTypes)); + let type = clone(createTupleType(elementTypes)); + type.pattern = node; + return type; } let contextualType = getContextualType(node); - let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; - if (contextualTupleLikeType) { - // If array literal is contextually typed by the implied type of a binding pattern, pad the resulting - // tuple type with elements from the binding tuple type to make the lengths equal. - if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { - let contextualElementTypes = (contextualTupleLikeType).elementTypes; - for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { - elementTypes.push(contextualElementTypes[i]); + if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { + let pattern = contextualType.pattern; + // If array literal is contextually typed by a binding pattern or an assignment pattern, + // pad the resulting tuple type to make the lengths equal. + if (pattern && pattern.kind === SyntaxKind.ArrayBindingPattern) { + let bindingElements = (pattern).elements; + for (let i = elementTypes.length; i < bindingElements.length; i++) { + let hasDefaultValue = bindingElements[i].initializer; + elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); + } + } + else if (pattern && pattern.kind === SyntaxKind.ArrayLiteralExpression) { + let assignmentElements = (pattern).elements; + for (let i = elementTypes.length; i < assignmentElements.length; i++) { + let hasDefaultValue = assignmentElements[i].kind === SyntaxKind.BinaryExpression && + (assignmentElements[i]).operatorToken.kind === SyntaxKind.EqualsToken; + elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); } } if (elementTypes.length) { @@ -7129,6 +7133,8 @@ namespace ts { let propertiesTable: SymbolTable = {}; let propertiesArray: Symbol[] = []; let contextualType = getContextualType(node); + let contextualTypeHasPattern = contextualType && contextualType.pattern && + contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern; let typeFlags: TypeFlags = 0; for (let memberDecl of node.properties) { @@ -7151,7 +7157,7 @@ namespace ts { let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); // If object literal is contextually typed by the implied type of a binding pattern, and if the // binding pattern specifies a default value for the property, make the property optional. - if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + if (contextualTypeHasPattern) { let impliedProp = getPropertyOfType(contextualType, member.name); if (impliedProp) { prop.flags |= impliedProp.flags & SymbolFlags.Optional; @@ -7185,7 +7191,7 @@ namespace ts { // If object literal is contextually typed by the implied type of a binding pattern, augment the result // type with those properties for which the binding pattern specifies a default value. - if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + if (contextualTypeHasPattern) { for (let prop of getPropertiesOfType(contextualType)) { if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { propertiesTable[prop.name] = prop; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1313fb5b0311e..d23a42e753af2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1795,7 +1795,6 @@ namespace ts { /* @internal */ ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 - ImpliedType = 0x02000000, // Type implied by object binding pattern /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1812,11 +1811,14 @@ namespace ts { PropagatingFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType } + export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; + // Properties common to all types export interface Type { - flags: TypeFlags; // Flags - /* @internal */ id: number; // Unique ID - symbol?: Symbol; // Symbol associated with type (if any) + flags: TypeFlags; // Flags + /* @internal */ id: number; // Unique ID + symbol?: Symbol; // Symbol associated with type (if any) + pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any) } /* @internal */ From e40b86f1958be0e70ddc769bbf3e1e0c822a3b51 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 13:19:06 -0700 Subject: [PATCH 06/17] Accepting new baselines --- .../declarationEmitDestructuringArrayPattern2.types | 2 +- ...estructuringArrayBindingPatternAndAssignment1ES5.types | 2 +- ...estructuringArrayBindingPatternAndAssignment1ES6.types | 2 +- ...tructuringArrayBindingPatternAndAssignment2.errors.txt | 8 +++++++- .../reference/destructuringWithLiteralInitializers.types | 2 +- tests/baselines/reference/downlevelLetConst12.types | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index 5820449cde9b9..57acfe1dde115 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -23,7 +23,7 @@ var [a11, b11, c11] = []; >a11 : any >b11 : any >c11 : any ->[] : [any, any, any] +>[] : [undefined, undefined, undefined] var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; >a2 : number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 9325fbf6b2d34..3af7b65c62549 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -93,7 +93,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [any] +>[] : [undefined] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index aaa56cde3bcf4..cded5cdec8e2e 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -94,7 +94,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [any] +>[] : [undefined] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index 5244dd55ec6f4..a2e5cb7e17c17 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,3 +1,5 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -11,10 +13,14 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (6 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is the type Any, or var [[a0], [[a1]]] = [] // Error + ~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index c0577cb995019..cbb1e343bf42c 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -200,7 +200,7 @@ function g3([x, y] = []) { } >g3 : ([x, y]?: [any, any]) => void >x : any >y : any ->[] : [any, any] +>[] : [undefined, undefined] g3(); >g3() : void diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types index 85002abbe5e89..a6146b55dd7fc 100644 --- a/tests/baselines/reference/downlevelLetConst12.types +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -13,7 +13,7 @@ const bar = 1; let [baz] = []; >baz : any ->[] : [any] +>[] : [undefined] let {a: baz2} = { a: 1 }; >a : any @@ -24,7 +24,7 @@ let {a: baz2} = { a: 1 }; const [baz3] = [] >baz3 : any ->[] : [any] +>[] : [undefined] const {a: baz4} = { a: 1 }; >a : any From bb8179766a46a12bba508f6603eb1c1c1b0320d0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:42:58 -0700 Subject: [PATCH 07/17] Check for excess properties --- src/compiler/checker.ts | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e08d30ca9b960..6f617d6979897 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7001,6 +7001,11 @@ namespace ts { return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); } + function hasDefaultValue(node: BindingElement | Expression): boolean { + return (node.kind === SyntaxKind.BindingElement && !!(node).initializer) || + (node.kind === SyntaxKind.BinaryExpression && (node).operatorToken.kind === SyntaxKind.EqualsToken); + } + function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type { let elements = node.elements; let hasSpreadElement = false; @@ -7044,21 +7049,12 @@ namespace ts { let contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { let pattern = contextualType.pattern; - // If array literal is contextually typed by a binding pattern or an assignment pattern, - // pad the resulting tuple type to make the lengths equal. - if (pattern && pattern.kind === SyntaxKind.ArrayBindingPattern) { - let bindingElements = (pattern).elements; - for (let i = elementTypes.length; i < bindingElements.length; i++) { - let hasDefaultValue = bindingElements[i].initializer; - elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); - } - } - else if (pattern && pattern.kind === SyntaxKind.ArrayLiteralExpression) { - let assignmentElements = (pattern).elements; - for (let i = elementTypes.length; i < assignmentElements.length; i++) { - let hasDefaultValue = assignmentElements[i].kind === SyntaxKind.BinaryExpression && - (assignmentElements[i]).operatorToken.kind === SyntaxKind.EqualsToken; - elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); + // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the + // resulting tuple type to make the lengths equal. + if (pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { + let patternElements = (pattern).elements; + for (let i = elementTypes.length; i < patternElements.length; i++) { + elementTypes.push(hasDefaultValue(patternElements[i]) ? (contextualType).elementTypes[i] : undefinedType); } } if (elementTypes.length) { @@ -7134,7 +7130,8 @@ namespace ts { let propertiesArray: Symbol[] = []; let contextualType = getContextualType(node); let contextualTypeHasPattern = contextualType && contextualType.pattern && - contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern; + (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); + let inDestructuringPattern = isAssignmentTarget(node); let typeFlags: TypeFlags = 0; for (let memberDecl of node.properties) { @@ -7155,13 +7152,24 @@ namespace ts { } typeFlags |= type.flags; let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); - // If object literal is contextually typed by the implied type of a binding pattern, and if the - // binding pattern specifies a default value for the property, make the property optional. - if (contextualTypeHasPattern) { + if (inDestructuringPattern) { + // If object literal is an assignment pattern and if the assignment pattern specifies a default value + // for the property, make the property optional. + if (memberDecl.kind === SyntaxKind.PropertyAssignment && hasDefaultValue((memberDecl).initializer)) { + prop.flags |= SymbolFlags.Optional; + } + } + else if (contextualTypeHasPattern) { + // If object literal is contextually typed by the implied type of a binding pattern, and if the + // binding pattern specifies a default value for the property, make the property optional. let impliedProp = getPropertyOfType(contextualType, member.name); if (impliedProp) { prop.flags |= impliedProp.flags & SymbolFlags.Optional; } + else if (!compilerOptions.suppressExcessPropertyErrors) { + error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, + symbolToString(member), typeToString(contextualType)); + } } prop.declarations = member.declarations; prop.parent = member.parent; @@ -7205,6 +7213,9 @@ namespace ts { let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); let freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags); + if (inDestructuringPattern) { + result.pattern = node; + } return result; function getIndexType(kind: IndexKind) { From a0ddd437efa1b4fb52b418192176727069debec6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:45:20 -0700 Subject: [PATCH 08/17] Modifying tests --- .../destructuring/declarationsAndAssignments.ts | 14 +++++++------- .../destructuringWithLiteralInitializers.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts index 2202a482f8bcf..69b7462cd03b9 100644 --- a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts +++ b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts @@ -2,8 +2,8 @@ function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -19,14 +19,14 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { x } = { x: 5, y: "hello" }; // Error, no y in target + var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index 8f6b77d95c9c8..04298d8cbd70d 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -2,6 +2,7 @@ function f1({ x, y }) { } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } f2({ x: 1 }); f2({ x: 1, y: 1 }); From f80142094614be2483b0d8eff31e5b5843d4edf9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:46:20 -0700 Subject: [PATCH 09/17] Accepting new baselines --- .../declarationEmitDestructuring4.errors.txt | 17 +++ .../declarationEmitDestructuring4.symbols | 21 --- .../declarationEmitDestructuring4.types | 32 ----- ...structuringObjectLiteralPattern.errors.txt | 43 ++++++ ...tDestructuringObjectLiteralPattern.symbols | 89 ------------ ...mitDestructuringObjectLiteralPattern.types | 122 ---------------- ...tructuringObjectLiteralPattern1.errors.txt | 29 ++++ ...DestructuringObjectLiteralPattern1.symbols | 42 ------ ...itDestructuringObjectLiteralPattern1.types | 63 --------- .../declarationsAndAssignments.errors.txt | 37 +++-- .../reference/declarationsAndAssignments.js | 28 ++-- ...ectBindingPatternAndAssignment3.errors.txt | 14 +- .../destructuringWithLiteralInitializers.js | 2 + ...structuringWithLiteralInitializers.symbols | 131 +++++++++--------- ...destructuringWithLiteralInitializers.types | 1 + ...ObjectBindingPatternParameter04.errors.txt | 17 +++ ...ptyObjectBindingPatternParameter04.symbols | 14 -- ...emptyObjectBindingPatternParameter04.types | 18 --- 18 files changed, 228 insertions(+), 492 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuring4.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuring4.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuring4.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types create mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt delete mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols delete mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.types diff --git a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt new file mode 100644 index 0000000000000..2787d5e66749f --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/declarationEmitDestructuring4.ts(9,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + +==== tests/cases/compiler/declarationEmitDestructuring4.ts (1 errors) ==== + // For an array binding pattern with empty elements, + // we will not make any modification and will emit + // the similar binding pattern users' have written + function baz([]) { } + function baz1([] = [1,2,3]) { } + function baz2([[]] = [[1,2,3]]) { } + + function baz3({}) { } + function baz4({} = { x: 10 }) { } + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuring4.symbols b/tests/baselines/reference/declarationEmitDestructuring4.symbols deleted file mode 100644 index 9f2eb162b6fe2..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.symbols +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring4.ts === -// For an array binding pattern with empty elements, -// we will not make any modification and will emit -// the similar binding pattern users' have written -function baz([]) { } ->baz : Symbol(baz, Decl(declarationEmitDestructuring4.ts, 0, 0)) - -function baz1([] = [1,2,3]) { } ->baz1 : Symbol(baz1, Decl(declarationEmitDestructuring4.ts, 3, 20)) - -function baz2([[]] = [[1,2,3]]) { } ->baz2 : Symbol(baz2, Decl(declarationEmitDestructuring4.ts, 4, 31)) - -function baz3({}) { } ->baz3 : Symbol(baz3, Decl(declarationEmitDestructuring4.ts, 5, 35)) - -function baz4({} = { x: 10 }) { } ->baz4 : Symbol(baz4, Decl(declarationEmitDestructuring4.ts, 7, 21)) ->x : Symbol(x, Decl(declarationEmitDestructuring4.ts, 8, 20)) - - diff --git a/tests/baselines/reference/declarationEmitDestructuring4.types b/tests/baselines/reference/declarationEmitDestructuring4.types deleted file mode 100644 index 9621d61e02bb0..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring4.ts === -// For an array binding pattern with empty elements, -// we will not make any modification and will emit -// the similar binding pattern users' have written -function baz([]) { } ->baz : ([]: any[]) => void - -function baz1([] = [1,2,3]) { } ->baz1 : ([]?: number[]) => void ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -function baz2([[]] = [[1,2,3]]) { } ->baz2 : ([[]]?: [number[]]) => void ->[[1,2,3]] : [number[]] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -function baz3({}) { } ->baz3 : ({}: {}) => void - -function baz4({} = { x: 10 }) { } ->baz4 : ({}?: { x: number; }) => void ->{ x: 10 } : { x: number; } ->x : number ->10 : number - - diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt new file mode 100644 index 0000000000000..92a8cba2d4002 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(3,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(4,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(6,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(7,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + + +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (6 errors) ==== + + var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x4 } = { x4: 5, y4: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. + var { y5 } = { x5: 5, y5: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. + var { x6, y6 } = { x6: 5, y6: "hello" }; + var { x7: a1 } = { x7: 5, y7: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. + var { y8: b1 } = { x8: 5, y8: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + + var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + + function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; + } + var { a4, b4, c4 } = f15(); + + module m { + export var { a4, b4, c4 } = f15(); + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols deleted file mode 100644 index 0a57a93f3d02b..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols +++ /dev/null @@ -1,89 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === - -var { } = { x: 5, y: "hello" }; ->x : Symbol(x, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 1, 11)) ->y : Symbol(y, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 1, 17)) - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 5)) ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 14)) ->y4 : Symbol(y4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 21)) - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 5)) ->x5 : Symbol(x5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 14)) ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 21)) - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 5)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 9)) ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 18)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 25)) - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 5)) ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) ->y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 25)) - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 5)) ->x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 18)) ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) ->a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 5)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 13)) ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) - -var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) ->x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 5)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) ->y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 18)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) ->z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 31)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) - -function f15() { ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) - - var a4 = "hello"; ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 12, 7)) - - var b4 = 1; ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 13, 7)) - - var c4 = true; ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 14, 7)) - - return { a4, b4, c4 }; ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 12)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 16)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 20)) -} -var { a4, b4, c4 } = f15(); ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 5)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 9)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 13)) ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) - -module m { ->m : Symbol(m, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 27)) - - export var { a4, b4, c4 } = f15(); ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 16)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 20)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 24)) ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) -} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types deleted file mode 100644 index 0911a27838bb2..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types +++ /dev/null @@ -1,122 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === - -var { } = { x: 5, y: "hello" }; ->{ x: 5, y: "hello" } : { x: number; y: string; } ->x : number ->5 : number ->y : string ->"hello" : string - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : number ->{ x4: 5, y4: "hello" } : { x4: number; y4: string; } ->x4 : number ->5 : number ->y4 : string ->"hello" : string - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : string ->{ x5: 5, y5: "hello" } : { x5: number; y5: string; } ->x5 : number ->5 : number ->y5 : string ->"hello" : string - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : number ->y6 : string ->{ x6: 5, y6: "hello" } : { x6: number; y6: string; } ->x6 : number ->5 : number ->y6 : string ->"hello" : string - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : any ->a1 : number ->{ x7: 5, y7: "hello" } : { x7: number; y7: string; } ->x7 : number ->5 : number ->y7 : string ->"hello" : string - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : any ->b1 : string ->{ x8: 5, y8: "hello" } : { x8: number; y8: string; } ->x8 : number ->5 : number ->y8 : string ->"hello" : string - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : any ->a2 : number ->y9 : any ->b2 : string ->{ x9: 5, y9: "hello" } : { x9: number; y9: string; } ->x9 : number ->5 : number ->y9 : string ->"hello" : string - -var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; ->a : any ->x11 : number ->b : any ->a : any ->y11 : string ->b : any ->a : any ->z11 : boolean ->{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } ->a : number ->1 : number ->b : { a: string; b: { a: boolean; }; } ->{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } ->a : string ->"hello" : string ->b : { a: boolean; } ->{ a: true } : { a: boolean; } ->a : boolean ->true : boolean - -function f15() { ->f15 : () => { a4: string; b4: number; c4: boolean; } - - var a4 = "hello"; ->a4 : string ->"hello" : string - - var b4 = 1; ->b4 : number ->1 : number - - var c4 = true; ->c4 : boolean ->true : boolean - - return { a4, b4, c4 }; ->{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } ->a4 : string ->b4 : number ->c4 : boolean -} -var { a4, b4, c4 } = f15(); ->a4 : string ->b4 : number ->c4 : boolean ->f15() : { a4: string; b4: number; c4: boolean; } ->f15 : () => { a4: string; b4: number; c4: boolean; } - -module m { ->m : typeof m - - export var { a4, b4, c4 } = f15(); ->a4 : string ->b4 : number ->c4 : boolean ->f15() : { a4: string; b4: number; c4: boolean; } ->f15 : () => { a4: string; b4: number; c4: boolean; } -} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt new file mode 100644 index 0000000000000..24fbcf99ad1d7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(3,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(4,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(6,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(7,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + + +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (6 errors) ==== + + var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x4 } = { x4: 5, y4: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. + var { y5 } = { x5: 5, y5: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. + var { x6, y6 } = { x6: 5, y6: "hello" }; + var { x7: a1 } = { x7: 5, y7: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. + var { y8: b1 } = { x8: 5, y8: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols deleted file mode 100644 index cac2431411e16..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols +++ /dev/null @@ -1,42 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === - -var { } = { x: 5, y: "hello" }; ->x : Symbol(x, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 1, 11)) ->y : Symbol(y, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 1, 17)) - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 5)) ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 14)) ->y4 : Symbol(y4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 21)) - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 5)) ->x5 : Symbol(x5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 14)) ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 21)) - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 5)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 9)) ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 18)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 25)) - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 5)) ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) ->y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 25)) - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 5)) ->x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 18)) ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) ->a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 5)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 13)) ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) - diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types deleted file mode 100644 index 5411f36fa9af8..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types +++ /dev/null @@ -1,63 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === - -var { } = { x: 5, y: "hello" }; ->{ x: 5, y: "hello" } : { x: number; y: string; } ->x : number ->5 : number ->y : string ->"hello" : string - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : number ->{ x4: 5, y4: "hello" } : { x4: number; y4: string; } ->x4 : number ->5 : number ->y4 : string ->"hello" : string - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : string ->{ x5: 5, y5: "hello" } : { x5: number; y5: string; } ->x5 : number ->5 : number ->y5 : string ->"hello" : string - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : number ->y6 : string ->{ x6: 5, y6: "hello" } : { x6: number; y6: string; } ->x6 : number ->5 : number ->y6 : string ->"hello" : string - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : any ->a1 : number ->{ x7: 5, y7: "hello" } : { x7: number; y7: string; } ->x7 : number ->5 : number ->y7 : string ->"hello" : string - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : any ->b1 : string ->{ x8: 5, y8: "hello" } : { x8: number; y8: string; } ->x8 : number ->5 : number ->y8 : string ->"hello" : string - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : any ->a2 : number ->y9 : any ->b2 : string ->{ x9: 5, y9: "hello" } : { x9: number; y9: string; } ->x9 : number ->5 : number ->y9 : string ->"hello" : string - diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 3e0666a96c030..802e72562af01 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,4 +1,9 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(6,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. @@ -16,15 +21,13 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (11 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (16 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -40,14 +43,26 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x } = { x: 5, y: "hello" }; // Error, no y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y } = { x: 5, y: "hello" }; // Error, no x in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index 5c47756e7fe0c..018aa5522cacb 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -3,8 +3,8 @@ function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -20,14 +20,14 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { x } = { x: 5, y: "hello" }; // Error, no y in target + var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; @@ -185,8 +185,8 @@ function f0() { var _a = [1, "hello"]; 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]; + var _c = [1, "hello"], x = _c[0], y = _c[1], z = _c[2]; + var _d = [0, 1, 2], x = _d[2]; var x; var y; } @@ -200,14 +200,14 @@ function f1() { var z; } function f2() { - var _a = { x: 5, y: "hello" }; - var x = { x: 5, y: "hello" }.x; - var y = { x: 5, y: "hello" }.y; + var _a = { x: 5, y: "hello" }; // Error, no x and y in target + var x = { x: 5, y: "hello" }.x; // Error, no y in target + var y = { x: 5, y: "hello" }.y; // Error, no x in target 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; // Error, no y in target + var b = { x: 5, y: "hello" }.y; // Error, no x in target var _c = { x: 5, y: "hello" }, a = _c.x, b = _c.y; var a; var b; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 9025f24f99217..4cee43144666a 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -4,13 +4,17 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,11): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,24): error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected. -==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (13 errors) ==== // Error var {h?} = { h?: 1 }; ~ @@ -27,10 +31,18 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ !!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. + ~~~~ +!!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { ~~~ !!! error TS1180: Property destructuring pattern expected. a: 1, b: 1, d1: 9, e: 10 + ~ +!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. } var {1} = { 1 }; ~ diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index c25216a55f860..a8251435d3999 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -3,6 +3,7 @@ function f1({ x, y }) { } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } f2({ x: 1 }); f2({ x: 1, y: 1 }); @@ -58,6 +59,7 @@ function f1(_a) { var x = _a.x, y = _a.y; } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2(_a) { var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; } diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index 992a9c3ace53b..9dc3960f2afea 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -10,141 +10,142 @@ f1({ x: 1, y: 1 }); >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 2, 4)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 2, 10)) +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 4, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 4, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 5, 16)) f2({ x: 1 }); >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) f2({ x: 1, y: 1 }); >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 6, 10)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 7, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 7, 10)) // (arg: { x?: number, y?: number }) => void function f3({ x = 0, y = 0 }) { } ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 9, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 9, 20)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 10, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 10, 20)) f3({}); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) f3({ x: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 11, 4)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) f3({ y: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) f3({ x: 1, y: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 10)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 14, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 14, 10)) // (arg?: { x: number, y: number }) => void function f4({ x, y } = { x: 0, y: 0 }) { } ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 16)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 24)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 30)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 17, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 17, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 17, 24)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 17, 30)) f4(); ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) f4({ x: 1, y: 1 }); ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 18, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 18, 10)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 19, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 19, 10)) // (arg?: { x: number, y?: number }) => void function f5({ x, y = 0 } = { x: 0 }) { } ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 21, 16)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 28)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 22, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 22, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 22, 28)) f5(); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) f5({ x: 1 }); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 23, 4)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) f5({ x: 1, y: 1 }); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 24, 10)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 25, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 25, 10)) // (arg?: { x?: number, y?: number }) => void function f6({ x = 0, y = 0 } = {}) { } ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 27, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 27, 20)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 28, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 28, 20)) f6(); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) f6({}); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) f6({ x: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 30, 4)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) f6({ y: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) f6({ x: 1, y: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 10)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 33, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 33, 10)) // (arg: [any, any]) => void function g1([x, y]) { } ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 35, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 35, 15)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 15)) g1([1, 1]); ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) // (arg: [number, number]) => void function g2([x = 0, y = 0]) { } ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 39, 19)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 40, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 19)) g2([1, 1]); ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) // (arg?: [any, any]) => void function g3([x, y] = []) { } ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 43, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 43, 15)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 44, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 44, 15)) g3(); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) g3([1, 1]); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) // (arg?: [number, number]) => void function g4([x, y] = [0, 0]) { } ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 15)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 49, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 49, 15)) g4(); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) g4([1, 1]); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index cbb1e343bf42c..7807ba201c3b3 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -14,6 +14,7 @@ f1({ x: 1, y: 1 }); >y : number >1 : number +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } >f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void >x : any diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt new file mode 100644 index 0000000000000..cf1b0e9a9a1f2 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,18): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,24): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,32): error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + + +==== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts (3 errors) ==== + + + function f({} = {a: 1, b: "2", c: true}) { + ~ +!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + var x, y, z; + } \ No newline at end of file diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols deleted file mode 100644 index 9922d4cd074d8..0000000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - - -function f({} = {a: 1, b: "2", c: true}) { ->f : Symbol(f, Decl(emptyObjectBindingPatternParameter04.ts, 0, 0)) ->a : Symbol(a, Decl(emptyObjectBindingPatternParameter04.ts, 2, 17)) ->b : Symbol(b, Decl(emptyObjectBindingPatternParameter04.ts, 2, 22)) ->c : Symbol(c, Decl(emptyObjectBindingPatternParameter04.ts, 2, 30)) - - var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter04.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter04.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter04.ts, 3, 13)) -} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types deleted file mode 100644 index 5ee32d422a916..0000000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types +++ /dev/null @@ -1,18 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - - -function f({} = {a: 1, b: "2", c: true}) { ->f : ({}?: { a: number; b: string; c: boolean; }) => void ->{a: 1, b: "2", c: true} : { a: number; b: string; c: boolean; } ->a : number ->1 : number ->b : string ->"2" : string ->c : boolean ->true : boolean - - var x, y, z; ->x : any ->y : any ->z : any -} From 31f8a8148c952fcc9716b2953d49c23715cc0438 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:46:45 -0700 Subject: [PATCH 10/17] Adding test for excess/missing properties --- .../missingAndExcessProperties.errors.txt | 85 +++++++++++++++++++ .../reference/missingAndExcessProperties.js | 69 +++++++++++++++ .../missingAndExcessProperties.ts | 33 +++++++ 3 files changed, 187 insertions(+) create mode 100644 tests/baselines/reference/missingAndExcessProperties.errors.txt create mode 100644 tests/baselines/reference/missingAndExcessProperties.js create mode 100644 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt new file mode 100644 index 0000000000000..294b564a23999 --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -0,0 +1,85 @@ +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,20): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + + +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ==== + // Missing properties + function f1() { + var { x, y } = {}; + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + var { x = 1, y } = {}; + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + var { x, y = 1 } = {}; + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + var { x = 1, y = 1 } = {}; + } + + // Missing properties + function f2() { + var x: number, y: number; + ({ x, y } = {}); + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + ({ x: x = 1, y } = {}); + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + ({ x, y: y = 1 } = {}); + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + ({ x: x = 1, y: y = 1 } = {}); + } + + // Excess properties + function f3() { + var { } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. + var { x, y } = { x: 0, y: 0 }; + } + + // Excess properties + function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + ({ x } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. + ({ y } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + ({ x, y } = { x: 0, y: 0 }); + } + \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.js b/tests/baselines/reference/missingAndExcessProperties.js new file mode 100644 index 0000000000000..b9fcadd9519ea --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.js @@ -0,0 +1,69 @@ +//// [missingAndExcessProperties.ts] +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +} + + +//// [missingAndExcessProperties.js] +// Missing properties +function f1() { + var _a = {}, x = _a.x, y = _a.y; + var _b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y; + var _d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e; + var _f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h; +} +// Missing properties +function f2() { + var x, y; + (_a = {}, x = _a.x, y = _a.y, _a); + (_b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y, _b); + (_d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e, _d); + (_f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h, _f); + var _a, _b, _c, _d, _e, _f, _g, _h; +} +// Excess properties +function f3() { + var _a = { x: 0, y: 0 }; + var x = { x: 0, y: 0 }.x; + var y = { x: 0, y: 0 }.y; + var _b = { x: 0, y: 0 }, x = _b.x, y = _b.y; +} +// Excess properties +function f4() { + var x, y; + ({ x: 0, y: 0 }); + (_a = { x: 0, y: 0 }, x = _a.x, _a); + (_b = { x: 0, y: 0 }, y = _b.y, _b); + (_c = { x: 0, y: 0 }, x = _c.x, y = _c.y, _c); + var _a, _b, _c; +} diff --git a/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts new file mode 100644 index 0000000000000..ef91b8249da11 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts @@ -0,0 +1,33 @@ +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +} From 546da60a2a9321d50856e28c10bee8be3264c0e2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:54:38 -0700 Subject: [PATCH 11/17] Correct propagation of includePatternInType flag --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f617d6979897..91234ebb38797 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2416,12 +2416,12 @@ namespace ts { // Return the type implied by a binding pattern element. This is the type of the initializer of the element if // one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding // pattern. Otherwise, it is the type any. - function getTypeFromBindingElement(element: BindingElement): Type { + function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean): Type { if (element.initializer) { return getWidenedType(checkExpressionCached(element.initializer)); } if (isBindingPattern(element.name)) { - return getTypeFromBindingPattern(element.name, /*includePatternInType*/ false); + return getTypeFromBindingPattern(element.name, includePatternInType); } return anyType; } @@ -2433,7 +2433,7 @@ namespace ts { let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0); let name = e.propertyName || e.name; let symbol = createSymbol(flags, name.text); - symbol.type = getTypeFromBindingElement(e); + symbol.type = getTypeFromBindingElement(e, includePatternInType); members[symbol.name] = symbol; }); let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); @@ -2450,7 +2450,7 @@ namespace ts { return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType; } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. - let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e)); + let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType)); let result = createTupleType(elementTypes); if (includePatternInType) { result = clone(result); From 27380f40dccd2b0df0c2b7356e1efff86cded02f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:55:13 -0700 Subject: [PATCH 12/17] Adding test --- .../destructuring/destructuringWithLiteralInitializers.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index 04298d8cbd70d..dd3a0ae28a6c5 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -33,6 +33,14 @@ f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); + // (arg: [any, any]) => void function g1([x, y]) { } g1([1, 1]); From 055363c98deaf588dd74fa4bd6215d26382b794b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:55:48 -0700 Subject: [PATCH 13/17] Accepting new baselines --- ...ArrayBindingPatternAndAssignment1ES5.types | 14 ++-- ...ArrayBindingPatternAndAssignment1ES6.types | 14 ++-- ...destructuringVariableDeclaration1ES5.types | 6 +- ...destructuringVariableDeclaration1ES6.types | 6 +- .../destructuringWithLiteralInitializers.js | 17 +++++ ...structuringWithLiteralInitializers.symbols | 67 ++++++++++++++----- ...destructuringWithLiteralInitializers.types | 52 ++++++++++++++ 7 files changed, 138 insertions(+), 38 deletions(-) diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 3af7b65c62549..fcd71e85dbfbb 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -98,13 +98,13 @@ var [c2] = []; var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] +>[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] +>[[]] : [[undefined]] +>[] : [undefined] +>[[[[]]]] : [[[[undefined]]]] +>[[[]]] : [[[undefined]]] +>[[]] : [[undefined]] +>[] : [undefined] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index cded5cdec8e2e..d154f0912148a 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -99,13 +99,13 @@ var [c2] = []; var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] +>[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] +>[[]] : [[undefined]] +>[] : [undefined] +>[[[[]]]] : [[[[undefined]]]] +>[[[]]] : [[[undefined]]] +>[[]] : [[undefined]] +>[] : [undefined] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index 620ad90d41488..c024fdfe86278 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } +>f : [number, number, { f3: number; f5: number; }, undefined] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index a3004f87c8265..730abd843a2bb 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } +>f : [number, number, { f3: number; f5: number; }, undefined] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index a8251435d3999..640b5a377561c 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -34,6 +34,14 @@ f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); + // (arg: [any, any]) => void function g1([x, y]) { } g1([1, 1]); @@ -95,6 +103,15 @@ f6({}); f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7(_a) { + var _b = (_a === void 0 ? { a: {} } : _a).a, _c = _b.x, x = _c === void 0 ? 0 : _c, _d = _b.y, y = _d === void 0 ? 0 : _d; +} +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); // (arg: [any, any]) => void function g1(_a) { var x = _a[0], y = _a[1]; diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index 9dc3960f2afea..fc8c7a2f6219c 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -107,45 +107,76 @@ f6({ x: 1, y: 1 }); >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 33, 4)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 33, 10)) +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 36, 39)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 18)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 25)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 36, 39)) + +f7(); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) + +f7({ a: {} }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 38, 4)) + +f7({ a: { x: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 39, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 9)) + +f7({ a: { y: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 40, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 9)) + +f7({ a: { x: 1, y: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 41, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 41, 9)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 41, 15)) + // (arg: [any, any]) => void function g1([x, y]) { } ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 15)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 41, 26)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 44, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 44, 15)) g1([1, 1]); ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 41, 26)) // (arg: [number, number]) => void function g2([x = 0, y = 0]) { } ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 40, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 19)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 19)) g2([1, 1]); ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) // (arg?: [any, any]) => void function g3([x, y] = []) { } ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 44, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 44, 15)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 52, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 52, 15)) g3(); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) g3([1, 1]); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) // (arg?: [number, number]) => void function g4([x, y] = [0, 0]) { } ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 49, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 49, 15)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 57, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 57, 15)) g4(); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) g4([1, 1]); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index 7807ba201c3b3..97c07bc281d2c 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -168,6 +168,58 @@ f6({ x: 1, y: 1 }); >y : number >1 : number +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>a : any +>x : number +>0 : number +>y : number +>0 : number +>{ a: {} } : { a: { x?: number; y?: number; }; } +>a : { x?: number; y?: number; } +>{} : { x?: number; y?: number; } + +f7(); +>f7() : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void + +f7({ a: {} }); +>f7({ a: {} }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: {} } : { a: {}; } +>a : {} +>{} : {} + +f7({ a: { x: 1 } }); +>f7({ a: { x: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { x: 1 } } : { a: { x: number; }; } +>a : { x: number; } +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f7({ a: { y: 1 } }); +>f7({ a: { y: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { y: 1 } } : { a: { y: number; }; } +>a : { y: number; } +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f7({ a: { x: 1, y: 1 } }); +>f7({ a: { x: 1, y: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { x: 1, y: 1 } } : { a: { x: number; y: number; }; } +>a : { x: number; y: number; } +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + // (arg: [any, any]) => void function g1([x, y]) { } >g1 : ([x, y]: [any, any]) => void From d5ff9ee1e1e20b82a08a44d1183c1ea545af8a3e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:22:50 -0700 Subject: [PATCH 14/17] Error when binding element has no value in initializer and no default --- src/compiler/checker.ts | 43 +++++++++++++------ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 91234ebb38797..e4d6929fe6bd6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2434,6 +2434,7 @@ namespace ts { let name = e.propertyName || e.name; let symbol = createSymbol(flags, name.text); symbol.type = getTypeFromBindingElement(e, includePatternInType); + symbol.bindingElement = e; members[symbol.name] = symbol; }); let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); @@ -2451,12 +2452,12 @@ namespace ts { } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType)); - let result = createTupleType(elementTypes); if (includePatternInType) { - result = clone(result); + let result = createNewTupleType(elementTypes); result.pattern = pattern; + return result; } - return result; + return createTupleType(elementTypes); } // Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself @@ -3124,7 +3125,7 @@ namespace ts { } function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature { - for (let s of signatureList) { + for (let s of signatureList) { if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) { return s; } @@ -4045,11 +4046,12 @@ namespace ts { function createTupleType(elementTypes: Type[]) { let id = getTypeListId(elementTypes); - let type = tupleTypes[id]; - if (!type) { - type = tupleTypes[id] = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes)); - type.elementTypes = elementTypes; - } + return tupleTypes[id] || (tupleTypes[id] = createNewTupleType(elementTypes)); + } + + function createNewTupleType(elementTypes: Type[]) { + let type = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes)); + type.elementTypes = elementTypes; return type; } @@ -7042,19 +7044,28 @@ namespace ts { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { - let type = clone(createTupleType(elementTypes)); + let type = createNewTupleType(elementTypes); type.pattern = node; return type; } let contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { let pattern = contextualType.pattern; - // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the - // resulting tuple type to make the lengths equal. + // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting + // tuple type with the corresponding binding or assignment element types to make the lengths equal. if (pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { let patternElements = (pattern).elements; for (let i = elementTypes.length; i < patternElements.length; i++) { - elementTypes.push(hasDefaultValue(patternElements[i]) ? (contextualType).elementTypes[i] : undefinedType); + let patternElement = patternElements[i]; + if (hasDefaultValue(patternElement)) { + elementTypes.push((contextualType).elementTypes[i]); + } + else { + if (patternElement.kind !== SyntaxKind.OmittedExpression) { + error(patternElement, Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); + } + elementTypes.push(unknownType); + } } } if (elementTypes.length) { @@ -7201,7 +7212,11 @@ namespace ts { // type with those properties for which the binding pattern specifies a default value. if (contextualTypeHasPattern) { for (let prop of getPropertiesOfType(contextualType)) { - if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { + if (!hasProperty(propertiesTable, prop.name)) { + if (!(prop.flags & SymbolFlags.Optional)) { + error(prop.valueDeclaration || (prop).bindingElement, + Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); + } propertiesTable[prop.name] = prop; propertiesArray.push(prop); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f7351bf6912d0..9686d6580f5de 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -415,6 +415,7 @@ namespace ts { The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." }, yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, + Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value" }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9fd08ef9bca07..515afda49aa79 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1649,6 +1649,10 @@ "category": "Error", "code": 2524 }, + "Initializer provides no value for this binding element and the binding element has no default value": { + "category": "Error", + "code": 2525 + }, "JSX element attributes type '{0}' must be an object type.": { "category": "Error", "code": 2600 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d23a42e753af2..cfdf869dd77ee 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1714,6 +1714,7 @@ namespace ts { resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration + bindingElement?: BindingElement; // Binding element associated with property symbol } /* @internal */ From a95c42384babcd3915c216e0a799a185db603813 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:27:35 -0700 Subject: [PATCH 15/17] Revising test --- .../destructuringWithLiteralInitializers.js | 23 ++++++--- ...structuringWithLiteralInitializers.symbols | 18 +++++-- ...destructuringWithLiteralInitializers.types | 48 ++++++++++++++----- .../destructuringWithLiteralInitializers.ts | 11 +++-- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index 640b5a377561c..740648b04e8fa 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -50,15 +50,20 @@ g1([1, 1]); function g2([x = 0, y = 0]) { } g2([1, 1]); -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } g3(); g3([1, 1]); // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } g4(); g4([1, 1]); + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +g5(); +g5([1, 1]); //// [destructuringWithLiteralInitializers.js] @@ -122,15 +127,21 @@ function g2(_a) { var _b = _a[0], x = _b === void 0 ? 0 : _b, _c = _a[1], y = _c === void 0 ? 0 : _c; } g2([1, 1]); -// (arg?: [any, any]) => void +// (arg?: [number, number]) => void function g3(_a) { - var _b = _a === void 0 ? [] : _a, x = _b[0], y = _b[1]; + var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; } g3(); g3([1, 1]); // (arg?: [number, number]) => void function g4(_a) { - var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; + var _b = _a === void 0 ? [0] : _a, x = _b[0], _c = _b[1], y = _c === void 0 ? 0 : _c; } g4(); g4([1, 1]); +// (arg?: [number, number]) => void +function g5(_a) { + var _b = _a === void 0 ? [] : _a, _c = _b[0], x = _c === void 0 ? 0 : _c, _d = _b[1], y = _d === void 0 ? 0 : _d; +} +g5(); +g5([1, 1]); diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index fc8c7a2f6219c..1141fc140c728 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -156,8 +156,8 @@ function g2([x = 0, y = 0]) { } g2([1, 1]); >g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } >g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 52, 13)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 52, 15)) @@ -169,7 +169,7 @@ g3([1, 1]); >g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } >g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 57, 13)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 57, 15)) @@ -180,3 +180,15 @@ g4(); g4([1, 1]); >g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 62, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 62, 19)) + +g5(); +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) + +g5([1, 1]); +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) + diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index 97c07bc281d2c..da1e4bfd6f389 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -248,40 +248,62 @@ g2([1, 1]); >1 : number >1 : number -// (arg?: [any, any]) => void -function g3([x, y] = []) { } ->g3 : ([x, y]?: [any, any]) => void ->x : any ->y : any ->[] : [undefined, undefined] +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } +>g3 : ([x, y]?: [number, number]) => void +>x : number +>y : number +>[0, 0] : [number, number] +>0 : number +>0 : number g3(); >g3() : void ->g3 : ([x, y]?: [any, any]) => void +>g3 : ([x, y]?: [number, number]) => void g3([1, 1]); >g3([1, 1]) : void ->g3 : ([x, y]?: [any, any]) => void +>g3 : ([x, y]?: [number, number]) => void >[1, 1] : [number, number] >1 : number >1 : number // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } ->g4 : ([x, y]?: [number, number]) => void +function g4([x, y = 0] = [0]) { } +>g4 : ([x, y = 0]?: [number, number]) => void >x : number >y : number ->[0, 0] : [number, number] >0 : number +>[0] : [number, number] >0 : number g4(); >g4() : void ->g4 : ([x, y]?: [number, number]) => void +>g4 : ([x, y = 0]?: [number, number]) => void g4([1, 1]); >g4([1, 1]) : void ->g4 : ([x, y]?: [number, number]) => void +>g4 : ([x, y = 0]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +>g5 : ([x = 0, y = 0]?: [number, number]) => void +>x : number +>0 : number +>y : number +>0 : number +>[] : [number, number] + +g5(); +>g5() : void +>g5 : ([x = 0, y = 0]?: [number, number]) => void + +g5([1, 1]); +>g5([1, 1]) : void +>g5 : ([x = 0, y = 0]?: [number, number]) => void >[1, 1] : [number, number] >1 : number >1 : number diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index dd3a0ae28a6c5..17de6dd28583a 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -49,12 +49,17 @@ g1([1, 1]); function g2([x = 0, y = 0]) { } g2([1, 1]); -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } g3(); g3([1, 1]); // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } g4(); g4([1, 1]); + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +g5(); +g5([1, 1]); From 273b9ff1ec12f4a81c8cc96296b3fef0aec6eac2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:27:58 -0700 Subject: [PATCH 16/17] Accepting new baselines --- ...nEmitDestructuringArrayPattern2.errors.txt | 22 +++ ...tionEmitDestructuringArrayPattern2.symbols | 40 ---- ...rationEmitDestructuringArrayPattern2.types | 70 ------- .../declarationsAndAssignments.errors.txt | 28 ++- ...BindingPatternAndAssignment1ES5.errors.txt | 65 +++++++ ...rayBindingPatternAndAssignment1ES5.symbols | 105 ----------- ...ArrayBindingPatternAndAssignment1ES5.types | 177 ------------------ ...BindingPatternAndAssignment1ES6.errors.txt | 64 +++++++ ...rayBindingPatternAndAssignment1ES6.symbols | 105 ----------- ...ArrayBindingPatternAndAssignment1ES6.types | 177 ------------------ ...rayBindingPatternAndAssignment2.errors.txt | 8 +- ...ectBindingPatternAndAssignment3.errors.txt | 4 +- ...destructuringVariableDeclaration1ES5.types | 6 +- ...destructuringVariableDeclaration1ES6.types | 6 +- .../reference/downlevelLetConst12.errors.txt | 20 ++ .../reference/downlevelLetConst12.symbols | 26 --- .../reference/downlevelLetConst12.types | 35 ---- .../reference/downlevelLetConst16.errors.txt | 8 +- .../missingAndExcessProperties.errors.txt | 46 +++-- 19 files changed, 242 insertions(+), 770 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types create mode 100644 tests/baselines/reference/downlevelLetConst12.errors.txt delete mode 100644 tests/baselines/reference/downlevelLetConst12.symbols delete mode 100644 tests/baselines/reference/downlevelLetConst12.types diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt new file mode 100644 index 0000000000000..ea5b38a3b2f34 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts (3 errors) ==== + var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + + var [x11 = 0, y11 = ""] = [1, "hello"]; + var [a11, b11, c11] = []; + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + + var [x13, y13] = [1, "hello"]; + var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols deleted file mode 100644 index 0a3c6f4044dee..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === -var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; ->x10 : Symbol(x10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 5)) ->y10 : Symbol(y10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 11)) ->z10 : Symbol(z10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 17)) - -var [x11 = 0, y11 = ""] = [1, "hello"]; ->x11 : Symbol(x11, Decl(declarationEmitDestructuringArrayPattern2.ts, 2, 5)) ->y11 : Symbol(y11, Decl(declarationEmitDestructuringArrayPattern2.ts, 2, 13)) - -var [a11, b11, c11] = []; ->a11 : Symbol(a11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 5)) ->b11 : Symbol(b11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 9)) ->c11 : Symbol(c11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 14)) - -var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; ->a2 : Symbol(a2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 5)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 10)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 15)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) ->c2 : Symbol(c2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 20)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 41)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 50)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 83)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) - -var [x13, y13] = [1, "hello"]; ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) - -var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; ->a3 : Symbol(a3, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 5)) ->b3 : Symbol(b3, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 8)) ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) ->x : Symbol(x, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 29)) ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y : Symbol(y, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 37)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) - diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types deleted file mode 100644 index 57acfe1dde115..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ /dev/null @@ -1,70 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === -var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; ->x10 : number ->y10 : string ->z10 : boolean ->[1, ["hello", [true]]] : [number, [string, [boolean]]] ->1 : number ->["hello", [true]] : [string, [boolean]] ->"hello" : string ->[true] : [boolean] ->true : boolean - -var [x11 = 0, y11 = ""] = [1, "hello"]; ->x11 : number ->0 : number ->y11 : string ->"" : string ->[1, "hello"] : [number, string] ->1 : number ->"hello" : string - -var [a11, b11, c11] = []; ->a11 : any ->b11 : any ->c11 : any ->[] : [undefined, undefined, undefined] - -var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; ->a2 : number ->b2 : string ->x12 : number ->y12 : any ->c2 : boolean ->["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] ->"abc" : string ->{ x12: 10, y12: false } : { x12: number; y12: boolean; } ->x12 : number ->10 : number ->y12 : boolean ->false : boolean ->[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] ->1 : number ->["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] ->"hello" : string ->{ x12: 5, y12: true } : { x12: number; y12: boolean; } ->x12 : number ->5 : number ->y12 : boolean ->true : boolean - -var [x13, y13] = [1, "hello"]; ->x13 : number ->y13 : string ->[1, "hello"] : [number, string] ->1 : number ->"hello" : string - -var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; ->a3 : (number | string)[] ->b3 : { x: number; y: string; } ->[[x13, y13], { x: x13, y: y13 }] : [(number | string)[], { x: number; y: string; }] ->[x13, y13] : (number | string)[] ->x13 : number ->y13 : string ->{ x: x13, y: y13 } : { x: number; y: string; } ->x : number ->x13 : number ->y : string ->y13 : string - diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 802e72562af01..cd72c12951cd5 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,3 +1,4 @@ +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -5,10 +6,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2459: Type '{}' has no property 'a' and no string index signature. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2459: Type '{}' has no property 'b' and no string index signature. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,5): error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'. @@ -21,12 +27,14 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (16 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (22 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [,, x] = [0, 1, 2]; var x: number; var y: string; @@ -98,7 +106,17 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [d, e, f] = [1]; // Error, [1] is a tuple + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value } function f9() { @@ -114,9 +132,9 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f10() { var { a, b } = {}; // Error ~ -!!! error TS2459: Type '{}' has no property 'a' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'b' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { a, b } = []; // Error ~ !!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt new file mode 100644 index 0000000000000..5fd60c296c967 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt @@ -0,0 +1,65 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts (3 errors) ==== + /* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + + // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. + // An expression of type S is considered assignable to an assignment target V if one of the following is true + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + + var [a0, a1]: any = undefined; + var [a2 = false, a3 = 1]: any = undefined; + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2] = [2, 3, 4]; + var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + + function foo() { + return [1, 2, 3]; + } + + var [b6, b7] = foo(); + var [...b8] = foo(); + + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1,2,3] + var [c0, c1] = [...temp]; + var [c2] = []; + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[c5], c6]: [[string|number], boolean] = [[1], true]; + var [, c7] = [1, 2, 3]; + var [,,, c8] = [1, 2, 3, 4]; + var [,,, c9] = [1, 2, 3, 4]; + var [,,,...c10] = [1, 2, 3, 4, "hello"]; + var [c11, c12, ...c13] = [1, 2, "string"]; + var [c14, c15, c16] = [1, 2, "string"]; + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols deleted file mode 100644 index d8e319f41204d..0000000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols +++ /dev/null @@ -1,105 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) ->a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) ->undefined : Symbol(undefined) - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) ->a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) ->undefined : Symbol(undefined) - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) ->b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) ->b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) ->b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) ->b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) - -function foo() { ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - - return [1, 2, 3]; -} - -var [b6, b7] = foo(); ->b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) ->b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - -var [...b8] = foo(); ->b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) - -var [c0, c1] = [...temp]; ->c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) ->c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) - -var [c2] = []; ->c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) ->c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) ->c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) - -var [, c7] = [1, 2, 3]; ->c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) - -var [,,, c8] = [1, 2, 3, 4]; ->c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) - -var [,,, c9] = [1, 2, 3, 4]; ->c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; ->c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) ->c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) ->c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) ->c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) ->c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types deleted file mode 100644 index fcd71e85dbfbb..0000000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ /dev/null @@ -1,177 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : any ->a1 : any ->undefined : undefined - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean ->false : boolean ->a3 : number ->1 : number ->undefined : undefined - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : number ->b1 : number ->b2 : number ->[2, 3, 4] : [number, number, number] ->2 : number ->3 : number ->4 : number - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number ->b4 : number ->b5 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -function foo() { ->foo : () => number[] - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} - -var [b6, b7] = foo(); ->b6 : number ->b7 : number ->foo() : number[] ->foo : () => number[] - -var [...b8] = foo(); ->b8 : number[] ->foo() : number[] ->foo : () => number[] - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : number[] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -var [c0, c1] = [...temp]; ->c0 : number ->c1 : number ->[...temp] : number[] ->...temp : number ->temp : number[] - -var [c2] = []; ->c2 : any ->[] : [undefined] - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any ->c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number ->c6 : boolean ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -var [, c7] = [1, 2, 3]; -> : undefined ->c7 : number ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, c8] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c8 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, c9] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c9 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->c10 : (number | string)[] ->[1, 2, 3, 4, "hello"] : (number | string)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : number | string ->c12 : number | string ->c13 : (number | string)[] ->[1, 2, "string"] : (number | string)[] ->1 : number ->2 : number ->"string" : string - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number ->c15 : number ->c16 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt new file mode 100644 index 0000000000000..a847cc44f0caf --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts (3 errors) ==== + + /* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + + // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. + // An expression of type S is considered assignable to an assignment target V if one of the following is true + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + + var [a0, a1]: any = undefined; + var [a2 = false, a3 = 1]: any = undefined; + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2] = [2, 3, 4]; + var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + + function foo() { + return [1, 2, 3]; + } + + var [b6, b7] = foo(); + var [...b8] = foo(); + + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1,2,3] + var [c0, c1] = [...temp]; + var [c2] = []; + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[c5], c6]: [[string|number], boolean] = [[1], true]; + var [, c7] = [1, 2, 3]; + var [,,, c8] = [1, 2, 3, 4]; + var [,,, c9] = [1, 2, 3, 4]; + var [,,,...c10] = [1, 2, 3, 4, "hello"]; + var [c11, c12, ...c13] = [1, 2, "string"]; + var [c14, c15, c16] = [1, 2, "string"]; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols deleted file mode 100644 index 33f9b4e88be8e..0000000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols +++ /dev/null @@ -1,105 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === - -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) ->a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) ->undefined : Symbol(undefined) - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) ->a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) ->undefined : Symbol(undefined) - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) ->b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) ->b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) ->b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) ->b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) - -function foo() { ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - - return [1, 2, 3]; -} - -var [b6, b7] = foo(); ->b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) ->b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - -var [...b8] = foo(); ->b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) - -var [c0, c1] = [...temp]; ->c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) ->c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) - -var [c2] = []; ->c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) ->c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) ->c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) - -var [, c7] = [1, 2, 3]; ->c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) - -var [,,, c8] = [1, 2, 3, 4]; ->c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) - -var [,,, c9] = [1, 2, 3, 4]; ->c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; ->c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) ->c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) ->c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) ->c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) ->c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types deleted file mode 100644 index d154f0912148a..0000000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ /dev/null @@ -1,177 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === - -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : any ->a1 : any ->undefined : undefined - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean ->false : boolean ->a3 : number ->1 : number ->undefined : undefined - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : number ->b1 : number ->b2 : number ->[2, 3, 4] : [number, number, number] ->2 : number ->3 : number ->4 : number - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number ->b4 : number ->b5 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -function foo() { ->foo : () => number[] - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} - -var [b6, b7] = foo(); ->b6 : number ->b7 : number ->foo() : number[] ->foo : () => number[] - -var [...b8] = foo(); ->b8 : number[] ->foo() : number[] ->foo : () => number[] - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : number[] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -var [c0, c1] = [...temp]; ->c0 : number ->c1 : number ->[...temp] : number[] ->...temp : number ->temp : number[] - -var [c2] = []; ->c2 : any ->[] : [undefined] - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any ->c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number ->c6 : boolean ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -var [, c7] = [1, 2, 3]; -> : undefined ->c7 : number ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, c8] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c8 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, c9] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c9 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->c10 : (number | string)[] ->[1, 2, 3, 4, "hello"] : (number | string)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : number | string ->c12 : number | string ->c13 : (number | string)[] ->[1, 2, "string"] : (number | string)[] ->1 : number ->2 : number ->"string" : string - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number ->c15 : number ->c16 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index a2e5cb7e17c17..082bc7aa72a23 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -18,9 +18,9 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss // S is the type Any, or var [[a0], [[a1]]] = [] // Error ~~~~ -!!! error TS2461: Type 'undefined' is not an array type. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 4cee43144666a..709774fb9b48c 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs Type '{ i: number; }' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. @@ -30,7 +30,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ -!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~~~~ !!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index c024fdfe86278..f8188147a7908 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, any]; } +>f : [number, number, { f3: number; f5: number; }, any] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, any] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index 730abd843a2bb..7b4fe5409dbaa 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, any]; } +>f : [number, number, { f3: number; f5: number; }, any] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, any] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/downlevelLetConst12.errors.txt b/tests/baselines/reference/downlevelLetConst12.errors.txt new file mode 100644 index 0000000000000..f29d9435dbbf4 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst12.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/compiler/downlevelLetConst12.ts (2 errors) ==== + + 'use strict' + // top level let\const should not be renamed + let foo; + const bar = 1; + + let [baz] = []; + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + let {a: baz2} = { a: 1 }; + + const [baz3] = [] + ~~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + const {a: baz4} = { a: 1 }; \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst12.symbols b/tests/baselines/reference/downlevelLetConst12.symbols deleted file mode 100644 index 97d6d5eebf8c0..0000000000000 --- a/tests/baselines/reference/downlevelLetConst12.symbols +++ /dev/null @@ -1,26 +0,0 @@ -=== tests/cases/compiler/downlevelLetConst12.ts === - -'use strict' -// top level let\const should not be renamed -let foo; ->foo : Symbol(foo, Decl(downlevelLetConst12.ts, 3, 3)) - -const bar = 1; ->bar : Symbol(bar, Decl(downlevelLetConst12.ts, 4, 5)) - -let [baz] = []; ->baz : Symbol(baz, Decl(downlevelLetConst12.ts, 6, 5)) - -let {a: baz2} = { a: 1 }; ->a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) ->baz2 : Symbol(baz2, Decl(downlevelLetConst12.ts, 7, 5)) ->a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) - -const [baz3] = [] ->baz3 : Symbol(baz3, Decl(downlevelLetConst12.ts, 9, 7)) - -const {a: baz4} = { a: 1 }; ->a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) ->baz4 : Symbol(baz4, Decl(downlevelLetConst12.ts, 10, 7)) ->a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) - diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types deleted file mode 100644 index a6146b55dd7fc..0000000000000 --- a/tests/baselines/reference/downlevelLetConst12.types +++ /dev/null @@ -1,35 +0,0 @@ -=== tests/cases/compiler/downlevelLetConst12.ts === - -'use strict' ->'use strict' : string - -// top level let\const should not be renamed -let foo; ->foo : any - -const bar = 1; ->bar : number ->1 : number - -let [baz] = []; ->baz : any ->[] : [undefined] - -let {a: baz2} = { a: 1 }; ->a : any ->baz2 : number ->{ a: 1 } : { a: number; } ->a : number ->1 : number - -const [baz3] = [] ->baz3 : any ->[] : [undefined] - -const {a: baz4} = { a: 1 }; ->a : any ->baz4 : number ->{ a: 1 } : { a: number; } ->a : number ->1 : number - diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt index 94c53360b8743..43acc162d7a61 100644 --- a/tests/baselines/reference/downlevelLetConst16.errors.txt +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -1,10 +1,12 @@ +tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/compiler/downlevelLetConst16.ts(195,14): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2459: Type 'undefined' has no property 'a' and no string index signature. tests/cases/compiler/downlevelLetConst16.ts(216,16): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefined' has no property 'a' and no string index signature. -==== tests/cases/compiler/downlevelLetConst16.ts (4 errors) ==== +==== tests/cases/compiler/downlevelLetConst16.ts (6 errors) ==== 'use strict' declare function use(a: any); @@ -156,6 +158,8 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin use(x); } for (let [y] = []; ;) { + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value use(y); } for (let {a: z} = {a: 1}; ;) { @@ -169,6 +173,8 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin use(x); } for (const [y] = []; ;) { + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value use(y); } for (const {a: z} = { a: 1 }; ;) { diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 294b564a23999..6b01500182950 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -1,11 +1,15 @@ -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,14): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -16,21 +20,29 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. -==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ==== +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (20 errors) ==== // Missing properties function f1() { var { x, y } = {}; ~ -!!! error TS2459: Type '{}' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { x = 1, y } = {}; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. ~ -!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { x, y = 1 } = {}; ~ -!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. var { x = 1, y = 1 } = {}; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. } // Missing properties @@ -38,15 +50,15 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): var x: number, y: number; ({ x, y } = {}); ~ -!!! error TS2459: Type '{}' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x: x = 1, y } = {}); ~ -!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x, y: y = 1 } = {}); ~ -!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x: x = 1, y: y = 1 } = {}); } From 262f122d997c1f82ebfb517a1986d398658591ed Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 17:03:13 -0700 Subject: [PATCH 17/17] Adding "." to error message --- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...nEmitDestructuringArrayPattern2.errors.txt | 12 +++---- .../declarationsAndAssignments.errors.txt | 32 +++++++++---------- ...BindingPatternAndAssignment1ES5.errors.txt | 12 +++---- ...BindingPatternAndAssignment1ES6.errors.txt | 12 +++---- ...rayBindingPatternAndAssignment2.errors.txt | 8 ++--- ...ectBindingPatternAndAssignment3.errors.txt | 4 +-- .../reference/downlevelLetConst12.errors.txt | 8 ++--- .../reference/downlevelLetConst16.errors.txt | 8 ++--- .../missingAndExcessProperties.errors.txt | 32 +++++++++---------- 11 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 9686d6580f5de..4f53537d0c38a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -415,7 +415,7 @@ namespace ts { The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." }, yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, - Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value" }, + Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 515afda49aa79..33749f672851f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1649,7 +1649,7 @@ "category": "Error", "code": 2524 }, - "Initializer provides no value for this binding element and the binding element has no default value": { + "Initializer provides no value for this binding element and the binding element has no default value.": { "category": "Error", "code": 2525 }, diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt index ea5b38a3b2f34..26998fd83ae83 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts (3 errors) ==== @@ -9,11 +9,11 @@ tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error T var [x11 = 0, y11 = ""] = [1, "hello"]; var [a11, b11, c11] = []; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index cd72c12951cd5..7c4671022ea4b 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -6,15 +6,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,5): error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'. @@ -34,7 +34,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [,, x] = [0, 1, 2]; var x: number; var y: string; @@ -107,16 +107,16 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [d, e, f] = [1]; // Error, [1] is a tuple ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. } function f9() { @@ -132,9 +132,9 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f10() { var { a, b } = {}; // Error ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { a, b } = []; // Error ~ !!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt index 5fd60c296c967..1f1bc85757b07 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts (3 errors) ==== @@ -48,12 +48,12 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss var [c0, c1] = [...temp]; var [c2] = []; ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; var [,,, c8] = [1, 2, 3, 4]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt index a847cc44f0caf..beefbc9a85bc7 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts (3 errors) ==== @@ -49,12 +49,12 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss var [c0, c1] = [...temp]; var [c2] = []; ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; var [,,, c8] = [1, 2, 3, 4]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index 082bc7aa72a23..914052859734a 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -18,9 +18,9 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss // S is the type Any, or var [[a0], [[a1]]] = [] // Error ~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 709774fb9b48c..bb4b79987e349 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs Type '{ i: number; }' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. @@ -30,7 +30,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~~ !!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { diff --git a/tests/baselines/reference/downlevelLetConst12.errors.txt b/tests/baselines/reference/downlevelLetConst12.errors.txt index f29d9435dbbf4..0af224b017e83 100644 --- a/tests/baselines/reference/downlevelLetConst12.errors.txt +++ b/tests/baselines/reference/downlevelLetConst12.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/compiler/downlevelLetConst12.ts (2 errors) ==== @@ -11,10 +11,10 @@ tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer pro let [baz] = []; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. let {a: baz2} = { a: 1 }; const [baz3] = [] ~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. const {a: baz4} = { a: 1 }; \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt index 43acc162d7a61..905d1a607e81d 100644 --- a/tests/baselines/reference/downlevelLetConst16.errors.txt +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/compiler/downlevelLetConst16.ts(195,14): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2459: Type 'undefined' has no property 'a' and no string index signature. tests/cases/compiler/downlevelLetConst16.ts(216,16): error TS2461: Type 'undefined' is not an array type. @@ -159,7 +159,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin } for (let [y] = []; ;) { ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. use(y); } for (let {a: z} = {a: 1}; ;) { @@ -174,7 +174,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin } for (const [y] = []; ;) { ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. use(y); } for (const {a: z} = { a: 1 }; ;) { diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 6b01500182950..0ee69d9af306c 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,14): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -25,17 +25,17 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): function f1() { var { x, y } = {}; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { x = 1, y } = {}; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { x, y = 1 } = {}; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. var { x = 1, y = 1 } = {}; @@ -50,15 +50,15 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): var x: number, y: number; ({ x, y } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x: x = 1, y } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x, y: y = 1 } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x: x = 1, y: y = 1 } = {}); }