Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New auto-import infrastructure#2390

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
andrewbranch merged 98 commits intomicrosoft:mainfromandrewbranch:autoimport
Jan 9, 2026
Merged
Show file tree
Hide file tree
Changes from81 commits
Commits
Show all changes
98 commits
Select commitHold shift + click to select a range
da0e338
WIP
andrewbranchOct 15, 2025
ea7ec1b
WIP
andrewbranchOct 16, 2025
5d88696
Merge branch 'main' into autoimport
andrewbranchOct 27, 2025
3482314
WIP add to existing, resolve fix
andrewbranchOct 29, 2025
654a104
Move change tracker, converters, utils to separate packages
andrewbranchOct 29, 2025
50be94c
WIP fix edits
andrewbranchOct 29, 2025
4e1e5ea
Move organizeimports
andrewbranchOct 29, 2025
76a99d7
Get hand-written tests working
andrewbranchOct 29, 2025
c357794
Remove trie and use word indices instead
andrewbranchOct 29, 2025
56e22dd
Merge branch 'main' into autoimport
andrewbranchOct 30, 2025
df73b49
WIP snapshot integration
andrewbranchOct 31, 2025
a185c2b
node_modules index building, WIP snapshot host
andrewbranchNov 4, 2025
8bcce85
Wire up to snapshot
andrewbranchNov 4, 2025
0f47ffb
System end to end
andrewbranchNov 5, 2025
7fb4085
Merge branch 'main' into autoimport
andrewbranchNov 7, 2025
7877d4e
Specifier cache, small fixes
andrewbranchNov 7, 2025
fb3318e
Optimize a bit
andrewbranchNov 10, 2025
1516a80
Start deleting stuff, convert fourslash tests
andrewbranchNov 11, 2025
13e1c46
Move ScriptElementKind to lsutil
andrewbranchNov 12, 2025
207c7e2
Merge branch 'main' into autoimport
andrewbranchNov 12, 2025
01ade0f
Revert submodule change
andrewbranchNov 12, 2025
04bbed1
Minimal checker-based alias resolution
andrewbranchNov 12, 2025
a34e2c1
Second resolution pass for ambient modules
andrewbranchNov 16, 2025
86506fc
Chip away at test failures
andrewbranchNov 17, 2025
8053a4f
Try searching dependencies for more files
andrewbranchNov 18, 2025
8b43d2b
Handle package shadowing
andrewbranchNov 19, 2025
9587948
WIP sort fixes
andrewbranchNov 19, 2025
33f3282
Chip away at tests more
andrewbranchNov 20, 2025
9392b86
Clean up export extracting, implement useRequire
andrewbranchNov 20, 2025
4bc5e2d
Fix more tests
andrewbranchNov 20, 2025
4ce391f
Finish going through existing enabled tests
andrewbranchNov 21, 2025
d0f1fe5
Enable other passing tests
andrewbranchNov 21, 2025
91d910d
Log more stats, try local name resolution before checker usage
andrewbranchNov 21, 2025
2b8b2a9
Merge branch 'main' into autoimport
andrewbranchNov 21, 2025
8b006b2
WIP codefixes
andrewbranchNov 22, 2025
3c7e27b
WIP code fix
andrewbranchNov 24, 2025
732793f
Initial plan
CopilotNov 22, 2025
87b670a
Port getFixesInfoForNonUMDImport to use new autoimport.View
CopilotNov 22, 2025
7f2d093
Apply formatting
CopilotNov 22, 2025
1bcf069
Convert UMD and type-only fixes to use autoimport.Fix
CopilotNov 24, 2025
1e0ca2b
Fix panics and add type-only import support
CopilotNov 25, 2025
46f3e40
Add JSDoc import type fix support
CopilotNov 25, 2025
96af867
Improve error handling for JSDoc import type fix
CopilotNov 25, 2025
a7e6432
Continue fixing tests
andrewbranchDec 2, 2025
6af6a81
Continue fixing tests
andrewbranchDec 2, 2025
4a30356
Handle node_modules that are excluded by package.json but imported by…
andrewbranchDec 3, 2025
bd11dde
Update failing tests
andrewbranchDec 3, 2025
3c4ef31
Delete old code
andrewbranchDec 3, 2025
c4e0fb7
Add basic benchmark
andrewbranchDec 3, 2025
f7719d9
Use one alias resolver + checker per node_modules package so intra-pa…
andrewbranchDec 4, 2025
4f6ff35
Start hammering out lifecycle bugs
andrewbranchDec 4, 2025
98ee737
Add more lifecycle tests
andrewbranchDec 5, 2025
e9ba700
Merge branch 'main' into autoimport
andrewbranchDec 5, 2025
a003bb6
Fix test
andrewbranchDec 6, 2025
34f1f4d
Clean up dirty state handling some
andrewbranchDec 8, 2025
873b1b5
Comment
andrewbranchDec 8, 2025
cbb1b88
Keep testing
andrewbranchDec 9, 2025
bf709e8
Merge branch 'main' into autoimport
andrewbranchDec 10, 2025
89632e7
WIP respecting new preferences and fixing tests
andrewbranchDec 10, 2025
67d47ac
Copy missing promoteFromTypeOnly logic
andrewbranchDec 10, 2025
c03e965
Handle endings
andrewbranchDec 10, 2025
538408c
Better panic message
andrewbranchDec 10, 2025
3a2f182
Disable JavaScript entrypoints for now
andrewbranchDec 11, 2025
6ba0adf
Add logging for skipped files
andrewbranchDec 11, 2025
7441386
Don’t retain any files
andrewbranchDec 11, 2025
c37ee83
Delete commented out code
andrewbranchDec 11, 2025
97564ac
Implement watch
andrewbranchDec 11, 2025
8fd03b9
Warm auto-import registry on file edit
andrewbranchDec 11, 2025
0c1db12
Fix some tests, delete some dead code
andrewbranchDec 11, 2025
9b84b1c
Sort only as much as needed in the server, and then deterministically…
andrewbranchDec 12, 2025
ce4a9bf
Optimize isFixPossiblyReExportingImportingFile
andrewbranchDec 12, 2025
390882d
Bail out of expensive error checking during alias resolution
andrewbranchDec 12, 2025
723a9d0
Update failing tests
andrewbranchDec 12, 2025
b13b974
Finish wildcard exports TODO
andrewbranchDec 12, 2025
4b87128
Finish more TODOs
andrewbranchDec 13, 2025
c140faf
Fix module augmentation TODO
andrewbranchDec 13, 2025
eb6cc62
Merge branch 'main' into autoimport
andrewbranchDec 15, 2025
4d49179
Delete zero value
andrewbranchDec 15, 2025
243d025
Only scrape dependencies and peerDependencies
andrewbranchDec 16, 2025
30d24e8
Fix tests, fix type/value filtering
andrewbranchDec 16, 2025
3b0ff4a
Lint/generate
andrewbranchDec 16, 2025
639d047
Fix target grouping for export *
andrewbranchDec 16, 2025
32f401a
Delete unused properties
andrewbranchDec 16, 2025
24f9c97
Fix crashing tests
andrewbranchDec 16, 2025
6b0992a
Fix race
andrewbranchDec 16, 2025
44e5546
Fix other race
andrewbranchDec 16, 2025
296b888
Address project update to-do
andrewbranchDec 17, 2025
2e3bada
Tolerate erroneously mixed export kinds
andrewbranchDec 17, 2025
36cc710
PR feedback
andrewbranchDec 17, 2025
72bd0b4
Improve package.json and already-imported package filtering
andrewbranchDec 19, 2025
6d3b84a
Add failing test for symlink-based duplication
andrewbranchDec 19, 2025
18aa311
Handle project reference redirects
andrewbranchJan 2, 2026
618e3e6
Update project references in node_modules without rebuilding full bucket
andrewbranchJan 5, 2026
97a3047
Update failing
andrewbranchJan 5, 2026
24eab79
Fix missing condition in possiblyNeedsRebuildForFile
andrewbranchJan 5, 2026
c810e0b
Remove baselines of skipped tests
andrewbranchJan 5, 2026
e186a02
Fix incorrect early return in (*Set).IsSubsetOf
andrewbranchJan 8, 2026
68a3613
Audit failing tests
andrewbranchJan 9, 2026
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
1 change: 1 addition & 0 deletionscmd/tsgo/lsp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,7 @@ func runLSP(args []string) int {
defer stop()

if err := s.Run(ctx); err != nil {
fmt.Fprintln(os.Stderr, err)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I haven’t looked at#2336 yet, but this could be what’s missing to show a stack trace.

return 1
}
return 0
Expand Down
6 changes: 3 additions & 3 deletionsinternal/api/api.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,7 +161,7 @@ func (api *API) GetSymbolAtPosition(ctx context.Context, projectId Handle[projec
return nil, errors.New("project not found")
}

languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
languageService := ls.NewLanguageService(project.ConfigFilePath(), project.GetProgram(), snapshot)
symbol, err := languageService.GetSymbolAtPosition(ctx, fileName, position)
if err != nil || symbol == nil {
return nil, err
Expand DownExpand Up@@ -203,7 +203,7 @@ func (api *API) GetSymbolAtLocation(ctx context.Context, projectId Handle[projec
if node == nil {
return nil, fmt.Errorf("node of kind %s not found at position %d in file %q", kind.String(), pos, sourceFile.FileName())
}
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
languageService := ls.NewLanguageService(project.ConfigFilePath(), project.GetProgram(), snapshot)
symbol := languageService.GetSymbolAtLocation(ctx, node)
if symbol == nil {
return nil, nil
Expand DownExpand Up@@ -233,7 +233,7 @@ func (api *API) GetTypeOfSymbol(ctx context.Context, projectId Handle[project.Pr
if !ok {
return nil, fmt.Errorf("symbol %q not found", symbolHandle)
}
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
languageService := ls.NewLanguageService(project.ConfigFilePath(), project.GetProgram(), snapshot)
t := languageService.GetTypeOfSymbol(ctx, symbol)
if t == nil {
return nil, nil
Expand Down
8 changes: 8 additions & 0 deletionsinternal/ast/symbol.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ func (s *Symbol) IsStatic() bool {
return modifierFlags&ModifierFlagsStatic != 0
}

// See comment on `declareModuleMember` in `binder.go`.
func (s *Symbol) CombinedLocalAndExportSymbolFlags() SymbolFlags {
if s.ExportSymbol != nil {
return s.Flags | s.ExportSymbol.Flags
}
return s.Flags
}

// SymbolTable

type SymbolTable map[string]*Symbol
Expand Down
48 changes: 35 additions & 13 deletionsinternal/ast/utilities.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1870,11 +1870,11 @@ func IsExpressionNode(node *Node) bool {
for node.Parent.Kind == KindQualifiedName {
node = node.Parent
}
return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) ||isJSXTagName(node)
return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) ||IsJsxTagName(node)
case KindPrivateIdentifier:
return IsBinaryExpression(node.Parent) && node.Parent.AsBinaryExpression().Left == node && node.Parent.AsBinaryExpression().OperatorToken.Kind == KindInKeyword
case KindIdentifier:
if IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) ||isJSXTagName(node) {
if IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) ||IsJsxTagName(node) {
return true
}
fallthrough
Expand DownExpand Up@@ -1991,15 +1991,6 @@ func IsJSDocTag(node *Node) bool {
return node.Kind >= KindFirstJSDocTagNode && node.Kind <= KindLastJSDocTagNode
}

func isJSXTagName(node *Node) bool {
parent := node.Parent
switch parent.Kind {
case KindJsxOpeningElement, KindJsxSelfClosingElement, KindJsxClosingElement:
return parent.TagName() == node
}
return false
}

func IsSuperCall(node *Node) bool {
return IsCallExpression(node) && node.Expression().Kind == KindSuperKeyword
}
Expand DownExpand Up@@ -3407,12 +3398,12 @@ func IsExternalModuleAugmentation(node *Node) bool {
func GetSourceFileOfModule(module *Symbol) *SourceFile {
declaration := module.ValueDeclaration
if declaration == nil {
declaration =getNonAugmentationDeclaration(module)
declaration =GetNonAugmentationDeclaration(module)
}
return GetSourceFileOfNode(declaration)
}

funcgetNonAugmentationDeclaration(symbol *Symbol) *Node {
funcGetNonAugmentationDeclaration(symbol *Symbol) *Node {
return core.Find(symbol.Declarations, func(d *Node) bool {
return !IsExternalModuleAugmentation(d) && !IsGlobalScopeAugmentation(d)
})
Expand DownExpand Up@@ -3888,6 +3879,37 @@ func GetContainingFunction(node *Node) *Node {
return FindAncestor(node.Parent, IsFunctionLike)
}

func ImportFromModuleSpecifier(node *Node) *Node {
if result := TryGetImportFromModuleSpecifier(node); result != nil {
return result
}
debug.FailBadSyntaxKind(node.Parent)
return nil
}

func TryGetImportFromModuleSpecifier(node *StringLiteralLike) *Node {
switch node.Parent.Kind {
case KindImportDeclaration, KindJSImportDeclaration, KindExportDeclaration:
return node.Parent
case KindExternalModuleReference:
return node.Parent.Parent
case KindCallExpression:
if IsImportCall(node.Parent) || IsRequireCall(node.Parent, false /*requireStringLiteralLikeArgument*/) {
return node.Parent
}
return nil
case KindLiteralType:
if !IsStringLiteral(node) {
return nil
}
if IsImportTypeNode(node.Parent.Parent) {
return node.Parent.Parent
}
return nil
}
return nil
}

func IsImplicitlyExportedJSTypeAlias(node *Node) bool {
return IsJSTypeAliasDeclaration(node) && IsSourceFile(node.Parent) && IsExternalOrCommonJSModule(node.Parent.AsSourceFile())
}
Expand Down
4 changes: 4 additions & 0 deletionsinternal/checker/checker.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14430,6 +14430,9 @@ func (c *Checker) getEmitSyntaxForModuleSpecifierExpression(usage *ast.Node) cor
}

func (c *Checker) errorNoModuleMemberSymbol(moduleSymbol *ast.Symbol, targetSymbol *ast.Symbol, node *ast.Node, name *ast.Node) {
if c.compilerOptions.NoCheck.IsTrue() {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Auto-imports uses checkers for minimal alias resolution, and these code paths go way down a rabbit hole hitting the file system and using the node builder to generate errors. Added some targeted short circuits.

return
}
moduleName := c.getFullyQualifiedName(moduleSymbol, node)
declarationName := scanner.DeclarationNameToString(name)
var suggestion *ast.Symbol
Expand DownExpand Up@@ -14641,6 +14644,7 @@ func (c *Checker) markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration *ast.N

func (c *Checker) resolveExternalModuleName(location *ast.Node, moduleReferenceExpression *ast.Node, ignoreErrors bool) *ast.Symbol {
errorMessage := diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations
ignoreErrors = ignoreErrors || c.compilerOptions.NoCheck.IsTrue()
return c.resolveExternalModuleNameWorker(location, moduleReferenceExpression, core.IfElse(ignoreErrors, nil, errorMessage), ignoreErrors, false /*isForAugmentation*/)
}

Expand Down
9 changes: 8 additions & 1 deletioninternal/checker/services.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ func (c *Checker) getSymbolsInScope(location *ast.Node, meaning ast.SymbolFlags)
// Copy the given symbol into symbol tables if the symbol has the given meaning
// and it doesn't already exists in the symbol table.
copySymbol := func(symbol *ast.Symbol, meaning ast.SymbolFlags) {
ifGetCombinedLocalAndExportSymbolFlags(symbol)&meaning != 0 {
if symbol.CombinedLocalAndExportSymbolFlags()&meaning != 0 {
id := symbol.Name
// We will copy all symbol regardless of its reserved name because
// symbolsToArray will check whether the key is a reserved name and
Expand DownExpand Up@@ -393,6 +393,13 @@ func (c *Checker) GetRootSymbols(symbol *ast.Symbol) []*ast.Symbol {
return result
}

func (c *Checker) GetMappedTypeSymbolOfProperty(symbol *ast.Symbol) *ast.Symbol {
if valueLinks := c.valueSymbolLinks.TryGet(symbol); valueLinks != nil {
return valueLinks.containingType.symbol
}
return nil
}

func (c *Checker) getImmediateRootSymbols(symbol *ast.Symbol) []*ast.Symbol {
if symbol.CheckFlags&ast.CheckFlagsSynthetic != 0 {
return core.MapNonNil(
Expand Down
8 changes: 0 additions & 8 deletionsinternal/checker/utilities.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1622,14 +1622,6 @@ func symbolsToArray(symbols ast.SymbolTable) []*ast.Symbol {
return result
}

// See comment on `declareModuleMember` in `binder.go`.
func GetCombinedLocalAndExportSymbolFlags(symbol *ast.Symbol) ast.SymbolFlags {
if symbol.ExportSymbol != nil {
return symbol.Flags | symbol.ExportSymbol.Flags
}
return symbol.Flags
}

func SkipAlias(symbol *ast.Symbol, checker *Checker) *ast.Symbol {
if symbol.Flags&ast.SymbolFlagsAlias != 0 {
return checker.GetAliasedSymbol(symbol)
Expand Down
6 changes: 6 additions & 0 deletionsinternal/collections/multimap.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,12 @@ type MultiMap[K comparable, V comparable] struct {
M map[K][]V
}

func NewMultiMapWithSizeHint[K comparable, V comparable](hint int) *MultiMap[K, V] {
return &MultiMap[K, V]{
M: make(map[K][]V, hint),
}
}

func GroupBy[K comparable, V comparable](items []V, groupId func(V) K) *MultiMap[K, V] {
m := &MultiMap[K, V]{}
for _, item := range items {
Expand Down
70 changes: 70 additions & 0 deletionsinternal/collections/set.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,9 @@ func NewSetWithSizeHint[T comparable](hint int) *Set[T] {
}

func (s *Set[T]) Has(key T) bool {
if s == nil {
return false
}
_, ok := s.M[key]
return ok
}
Expand All@@ -30,14 +33,23 @@ func (s *Set[T]) Delete(key T) {
}

func (s *Set[T]) Len() int {
if s == nil {
return 0
}
return len(s.M)
}

func (s *Set[T]) Keys() map[T]struct{} {
if s == nil {
return nil
}
return s.M
}

func (s *Set[T]) Clear() {
if s == nil {
return
}
clear(s.M)
}

Expand All@@ -58,6 +70,37 @@ func (s *Set[T]) Clone() *Set[T] {
return clone
}

func (s *Set[T]) Union(other *Set[T]) {
if s.Len() == 0 && other.Len() == 0 {
return
}
if s == nil {
panic("cannot modify nil Set")
}
if s.M == nil {
s.M = maps.Clone(other.M)
return
}
maps.Copy(s.M, other.M)
}

func (s *Set[T]) UnionedWith(other *Set[T]) *Set[T] {
if s == nil && other == nil {
return nil
}
result := s.Clone()
if other != nil {
if result == nil {
result = &Set[T]{}
}
if result.M == nil {
result.M = make(map[T]struct{}, len(other.M))
}
maps.Copy(result.M, other.M)
}
return result
}

func (s *Set[T]) Equals(other *Set[T]) bool {
if s == other {
return true
Expand All@@ -68,6 +111,33 @@ func (s *Set[T]) Equals(other *Set[T]) bool {
return maps.Equal(s.M, other.M)
}

func (s *Set[T]) IsSubsetOf(other *Set[T]) bool {
if s == nil {
return true
}
if other == nil {
return false
}
for key := range s.M {
if !other.Has(key) {
return false
}
}
return true
}

func (s *Set[T]) Intersects(other *Set[T]) bool {
if s == nil || other == nil {
return false
}
for key := range s.M {
if other.Has(key) {
return true
}
}
return false
}

func NewSetFromItems[T comparable](items ...T) *Set[T] {
s := &Set[T]{}
for _, item := range items {
Expand Down
2 changes: 2 additions & 0 deletionsinternal/compiler/filesparser.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,8 @@ type parseTask struct {
typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
typeResolutionsTrace []module.DiagAndArgs
resolutionDiagnostics []*ast.Diagnostic
resolvedPackageNames collections.Set[string]
unresolvedPackageNames collections.Set[string]
processingDiagnostics []*processingDiagnostic
importHelpersImportSpecifier *ast.Node
jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier
Expand Down
54 changes: 54 additions & 0 deletionsinternal/compiler/program.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ import (
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/locale"
"github.com/microsoft/typescript-go/internal/module"
"github.com/microsoft/typescript-go/internal/modulespecifiers"
"github.com/microsoft/typescript-go/internal/outputpaths"
"github.com/microsoft/typescript-go/internal/packagejson"
"github.com/microsoft/typescript-go/internal/parser"
Expand DownExpand Up@@ -72,6 +73,11 @@ type Program struct {
knownSymlinks *symlinks.KnownSymlinks
knownSymlinksOnce sync.Once

// Used by auto-imports
packageNamesOnce sync.Once
resolvedPackageNames *collections.Set[string]
unresolvedPackageNames *collections.Set[string]

// Used by workspace/symbol
hasTSFileOnce sync.Once
hasTSFile bool
Expand DownExpand Up@@ -250,6 +256,8 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos
programDiagnostics: p.programDiagnostics,
hasEmitBlockingDiagnostics: p.hasEmitBlockingDiagnostics,
unresolvedImports: p.unresolvedImports,
resolvedPackageNames: p.resolvedPackageNames,
unresolvedPackageNames: p.unresolvedPackageNames,
knownSymlinks: p.knownSymlinks,
}
result.initCheckerPool()
Expand DownExpand Up@@ -1630,6 +1638,52 @@ func (p *Program) SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmi
return sourceFileMayBeEmitted(sourceFile, p, forceDtsEmit)
}

func (p *Program) ResolvedPackageNames() *collections.Set[string] {
p.collectPackageNames()
return p.resolvedPackageNames
}

func (p *Program) UnresolvedPackageNames() *collections.Set[string] {
p.collectPackageNames()
return p.unresolvedPackageNames
}

func (p *Program) collectPackageNames() {
p.packageNamesOnce.Do(func() {
if p.resolvedPackageNames == nil {
p.resolvedPackageNames = &collections.Set[string]{}
p.unresolvedPackageNames = &collections.Set[string]{}
for _, file := range p.files {
if p.IsSourceFileDefaultLibrary(file.Path()) || p.IsSourceFileFromExternalLibrary(file) {
continue
}
for _, imp := range file.Imports() {
if tspath.IsExternalModuleNameRelative(imp.Text()) {
continue
}
if resolvedModules, ok := p.resolvedModules[file.Path()]; ok {
key := module.ModeAwareCacheKey{Name: imp.Text(), Mode: p.GetModeForUsageLocation(file, imp)}
if resolvedModule, ok := resolvedModules[key]; ok && resolvedModule.IsResolved() {
if !resolvedModule.IsExternalLibraryImport {
continue
}
name := resolvedModule.PackageId.Name
if name == "" {
// node_modules package, but no name in package.json - this can happen in a monorepo package,
// and unfortunately in lots of fourslash tests
name = modulespecifiers.GetPackageNameFromDirectory(resolvedModule.ResolvedFileName)
}
p.resolvedPackageNames.Add(name)
continue
}
}
p.unresolvedPackageNames.Add(imp.Text())
}
}
}
})
}

func (p *Program) IsLibFile(sourceFile *ast.SourceFile) bool {
_, ok := p.libFiles[sourceFile.Path()]
return ok
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2026 Movatter.jp