-
Notifications
You must be signed in to change notification settings - Fork 748
Add missing TS6504 diagnostic for JavaScript files without allowJs #2104
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: jakebailey <[email protected]>
jakebailey
left a comment
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.
I think this seems fine?
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.
Pull Request Overview
This PR adds the missing TS6504 diagnostic for JavaScript files compiled without the allowJs option enabled. Previously, tsgo silently ignored these files while tsc reports a helpful error message, making tsgo less user-friendly.
Key Changes
- Modified
internal/compiler/fileloader.goto detect JavaScript files and report TS6504 diagnostic whenallowJsis not enabled - Updated 26 test baseline files to reflect the new behavior, showing convergence with TypeScript's behavior
Reviewed Changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/compiler/fileloader.go | Added logic to detect JS files without allowJs and report TS6504 diagnostic with file inclusion context |
| testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt.diff | Removed diff showing convergence - now properly reports TS6504 for JS files |
| testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt | Added TS6504 error alongside existing TS5052 error |
| testdata/baselines/reference/submodule/compiler/jsFileCompilationWithoutJsExtensions.errors.txt.diff | Removed diff showing convergence |
| testdata/baselines/reference/submodule/compiler/jsFileCompilationWithoutJsExtensions.errors.txt | Added TS6504 error for JS file compilation |
| testdata/baselines/reference/submodule/conformance/nodeModulesAtTypesPriority.errors.txt.diff | Removed diff showing convergence for node_modules JS files |
| testdata/baselines/reference/submodule/conformance/nodeModulesAtTypesPriority.errors.txt | Added TS6504 errors for JS files in node_modules |
| testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=preserve).errors.txt.diff | Removed diff for bundler module resolution |
| testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=preserve).errors.txt | Added TS6504 errors for .cjs and .js files |
| testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=esnext).errors.txt.diff | Removed diff for esnext module |
| testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=esnext).errors.txt | Added TS6504 errors for bundler with esnext |
| testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=preserve).errors.txt.diff | Removed diff for bundler conditions |
| testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=preserve).errors.txt | Added TS6504 errors for .node.js and .web.js files |
| testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=esnext).errors.txt.diff | Removed diff for esnext with bundler conditions |
| testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=esnext).errors.txt | Added TS6504 errors for conditional JS files |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt.diff | Removed diff for node16 module |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt | Added TS6504 error for exports with node16 |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node18).errors.txt.diff | Removed diff for node18 module |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node18).errors.txt | Added TS6504 error for exports with node18 |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node20).errors.txt.diff | Removed diff for node20 module |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node20).errors.txt | Added TS6504 error for exports with node20 |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt.diff | Removed diff for nodenext module |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt | Added TS6504 error for exports with nodenext |
| testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt.diff | Removed diff for bundler module resolution |
| testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt | Added TS6504 errors for multiple JS files with bundler resolution |
| testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt.diff | Removed diff for node16 module resolution |
| testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt | Added TS6504 errors for multiple JS files with node16 resolution |
Co-authored-by: Copilot <[email protected]>
| libFile: libFile, | ||
| includeReason: includeReason, | ||
| }) | ||
| } else if tspath.HasExtension(absPath) { |
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 seems good but arent we currently checking this only for root files and not for resolved triple slash refs or project reference files etc as we did in strada
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.
That's true; Strada had this in getSourceFileFromReferenceWorker which was called by processSourceFile, so we do need to do this somewhere else.
Let's try this for fun:
@copilot Reexamine program.ts's getSourceFileFromReferenceWorker, callers, etc, and place this check in the correct place in the Go implementation.
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.
Fixed in b07f77b. Moved the check from addRootTask to parseTask.load() so it now catches all file inclusion paths (root files, triple-slash references, type references, etc.). Tested with both tsgo a.js and triple-slash references like /// <reference path="helper.js" /> - both now correctly report TS6504.
Moved the TS6504 diagnostic check from addRootTask to parseTask.load() so it catches all file inclusion paths (root files, triple-slash refs, type refs, etc.), not just root files. This matches TypeScript's behavior where getSourceFileFromReferenceWorker is called for all file types. Co-authored-by: jakebailey <[email protected]>
|
This introduces a data race. I'm not sure This PR has: Which is obviously wrong, but |
|
@copilot See above. Make |
Added mutex protection to includeProcessor to prevent concurrent access to processingDiagnostics and fileIncludeReasons. The data race was occurring when multiple goroutines in parseTask.load() called addProcessingDiagnostic simultaneously. Changes: - Added mu sync.Mutex to includeProcessor struct - Protected all reads/writes to processingDiagnostics with mutex - Protected all reads/writes to fileIncludeReasons with mutex - Added addFileIncludeReason() and getFileIncludeReasons() helper methods - Updated all direct field accesses to use protected methods - Used maps.Copy in GetIncludeReasons() as suggested by linter Co-authored-by: jakebailey <[email protected]>
Fixed in d1c8f3b. Added mutex protection to |
Fix missing error TS6504 when JS file compiled without allowJs
Summary
This PR fixes the issue where
tsgowas not reporting error TS6504 when compiling JavaScript files without theallowJsoption enabled.Changes:
parseTask.load()infilesparser.goto detect JS files without allowJsaddRootTask()to include files with extensions even if unsupported, so they can be checked in load()includeProcessorfor concurrent access to diagnostic and file reason mapsTesting:
tsgo a.jsnow reports error TS6504/// <reference path="helper.js" />now reports error TS6504tscOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.