Skip to content

Remove binding pattern normalization #1

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4306,10 +4306,9 @@ namespace ts {
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) {
type = getTypeWithFacts(type, TypeFacts.NEUndefined);
}
type = declaration.initializer ?
return declaration.initializer ?
getUnionType([type, checkExpressionCached(declaration.initializer)], /*subtypeReduction*/ true) :
type;
return shouldKeepLiteralType(declaration) ? type : getWidenedLiteralType(type);
}

function getTypeForDeclarationFromJSDocComment(declaration: Node) {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrowFunctionExpressions.types
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var p9 = ({ a: { b = 1 } = { b: 1 } }) => { };
>p9 : ({ a: { b } }: { a?: { b?: 1; }; }) => void
>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b } }: { a?: { b?: 1; }; }) => void
>a : any
>b : number
>b : 1
>1 : 1
>{ b: 1 } : { b?: 1; }
>b : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ interface StringUnion {
}
function h({ prop = "baz" }: StringUnion) {}
>h : ({ prop }: StringUnion) => void
>prop : string
>prop : "foo" | "bar" | "baz"
>"baz" : "baz"
>StringUnion : StringUnion

10 changes: 5 additions & 5 deletions tests/baselines/reference/contextuallyTypedIife.types
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@
>19 : 19

(({ u = 22 } = { u: 23 }) => u)();
>(({ u = 22 } = { u: 23 }) => u)() : number
>(({ u = 22 } = { u: 23 }) => u) : ({ u }?: { u?: 23; }) => number
>({ u = 22 } = { u: 23 }) => u : ({ u }?: { u?: 23; }) => number
>u : number
>(({ u = 22 } = { u: 23 }) => u)() : 22 | 23
>(({ u = 22 } = { u: 23 }) => u) : ({ u }?: { u?: 23; }) => 22 | 23
>({ u = 22 } = { u: 23 }) => u : ({ u }?: { u?: 23; }) => 22 | 23
>u : 22 | 23
>22 : 22
>{ u: 23 } : { u?: 23; }
>u : number
>23 : 23
>u : number
>u : 22 | 23

// contextually typed parameters.
let twelve = (f => f(12))(i => i);
Expand Down
10 changes: 5 additions & 5 deletions tests/baselines/reference/contextuallyTypedIifeStrict.types
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@
>19 : 19

(({ u = 22 } = { u: 23 }) => u)();
>(({ u = 22 } = { u: 23 }) => u)() : number
>(({ u = 22 } = { u: 23 }) => u) : ({ u }?: { u?: 23; }) => number
>({ u = 22 } = { u: 23 }) => u : ({ u }?: { u?: 23; }) => number
>u : number
>(({ u = 22 } = { u: 23 }) => u)() : 22 | 23
>(({ u = 22 } = { u: 23 }) => u) : ({ u }?: { u?: 23; }) => 22 | 23
>({ u = 22 } = { u: 23 }) => u : ({ u }?: { u?: 23; }) => 22 | 23
>u : 22 | 23
>22 : 22
>{ u: 23 } : { u?: 23; }
>u : number
>23 : 23
>u : number
>u : 22 | 23

// contextually typed parameters.
let twelve = (f => f(12))(i => i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/compiler/declarationEmitDestructuring2.ts ===
function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { }
>f : ({ x, y: [a, b, c, d] }?: { x?: 10; y?: [2, 4, 6, 8]; }) => void
>x : number
>x : 10
>10 : 10
>y : any
>a : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var [x10, [y10, [z10]]] = [1, ["hello", [true]]];
>true : true

var [x11 = 0, y11 = ""] = [1, "hello"];
>x11 : number
>x11 : 1 | 0
>0 : 0
>y11 : string
>y11 : "hello" | ""
>"" : ""
>[1, "hello"] : [1, "hello"]
>1 : 1
Expand Down
15 changes: 12 additions & 3 deletions tests/baselines/reference/declarationsAndAssignments.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25):
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(58,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type 'string | number' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:16, but here has type 'string'.
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(51,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type '1 | 0' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 49:9, but here has type 'number'.
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(52,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type '"hello" | ""' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 49:16, but here has type 'string'.
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(57,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type '1 | 0' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:9, but here has type 'number'.
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(58,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type 'string | 1' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:16, but here has 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.
Expand All @@ -25,7 +28,7 @@ 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 (22 errors) ====
==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (25 errors) ====
function f0() {
var [] = [1, "hello"];
var [x] = [1, "hello"];
Expand Down Expand Up @@ -91,15 +94,21 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9):
function f6() {
var [x = 0, y = ""] = [1, "hello"];
var x: number;
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type '1 | 0' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 49:9, but here has type 'number'.
var y: string;
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type '"hello" | ""' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 49:16, but here has type 'string'.
}

function f7() {
var [x = 0, y = 1] = [1, "hello"]; // Error, initializer for y must be string
var x: number;
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type '1 | 0' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:9, but here has type 'number'.
var y: string;
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type 'string | number' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:16, but here has type 'string'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' has type 'string | 1' at tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts 55:16, but here has type 'string'.
}

function f8() {
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/declarationsAndAssignments.types
Original file line number Diff line number Diff line change
Expand Up @@ -217,38 +217,38 @@ function f6() {
>f6 : () => void

var [x = 0, y = ""] = [1, "hello"];
>x : number
>x : 1 | 0
>0 : 0
>y : string
>y : "hello" | ""
>"" : ""
>[1, "hello"] : [1, "hello"]
>1 : 1
>"hello" : "hello"

var x: number;
>x : number
>x : 1 | 0

var y: string;
>y : string
>y : "hello" | ""
}

function f7() {
>f7 : () => void

var [x = 0, y = 1] = [1, "hello"]; // Error, initializer for y must be string
>x : number
>x : 1 | 0
>0 : 0
>y : string | number
>y : string | 1
>1 : 1
>[1, "hello"] : [1, string]
>1 : 1
>"hello" : "hello"

var x: number;
>x : number
>x : 1 | 0

var y: string;
>y : string | number
>y : string | 1
}

function f8() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function bar(): J {
>3 : 3
}
var [b3 = "string", b4, b5] = bar(); // Error
>b3 : string | Number
>b3 : Number | "string"
>"string" : "string"
>b4 : Number
>b5 : Number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var temp = { t1: true, t2: "false" };
>"false" : "false"

var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>b2 : number
>b2 : 3
>3 : 3
>b3 : boolean
>true : true
Expand All @@ -62,9 +62,9 @@ var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>"hello" : "hello"

var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
>b5 : number
>b5 : 3
>3 : 3
>b6 : boolean
>b6 : true
>true : true
>b7 : { t1: boolean; t2: string; }
>temp : { t1: boolean; t2: string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var temp = { t1: true, t2: "false" };
>"false" : "false"

var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>b2 : number
>b2 : 3
>3 : 3
>b3 : boolean
>true : true
Expand All @@ -62,9 +62,9 @@ var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>"hello" : "hello"

var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
>b5 : number
>b5 : 3
>3 : 3
>b6 : boolean
>b6 : true
>true : true
>b7 : { t1: boolean; t2: string; }
>temp : { t1: boolean; t2: string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var temp = { t1: true, t2: "false" };
>"false" : "false"

var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>b2 : number
>b2 : 3
>3 : 3
>b3 : boolean
>true : true
Expand All @@ -62,9 +62,9 @@ var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>"hello" : "hello"

var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
>b5 : number
>b5 : 3
>3 : 3
>b6 : boolean
>b6 : true
>true : true
>b7 : { t1: boolean; t2: string; }
>temp : { t1: boolean; t2: string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var temp = { t1: true, t2: "false" };
>"false" : "false"

var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error
>b0 : number
>b0 : 3
>3 : 3
>b1 : boolean
>true : true
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/emitArrowFunctionES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var p9 = ({ a: { b = 1 } = { b: 1 } }) => { };
>p9 : ({ a: { b } }: { a?: { b?: 1; }; }) => void
>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b } }: { a?: { b?: 1; }; }) => void
>a : any
>b : number
>b : 1
>1 : 1
>{ b: 1 } : { b?: 1; }
>b : number
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/for-of43.types
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for (var {x: a = "", y: b = true} of array) {
>a : string
>"" : ""
>y : any
>b : number | boolean
>b : number | true
>true : true
>array : { x: string; y: number; }[]

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/literalTypes2.types
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ function f6() {
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
>x1 : boolean
>true : true
>x2 : number
>x2 : 1 | 0
>0 : 0
>x3 : string
>x3 : "foo" | "bar"
>"foo" : "foo"
>{ x1: false, x2: 1, x3: "bar" } : { x1?: false; x2?: 1; x3?: "bar"; }
>x1 : boolean
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/literalTypesAndTypeAssertions.types
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let x2 = 1;
>1 : 1

let { a = "foo" } = { a: "foo" };
>a : string
>a : "foo"
>"foo" : "foo"
>{ a: "foo" } : { a?: "foo"; }
>a : string
Expand All @@ -44,7 +44,7 @@ let { b = "foo" as "foo" } = { b: "bar" };
>"bar" : "bar"

let { c = "foo" } = { c: "bar" as "bar" };
>c : string
>c : "foo" | "bar"
>"foo" : "foo"
>{ c: "bar" as "bar" } : { c?: "bar"; }
>c : "bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ let [a, b, c] = [1, 2, 3]; // no error
>3 : 3

let [a1 = 10, b1 = 10, c1 = 10] = [1, 2, 3]; // no error
>a1 : number
>a1 : 1 | 10
>10 : 10
>b1 : number
>b1 : 2 | 10
>10 : 10
>c1 : number
>c1 : 3 | 10
>10 : 10
>[1, 2, 3] : [1, 2, 3]
>1 : 1
Expand Down Expand Up @@ -76,11 +76,11 @@ let {x, y, z} = { x: 1, y: 2, z: 3 }; // no error
>3 : 3

let {x1 = 10, y1 = 10, z1 = 10} = { x1: 1, y1: 2, z1: 3 }; // no error
>x1 : number
>x1 : 1 | 10
>10 : 10
>y1 : number
>y1 : 2 | 10
>10 : 10
>z1 : number
>z1 : 3 | 10
>10 : 10
>{ x1: 1, y1: 2, z1: 3 } : { x1?: 1; y1?: 2; z1?: 3; }
>x1 : number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(4,13): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(5,15): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type 'number' at tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts 3:12, but here has type '0'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(5,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(6,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type 'number' at tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts 3:12, but here has type '0'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(6,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(7,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.


==== tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts (5 errors) ====
==== tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts (7 errors) ====
if (true) {
let x;
if (true) {
Expand All @@ -14,9 +16,13 @@ tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS24
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
var { x = 0 } = { x: 0 }; // Error
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type 'number' at tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts 3:12, but here has type '0'.
~
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
var { x: x = 0 } = { x: 0 }; // Error
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' has type 'number' at tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts 3:12, but here has type '0'.
~
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
var { x } = { x: 0 }; // Error
~
Expand Down
Loading