@@ -91,14 +91,6 @@ type nodeBuilderImpl struct {
91
91
links core.LinkStore [* ast.Node , NodeBuilderLinks ]
92
92
symbolLinks core.LinkStore [* ast.Symbol , NodeBuilderSymbolLinks ]
93
93
94
- // closures
95
- typeToTypeNode func (t * Type ) * ast.TypeNode
96
- typeReferenceToTypeNode func (t * Type ) * ast.TypeNode
97
- conditionalTypeToTypeNode func (t * Type ) * ast.TypeNode
98
- createTypeNodeFromObjectType func (t * Type ) * ast.TypeNode
99
- isStringNamed func (d * ast.Declaration ) bool
100
- isSingleQuotedStringNamed func (d * ast.Declaration ) bool
101
-
102
94
// state
103
95
ctx * NodeBuilderContext
104
96
}
@@ -111,20 +103,10 @@ const (
111
103
// Node builder utility functions
112
104
113
105
func newNodeBuilderImpl (ch * Checker , e * printer.EmitContext ) nodeBuilderImpl {
114
- result := nodeBuilderImpl {f : e .Factory .AsNodeFactory (), ch : ch , e : e , typeToTypeNode : nil , typeReferenceToTypeNode : nil , conditionalTypeToTypeNode : nil , ctx : nil }
115
- result .initializeClosures ()
106
+ result := nodeBuilderImpl {f : e .Factory .AsNodeFactory (), ch : ch , e : e }
116
107
return result
117
108
}
118
109
119
- func (b * nodeBuilderImpl ) initializeClosures () {
120
- b .typeToTypeNode = b .typeToTypeNodeWorker
121
- b .typeReferenceToTypeNode = b .typeReferenceToTypeNodeWorker
122
- b .conditionalTypeToTypeNode = b .conditionalTypeToTypeNodeWorker
123
- b .createTypeNodeFromObjectType = b .createTypeNodeFromObjectTypeWorker
124
- b .isStringNamed = b .isStringNamedWorker
125
- b .isSingleQuotedStringNamed = b .isSingleQuotedStringNamedWorker
126
- }
127
-
128
110
func (b * nodeBuilderImpl ) saveRestoreFlags () func () {
129
111
flags := b .ctx .flags
130
112
internalFlags := b .ctx .internalFlags
@@ -1976,7 +1958,7 @@ func (b *nodeBuilderImpl) createPropertyNameNodeForIdentifierOrLiteral(name stri
1976
1958
return result
1977
1959
}
1978
1960
1979
- func (b * nodeBuilderImpl ) isStringNamedWorker (d * ast.Declaration ) bool {
1961
+ func (b * nodeBuilderImpl ) isStringNamed (d * ast.Declaration ) bool {
1980
1962
name := ast .GetNameOfDeclaration (d )
1981
1963
if name == nil {
1982
1964
return false
@@ -1992,7 +1974,7 @@ func (b *nodeBuilderImpl) isStringNamedWorker(d *ast.Declaration) bool {
1992
1974
return ast .IsStringLiteral (name )
1993
1975
}
1994
1976
1995
- func (b * nodeBuilderImpl ) isSingleQuotedStringNamedWorker (d * ast.Declaration ) bool {
1977
+ func (b * nodeBuilderImpl ) isSingleQuotedStringNamed (d * ast.Declaration ) bool {
1996
1978
return false // !!!
1997
1979
// TODO: actually support single-quote-style-maintenance
1998
1980
// name := ast.GetNameOfDeclaration(d)
@@ -2216,7 +2198,7 @@ func (b *nodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
2216
2198
}
2217
2199
}
2218
2200
2219
- func (b * nodeBuilderImpl ) createTypeNodeFromObjectTypeWorker (t * Type ) * ast.TypeNode {
2201
+ func (b * nodeBuilderImpl ) createTypeNodeFromObjectType (t * Type ) * ast.TypeNode {
2220
2202
if b .ch .isGenericMappedType (t ) || (t .objectFlags & ObjectFlagsMapped != 0 && t .AsMappedType ().containsError ) {
2221
2203
return b .createMappedTypeNodeFromType (t )
2222
2204
}
@@ -2329,7 +2311,7 @@ func (b *nodeBuilderImpl) createAnonymousTypeNode(t *Type) *ast.TypeNode {
2329
2311
if _ , ok := b .ctx .visitedTypes [typeId ]; ok {
2330
2312
return b .createElidedInformationPlaceholder ()
2331
2313
}
2332
- return b .visitAndTransformType (t , b .createTypeNodeFromObjectType )
2314
+ return b .visitAndTransformType (t , ( * nodeBuilderImpl ) .createTypeNodeFromObjectType )
2333
2315
}
2334
2316
var isInstanceType ast.SymbolFlags
2335
2317
if isClassInstanceSide (b .ch , t ) {
@@ -2355,7 +2337,7 @@ func (b *nodeBuilderImpl) createAnonymousTypeNode(t *Type) *ast.TypeNode {
2355
2337
return b .createElidedInformationPlaceholder ()
2356
2338
}
2357
2339
} else {
2358
- return b .visitAndTransformType (t , b .createTypeNodeFromObjectType )
2340
+ return b .visitAndTransformType (t , ( * nodeBuilderImpl ) .createTypeNodeFromObjectType )
2359
2341
}
2360
2342
} else {
2361
2343
// Anonymous types without a symbol are never circular.
@@ -2386,12 +2368,12 @@ func (b *nodeBuilderImpl) typeToTypeNodeOrCircularityElision(t *Type) *ast.TypeN
2386
2368
}
2387
2369
return b .createElidedInformationPlaceholder ()
2388
2370
}
2389
- return b .visitAndTransformType (t , b .typeToTypeNode )
2371
+ return b .visitAndTransformType (t , ( * nodeBuilderImpl ) .typeToTypeNode )
2390
2372
}
2391
2373
return b .typeToTypeNode (t )
2392
2374
}
2393
2375
2394
- func (b * nodeBuilderImpl ) conditionalTypeToTypeNodeWorker (_t * Type ) * ast.TypeNode {
2376
+ func (b * nodeBuilderImpl ) conditionalTypeToTypeNode (_t * Type ) * ast.TypeNode {
2395
2377
t := _t .AsConditionalType ()
2396
2378
checkTypeNode := b .typeToTypeNode (t .checkType )
2397
2379
b .ctx .approximateLength += 15
@@ -2449,7 +2431,7 @@ func (b *nodeBuilderImpl) getParentSymbolOfTypeParameter(typeParameter *TypePara
2449
2431
return b .ch .getSymbolOfNode (host )
2450
2432
}
2451
2433
2452
- func (b * nodeBuilderImpl ) typeReferenceToTypeNodeWorker (t * Type ) * ast.TypeNode {
2434
+ func (b * nodeBuilderImpl ) typeReferenceToTypeNode (t * Type ) * ast.TypeNode {
2453
2435
var typeArguments []* Type = b .ch .getTypeArguments (t )
2454
2436
if t .Target () == b .ch .globalArrayType || t .Target () == b .ch .globalReadonlyArrayType {
2455
2437
if b .ctx .flags & nodebuilder .FlagsWriteArrayAsGenericType != 0 {
@@ -2583,7 +2565,7 @@ func (b *nodeBuilderImpl) typeReferenceToTypeNodeWorker(t *Type) *ast.TypeNode {
2583
2565
}
2584
2566
}
2585
2567
2586
- func (b * nodeBuilderImpl ) visitAndTransformType (t * Type , transform func (t * Type ) * ast.TypeNode ) * ast.TypeNode {
2568
+ func (b * nodeBuilderImpl ) visitAndTransformType (t * Type , transform func (b * nodeBuilderImpl , t * Type ) * ast.TypeNode ) * ast.TypeNode {
2587
2569
typeId := t .id
2588
2570
isConstructorObject := t .objectFlags & ObjectFlagsAnonymous != 0 && t .symbol != nil && t .symbol .Flags & ast .SymbolFlagsClass != 0
2589
2571
var id * CompositeSymbolIdentity
@@ -2629,7 +2611,7 @@ func (b *nodeBuilderImpl) visitAndTransformType(t *Type, transform func(t *Type)
2629
2611
prevTrackedSymbols := b .ctx .trackedSymbols
2630
2612
b .ctx .trackedSymbols = nil
2631
2613
startLength := b .ctx .approximateLength
2632
- result := transform (t )
2614
+ result := transform (b , t )
2633
2615
addedLength := b .ctx .approximateLength - startLength
2634
2616
if ! b .ctx .reportedDiagnostic && ! b .ctx .encounteredError {
2635
2617
links := b .links .Get (b .ctx .enclosingDeclaration )
@@ -2668,7 +2650,7 @@ func (b *nodeBuilderImpl) visitAndTransformType(t *Type, transform func(t *Type)
2668
2650
// }
2669
2651
}
2670
2652
2671
- func (b * nodeBuilderImpl ) typeToTypeNodeWorker (t * Type ) * ast.TypeNode {
2653
+ func (b * nodeBuilderImpl ) typeToTypeNode (t * Type ) * ast.TypeNode {
2672
2654
inTypeAlias := b .ctx .flags & nodebuilder .FlagsInTypeAlias
2673
2655
b .ctx .flags &^= nodebuilder .FlagsInTypeAlias
2674
2656
@@ -2830,7 +2812,7 @@ func (b *nodeBuilderImpl) typeToTypeNodeWorker(t *Type) *ast.TypeNode {
2830
2812
if objectFlags & ObjectFlagsReference != 0 {
2831
2813
// Debug.assert(t.flags&TypeFlagsObject != 0) // !!!
2832
2814
if t .AsTypeReference ().node != nil {
2833
- return b .visitAndTransformType (t , b .typeReferenceToTypeNode )
2815
+ return b .visitAndTransformType (t , ( * nodeBuilderImpl ) .typeReferenceToTypeNode )
2834
2816
} else {
2835
2817
return b .typeReferenceToTypeNode (t )
2836
2818
}
@@ -2936,7 +2918,7 @@ func (b *nodeBuilderImpl) typeToTypeNodeWorker(t *Type) *ast.TypeNode {
2936
2918
return b .f .NewIndexedAccessTypeNode (objectTypeNode , indexTypeNode )
2937
2919
}
2938
2920
if t .flags & TypeFlagsConditional != 0 {
2939
- return b .visitAndTransformType (t , b .conditionalTypeToTypeNode )
2921
+ return b .visitAndTransformType (t , ( * nodeBuilderImpl ) .conditionalTypeToTypeNode )
2940
2922
}
2941
2923
if t .flags & TypeFlagsSubstitution != 0 {
2942
2924
typeNode := b .typeToTypeNode (t .AsSubstitutionType ().baseType )
0 commit comments