Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

tsgo was silently ignoring JavaScript files when allowJs was not enabled, while tsc reports error TS6504. This made tsgo less helpful for users accidentally compiling .js files.

Changes

Modified internal/compiler/fileloader.go:

  • Added diagnostic in addRootTask when a root file has a JS extension but allowJs is not enabled
  • Uses existing processingDiagnosticKindExplainingFileInclude infrastructure to report the error with file inclusion context
} else if tspath.HasExtension(fileName) {
    canonicalFileName := tspath.GetCanonicalFileName(fileName, p.opts.Host.FS().UseCaseSensitiveFileNames())
    if tspath.HasJSFileExtension(canonicalFileName) {
        p.includeProcessor.addProcessingDiagnostic(&processingDiagnostic{
            kind: processingDiagnosticKindExplainingFileInclude,
            data: &includeExplainingDiagnostic{
                diagnosticReason: includeReason,
                message:          diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option,
                args:             []any{fileName},
            },
        })
    }
}

Test baselines updated to match TypeScript compiler output.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • centralus-2.in.applicationinsights.azure.com
    • Triggering command: go build -tags=noembed,release -o ./built/local/ ./cmd/tsgo (dns block)
    • Triggering command: go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0 custom (dns block)
    • Triggering command: go build -ldflags -s -w -X 'main.version=v2.6.0-custom-gcl-94jqzDflNoq1ZZ2lGqIGB8QB8Hs6XG3sDaDhRRIDkMc' -X 'main.date=2025-11-15 19:42:41.252383861 +0000 UTC' -o custom-gcl ./cmd/golangci-lint (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Missing error when JS file compiled without allowJs on</issue_title>
<issue_description>## Steps to reproduce


D:\Throwaway\corsarepro>tsc a.js
error TS6504: File 'a.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
  The file is in the program because:
    Root file specified for compilation


Found 1 error.


D:\Throwaway\corsarepro>tsgo a.js

D:\Throwaway\corsarepro>
```</issue_description>

<agent_instructions>Use print debugging and `go test -v` to trace why the file is not being included or errored on for the test case diff mentioned in the issue thread. Print debugging with the tsgo binary on the example in the issue itself may also work.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@jakebailey</author><body>
I assume this is https://github.com/microsoft/typescript-go/blob/05f4d69f81d416946ce46a374d91b78c0fbd37c8/testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt.diff#L5</body></comment_new>
</comments>


💡 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.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing error when JS file compiled without allowJs Add missing TS6504 diagnostic for JavaScript files without allowJs Nov 15, 2025
Copilot AI requested a review from jakebailey November 15, 2025 19:48
Copilot finished work on behalf of jakebailey November 15, 2025 19:48
@jakebailey jakebailey marked this pull request as ready for review November 19, 2025 20:52
Copy link
Member

@jakebailey jakebailey left a 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?

Copilot finished reviewing on behalf of jakebailey November 19, 2025 20:56
Copy link
Contributor

Copilot AI left a 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.go to detect JavaScript files and report TS6504 diagnostic when allowJs is 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 <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing error when JS file compiled without allowJs on

2 participants