Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (p *fileLoader) toPath(file string) tspath.Path {

func (p *fileLoader) addRootTask(fileName string, libFile *LibFile, includeReason *FileIncludeReason) {
absPath := tspath.GetNormalizedAbsolutePath(fileName, p.opts.Host.GetCurrentDirectory())
if core.Tristate.IsTrue(p.opts.Config.CompilerOptions().AllowNonTsExtensions) || slices.Contains(p.supportedExtensions, tspath.TryGetExtensionFromPath(absPath)) {
if p.opts.Config.CompilerOptions().AllowNonTsExtensions.IsTrue() || tspath.HasExtension(absPath) {
p.rootTasks = append(p.rootTasks, &parseTask{
normalizedFilePath: absPath,
libFile: libFile,
Expand Down
35 changes: 35 additions & 0 deletions internal/compiler/filesparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/module"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
Expand All @@ -31,6 +32,7 @@ type parseTask struct {
typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
typeResolutionsTrace []module.DiagAndArgs
resolutionDiagnostics []*ast.Diagnostic
processingDiagnostics []*processingDiagnostic
importHelpersImportSpecifier *ast.Node
jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier

Expand Down Expand Up @@ -61,6 +63,34 @@ func (t *parseTask) load(loader *fileLoader) {
return
}

if tspath.HasExtension(t.normalizedFilePath) {
compilerOptions := loader.opts.Config.CompilerOptions()
allowNonTsExtensions := compilerOptions.AllowNonTsExtensions.IsTrue()
if !allowNonTsExtensions {
canonicalFileName := tspath.GetCanonicalFileName(t.normalizedFilePath, loader.opts.Host.FS().UseCaseSensitiveFileNames())
supported := false
for _, ext := range loader.supportedExtensions {
if tspath.FileExtensionIs(canonicalFileName, ext) {
supported = true
break
}
}
if !supported {
if tspath.HasJSFileExtension(canonicalFileName) {
t.processingDiagnostics = append(t.processingDiagnostics, &processingDiagnostic{
kind: processingDiagnosticKindExplainingFileInclude,
data: &includeExplainingDiagnostic{
diagnosticReason: t.includeReason,
message: diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option,
args: []any{t.normalizedFilePath},
},
})
}
return
}
}
}

loader.totalFileCount.Add(1)
if t.libFile != nil {
loader.libFileCount.Add(1)
Expand Down Expand Up @@ -319,6 +349,11 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
}
file := task.file
path := task.path

if len(task.processingDiagnostics) > 0 {
loader.includeProcessor.processingDiagnostics = append(loader.includeProcessor.processingDiagnostics, task.processingDiagnostics...)
}

if file == nil {
// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
missingFiles = append(missingFiles, task.normalizedFilePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
error TS5052: Option 'checkJs' cannot be specified without specifying option 'allowJs'.
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


!!! error TS5052: Option 'checkJs' cannot be specified without specifying option 'allowJs'.
!!! error TS6504: File 'a.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== a.js (0 errors) ====
var x;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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


!!! error TS6504: File 'a.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== a.js (0 errors) ====
declare var v;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
error TS6504: File '/node_modules/conditions/index.node.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
error TS6504: File '/node_modules/conditions/index.web.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


!!! error TS6504: File '/node_modules/conditions/index.node.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
!!! error TS6504: File '/node_modules/conditions/index.web.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== /node_modules/conditions/package.json (0 errors) ====
{
"name": "conditions",
"version": "1.0.0",
"type": "module",
"main": "index.cjs",
"types": "index.d.cts",
"exports": {
".": {
"node": "./index.node.js",
"default": "./index.web.js"
}
}
}

==== /node_modules/conditions/index.node.js (0 errors) ====
export const node = 0;

==== /node_modules/conditions/index.node.d.ts (0 errors) ====
export const node: number;

==== /node_modules/conditions/index.web.js (0 errors) ====
export const web = 0;

==== /node_modules/conditions/index.web.d.ts (0 errors) ====
export const web: number;

==== /main.ts (0 errors) ====
import { web } from "conditions";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
error TS6504: File '/node_modules/conditions/index.node.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
error TS6504: File '/node_modules/conditions/index.web.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


!!! error TS6504: File '/node_modules/conditions/index.node.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
!!! error TS6504: File '/node_modules/conditions/index.web.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== /node_modules/conditions/package.json (0 errors) ====
{
"name": "conditions",
"version": "1.0.0",
"type": "module",
"main": "index.cjs",
"types": "index.d.cts",
"exports": {
".": {
"node": "./index.node.js",
"default": "./index.web.js"
}
}
}

==== /node_modules/conditions/index.node.js (0 errors) ====
export const node = 0;

==== /node_modules/conditions/index.node.d.ts (0 errors) ====
export const node: number;

==== /node_modules/conditions/index.web.js (0 errors) ====
export const web = 0;

==== /node_modules/conditions/index.web.d.ts (0 errors) ====
export const web: number;

==== /main.ts (0 errors) ====
import { web } from "conditions";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
error TS6504: File '/node_modules/dual/index.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
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.


!!! error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
!!! error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== /node_modules/dual/package.json (0 errors) ====
{
"name": "dual",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
error TS6504: File '/node_modules/dual/index.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
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.


!!! error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
!!! error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== /node_modules/dual/package.json (0 errors) ====
{
"name": "dual",
Expand Down
Loading