-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Conformance test for Spec Change in Section 3.8.2.2 parameter Declaration and 6.4 Destructuring parameter declarations #2735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5039b4b
Conformance test for 3.8.2.2 and 6.4
b29077a
Add destructuring parameter with generic
2499b3e
Organize test files and add spec description in the comment
6144694
Update tests files with more conformance from section 6.4
55f9aba
Move tests with errors to separate file
0443bfb
Merge branch 'master' into conformanceParameterDecl
3a15b3f
Move error test cases into separate files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
tests/baselines/reference/destructuringParameterDeclaration1.errors.txt
Large diffs are not rendered by default.
Oops, something went wrong.
287 changes: 287 additions & 0 deletions
287
tests/baselines/reference/destructuringParameterDeclaration1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,287 @@ | ||
| //// [destructuringParameterDeclaration1.ts] | ||
| // A parameter declaration may specify either an identifier or a binding pattern. | ||
| // The identifiers specified in parameter declarations and binding patterns | ||
| // in a parameter list must be unique within that parameter list. | ||
|
|
||
| // If the declaration includes a type annotation, the parameter is of that type | ||
| function a1([a, b, [[c]]]: [number, number, string[][]]) { } | ||
| function a2(o: { x: number, a: number }) { } | ||
| function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; | ||
| function a4({x, a}: { x: number, a: number }) { } | ||
|
|
||
| a1([1, 2, [["world"]]]); | ||
| a1([1, 2, [["world"]], 3]); | ||
| a1([1, "string", [["world"]]); // Error | ||
| a1([1, 2, [["world"]], "string"]); // Error | ||
|
|
||
|
|
||
| // If the declaration includes an initializer expression (which is permitted only | ||
| // when the parameter list occurs in conjunction with a function body), | ||
| // the parameter type is the widened form (section 3.11) of the type of the initializer expression. | ||
|
|
||
| function b1(z = [undefined, null]) { }; | ||
| function b2(z = null, o = { x: 0, y: undefined }) { } | ||
| function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } | ||
|
|
||
| interface F1 { | ||
| b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body | ||
| b5(z, y, [, a, b], {p, m: { q, r}}); | ||
| } | ||
|
|
||
| function b6([a, z, y] = [undefined, null, undefined]) { } | ||
| function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } | ||
|
|
||
| b1([1, 2, 3]); // z is widen to the type any[] | ||
| b2("string", { x: 200, y: "string" }); | ||
| b2("string", { x: 200, y: true }); | ||
| b2("string", { x: "string", y: true }); // Error | ||
| b6(["string", 1, 2]); // Shouldn't be an error | ||
| b7([["string"], 1, [[true, false]]]); // Shouldn't be an error | ||
|
|
||
|
|
||
| // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) | ||
| enum Foo { a } | ||
| function c0({z: {x, y: {j}}}) { } | ||
| function c1({z} = { z: 10 }) { } | ||
| function c2({z = 10}) { } | ||
| function c3({b}: { b: number|string} = { b: "hello" }) { } | ||
| function c4([z], z: number) { } // Duplicate identifier | ||
| function c5([a, b, [[c]]]) { } | ||
| function c6([a, b, [[c=1]]]) { } | ||
|
|
||
| c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } | ||
| c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } | ||
| c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } | ||
|
|
||
| c1({}); // Error, implied type is {z:number}? | ||
| c1({ z: true }); // Error, implied type is {z:number}? | ||
| c1(); // Implied type is {z:number}? | ||
| c1({ z: 1 }) // Implied type is {z:number}? | ||
|
|
||
| c2({}); // Implied type is {z?: number} | ||
| c2({z:1}); // Implied type is {z?: number} | ||
| c2({z:false}); // Error, implied type is {z?: number} | ||
|
|
||
| c3({ b: 1 }); // Implied type is { b: number|string }. | ||
| c3({ b: true }); // Error, implied type is { b: number|string }. | ||
|
|
||
| c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] | ||
| c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] | ||
| c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] | ||
|
|
||
| c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer | ||
|
|
||
| // A parameter can be marked optional by following its name or binding pattern with a question mark (?) | ||
| // or by including an initializer. | ||
|
|
||
| function d0(x?) { } | ||
| function d0(x = 10) { } | ||
| function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature | ||
| function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature | ||
|
|
||
| interface F2 { | ||
| d3([a, b, c]?); | ||
| d4({x, y, z}?); | ||
| e0([a, b, c]); | ||
| } | ||
|
|
||
| class C2 implements F2 { | ||
| constructor() { } | ||
| d3() { } | ||
| d4() { } | ||
| e0([a, b, c]) { } | ||
| } | ||
|
|
||
| class C3 implements F2 { | ||
| d3([a, b, c]) { } | ||
| d4({x, y, z}) { } | ||
| e0([a, b, c]) { } | ||
| } | ||
|
|
||
| class C4 implements F2 { | ||
| d3([a, b, c]?) { } | ||
| d4({x, y, c}) { } | ||
| e0([a, b, q]) { } | ||
| } | ||
|
|
||
| function d5({x, y} = { x: 1, y: 2 }) { } | ||
| d5(); // Parameter is optional as its declaration included an initializer | ||
|
|
||
| // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, | ||
| // as such annotations would conflict with the already established meaning of colons in object literals. | ||
| // Type annotations must instead be written on the top- level parameter declaration | ||
|
|
||
| function e1({x: number}) { } // x has type any NOT number | ||
| function e2({x}: { x: number }) { } // x is type number | ||
| function e3({x}: { x?: number }) { } // x is an optional with type number | ||
| function e4({x: [number,string,any] }) { } // x has type [any, any, any] | ||
| function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] | ||
|
|
||
| function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //// [destructuringParameterDeclaration1.js] | ||
| // A parameter declaration may specify either an identifier or a binding pattern. | ||
| // The identifiers specified in parameter declarations and binding patterns | ||
| // in a parameter list must be unique within that parameter list. | ||
| // If the declaration includes a type annotation, the parameter is of that type | ||
| function a1(_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2][0][0]; | ||
| } | ||
| function a2(o) { } | ||
| function a3(_a) { | ||
| var j = _a.j, k = _a.k, _b = _a.l, m = _b.m, n = _b.n, _c = _a.q, a = _c[0], b = _c[1], c = _c[2]; | ||
| } | ||
| ; | ||
| function a4(_a) { | ||
| var x = _a.x, a = _a.a; | ||
| } | ||
| a1([1, 2, [["world"]]]); | ||
| a1([1, 2, [["world"]], 3]); | ||
| a1([1, "string", [["world"]]]); // Error | ||
| a1([1, 2, [["world"]], "string"]); // Error | ||
| // If the declaration includes an initializer expression (which is permitted only | ||
| // when the parameter list occurs in conjunction with a function body), | ||
| // the parameter type is the widened form (section 3.11) of the type of the initializer expression. | ||
| function b1(z) { | ||
| if (z === void 0) { z = [undefined, null]; } | ||
| } | ||
| ; | ||
| function b2(z, o) { | ||
| if (z === void 0) { z = null; } | ||
| if (o === void 0) { o = { x: 0, y: undefined }; } | ||
| } | ||
| function b3(_a) { | ||
| var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; | ||
| } | ||
| function b6(_a) { | ||
| var _b = _a === void 0 ? [undefined, null, undefined] : _a, a = _b[0], z = _b[1], y = _b[2]; | ||
| } | ||
| function b7(_a) { | ||
| var _b = _a === void 0 ? [[undefined], undefined, [[undefined, undefined]]] : _a, a = _b[0][0], b = _b[1], _c = _b[2][0], c = _c[0], d = _c[1]; | ||
| } | ||
| b1([1, 2, 3]); // z is widen to the type any[] | ||
| b2("string", { x: 200, y: "string" }); | ||
| b2("string", { x: 200, y: true }); | ||
| b2("string", { x: "string", y: true }); // Error | ||
| b6(["string", 1, 2]); // Shouldn't be an error | ||
| b7([["string"], 1, [[true, false]]]); // Shouldn't be an error | ||
| // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) | ||
| var Foo; | ||
| (function (Foo) { | ||
| Foo[Foo["a"] = 0] = "a"; | ||
| })(Foo || (Foo = {})); | ||
| function c0(_a) { | ||
| var _b = _a.z, x = _b.x, j = _b.y.j; | ||
| } | ||
| function c1(_a) { | ||
| var z = (_a === void 0 ? { z: 10 } : _a).z; | ||
| } | ||
| function c2(_a) { | ||
| var _b = _a.z, z = _b === void 0 ? 10 : _b; | ||
| } | ||
| function c3(_a) { | ||
| var b = (_a === void 0 ? { b: "hello" } : _a).b; | ||
| } | ||
| function c4(_a, z) { | ||
| var z = _a[0]; | ||
| } // Duplicate identifier | ||
| function c5(_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2][0][0]; | ||
| } | ||
| function c6(_a) { | ||
| var a = _a[0], b = _a[1], _b = _a[2][0][0], c = _b === void 0 ? 1 : _b; | ||
| } | ||
| c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} } | ||
| c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} } | ||
| c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } | ||
| c1({}); // Error, implied type is {z:number}? | ||
| c1({ z: true }); // Error, implied type is {z:number}? | ||
| c1(); // Implied type is {z:number}? | ||
| c1({ z: 1 }); // Implied type is {z:number}? | ||
| c2({}); // Implied type is {z?: number} | ||
| c2({ z: 1 }); // Implied type is {z?: number} | ||
| c2({ z: false }); // Error, implied type is {z?: number} | ||
| c3({ b: 1 }); // Implied type is { b: number|string }. | ||
| c3({ b: true }); // Error, implied type is { b: number|string }. | ||
| c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] | ||
| c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] | ||
| c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] | ||
| c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer | ||
| // A parameter can be marked optional by following its name or binding pattern with a question mark (?) | ||
| // or by including an initializer. | ||
| function d0(x) { } | ||
| function d0(x) { | ||
| if (x === void 0) { x = 10; } | ||
| } | ||
| function d1(_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2]; | ||
| } // Error, binding pattern can't be optional in implementation signature | ||
| function d2(_a) { | ||
| var x = _a.x, y = _a.y, z = _a.z; | ||
| } // Error, binding pattern can't be optional in implementation signature | ||
| var C2 = (function () { | ||
| function C2() { | ||
| } | ||
| C2.prototype.d3 = function () { }; | ||
| C2.prototype.d4 = function () { }; | ||
| C2.prototype.e0 = function (_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2]; | ||
| }; | ||
| return C2; | ||
| })(); | ||
| var C3 = (function () { | ||
| function C3() { | ||
| } | ||
| C3.prototype.d3 = function (_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2]; | ||
| }; | ||
| C3.prototype.d4 = function (_a) { | ||
| var x = _a.x, y = _a.y, z = _a.z; | ||
| }; | ||
| C3.prototype.e0 = function (_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2]; | ||
| }; | ||
| return C3; | ||
| })(); | ||
| var C4 = (function () { | ||
| function C4() { | ||
| } | ||
| C4.prototype.d3 = function (_a) { | ||
| var a = _a[0], b = _a[1], c = _a[2]; | ||
| }; | ||
| C4.prototype.d4 = function (_a) { | ||
| var x = _a.x, y = _a.y, c = _a.c; | ||
| }; | ||
| C4.prototype.e0 = function (_a) { | ||
| var a = _a[0], b = _a[1], q = _a[2]; | ||
| }; | ||
| return C4; | ||
| })(); | ||
| function d5(_a) { | ||
| var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y; | ||
| } | ||
| d5(); // Parameter is optional as its declaration included an initializer | ||
| // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, | ||
| // as such annotations would conflict with the already established meaning of colons in object literals. | ||
| // Type annotations must instead be written on the top- level parameter declaration | ||
| function e1(_a) { | ||
| var number = _a.x; | ||
| } // x has type any NOT number | ||
| function e2(_a) { | ||
| var x = _a.x; | ||
| } // x is type number | ||
| function e3(_a) { | ||
| var x = _a.x; | ||
| } // x is an optional with type number | ||
| function e4(_a) { | ||
| var _b = _a.x, number = _b[0], string = _b[1], any = _b[2]; | ||
| } // x has type [any, any, any] | ||
| function e5(_a) { | ||
| var _b = _a.x, a = _b[0], b = _b[1], c = _b[2]; | ||
| } // x has type [any, any, any] | ||
| function e6(_a) { | ||
| var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; | ||
| } // should be an error, duplicate identifier; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change, we want this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should merge in from master to ensure it doesn't get kept.