Skip to content

Commit caa792d

Browse files
committed
Format code
1 parent c60d510 commit caa792d

File tree

3 files changed

+37
-47
lines changed

3 files changed

+37
-47
lines changed

snapshots/input/syntax/src/constructor.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
// export class Constructor {
2-
// constructor(public readonly property: number) {}
3-
// }
4-
51
namespace Yay {
62
export class SuperConstructor {
7-
constructor(public readonly property: number) {
8-
}
3+
constructor(public readonly property: number) {}
94
}
105

116
export namespace Woo {
@@ -16,8 +11,7 @@ namespace Yay {
1611
}
1712

1813
export class SuperConstructor2 {
19-
constructor(public readonly property: number) {
20-
}
14+
constructor(public readonly property: number) {}
2115
}
2216

2317
export function useConstructor(): Yay.SuperConstructor {

snapshots/output/syntax/src/constructor.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
// export class Constructor {
1+
namespace Yay {
22
// definition syntax 1.0.0 src/`constructor.ts`/
33
//documentation ```ts\nmodule "constructor.ts"\n```
4-
// constructor(public readonly property: number) {}
5-
// }
6-
7-
namespace Yay {
84
// ^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/
95
// documentation ```ts\nYay: typeof Yay\n```
106
export class SuperConstructor {
117
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#
128
// documentation ```ts\nclass SuperConstructor\n```
13-
constructor(public readonly property: number) {
9+
constructor(public readonly property: number) {}
1410
// ^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#`<constructor>`().
1511
// documentation ```ts\nconstructor(property: number): SuperConstructor\n```
1612
// ^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#`<constructor>`().(property)
1713
// documentation ```ts\n(property) property: number\n```
18-
}
1914
}
2015

2116
export namespace Woo {
@@ -34,12 +29,11 @@
3429
export class SuperConstructor2 {
3530
// ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#
3631
// documentation ```ts\nclass SuperConstructor2\n```
37-
constructor(public readonly property: number) {
32+
constructor(public readonly property: number) {}
3833
// ^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#`<constructor>`().
3934
// documentation ```ts\nconstructor(property: number): SuperConstructor2\n```
4035
// ^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#`<constructor>`().(property)
4136
// documentation ```ts\n(property) property: number\n```
42-
}
4337
}
4438

4539
export function useConstructor(): Yay.SuperConstructor {

src/FileIndexer.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class FileIndexer {
7777
this.visitSymbolOccurrence(node, sym)
7878
}
7979
}
80-
80+
8181
ts.forEachChild(node, node => this.visit(node))
8282
}
8383

@@ -117,7 +117,9 @@ export class FileIndexer {
117117
if (isDefinitionNode) {
118118
role |= scip.scip.SymbolRole.Definition
119119
}
120-
const declarations = ts.isConstructorDeclaration(node) ? [node] : isDefinitionNode
120+
const declarations = ts.isConstructorDeclaration(node)
121+
? [node]
122+
: isDefinitionNode
121123
? // Don't emit ambiguous definition at definition-site. You can reproduce
122124
// ambiguous results by triggering "Go to definition" in VS Code on `Conflict`
123125
// in the example below:
@@ -131,19 +133,15 @@ export class FileIndexer {
131133
let scipSymbol = this.scipSymbol(declaration)
132134

133135
if (
134-
(
135-
(
136-
ts.isIdentifier(node) &&
137-
ts.isNewExpression(node.parent)
138-
) ||
139-
(
140-
ts.isPropertyAccessExpression(node.parent) &&
141-
ts.isNewExpression(node.parent.parent)
142-
)
143-
) &&
136+
((ts.isIdentifier(node) && ts.isNewExpression(node.parent)) ||
137+
(ts.isPropertyAccessExpression(node.parent) &&
138+
ts.isNewExpression(node.parent.parent))) &&
144139
ts.isClassDeclaration(declaration)
145140
) {
146-
scipSymbol = ScipSymbol.global(scipSymbol, methodDescriptor("<constructor>"))
141+
scipSymbol = ScipSymbol.global(
142+
scipSymbol,
143+
methodDescriptor('<constructor>')
144+
)
147145
}
148146

149147
if (scipSymbol.isEmpty()) {
@@ -491,26 +489,28 @@ export class FileIndexer {
491489
return undefined
492490
}
493491

494-
private asSignatureDeclaration(node: ts.Node, sym: ts.Symbol): ts.SignatureDeclaration | undefined {
495-
const declaration = sym.declarations?.[0]
496-
if (!declaration) {
497-
return undefined
498-
}
499-
return ts.isConstructorDeclaration(node)
500-
? node
501-
: ts.isFunctionDeclaration(declaration)
502-
? declaration
503-
: ts.isMethodDeclaration(declaration)
504-
? declaration
505-
: undefined
506-
}
507-
508492
private signatureForDocumentation(node: ts.Node, sym: ts.Symbol): string {
509493
const kind = scriptElementKind(node, sym)
510494
const type = (): string =>
511495
this.checker.typeToString(this.checker.getTypeAtLocation(node))
496+
const asSignatureDeclaration = (
497+
node: ts.Node,
498+
sym: ts.Symbol
499+
): ts.SignatureDeclaration | undefined => {
500+
const declaration = sym.declarations?.[0]
501+
if (!declaration) {
502+
return undefined
503+
}
504+
return ts.isConstructorDeclaration(node)
505+
? node
506+
: ts.isFunctionDeclaration(declaration)
507+
? declaration
508+
: ts.isMethodDeclaration(declaration)
509+
? declaration
510+
: undefined
511+
}
512512
const signature = (): string | undefined => {
513-
const signatureDeclaration = this.asSignatureDeclaration(node, sym)
513+
const signatureDeclaration = asSignatureDeclaration(node, sym)
514514
if (!signatureDeclaration) {
515515
return undefined
516516
}
@@ -535,7 +535,7 @@ export class FileIndexer {
535535
case ts.ScriptElementKind.classElement:
536536
case ts.ScriptElementKind.localClassElement:
537537
if (ts.isConstructorDeclaration(node)) {
538-
return 'constructor' + signature()
538+
return 'constructor' + signature()!
539539
}
540540
return 'class ' + node.getText()
541541
case ts.ScriptElementKind.interfaceElement:
@@ -798,5 +798,7 @@ function declarationName(node: ts.Node): ts.Node | undefined {
798798
* ^^^^^^^^^^^^^^^^^^^^^ node.parent
799799
*/
800800
function isDefinition(node: ts.Node): boolean {
801-
return declarationName(node.parent) === node || ts.isConstructorDeclaration(node)
801+
return (
802+
declarationName(node.parent) === node || ts.isConstructorDeclaration(node)
803+
)
802804
}

0 commit comments

Comments
 (0)