Skip to content

Conversation

@lauckhart
Copy link

This fixes a bug whereby a wildcard package.json export such as:

./foo/*/index.js

when matched against an import such as:

import "./foo/index.js";

would crash:

panic: runtime error: slice bounds out of range [50:49]

goroutine 31853 [running]:
github.com/microsoft/typescript-go/internal/modulespecifiers.tryGetModuleNameFromExportsOrImports(0x140001a8908, {0x1096fdd18, 0x14017902078}, {0x1400021c100, 0x3a}, {0x14000298310, 0x23}, {0x14000010fc0, 0xc}, {{0x58?, ...}, ...}, ...)
        github.com/microsoft/typescript-go/internal/modulespecifiers/specifiers.go:1215 +0xfe8
github.com/microsoft/typescript-go/internal/modulespecifiers.tryGetModuleNameFromPackageJsonImports-range1(...)
        github.com/microsoft/typescript-go/internal/modulespecifiers/specifiers.go:1000
github.com/microsoft/typescript-go/internal/modulespecifiers.tryGetModuleNameFromPackageJsonImports.(*OrderedMap[...]).Entries.func1(...)
        github.com/microsoft/typescript-go/internal/collections/ordered_map.go:175
github.com/microsoft/typescript-go/internal/modulespecifiers.tryGetModuleNameFromPackageJsonImports({0x1400021c100, 0x3a}, {0x140002dafc0?, 0x23?}, 0x140001a8908, {0x1096fdd18, 0x14017902078}, 0x63, 0x0)
        github.com/microsoft/typescript-go/internal/modulespecifiers/specifiers.go:990 +0x3e8
github.com/microsoft/typescript-go/internal/modulespecifiers.getLocalModuleSpecifier({0x1400021c100, 0x3a}, {0x0, {0x140002dafc0, 0x3d}, {0x140002dafc0, 0x2f}}, 0x140001a8908, {0x1096fdd18, 0x14017902078}, ...)
        github.com/microsoft/typescript-go/internal/modulespecifiers/specifiers.go:496 +0x8c4
...

@lauckhart
Copy link
Author

@microsoft-github-policy-service agree

lauckhart added a commit to lauckhart/matter.js that referenced this pull request Dec 7, 2025
tsgo will crash without microsoft/typescript-go#2264

Additional tweaks are required for typescript language changes.

There are additional semantic errors (I assume bugs) that affect the tsgo CLI but not language server that also need further investigation.
Apollon77 pushed a commit to matter-js/matter.js that referenced this pull request Dec 8, 2025
tsgo will crash without microsoft/typescript-go#2264

Additional tweaks are required for typescript language changes.

There are additional semantic errors (I assume bugs) that affect the tsgo CLI but not language server that also need further investigation.
@jakebailey
Copy link
Member

Is there a test you can make for this?

The fix seems obviously right, however. The original code looked more like:

            case MatchingMode.Pattern:
                const starPos = pathOrPattern.indexOf("*");
                const leadingSlice = pathOrPattern.slice(0, starPos);
                const trailingSlice = pathOrPattern.slice(starPos + 1);
                if (canTryTsExtension && startsWith(targetFilePath, leadingSlice, ignoreCase) && endsWith(targetFilePath, trailingSlice, ignoreCase)) {
                    const starReplacement = targetFilePath.slice(leadingSlice.length, targetFilePath.length - trailingSlice.length);
                    return { moduleFileToTry: replaceFirstStar(packageName, starReplacement) };
                }

Which we could technically replicate?

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.

2 participants