Skip to content

Conversation

jramsay
Copy link
Member

@jramsay jramsay commented Oct 26, 2016

Fix for #11719 - TSServer: JS files should display syntactic errors for TS syntax

For JavaScript files, report semantic errors for using TypeScript-only constructs from within a JavaScript file as syntactic errors.

…only constructs from within a JavaScript file as syntactic errors.
@jramsay
Copy link
Member Author

jramsay commented Oct 26, 2016

// cc: @mhegazy, @vladima , @billti

// For JavaScript files, we report semantic errors for using TypeScript-only
// constructs from within a JavaScript file as syntactic errors.
if (isSourceFileJavaScript(sourceFile) && !sourceFile.parseJavaScriptDiagnostics) {
sourceFile.parseJavaScriptDiagnostics = getJavaScriptSemanticDiagnosticsForFile(sourceFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the name to getJavaScriptSyntacticDiagnosticsForFile

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// constructs from within a JavaScript file as syntactic errors.
if (isSourceFileJavaScript(sourceFile) && !sourceFile.parseJavaScriptDiagnostics) {
sourceFile.parseJavaScriptDiagnostics = getJavaScriptSemanticDiagnosticsForFile(sourceFile);
sourceFile.parseDiagnostics = sourceFile.parseDiagnostics.concat(sourceFile.parseJavaScriptDiagnostics);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would not change the parseDiagnostics here.

if (isSourceFileJavaScript(sourceFile) && !sourceFile.parseJavaScriptDiagnostics) {
sourceFile.parseJavaScriptDiagnostics = getJavaScriptSemanticDiagnosticsForFile(sourceFile);
sourceFile.parseDiagnostics = sourceFile.parseDiagnostics.concat(sourceFile.parseJavaScriptDiagnostics);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider changing it to:

   if (isSourceFileJavaScript(sourceFile))
            if (!sourceFile.additionalSyntacticDiagnostics) {
                sourceFile.additionalSyntacticDiagnostics = getJavaScriptAdditionalSyntacticDiagnosticsForFile(sourceFile);
            }
        return concatenate(sourceFile.additionalSyntacticDiagnostics, sourceFile.parseDiagnostics);
    }
    return sourceFile.parseDiagnostics;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good - done

@jramsay jramsay merged commit 980f9fd into master Oct 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
@jakebailey jakebailey deleted the AddJavaScriptSemanticErrorsToSyntacticErrors branch November 7, 2022 17:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants