@@ -671,17 +671,22 @@ 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+ [ 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+ ] ,
685690] ) ;
686691
687692/**
@@ -700,7 +705,13 @@ const topLevelAwaitDiagnosticCodes = [
700705 * Check if a function can recover gracefully.
701706 */
702707function 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 (
711+ deps === null ||
712+ ( deps && error . diagnosticCodes . some ( ( code ) => deps . has ( code ) ) )
713+ ) ;
714+ } ) ;
704715}
705716
706717/**
0 commit comments