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
14 changes: 10 additions & 4 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10983,7 +10983,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
result := make(map[string][]*Node)

addDeclaration := func(declaration *Node) {
name := getDeclarationName(declaration)
name := GetDeclarationName(declaration)
if name != "" {
result[name] = append(result[name], declaration)
}
Expand All @@ -10993,7 +10993,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
visit = func(node *Node) bool {
switch node.Kind {
case KindFunctionDeclaration, KindFunctionExpression, KindMethodDeclaration, KindMethodSignature:
declarationName := getDeclarationName(node)
declarationName := GetDeclarationName(node)
if declarationName != "" {
declarations := result[declarationName]
var lastDeclaration *Node
Expand Down Expand Up @@ -11025,7 +11025,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
break
}
fallthrough
case KindVariableDeclaration, KindBindingElement:
case KindVariableDeclaration, KindBindingElement, KindCommonJSExport:
name := node.Name()
if name != nil {
if IsBindingPattern(name) {
Expand Down Expand Up @@ -11074,6 +11074,12 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
}
}
}
case KindBinaryExpression:
switch GetAssignmentDeclarationKind(node.AsBinaryExpression()) {
case JSDeclarationKindThisProperty, JSDeclarationKindProperty:
addDeclaration(node)
}
node.ForEachChild(visit)
default:
node.ForEachChild(visit)
}
Expand All @@ -11083,7 +11089,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
return result
}

func getDeclarationName(declaration *Node) string {
func GetDeclarationName(declaration *Node) string {
name := GetNonAssignedNameOfDeclaration(declaration)
if name != nil {
if IsComputedPropertyName(name) {
Expand Down
21 changes: 21 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type Program struct {
// Cached unresolved imports for ATA
unresolvedImportsOnce sync.Once
unresolvedImports *collections.Set[string]

// Used by workspace/symbol
hasTSFileOnce sync.Once
hasTSFile bool
}

// FileExists implements checker.Program.
Expand Down Expand Up @@ -1634,6 +1638,23 @@ func (p *Program) SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmi
return sourceFileMayBeEmitted(sourceFile, p, forceDtsEmit)
}

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

func (p *Program) HasTSFile() bool {
p.hasTSFileOnce.Do(func() {
for _, file := range p.files {
if tspath.HasImplementationTSFileExtension(file.FileName()) {
p.hasTSFile = true
break
}
}
})
return p.hasTSFile
}

var plainJSErrors = collections.NewSetFromItems(
// binder errors
diagnostics.Cannot_redeclare_block_scoped_variable_0.Code(),
Expand Down
Loading
Loading