@@ -9,15 +9,24 @@ function createArrowFunction(type: ts.Type, rootName: string, optional: boolean,
9
9
const functionMap : VisitorContext [ 'functionMap' ] = new Map ( ) ;
10
10
const functionNames : VisitorContext [ 'functionNames' ] = new Set ( ) ;
11
11
const visitorContext = { ...partialVisitorContext , functionNames, functionMap } ;
12
+ const emitDetailedErrors = ! ! visitorContext . options . emitDetailedErrors ;
12
13
const functionName = partialVisitorContext . options . shortCircuit
13
14
? visitShortCircuit ( visitorContext )
14
15
: ( optional
15
16
? visitUndefinedOrType ( type , visitorContext )
16
17
: visitType ( type , visitorContext )
17
18
) ;
18
19
19
- const errorIdentifier = ts . createIdentifier ( 'error' ) ;
20
- const declarations = sliceMapValues ( functionMap ) ;
20
+ const variableDeclarations : ts . VariableStatement [ ] = [ ] ;
21
+ if ( emitDetailedErrors ) {
22
+ variableDeclarations . push (
23
+ ts . createVariableStatement (
24
+ [ ts . createModifier ( ts . SyntaxKind . ConstKeyword ) ] ,
25
+ [ ts . createVariableDeclaration ( VisitorUtils . pathIdentifier , undefined , ts . createArrayLiteral ( [ ts . createStringLiteral ( rootName ) ] ) ) ]
26
+ )
27
+ ) ;
28
+ }
29
+ const functionDeclarations = sliceMapValues ( functionMap ) ;
21
30
22
31
return ts . createArrowFunction (
23
32
undefined ,
@@ -35,16 +44,9 @@ function createArrowFunction(type: ts.Type, rootName: string, optional: boolean,
35
44
undefined ,
36
45
undefined ,
37
46
ts . createBlock ( [
38
- ts . createVariableStatement (
39
- [ ts . createModifier ( ts . SyntaxKind . ConstKeyword ) ] ,
40
- [ ts . createVariableDeclaration ( VisitorUtils . pathIdentifier , undefined , ts . createArrayLiteral ( [ ts . createStringLiteral ( rootName ) ] ) ) ]
41
- ) ,
42
- ...declarations ,
43
- ts . createVariableStatement (
44
- [ ts . createModifier ( ts . SyntaxKind . ConstKeyword ) ] ,
45
- [ ts . createVariableDeclaration ( errorIdentifier , undefined , ts . createCall ( ts . createIdentifier ( functionName ) , undefined , [ VisitorUtils . objectIdentifier ] ) ) ]
46
- ) ,
47
- ts . createReturn ( errorIdentifier )
47
+ ...variableDeclarations ,
48
+ ...functionDeclarations ,
49
+ ts . createReturn ( ts . createCall ( ts . createIdentifier ( functionName ) , undefined , [ VisitorUtils . objectIdentifier ] ) )
48
50
] )
49
51
) ;
50
52
}
0 commit comments