8000 Do not add extra space for ommited expressions. · sweshgit/TypeScript@4bf5f82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bf5f82

Browse files
committed
Do not add extra space for ommited expressions.
1 parent 8b9afce commit 4bf5f82

9 files changed

+39
-40
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,23 +2211,22 @@ namespace ts {
22112211

22122212
function buildBindingElementDisplay(bindingElement: BindingElement, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
22132213
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
2214-
writeSpace(writer);
2214+
return;
22152215
}
2216-
else if (bindingElement.kind === SyntaxKind.BindingElement) {
2217-
if (bindingElement.propertyName) {
2218-
writer.writeSymbol(getTextOfNode(bindingElement.propertyName), bindingElement.symbol);
2219-
writePunctuation(writer, SyntaxKind.ColonToken);
2216+
Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
2217+
if (bindingElement.propertyName) {
2218+
writer.writeSymbol(getTextOfNode(bindingElement.propertyName), bindingElement.symbol);
2219+
writePunctuation(writer, SyntaxKind.ColonToken);
2220+
}
2221+
if (bindingElement.name) {
2222+
if (isBindingPattern(bindingElement.name)) {
2223+
buildBindingPatternDisplay(<BindingPattern>bindingElement.name, writer, enclosingDeclaration, flags, symbolStack);
22202224
}
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);
2225+
else {
2226+
if (bindingElement.dotDotDotToken) {
2227+
writePunctuation(writer, SyntaxKind.DotDotDotToken);
22302228
}
2229+
appendSymbolNameOnly(bindingElement.symbol, writer);
22312230
}
22322231
}
22332232
}

tests/baselines/reference/arrayBindingPatternOmittedExpressions.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var results: string[];
2525

2626

2727
function f([, a, , b, , , , s, , , ] = results) {
28-
>f : ([ , a, , b, , , , s, , ,]?: string[]) => void
28+
>f : ([, a, , b, , , , s, , ,]?: string[]) => void
2929
> : undefined
3030
>a : string
3131
> : undefined

tests/baselines/reference/arrowFunctionExpressions.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ var p2 = ([...a]) => { };
6565
>a : any[]
6666

6767
var p3 = ([, a]) => { };
68-
>p3 : ([ , a]: [any, any]) => void
69-
>([, a]) => { } : ([ , a]: [any, any]) => void
68+
>p3 : ([, a]: [any, any]) => void
69+
>([, a]) => { } : ([, a]: [any, any]) => void
7070
> : undefined
7171
>a : any
7272

7373
var p4 = ([, ...a]) => { };
74-
>p4 : ([ , ...a]: any[]) => void
75-
>([, ...a]) => { } : ([ , ...a]: any[]) => void
74+
>p4 : ([, ...a]: any[]) => void
75+
>([, ...a]) => { } : ([, ...a]: any[]) => void
7676
> : undefined
7777
>a : any[]
7878

tests/baselines/reference/declarationEmitDestructuring5.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
=== tests/cases/compiler/declarationEmitDestructuring5.ts ===
22
function baz([, z, , ]) { }
3-
>baz : ([ , z, ,]: [any, any, any]) => void
3+
>baz : ([, z, ,]: [any, any, any]) => void
44
> : undefined
55
>z : any
66
> : undefined
77

88
function foo([, b, ]: [any, any]): void { }
9-
>foo : ([ , b,]: [any, any]) => void
9+
>foo : ([, b,]: [any, any]) => void
1010
> : undefined
1111
>b : any
1212

1313
function bar([z, , , ]) { }
14-
>bar : ([z, , ,]: [any, any, any]) => void
14+
>bar : ([z, , ,]: [any, any, any]) => void
1515
>z : any
1616
> : undefined
1717
> : undefined
1818

1919
function bar1([z, , , ] = [1, 3, 4, 6, 7]) { }
20-
>bar1 : ([z, , ,]?: [number, number, number, number, number]) => void
20+
>bar1 : ([z, , ,]?: [number, number, number, number, number]) => void
2121
>z : number
2222
> : undefined
2323
> : undefined
@@ -29,7 +29,7 @@ function bar1([z, , , ] = [1, 3, 4, 6, 7]) { }
2929
>7 : number
3030

3131
function bar2([,,z, , , ]) { }
32-
>bar2 : ([ , , z, , ,]: [any, any, any, any, any]) => void
32+
>bar2 : ([, , z, , ,]: [any, any, any, any, any]) => void
3333
> : undefined
3434
> : undefined
3535
>z : any

tests/baselines/reference/emitArrowFunctionES6.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ var p2 = ([...a]) => { };
5252
>a : any[]
5353

5454
var p3 = ([, a]) => { };
55-
>p3 : ([ , a]: [any, any]) => void
56-
>([, a]) => { } : ([ , a]: [any, any]) => void
55+
>p3 : ([, a]: [any, any]) => void
56+
>([, a]) => { } : ([, a]: [any, any]) => void
5757
> : undefined
5858
>a : any
5959

6060
var p4 = ([, ...a]) => { };
61-
>p4 : ([ , ...a]: Iterable<any>) => void
62-
>([, ...a]) => { } : ([ , ...a]: Iterable<any>) => void
61+
>p4 : ([, ...a]: Iterable<any>) => void
< 935E code>62+
>([, ...a]) => { } : ([, ...a]: Iterable<any>) => void
6363
> : undefined
6464
>a : any[]
6565

tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var robotA: Robot = [1, "mower", "mowing"];
1818
>"mowing" : string
1919

2020
function foo1([, nameA]: Robot) {
21-
>foo1 : ([ , nameA]: [number, string, string]) => void
21+
>foo1 : ([, nameA]: [number, string, string]) => void
2222
> : undefined
2323
>nameA : string
2424
>Robot : [number, string, string]
@@ -75,12 +75,12 @@ function foo4([numberA3, ...robotAInfo]: Robot) {
7575

7676
foo1(robotA);
7777
>foo1(robotA) : void
78-
>foo1 : ([ , nameA]: [number, string, string]) => void
78+
>foo1 : ([, nameA]: [number, string, string]) => void
7979
>robotA : [number, string, string]
8080

8181
foo1([2, "trimmer", "trimming"]);
8282
>foo1([2, "trimmer", "trimming"]) : void
83-
>foo1 : ([ , nameA]: [number, string, string]) => void
83+
>foo1 : ([, nameA]: [number, string, string]) => void
8484
>[2, "trimmer", "trimming"] : [number, string, string]
8585
>2 : number
8686
>"trimmer" : string

tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern2.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var robotA: Robot = ["trimmer", ["trimming", "edging"]];
1919
>"edging" : string
2020

2121
function foo1([, skillA]: Robot) {
22-
>foo1 : ([ , skillA]: [string, [string, string]]) => void
22+
>foo1 : ([, skillA]: [string, [string, string]]) => void
2323
> : undefined
2424
>skillA : [string, string]
2525
>Robot : [string, [string, string]]
@@ -75,12 +75,12 @@ function foo4([...multiRobotAInfo]: Robot) {
7575

7676
foo1(robotA);
7777
>foo1(robotA) : void
78-
>foo1 : ([ , skillA]: [string, [string, string]]) => void
78+
>foo1 : ([, skillA]: [string, [string, string]]) => void
7979
>robotA : [string, [string, string]]
8080

8181
foo1(["roomba", ["vaccum", "mopping"]]);
8282
>foo1(["roomba", ["vaccum", "mopping"]]) : void
83-
>foo1 : ([ , skillA]: [string, [string, string]]) => void
83+
>foo1 : ([, skillA]: [string, [string, string]]) => void
8484
>["roomba", ["vaccum", "mopping"]] : [string, [string, string]]
8585
>"roomba" : string
8686
>["vaccum", "mopping"] : [string, string]

tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var robotA: Robot = [1, "mower", "mowing"];
1818
>"mowing" : string
1919

2020
function foo1([, nameA = "noName"]: Robot = [-1, "name", "skill"]) {
21-
>foo1 : ([ , nameA]?: [number, string, string]) => void
21+
>foo1 : ([, nameA]?: [number, string, string]) => void
2222
> : undefined
2323
>nameA : string
2424
>"noName" : string
@@ -104,12 +104,12 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) {
104104

105105
foo1(robotA);
106106
>foo1(robotA) : void
107-
>foo1 : ([ , nameA]?: [number, string, string]) => void
107+
>foo1 : ([, nameA]?: [number, string, string]) => void
108108
>robotA : [number, string, string]
109109

110110
foo1([2, "trimmer", "trimming"]);
111111
>foo1([2, "trimmer", "trimming"]) : void
112-
>foo1 : ([ , nameA]?: [number, string, string]) => void
112+
>foo1 : ([, nameA]?: [number, string, string]) => void
113113
>[2, "trimmer", "trimming"] : [number, string, string]
114114
>2 : number
115115
>"trimmer" : string

tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues2.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var robotA: Robot = ["trimmer", ["trimming", "edging"]];
1919
>"edging" : string
2020

2121
function foo1([, skillA = ["noSkill", "noSkill"]]: Robot= ["name", ["skill1", "skill2"]]) {
22-
>foo1 : ([ , skillA]?: [string, string[]]) => void
22+
>foo1 : ([, skillA]?: [string, string[]]) => void
2323
> : undefined
2424
>skillA : string[]
2525
>["noSkill", "noSkill"] : string[]
@@ -88,12 +88,12 @@ function foo3([nameMA = "noName", [
8888

8989
foo1(robotA);
9090
>foo1(robotA) : void
91-
>foo1 : ([ , skillA]?: [string, string[]]) => void
91+
>foo1 : ([, skillA]?: [string, string[]]) => void
9292
>robotA : [string, string[]]
9393

9494
foo1(["roomba", ["vaccum", "mopping"]]);
9595
>foo1(["roomba", ["vaccum", "mopping"]]) : void
96-
>foo1 : ([ , skillA]?: [string, string[]]) => void
96+
>foo1 : ([, skillA]?: [string, string[]]) => void
9797
>["roomba", ["vaccum", "mopping"]] : [string, string[]]
9898
>"roomba" : string
9999
>["vaccum", "mopping"] : string[]

0 commit comments

Comments
 (0)
0