@@ -671,17 +671,25 @@ function lineCount(value: string) {
671671/**
672672 * TS diagnostic codes which are recoverable, meaning that the user likely entered and incomplete line of code
673673 * 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.
674676 */
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+ [
686+ 2391 , // "Function implementation is missing or not immediately following the declaration."
687+ new Set ( [ 1005 ] )
688+ ] ,
689+ [
690+ 7010 , // "Function, which lacks return-type annotation, implicitly has an 'any' return type."
691+ new Set ( [ 1005 ] ) // happens when fn signature spread across multiple lines: 'function a(\nb: any\n) {'
692+ ]
685693] ) ;
686694
687695/**
@@ -700,7 +708,10 @@ const topLevelAwaitDiagnosticCodes = [
700708 * Check if a function can recover gracefully.
701709 */
702710function isRecoverable ( error : TSError ) {
703- return error . diagnosticCodes . every ( ( code ) => RECOVERY_CODES . has ( code ) ) ;
711+ return error . diagnosticCodes . every ( ( code ) => {
712+ const deps = RECOVERY_CODES . get ( code ) ;
713+ return deps === null || ( deps && error . diagnosticCodes . some ( code => deps . has ( code ) ) ) ;
714+ } ) ;
704715}
705716
706717/**
0 commit comments