@@ -671,17 +671,22 @@ function lineCount(value: string) {
671
671
/**
672
672
* TS diagnostic codes which are recoverable, meaning that the user likely entered and incomplete line of code
673
673
* and should be prompted for the next. For example, starting a multi-line for() loop and not finishing it.
674
+ * null value means code is always recoverable. `Set` means code is only recoverable when occurring alongside at least one
675
+ * of the other codes.
674
676
*/
675
- const RECOVERY_CODES : Set < number > = new Set ( [
676
- 1003 , // "Identifier expected."
677
- 1005 , // "')' expected."
678
- 1109 , // "Expression expected."
679
- 1126 , // "Unexpected end of text."
680
- 1160 , // "Unterminated template literal."
681
- 1161 , // "Unterminated regular expression literal."
682
- 2355 , // "A function whose declared type is neither 'void' nor 'any' must return a value."
683
- 2391 , // "Function implementation is missing or not immediately following the declaration."
684
- 7010 , // "Function, which lacks return-type annotation, implicitly has an 'any' return type."
677
+ const RECOVERY_CODES : Map < number , Set < number > | null > = new Map ( [
678
+ [ 1003 , null ] , // "Identifier expected."
679
+ [ 1005 , null ] , // "')' expected.", "'}' expected."
680
+ [ 1109 , null ] , // "Expression expected."
681
+ [ 1126 , null ] , // "Unexpected end of text."
682
+ [ 1160 , null ] , // "Unterminated template literal."
683
+ [ 1161 , null ] , // "Unterminated regular expression literal."
684
+ [ 2355 , null ] , // "A function whose declared type is neither 'void' nor 'any' must return a value."
685
+ [ 2391 , null ] , // "Function implementation is missing or not immediately following the declaration."
686
+ [
687
+ 7010 , // "Function, which lacks return-type annotation, implicitly has an 'any' return type."
688
+ new Set ( [ 1005 ] ) // happens when fn signature spread across multiple lines: 'function a(\nb: any\n) {'
689
+ ]
685
690
] ) ;
686
691
687
692
/**
@@ -700,7 +705,10 @@ const topLevelAwaitDiagnosticCodes = [
700
705
* Check if a function can recover gracefully.
701
706
*/
702
707
function isRecoverable ( error : TSError ) {
703
- return error . diagnosticCodes . every ( ( code ) => RECOVERY_CODES . has ( code ) ) ;
708
+ return error . diagnosticCodes . every ( ( code ) => {
709
+ const deps = RECOVERY_CODES . get ( code ) ;
710
+ return deps === null || ( deps && error . diagnosticCodes . some ( code => deps . has ( code ) ) ) ;
711
+ } ) ;
704
712
}
705
713
706
714
/**
0 commit comments