Skip to content

Commit c3cfebf

Browse files
committed
Code review comments
1 parent 7680cdf commit c3cfebf

18 files changed

+101
-102
lines changed

src/compiler/checker.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -2192,16 +2192,16 @@ namespace ts {
21922192
}
21932193

21942194
function buildBindingPatternDisplay(bindingPattern: BindingPattern, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2195-
// We have to explicitly emit square bracket and bracket because these tokens are not store inside the node.
2195+
// We have to explicitly emit square bracket and bracket because these tokens are not stored inside the node.
21962196
if (bindingPattern.kind === SyntaxKind.ObjectBindingPattern) {
21972197
writePunctuation(writer, SyntaxKind.OpenBraceToken);
2198-
buildDisplayForCommaSeparatedList(bindingPattern.elements, writer, enclosingDeclaration, flags, symbolStack, buildBindingElementDisplay);
2198+
buildDisplayForCommaSeparatedList(bindingPattern.elements, writer, e => buildBindingElementDisplay(e, writer, enclosingDeclaration, flags, symbolStack));
21992199
writePunctuation(writer, SyntaxKind.CloseBraceToken);
22002200
}
22012201
else if (bindingPattern.kind === SyntaxKind.ArrayBindingPattern) {
22022202
writePunctuation(writer, SyntaxKind.OpenBracketToken);
22032203
const elements = bindingPattern.elements;
2204-
buildDisplayForCommaSeparatedList(elements, writer, enclosingDeclaration, flags, symbolStack, buildBindingElementDisplay);
2204+
buildDisplayForCommaSeparatedList(elements, writer, e => buildBindingElementDisplay(e, writer, enclosingDeclaration, flags, symbolStack));
22052205
if (elements && elements.hasTrailingComma) {
22062206
writePunctuation(writer, SyntaxKind.CommaToken);
22072207
}
@@ -2217,35 +2217,34 @@ namespace ts {
22172217
if (bindingElement.propertyName) {
22182218
writer.writeSymbol(getTextOfNode(bindingElement.propertyName), bindingElement.symbol);
22192219
writePunctuation(writer, SyntaxKind.ColonToken);
2220+
writeSpace(writer);
22202221
}
2221-
if (bindingElement.name) {
2222-
if (isBindingPattern(bindingElement.name)) {
2223-
buildBindingPatternDisplay(<BindingPattern>bindingElement.name, writer, enclosingDeclaration, flags, symbolStack);
2224-
}
2225-
else {
2226-
if (bindingElement.dotDotDotToken) {
2227-
writePunctuation(writer, SyntaxKind.DotDotDotToken);
2228-
}
2229-
appendSymbolNameOnly(bindingElement.symbol, writer);
2222+
if (isBindingPattern(bindingElement.name)) {
2223+
buildBindingPatternDisplay(<BindingPattern>bindingElement.name, writer, enclosingDeclaration, flags, symbolStack);
2224+
}
2225+
else {
2226+
if (bindingElement.dotDotDotToken) {
2227+
writePunctuation(writer, SyntaxKind.DotDotDotToken);
22302228
}
2229+
appendSymbolNameOnly(bindingElement.symbol, writer);
22312230
}
22322231
}
22332232

22342233
function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
22352234
if (typeParameters && typeParameters.length) {
22362235
writePunctuation(writer, SyntaxKind.LessThanToken);
2237-
buildDisplayForCommaSeparatedList(typeParameters, writer, enclosingDeclaration, flags, symbolStack, buildTypeParameterDisplay);
2236+
buildDisplayForCommaSeparatedList(typeParameters, writer, p => buildTypeParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack));
22382237
writePunctuation(writer, SyntaxKind.GreaterThanToken);
22392238
}
22402239
}
22412240

2242-
function buildDisplayForCommaSeparatedList<T>(list: T[], writer: SymbolWriter, enclosingDeclaration: Node, flags: TypeFormatFlags, symbolStack: Symbol[], action: (item: T, writer: SymbolWriter, enclosingDeclaration: Node, flags: TypeFormatFlags, symbolStack: Symbol[]) => void) {
2241+
function buildDisplayForCommaSeparatedList<T>(list: T[], writer: SymbolWriter, action: (item: T) => void) {
22432242
for (let i = 0; i < list.length; i++) {
22442243
if (i > 0) {
22452244
writePunctuation(writer, SyntaxKind.CommaToken);
22462245
writeSpace(writer);
22472246
}
2248-
action(list[i], writer, enclosingDeclaration, flags, symbolStack);
2247+
action(list[i]);
22492248
}
22502249
}
22512250

tests/baselines/reference/arrowFunctionExpressions.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ var p6 = ({ a }) => { };
8888
>a : any
8989

9090
var p7 = ({ a: { b } }) => { };
91-
>p7 : ({a:{b}}: { a: { b: any; }; }) => void
92-
>({ a: { b } }) => { } : ({a:{b}}: { a: { b: any; }; }) => void
91+
>p7 : ({a: {b}}: { a: { b: any; }; }) => void
92+
>({ a: { b } }) => { } : ({a: {b}}: { a: { b: any; }; }) => void
9393
>a : any
9494
>b : any
9595

@@ -100,8 +100,8 @@ var p8 = ({ a = 1 }) => { };
100100
>1 : number
101101

102102
var p9 = ({ a: { b = 1 } = { b: 1 } }) => { };
103-
>p9 : ({a:{b}}: { a?: { b?: number; }; }) => void
104-
>({ a: { b = 1 } = { b: 1 } }) => { } : ({a:{b}}: { a?: { b?: number; }; }) => void
103+
>p9 : ({a: {b}}: { a?: { b?: number; }; }) => void
104+
>({ a: { b = 1 } = { b: 1 } }) => { } : ({a: {b}}: { a?: { b?: number; }; }) => void
105105
>a : any
106106
>b : number
107107
>1 : number

tests/baselines/reference/declarationEmitDestructuring1.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { }
2121
>c1 : string
2222

2323
function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { }
24-
>baz : ({a2, b2:{b1, c1}}: { a2: number; b2: { b1: boolean; c1: string; }; }) => void
24+
>baz : ({a2, b2: {b1, c1}}: { a2: number; b2: { b1: boolean; c1: string; }; }) => void
2525
>a2 : number
2626
>b2 : any
2727
>b1 : boolean

tests/baselines/reference/declarationEmit_bindingPatters.js renamed to tests/baselines/reference/declarationEmit_bindingPatterns.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//// [declarationEmit_bindingPatters.ts]
1+
//// [declarationEmit_bindingPatterns.ts]
22

33
const k = ({x: z = 'y'}) => { }
44

55
var a;
66
function f({} = a, [] = a, { p: {} = a} = a) {
77
}
88

9-
//// [declarationEmit_bindingPatters.js]
9+
//// [declarationEmit_bindingPatterns.js]
1010
var k = function (_a) {
1111
var _b = _a.x, z = _b === void 0 ? 'y' : _b;
1212
};
@@ -18,8 +18,8 @@ function f(_a, _b, _c) {
1818
}
1919

2020

21-
//// [declarationEmit_bindingPatters.d.ts]
22-
declare const k: ({x:z}: {
21+
//// [declarationEmit_bindingPatterns.d.ts]
22+
declare const k: ({x: z}: {
2323
x?: string;
2424
}) => void;
2525
declare var a: any;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/declarationEmit_bindingPatterns.ts ===
2+
3+
const k = ({x: z = 'y'}) => { }
4+
>k : Symbol(k, Decl(declarationEmit_bindingPatterns.ts, 1, 5))
5+
>x : Symbol(x)
6+
>z : Symbol(z, Decl(declarationEmit_bindingPatterns.ts, 1, 12))
7+
8+
var a;
9+
>a : Symbol(a, Decl(declarationEmit_bindingPatterns.ts, 3, 3))
10+
11+
function f({} = a, [] = a, { p: {} = a} = a) {
12+
>f : Symbol(f, Decl(declarationEmit_bindingPatterns.ts, 3, 6))
13+
>a : Symbol(a, Decl(declarationEmit_bindingPatterns.ts, 3, 3))
14+
>a : Symbol(a, Decl(declarationEmit_bindingPatterns.ts, 3, 3))
15+
>a : Symbol(a, Decl(declarationEmit_bindingPatterns.ts, 3, 3))
16+
>a : Symbol(a, Decl(declarationEmit_bindingPatterns.ts, 3, 3))
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/declarationEmit_bindingPatterns.ts ===
2+
3+
const k = ({x: z = 'y'}) => { }
4+
>k : ({x: z}: { x?: string; }) => void
5+
>({x: z = 'y'}) => { } : ({x: z}: { x?: string; }) => void
6+
>x : any
7+
>z : string
8+
>'y' : string
9+
10+
var a;
11+
>a : any
12+
13+
function f({} = a, [] = a, { p: {} = a} = a) {
14+
>f : ({}?: any, []?: any, {p: {}}?: any) => void
15+
>a : any
16+
>a : any
17+
>p : any
18+
>a : any
19+
>a : any
20+
}

tests/baselines/reference/declarationEmit_bindingPatters.symbols

-17
This file was deleted.

tests/baselines/reference/declarationEmit_bindingPatters.types

-20
This file was deleted.

tests/baselines/reference/destructuringInFunctionType.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type T3 = ([{ a: b }, { b: a }]);
4040
>a : a
4141

4242
type F3 = ([{ a: b }, { b: a }]) => void;
43-
>F3 : ([{a:b}, {b:a}]: [{ a: any; }, { b: any; }]) => void
43+
>F3 : ([{a: b}, {b: a}]: [{ a: any; }, { b: any; }]) => void
4444
>a : any
4545
>b : any
4646
>b : any
@@ -53,13 +53,13 @@ type T4 = ([{ a: [b, c] }]);
5353
>c : c
5454

5555
type F4 = ([{ a: [b, c] }]) => void;
56-
>F4 : ([{a:[b, c]}]: [{ a: [any, any]; }]) => void
56+
>F4 : ([{a: [b, c]}]: [{ a: [any, any]; }]) => void
5757
>a : any
5858
>b : any
5959
>c : any
6060

6161
type C1 = new ([{ a: [b, c] }]) => void;
62-
>C1 : new ([{a:[b, c]}]: [{ a: [any, any]; }]) => void
62+
>C1 : new ([{a: [b, c]}]: [{ a: [any, any]; }]) => void
6363
>a : any
6464
>b : any
6565
>c : any

tests/baselines/reference/destructuringWithLiteralInitializers.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ f6({ x: 1, y: 1 });
170170

171171
// (arg?: { a: { x?: number, y?: number } }) => void
172172
function f7({ a: { x = 0, y = 0 } } = { a: {} }) { }
173-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
173+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
174174
>a : any
175175
>x : number
176176
>0 : number
@@ -182,18 +182,18 @@ function f7({ a: { x = 0, y = 0 } } = { a: {} }) { }
182182

183183
f7();
184184
>f7() : void
185-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
185+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
186186

187187
f7({ a: {} });
188188
>f7({ a: {} }) : void
189-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
189+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
190190
>{ a: {} } : { a: {}; }
191191
>a : {}
192192
>{} : {}
193193

194194
f7({ a: { x: 1 } });
195195
>f7({ a: { x: 1 } }) : void
196-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
196+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
197197
>{ a: { x: 1 } } : { a: { x: number; }; }
198198
>a : { x: number; }
199199
>{ x: 1 } : { x: number; }
@@ -202,7 +202,7 @@ f7({ a: { x: 1 } });
202202

203203
f7({ a: { y: 1 } });
204204
>f7({ a: { y: 1 } }) : void
205-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
205+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
206206
>{ a: { y: 1 } } : { a: { y: number; }; }
207207
>a : { y: number; }
208208
>{ y: 1 } : { y: number; }
@@ -211,7 +211,7 @@ f7({ a: { y: 1 } });
211211

212212
f7({ a: { x: 1, y: 1 } });
213213
>f7({ a: { x: 1, y: 1 } }) : void
214-
>f7 : ({a:{x, y}}?: { a: { x?: number; y?: number; }; }) => void
214+
>f7 : ({a: {x, y}}?: { a: { x?: number; y?: number; }; }) => void
215215
>{ a: { x: 1, y: 1 } } : { a: { x: number; y: number; }; }
216216
>a : { x: number; y: number; }
217217
>{ x: 1, y: 1 } : { x: number; y: number; }

tests/baselines/reference/emitArrowFunctionES6.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ var p6 = ({ a }) => { };
7575
>a : any
7676

7777
var p7 = ({ a: { b } }) => { };
78-
>p7 : ({a:{b}}: { a: { b: any; }; }) => void
79-
>({ a: { b } }) => { } : ({a:{b}}: { a: { b: any; }; }) => void
78+
>p7 : ({a: {b}}: { a: { b: any; }; }) => void
79+
>({ a: { b } }) => { } : ({a: {b}}: { a: { b: any; }; }) => void
8080
>a : any
8181
>b : any
8282

@@ -87,8 +87,8 @@ var p8 = ({ a = 1 }) => { };
8787
>1 : number
8888

8989
var p9 = ({ a: { b = 1 } = { b: 1 } }) => { };
90-
>p9 : ({a:{b}}: { a?: { b?: number; }; }) => void
91-
>({ a: { b = 1 } = { b: 1 } }) => { } : ({a:{b}}: { a?: { b?: number; }; }) => void
90+
>p9 : ({a: {b}}: { a?: { b?: number; }; }) => void
91+
>({ a: { b = 1 } = { b: 1 } }) => { } : ({a: {b}}: { a?: { b?: number; }; }) => void
9292
>a : any
9393
>b : number
9494
>1 : number

tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@
6262
}
6363

6464
function f({} = a, [] = a, { p: {} = a} = a) {
65-
>f : ({}?: any, []?: any, {p:{}}?: any) => ({}?: any, []?: any, {p:{}}?: any) => any
65+
>f : ({}?: any, []?: any, {p: {}}?: any) => ({}?: any, []?: any, {p: {}}?: any) => any
6666
>a : any
6767
>a : any
6868
>p : any
6969
>a : any
7070
>a : any
7171

7272
return ({} = a, [] = a, { p: {} = a } = a) => a;
73-
>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, {p:{}}?: any) => any
73+
>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, {p: {}}?: any) => any
7474
>a : any
7575
>a : any
7676
>p : any

tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@
6262
}
6363

6464
function f({} = a, [] = a, { p: {} = a} = a) {
65-
>f : ({}?: any, []?: any, {p:{}}?: any) => ({}?: any, []?: any, {p:{}}?: any) => any
65+
>f : ({}?: any, []?: any, {p: {}}?: any) => ({}?: any, []?: any, {p: {}}?: any) => any
6666
>a : any
6767
>a : any
6868
>p : any
6969
>a : any
7070
>a : any
7171

7272
return ({} = a, [] = a, { p: {} = a } = a) => a;
73-
>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, {p:{}}?: any) => any
73+
>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, {p: {}}?: any) => any
7474
>a : any
7575
>a : any
7676
>p : any

tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no
3737
>"none" : string
3838

3939
function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) {
40-
>foo1 : ({skills:{primary:primaryA, secondary:secondaryA}}: Robot) => void
40+
>foo1 : ({skills: {primary: primaryA, secondary: secondaryA}}: Robot) => void
4141
>skills : any
4242
>primary : any
4343
>primaryA : string
@@ -53,7 +53,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) {
5353
>primaryA : string
5454
}
5555
function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) {
56-
>foo2 : ({name:nameC, skills:{primary:primaryB, secondary:secondaryB}}: Robot) => void
56+
>foo2 : ({name: nameC, skills: {primary: primaryB, secondary: secondaryB}}: Robot) => void
5757
>name : any
5858
>nameC : string
5959
>skills : any
@@ -87,12 +87,12 @@ function foo3({ skills }: Robot) {
8787

8888
foo1(robotA);
8989
>foo1(robotA) : void
90-
>foo1 : ({skills:{primary:primaryA, secondary:secondaryA}}: Robot) => void
90+
>foo1 : ({skills: {primary: primaryA, secondary: secondaryA}}: Robot) => void
9191
>robotA : Robot
9292

9393
foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
9494
>foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
95-
>foo1 : ({skills:{primary:primaryA, secondary:secondaryA}}: Robot) => void
95+
>foo1 : ({skills: {primary: primaryA, secondary: secondaryA}}: Robot) => void
9696
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
9797
>name : string
9898
>"Edger" : string
@@ -105,12 +105,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming"
105105

106106
foo2(robotA);
107107
>foo2(robotA) : void
108-
>foo2 : ({name:nameC, skills:{primary:primaryB, secondary:secondaryB}}: Robot) => void
108+
>foo2 : ({name: nameC, skills: {primary: primaryB, secondary: secondaryB}}: Robot) => void
109109
>robotA : Robot
110110

111111
foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
112112
>foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
113-
>foo2 : ({name:nameC, skills:{primary:primaryB, secondary:secondaryB}}: Robot) => void
113+
>foo2 : ({name: nameC, skills: {primary: primaryB, secondary: secondaryB}}: Robot) => void
114114
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
115115
>name : string
116116
>"Edger" : string

0 commit comments

Comments
 (0)