Skip to content

Commit 6cac4ab

Browse files
authored
Replace no-default-lib on AST with Program method, remove no-default-lib support (microsoft#1291)
1 parent a7fac73 commit 6cac4ab

File tree

11 files changed

+2517
-9
lines changed

11 files changed

+2517
-9
lines changed

internal/ast/ast.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10012,7 +10012,6 @@ type SourceFile struct {
1001210012
LanguageVariant core.LanguageVariant
1001310013
ScriptKind core.ScriptKind
1001410014
IsDeclarationFile bool
10015-
HasNoDefaultLib bool
1001610015
UsesUriStyleNodeCoreModules core.Tristate
1001710016
Identifiers map[string]string
1001810017
IdentifierCount int
@@ -10138,7 +10137,6 @@ func (node *SourceFile) copyFrom(other *SourceFile) {
1013810137
node.LanguageVariant = other.LanguageVariant
1013910138
node.ScriptKind = other.ScriptKind
1014010139
node.IsDeclarationFile = other.IsDeclarationFile
10141-
node.HasNoDefaultLib = other.HasNoDefaultLib
1014210140
node.UsesUriStyleNodeCoreModules = other.UsesUriStyleNodeCoreModules
1014310141
node.Identifiers = other.Identifiers
1014410142
node.imports = other.imports

internal/checker/checker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ type Program interface {
539539
GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
540540
SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmit bool) bool
541541
IsSourceFromProjectReference(path tspath.Path) bool
542+
IsSourceFileDefaultLibrary(path tspath.Path) bool
542543
GetSourceAndProjectReference(path tspath.Path) *tsoptions.SourceAndProjectReference
543544
GetRedirectForResolution(file ast.HasFileName) *tsoptions.ParsedCommandLine
544545
CommonSourceDirectory() string

internal/checker/relater.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func (c *Checker) elaborateElement(source *Type, target *Type, relation *Relatio
587587
issuedElaboration := false
588588
if targetProp == nil {
589589
indexInfo := c.getApplicableIndexInfo(target, nameType)
590-
if indexInfo != nil && indexInfo.declaration != nil && !ast.GetSourceFileOfNode(indexInfo.declaration).HasNoDefaultLib {
590+
if indexInfo != nil && indexInfo.declaration != nil && !c.program.IsSourceFileDefaultLibrary(ast.GetSourceFileOfNode(indexInfo.declaration).Path()) {
591591
issuedElaboration = true
592592
diagnostic.AddRelatedInfo(createDiagnosticForNode(indexInfo.declaration, diagnostics.The_expected_type_comes_from_this_index_signature))
593593
}
@@ -602,7 +602,7 @@ func (c *Checker) elaborateElement(source *Type, target *Type, relation *Relatio
602602
if propertyName == "" || nameType.flags&TypeFlagsUniqueESSymbol != 0 {
603603
propertyName = c.TypeToString(nameType)
604604
}
605-
if !ast.GetSourceFileOfNode(targetNode).HasNoDefaultLib {
605+
if !c.program.IsSourceFileDefaultLibrary(ast.GetSourceFileOfNode(targetNode).Path()) {
606606
diagnostic.AddRelatedInfo(createDiagnosticForNode(targetNode, diagnostics.The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1, propertyName, c.TypeToString(target)))
607607
}
608608
}

internal/checker/utilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ func forEachYieldExpression(body *ast.Node, visitor func(expr *ast.Node)) {
14701470
func SkipTypeChecking(sourceFile *ast.SourceFile, options *core.CompilerOptions, host Program) bool {
14711471
return options.NoCheck.IsTrue() ||
14721472
options.SkipLibCheck.IsTrue() && sourceFile.IsDeclarationFile ||
1473-
options.SkipDefaultLibCheck.IsTrue() && sourceFile.HasNoDefaultLib ||
1473+
options.SkipDefaultLibCheck.IsTrue() && host.IsSourceFileDefaultLibrary(sourceFile.Path()) ||
14741474
host.IsSourceFromProjectReference(sourceFile.Path()) ||
14751475
!canIncludeBindAndCheckDiagnostics(sourceFile, options)
14761476
}

internal/compiler/fileloader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type processedFiles struct {
5050
sourceFileMetaDatas map[tspath.Path]ast.SourceFileMetaData
5151
jsxRuntimeImportSpecifiers map[tspath.Path]*jsxRuntimeImportSpecifier
5252
importHelpersImportSpecifiers map[tspath.Path]*ast.Node
53+
libFiles collections.Set[tspath.Path]
5354
// List of present unsupported extensions
5455
unsupportedExtensions []string
5556
sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
@@ -130,6 +131,7 @@ func processAllProgramFiles(
130131
var importHelpersImportSpecifiers map[tspath.Path]*ast.Node
131132
var unsupportedExtensions []string
132133
var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
134+
var libFileSet collections.Set[tspath.Path]
133135

134136
loader.parseTasks.collect(&loader, loader.rootTasks, func(task *parseTask, _ []tspath.Path) {
135137
if task.isRedirected {
@@ -148,6 +150,7 @@ func processAllProgramFiles(
148150
}
149151
if task.isLib {
150152
libFiles = append(libFiles, file)
153+
libFileSet.Add(path)
151154
} else {
152155
files = append(files, file)
153156
}
@@ -197,6 +200,7 @@ func processAllProgramFiles(
197200
importHelpersImportSpecifiers: importHelpersImportSpecifiers,
198201
unsupportedExtensions: unsupportedExtensions,
199202
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
203+
libFiles: libFileSet,
200204
}
201205
}
202206

internal/compiler/program.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ func (p *Program) initCheckerPool() {
213213
func canReplaceFileInProgram(file1 *ast.SourceFile, file2 *ast.SourceFile) bool {
214214
return file2 != nil &&
215215
file1.ParseOptions() == file2.ParseOptions() &&
216-
file1.HasNoDefaultLib == file2.HasNoDefaultLib &&
217216
file1.UsesUriStyleNodeCoreModules == file2.UsesUriStyleNodeCoreModules &&
218217
slices.EqualFunc(file1.Imports(), file2.Imports(), equalModuleSpecifiers) &&
219218
slices.EqualFunc(file1.ModuleAugmentations, file2.ModuleAugmentations, equalModuleAugmentationNames) &&
@@ -642,6 +641,10 @@ func (p *Program) GetDefaultResolutionModeForFile(sourceFile ast.HasFileName) co
642641
return getDefaultResolutionModeForFile(sourceFile.FileName(), p.sourceFileMetaDatas[sourceFile.Path()], p.projectReferenceFileMapper.getCompilerOptionsForFile(sourceFile))
643642
}
644643

644+
func (p *Program) IsSourceFileDefaultLibrary(path tspath.Path) bool {
645+
return p.libFiles.Has(path)
646+
}
647+
645648
func (p *Program) CommonSourceDirectory() string {
646649
p.commonSourceDirectoryOnce.Do(func() {
647650
p.commonSourceDirectory = outputpaths.GetCommonSourceDirectory(

internal/parser/parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6544,7 +6544,6 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
65446544
context.TypeReferenceDirectives = nil
65456545
context.LibReferenceDirectives = nil
65466546
// context.AmdDependencies = nil
6547-
context.HasNoDefaultLib = false
65486547
for _, pragma := range context.Pragmas {
65496548
switch pragma.Name {
65506549
case "reference":
@@ -6556,7 +6555,7 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
65566555
noDefaultLib, noDefaultLibOk := pragma.Args["no-default-lib"]
65576556
switch {
65586557
case noDefaultLibOk && noDefaultLib.Value == "true":
6559-
context.HasNoDefaultLib = true
6558+
// Ignored.
65606559
case typesOk:
65616560
var parsed core.ResolutionMode
65626561
if resolutionModeOk {

internal/transformers/declarations/transform.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ func (tx *DeclarationTransformer) transformSourceFile(node *ast.SourceFile) *ast
196196
result := tx.Factory().UpdateSourceFile(node, combinedStatements)
197197
result.AsSourceFile().LibReferenceDirectives = tx.getLibReferences()
198198
result.AsSourceFile().TypeReferenceDirectives = tx.getTypeReferences()
199-
result.AsSourceFile().HasNoDefaultLib = node.HasNoDefaultLib
200199
result.AsSourceFile().IsDeclarationFile = true
201200
result.AsSourceFile().ReferencedFiles = tx.getReferencedFiles(outputFilePath)
202201
return result.AsNode()

internal/transformers/tstransforms/importelision_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func (p *fakeProgram) GetResolvedModules() map[tspath.Path]module.ModeAwareCache
156156
panic("unimplemented")
157157
}
158158

159+
func (p *fakeProgram) IsSourceFileDefaultLibrary(path tspath.Path) bool {
160+
return false
161+
}
162+
159163
func TestImportElision(t *testing.T) {
160164
t.Parallel()
161165
data := []struct {

0 commit comments

Comments
 (0)