-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix #15200: Query for semantic errors on .js files with '@ts-check' with no config file #15260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f6324e7
92d592c
8c33a79
35024b4
420908e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -908,6 +908,13 @@ namespace ts { | |
|
|
||
| function getSemanticDiagnosticsForFileNoCache(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { | ||
| return runWithCancellationToken(() => { | ||
| // If skipLibCheck is enabled, skip reporting errors if file is a declaration file. | ||
| // If skipDefaultLibCheck is enabled, skip reporting errors if file contains a | ||
| // '/// <reference no-default-lib="true"/>' directive. | ||
| if (options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have this check in two places ? I see similar check in checkSourceFileWorker in checker.ts. Do we need to remove that check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, will get that fixed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember now why i did not do that, we call TypeChecker.getDiagnostics from the tests directly. |
||
| return emptyArray; | ||
| } | ||
|
|
||
| const typeChecker = getDiagnosticsProducingTypeChecker(); | ||
|
|
||
| Debug.assert(!!sourceFile.bindDiagnostics); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,15 +25,26 @@ namespace ts.server { | |
| return ((1e9 * seconds) + nanoseconds) / 1000000.0; | ||
| } | ||
|
|
||
| function shouldSkipSemanticCheck(project: Project) { | ||
| if (project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) { | ||
| return project.isJsOnlyProject(); | ||
| } | ||
| else { | ||
| // For configured projects, require that skipLibCheck be set also | ||
| const options = project.getCompilerOptions(); | ||
| return options.skipLibCheck && !options.checkJs && project.isJsOnlyProject(); | ||
| function isDeclarationFileInJSOnlyNonConfiguredProject(project: Project, file: NormalizedPath) { | ||
| // Checking for semantic diagnostics is an expensive process. We want to avoid it if we | ||
| // know for sure it is not needed. | ||
| // For instance, .d.ts files injected by ATA automatically do not produce any relevant | ||
| // errors to a JS- only project. | ||
| // | ||
| // Note that configured projects can set skipLibCheck (on by default in jsconfig.json) to | ||
| // disable checking for declaration files. We only need to verify for inferred projects (e.g. | ||
| // miscellaneous context in VS) and external projects(e.g.VS.csproj project) with only JS | ||
| // files. | ||
| // | ||
| // We still want to check .js files in a JS-only inferred or external project (e.g. if the | ||
| // file has '// @ts-check'). | ||
|
|
||
| if ((project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) && | ||
| project.isJsOnlyProject()) { | ||
| const scriptInfo = project.getScriptInfoForNormalizedPath(file); | ||
| return scriptInfo && !scriptInfo.isJavaScript(); | ||
| } | ||
| return false; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this always returns false for configured projects (as the above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. program.getSemanticDiagnostics should do the right thing for configured projects.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Again, maybe clarify in comments in the function then. It seems this only returns |
||
| } | ||
|
|
||
| interface FileStart { | ||
|
|
@@ -489,7 +500,7 @@ namespace ts.server { | |
| private semanticCheck(file: NormalizedPath, project: Project) { | ||
| try { | ||
| let diags: Diagnostic[] = []; | ||
| if (!shouldSkipSemanticCheck(project)) { | ||
| if (!isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) { | ||
| diags = project.getLanguageService().getSemanticDiagnostics(file); | ||
| } | ||
|
|
||
|
|
@@ -597,7 +608,7 @@ namespace ts.server { | |
|
|
||
| private getDiagnosticsWorker(args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) { | ||
| const { project, file } = this.getFileAndProject(args); | ||
| if (isSemantic && shouldSkipSemanticCheck(project)) { | ||
| if (isSemantic && isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) { | ||
| return []; | ||
| } | ||
| const scriptInfo = project.getScriptInfoForNormalizedPath(file); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // @skipDefaultLibCheck: false | ||
| /// <reference no-default-lib="true"/> | ||
| var x; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| // @skipDefaultLibCheck: false | ||
| "use strict"; | ||
| var eval; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't making much sense to me as written. If you have no-default-lib set to true, then I assume there is no default lib to check - in which case, what difference does skipDefaultLibCheck make?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no-default-libis just a triple-slash directive. it can exist any where.We have two flags, for historic reasons:
/// <reference no-default-lib="true"/>in them. This flag is now deprecated, but we still honor it.