Skip to content

Specifying declaration files in "moduleSuffixes" leads to panic #2650

@voronin-ivan

Description

@voronin-ivan

Hi there,

I've noticed that specifying declaration files in "moduleSuffixes" leads to panic. It works as expected with TS 5.9.2, and our company has been using this to improve LSP performance by generating d.ts files with oxc on the fly. Considering that tsgo currently consumes ~20% more memory than the stable version, I'd like to keep this optimisation.

Stack trace

panic: should be able to extract TS extension from string that passes IsDeclarationFileName

goroutine 245833 [running]:
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModule(0x14146f0cc08, 0x1410c2e4660, {0x14108f49c22, 0x26}, 0x103c798c0, 0x1410c08b200, 0x0)
        github.com/microsoft/typescript-go/internal/checker/checker.go:14825 +0x1b78
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModuleNameWorker(0x14146f0cc08, 0x1410c2e4660, 0x1410c08b200, 0x103c798c0, 0x0, 0x0)
        github.com/microsoft/typescript-go/internal/checker/checker.go:14727 +0x80
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModuleName(0x14146f0cc08?, 0x1410c2e4660?, 0x1400bd74bc8?, 0xf4?)
        github.com/microsoft/typescript-go/internal/checker/checker.go:14722 +0x50
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkImportDeclaration(0x14146f0cc08, 0x1410c2e4660)
        github.com/microsoft/typescript-go/internal/checker/checker.go:5159 +0x178
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElementWorker(0x14146f0cc08, 0x1410c2e4660)
        github.com/microsoft/typescript-go/internal/checker/checker.go:2297 +0x320
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElement(0x14146f0cc08, 0x14148f7b830?)
        github.com/microsoft/typescript-go/internal/checker/checker.go:2168 +0x58
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElements(0x14146f0cc08, {0x1410c099440, 0x5, 0x102e8b364?})
        github.com/microsoft/typescript-go/internal/checker/checker.go:2158 +0x34
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceFile(0x14146f0cc08, {0x1036089c0, 0x103cce300}, 0x1410c0d9888)
        github.com/microsoft/typescript-go/internal/checker/checker.go:2130 +0xf4
github.com/microsoft/typescript-go/internal/checker.(*Checker).getDiagnostics(0x14146f0cc08, {0x1036089c0?, 0x103cce300?}, 0x1410c0d9888, 0x14146f0ce00)
        github.com/microsoft/typescript-go/internal/checker/checker.go:13575 +0x3c
github.com/microsoft/typescript-go/internal/checker.(*Checker).GetDiagnostics(...)
        github.com/microsoft/typescript-go/internal/checker/checker.go:13564
github.com/microsoft/typescript-go/internal/compiler.(*Program).getBindAndCheckDiagnosticsForFile.func1(0x1400018a008?, {0x1036089c0, 0x103cce300}, 0x1410c0d9888)
        github.com/microsoft/typescript-go/internal/compiler/program.go:1114 +0x80
github.com/microsoft/typescript-go/internal/compiler.(*Program).getBindAndCheckDiagnosticsForFile(0x1400018a008, {0x1036089c0, 0x103cce300}, 0x1410c0d9888)
        github.com/microsoft/typescript-go/internal/compiler/program.go:1116 +0x70
github.com/microsoft/typescript-go/internal/compiler.(*Program).getSemanticDiagnosticsForFile(0x1400018a008, {0x1036089c0?, 0x103cce300?}, 0x1410c0d9888)
        github.com/microsoft/typescript-go/internal/compiler/program.go:1094 +0x2c
github.com/microsoft/typescript-go/internal/compiler.(*Program).collectDiagnosticsFromFiles.func1()
        github.com/microsoft/typescript-go/internal/compiler/program.go:455 +0x40
github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue.func1()
        github.com/microsoft/typescript-go/internal/core/workgroup.go:40 +0x24
sync.(*WaitGroup).Go.func1()
        sync/waitgroup.go:239 +0x4c
created by sync.(*WaitGroup).Go in goroutine 1
        sync/waitgroup.go:237 +0x70

Steps to reproduce

  1. Add "moduleSuffixes": [".d", ""] to compilerOptions in the project config.
  2. Run typecheck for this project or try to open it in an IDE with Native Preview enabled.

Note: all other suffixes work as expected, for example, [".ios", ".android", ".gen.d", ""].


Thank you for all the great work on tsgo! ❤️

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions