@@ -725,6 +725,12 @@ namespace ts {
725725 }
726726
727727 function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : Diagnostic [ ] {
728+ // For JavaScript files, we report semantic errors for using TypeScript-only
729+ // constructs from within a JavaScript file as syntactic errors.
730+ if ( isSourceFileJavaScript ( sourceFile ) && ! sourceFile . parseJavaScriptDiagnostics ) {
731+ sourceFile . parseJavaScriptDiagnostics = getJavaScriptSemanticDiagnosticsForFile ( sourceFile ) ;
732+ sourceFile . parseDiagnostics = sourceFile . parseDiagnostics . concat ( sourceFile . parseJavaScriptDiagnostics ) ;
733+ }
728734 return sourceFile . parseDiagnostics ;
729735 }
730736
@@ -757,12 +763,10 @@ namespace ts {
757763
758764 Debug . assert ( ! ! sourceFile . bindDiagnostics ) ;
759765 const bindDiagnostics = sourceFile . bindDiagnostics ;
760- // For JavaScript files, we don't want to report the normal typescript semantic errors.
761- // Instead, we just report errors for using TypeScript-only constructs from within a
762- // JavaScript file.
763- const checkDiagnostics = isSourceFileJavaScript ( sourceFile ) ?
764- getJavaScriptSemanticDiagnosticsForFile ( sourceFile ) :
765- typeChecker . getDiagnostics ( sourceFile , cancellationToken ) ;
766+ // For JavaScript files, we don't want to report semantic errors.
767+ // Instead, we'll report errors for using TypeScript-only constructs from within a
768+ // JavaScript file when we get syntactic diagnostics for the file.
769+ const checkDiagnostics = isSourceFileJavaScript ( sourceFile ) ? [ ] : typeChecker . getDiagnostics ( sourceFile , cancellationToken ) ;
766770 const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
767771 const programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
768772
0 commit comments