@@ -9,15 +9,24 @@ function createArrowFunction(type: ts.Type, rootName: string, optional: boolean,
99 const functionMap : VisitorContext [ 'functionMap' ] = new Map ( ) ;
1010 const functionNames : VisitorContext [ 'functionNames' ] = new Set ( ) ;
1111 const visitorContext = { ...partialVisitorContext , functionNames, functionMap } ;
12+ const emitDetailedErrors = ! ! visitorContext . options . emitDetailedErrors ;
1213 const functionName = partialVisitorContext . options . shortCircuit
1314 ? visitShortCircuit ( visitorContext )
1415 : ( optional
1516 ? visitUndefinedOrType ( type , visitorContext )
1617 : visitType ( type , visitorContext )
1718 ) ;
1819
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 ) ;
2130
2231 return ts . createArrowFunction (
2332 undefined ,
@@ -35,16 +44,9 @@ function createArrowFunction(type: ts.Type, rootName: string, optional: boolean,
3544 undefined ,
3645 undefined ,
3746 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 ] ) )
4850 ] )
4951 ) ;
5052}
0 commit comments