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
2 changes: 1 addition & 1 deletion microsoft/typescript-go
Submodule typescript-go updated 137 files
66 changes: 38 additions & 28 deletions pkg/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,33 @@ type Binder struct {
bindFunc func(*ast.Node) bool
unreachableFlow *ast.FlowNode

container *ast.Node
thisContainer *ast.Node
blockScopeContainer *ast.Node
lastContainer *ast.Node
currentFlow *ast.FlowNode
currentBreakTarget *ast.FlowLabel
currentContinueTarget *ast.FlowLabel
currentReturnTarget *ast.FlowLabel
currentTrueTarget *ast.FlowLabel
currentFalseTarget *ast.FlowLabel
currentExceptionTarget *ast.FlowLabel
preSwitchCaseFlow *ast.FlowNode
activeLabelList *ActiveLabel
emitFlags ast.NodeFlags
seenThisKeyword bool
hasExplicitReturn bool
hasFlowEffects bool
inStrictMode bool
inAssignmentPattern bool
seenParseError bool
symbolCount int
classifiableNames collections.Set[string]
symbolPool core.Pool[ast.Symbol]
flowNodePool core.Pool[ast.FlowNode]
flowListPool core.Pool[ast.FlowList]
singleDeclarationsPool core.Pool[*ast.Node]
container *ast.Node
thisContainer *ast.Node
blockScopeContainer *ast.Node
lastContainer *ast.Node
currentFlow *ast.FlowNode
currentBreakTarget *ast.FlowLabel
currentContinueTarget *ast.FlowLabel
currentReturnTarget *ast.FlowLabel
currentTrueTarget *ast.FlowLabel
currentFalseTarget *ast.FlowLabel
currentExceptionTarget *ast.FlowLabel
preSwitchCaseFlow *ast.FlowNode
activeLabelList *ActiveLabel
emitFlags ast.NodeFlags
seenThisKeyword bool
hasExplicitReturn bool
hasFlowEffects bool
inStrictMode bool
inAssignmentPattern bool
seenParseError bool
symbolCount int
classifiableNames collections.Set[string]
notConstEnumOnlyModules collections.Set[*ast.Symbol]
symbolPool core.Pool[ast.Symbol]
flowNodePool core.Pool[ast.FlowNode]
flowListPool core.Pool[ast.FlowList]
singleDeclarationsPool core.Pool[*ast.Node]
}

func (b *Binder) options() core.SourceFileAffectingCompilerOptions {
Expand Down Expand Up @@ -794,9 +795,17 @@ func (b *Binder) bindModuleDeclaration(node *ast.Node) {
state := b.declareModuleSymbol(node)
if state != ast.ModuleInstanceStateNonInstantiated {
symbol := node.Symbol()
if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) != 0 || state != ast.ModuleInstanceStateConstEnumOnly {
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
constEnumOnlyModule := (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) == 0) &&
// Current must be `const enum` only
state == ast.ModuleInstanceStateConstEnumOnly &&
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
!b.notConstEnumOnlyModules.Has(symbol)
if constEnumOnlyModule {
symbol.Flags |= ast.SymbolFlagsConstEnumOnlyModule
} else {
symbol.Flags &^= ast.SymbolFlagsConstEnumOnlyModule
b.notConstEnumOnlyModules.Add(symbol)
}
}
}
Expand Down Expand Up @@ -2424,6 +2433,7 @@ func (b *Binder) addDeclarationToSymbol(symbol *ast.Symbol, node *ast.Node, symb
// On merge of const enum module with class or function, reset const enum only flag (namespaces will already recalculate)
if symbol.Flags&ast.SymbolFlagsConstEnumOnlyModule != 0 && symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) != 0 {
symbol.Flags &^= ast.SymbolFlagsConstEnumOnlyModule
b.notConstEnumOnlyModules.Add(symbol)
}
if symbolFlags&ast.SymbolFlagsValue != 0 {
SetValueDeclaration(symbol, node)
Expand Down
16 changes: 7 additions & 9 deletions pkg/bundled/noembed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package bundled
import (
"fmt"
"os"
"path/filepath"
"sync"
"testing"

"github.com/buke/typescript-go-internal/pkg/tspath"
"github.com/buke/typescript-go-internal/pkg/vfs"
"github.com/buke/typescript-go-internal/pkg/vfs/osvfs"
)

const embedded = false
Expand All @@ -24,11 +24,9 @@ var executableDir = sync.OnceValue(func() string {
if err != nil {
panic(fmt.Sprintf("bundled: failed to get executable path: %v", err))
}
exe, err = filepath.EvalSymlinks(exe)
if err != nil {
panic(fmt.Sprintf("bundled: failed to evaluate symlinks: %v", err))
}
return filepath.Dir(exe)
exe = tspath.NormalizeSlashes(exe)
exe = osvfs.FS().Realpath(exe)
return tspath.GetDirectoryPath(exe)
})

var libPath = sync.OnceValue(func() string {
Expand All @@ -37,10 +35,10 @@ var libPath = sync.OnceValue(func() string {
}
dir := executableDir()

libdts := filepath.Join(dir, "lib.d.ts")
if _, err := os.Stat(libdts); err != nil {
libdts := tspath.CombinePaths(dir, "lib.d.ts")
if info := osvfs.FS().Stat(libdts); info == nil {
panic(fmt.Sprintf("bundled: %v does not exist; this executable may be misplaced", libdts))
}

return tspath.NormalizeSlashes(dir)
return dir
})
2 changes: 1 addition & 1 deletion pkg/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (r *EmitResolver) IsTopLevelValueImportEqualsWithEntityName(node *ast.Node)
return false
}
if ast.IsImportEqualsDeclaration(node) &&
(ast.NodeIsMissing(node.AsImportEqualsDeclaration().ModuleReference) || node.AsImportEqualsDeclaration().ModuleReference.Kind != ast.KindExternalModuleReference) {
(ast.NodeIsMissing(node.AsImportEqualsDeclaration().ModuleReference) || node.AsImportEqualsDeclaration().ModuleReference.Kind == ast.KindExternalModuleReference) {
return false
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,20 @@ var (
defaultDocumentSymbolCapabilities = &lsproto.DocumentSymbolClientCapabilities{
HierarchicalDocumentSymbolSupport: ptrTrue,
}
defaultFoldingRangeCapabilities = &lsproto.FoldingRangeClientCapabilities{
RangeLimit: ptrTo[uint32](5000),
// LineFoldingOnly: ptrTrue,
FoldingRangeKind: &lsproto.ClientFoldingRangeKindOptions{
ValueSet: &[]lsproto.FoldingRangeKind{
lsproto.FoldingRangeKindComment,
lsproto.FoldingRangeKindImports,
lsproto.FoldingRangeKindRegion,
},
},
FoldingRange: &lsproto.ClientFoldingRangeOptions{
CollapsedText: ptrTrue, // Unused by our testing, but set to exercise the code.
},
}
)

func getCapabilitiesWithDefaults(capabilities *lsproto.ClientCapabilities) *lsproto.ClientCapabilities {
Expand Down Expand Up @@ -554,6 +568,9 @@ func getCapabilitiesWithDefaults(capabilities *lsproto.ClientCapabilities) *lspr
if capabilitiesWithDefaults.TextDocument.DocumentSymbol == nil {
capabilitiesWithDefaults.TextDocument.DocumentSymbol = defaultDocumentSymbolCapabilities
}
if capabilitiesWithDefaults.TextDocument.FoldingRange == nil {
capabilitiesWithDefaults.TextDocument.FoldingRange = defaultFoldingRangeCapabilities
}
return &capabilitiesWithDefaults
}

Expand Down
Loading