Skip to content

Commit be81386

Browse files
dependabot[bot]github-actions[bot]buke
authored
deps(deps): bump microsoft/typescript-go from f16a4b7 to 5ac8497 (#49)
* deps(deps): bump microsoft/typescript-go from `f16a4b7` to `5ac8497` Bumps [microsoft/typescript-go](https://github.com/microsoft/typescript-go) from `f16a4b7` to `5ac8497`. - [Commits](microsoft/typescript-go@f16a4b7...5ac8497) --- updated-dependencies: - dependency-name: microsoft/typescript-go dependency-version: 5ac849745370fdc0ce72a07125d6b76b49517d0f dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(sync): mirror internal packages into pkg/ (auto) (#50) Co-authored-by: buke <1013738+buke@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: buke <1013738+buke@users.noreply.github.com>
1 parent d7ae476 commit be81386

File tree

439 files changed

+25307
-1536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

439 files changed

+25307
-1536
lines changed

microsoft/typescript-go

Submodule typescript-go updated 455 files

pkg/ast/ast.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/buke/typescript-go-internal/pkg/collections"
1111
"github.com/buke/typescript-go-internal/pkg/core"
1212
"github.com/buke/typescript-go-internal/pkg/tspath"
13+
"github.com/zeebo/xxh3"
1314
)
1415

1516
// Visitor
@@ -10779,8 +10780,10 @@ type SourceFile struct {
1077910780

1078010781
// Fields set by language service
1078110782

10783+
Hash xxh3.Uint128
1078210784
tokenCacheMu sync.Mutex
1078310785
tokenCache map[core.TextRange]*Node
10786+
tokenFactory *NodeFactory
1078410787
declarationMapMu sync.Mutex
1078510788
declarationMap map[string][]*Node
1078610789
}
@@ -10937,11 +10940,14 @@ func (node *SourceFile) BindOnce(bind func()) {
1093710940
})
1093810941
}
1093910942

10943+
// Gets a token from the file's token cache, or creates it if it does not already exist.
10944+
// This function should NOT be used for creating synthetic tokens that are not in the file in the first place.
1094010945
func (node *SourceFile) GetOrCreateToken(
1094110946
kind Kind,
1094210947
pos int,
1094310948
end int,
1094410949
parent *Node,
10950+
flags TokenFlags,
1094510951
) *TokenNode {
1094610952
node.tokenCacheMu.Lock()
1094710953
defer node.tokenCacheMu.Unlock()
@@ -10959,13 +10965,57 @@ func (node *SourceFile) GetOrCreateToken(
1095910965
return token
1096010966
}
1096110967

10962-
token := newNode(kind, &Token{}, NodeFactoryHooks{})
10968+
token := createToken(kind, node, pos, end, flags)
1096310969
token.Loc = loc
1096410970
token.Parent = parent
1096510971
node.tokenCache[loc] = token
1096610972
return token
1096710973
}
1096810974

10975+
// `kind` should be a token kind.
10976+
func createToken(kind Kind, file *SourceFile, pos, end int, flags TokenFlags) *Node {
10977+
if file.tokenFactory == nil {
10978+
file.tokenFactory = NewNodeFactory(NodeFactoryHooks{})
10979+
}
10980+
text := file.text[pos:end]
10981+
switch kind {
10982+
case KindNumericLiteral:
10983+
literal := file.tokenFactory.NewNumericLiteral(text)
10984+
literal.AsNumericLiteral().TokenFlags = flags & TokenFlagsNumericLiteralFlags
10985+
return literal
10986+
case KindBigIntLiteral:
10987+
literal := file.tokenFactory.NewBigIntLiteral(text)
10988+
literal.AsBigIntLiteral().TokenFlags = flags & TokenFlagsNumericLiteralFlags
10989+
return literal
10990+
case KindStringLiteral:
10991+
literal := file.tokenFactory.NewStringLiteral(text)
10992+
literal.AsStringLiteral().TokenFlags = flags & TokenFlagsStringLiteralFlags
10993+
return literal
10994+
case KindJsxText, KindJsxTextAllWhiteSpaces:
10995+
return file.tokenFactory.NewJsxText(text, kind == KindJsxTextAllWhiteSpaces)
10996+
case KindRegularExpressionLiteral:
10997+
literal := file.tokenFactory.NewRegularExpressionLiteral(text)
10998+
literal.AsRegularExpressionLiteral().TokenFlags = flags & TokenFlagsRegularExpressionLiteralFlags
10999+
return literal
11000+
case KindNoSubstitutionTemplateLiteral:
11001+
literal := file.tokenFactory.NewNoSubstitutionTemplateLiteral(text)
11002+
literal.AsNoSubstitutionTemplateLiteral().TokenFlags = flags & TokenFlagsTemplateLiteralLikeFlags
11003+
return literal
11004+
case KindTemplateHead:
11005+
return file.tokenFactory.NewTemplateHead(text, "" /*rawText*/, flags&TokenFlagsTemplateLiteralLikeFlags)
11006+
case KindTemplateMiddle:
11007+
return file.tokenFactory.NewTemplateMiddle(text, "" /*rawText*/, flags&TokenFlagsTemplateLiteralLikeFlags)
11008+
case KindTemplateTail:
11009+
return file.tokenFactory.NewTemplateTail(text, "" /*rawText*/, flags&TokenFlagsTemplateLiteralLikeFlags)
11010+
case KindIdentifier:
11011+
return file.tokenFactory.NewIdentifier(text)
11012+
case KindPrivateIdentifier:
11013+
return file.tokenFactory.NewPrivateIdentifier(text)
11014+
default: // Punctuation and keywords
11015+
return file.tokenFactory.NewToken(kind)
11016+
}
11017+
}
11018+
1096911019
func IsSourceFile(node *Node) bool {
1097011020
return node.Kind == KindSourceFile
1097111021
}

pkg/ast/diagnostic.go

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package ast
22

33
import (
4-
"maps"
54
"slices"
65
"strings"
6+
"sync"
77

8+
"github.com/buke/typescript-go-internal/pkg/collections"
89
"github.com/buke/typescript-go-internal/pkg/core"
910
"github.com/buke/typescript-go-internal/pkg/diagnostics"
1011
"github.com/buke/typescript-go-internal/pkg/locale"
@@ -140,28 +141,42 @@ func NewCompilerDiagnostic(message *diagnostics.Message, args ...any) *Diagnosti
140141
}
141142

142143
type DiagnosticsCollection struct {
143-
fileDiagnostics map[string][]*Diagnostic
144-
nonFileDiagnostics []*Diagnostic
144+
mu sync.Mutex
145+
count int
146+
fileDiagnostics map[string][]*Diagnostic
147+
fileDiagnosticsSorted collections.Set[string]
148+
nonFileDiagnostics []*Diagnostic
149+
nonFileDiagnosticsSorted bool
145150
}
146151

147152
func (c *DiagnosticsCollection) Add(diagnostic *Diagnostic) {
153+
c.mu.Lock()
154+
defer c.mu.Unlock()
155+
156+
c.count++
157+
148158
if diagnostic.File() != nil {
149159
fileName := diagnostic.File().FileName()
150160
if c.fileDiagnostics == nil {
151161
c.fileDiagnostics = make(map[string][]*Diagnostic)
152162
}
153-
c.fileDiagnostics[fileName] = core.InsertSorted(c.fileDiagnostics[fileName], diagnostic, CompareDiagnostics)
163+
c.fileDiagnostics[fileName] = append(c.fileDiagnostics[fileName], diagnostic)
164+
c.fileDiagnosticsSorted.Delete(fileName)
154165
} else {
155-
c.nonFileDiagnostics = core.InsertSorted(c.nonFileDiagnostics, diagnostic, CompareDiagnostics)
166+
c.nonFileDiagnostics = append(c.nonFileDiagnostics, diagnostic)
167+
c.nonFileDiagnosticsSorted = false
156168
}
157169
}
158170

159171
func (c *DiagnosticsCollection) Lookup(diagnostic *Diagnostic) *Diagnostic {
172+
c.mu.Lock()
173+
defer c.mu.Unlock()
174+
160175
var diagnostics []*Diagnostic
161176
if diagnostic.File() != nil {
162-
diagnostics = c.fileDiagnostics[diagnostic.File().FileName()]
177+
diagnostics = c.getDiagnosticsForFileLocked(diagnostic.File().FileName())
163178
} else {
164-
diagnostics = c.nonFileDiagnostics
179+
diagnostics = c.getGlobalDiagnosticsLocked()
165180
}
166181
if i, ok := slices.BinarySearchFunc(diagnostics, diagnostic, CompareDiagnostics); ok {
167182
return diagnostics[i]
@@ -170,20 +185,45 @@ func (c *DiagnosticsCollection) Lookup(diagnostic *Diagnostic) *Diagnostic {
170185
}
171186

172187
func (c *DiagnosticsCollection) GetGlobalDiagnostics() []*Diagnostic {
173-
return c.nonFileDiagnostics
188+
c.mu.Lock()
189+
defer c.mu.Unlock()
190+
191+
return c.getGlobalDiagnosticsLocked()
192+
}
193+
194+
func (c *DiagnosticsCollection) getGlobalDiagnosticsLocked() []*Diagnostic {
195+
if !c.nonFileDiagnosticsSorted {
196+
slices.SortStableFunc(c.nonFileDiagnostics, CompareDiagnostics)
197+
c.nonFileDiagnosticsSorted = true
198+
}
199+
return slices.Clone(c.nonFileDiagnostics)
174200
}
175201

176202
func (c *DiagnosticsCollection) GetDiagnosticsForFile(fileName string) []*Diagnostic {
177-
return c.fileDiagnostics[fileName]
203+
c.mu.Lock()
204+
defer c.mu.Unlock()
205+
206+
return c.getDiagnosticsForFileLocked(fileName)
207+
}
208+
209+
func (c *DiagnosticsCollection) getDiagnosticsForFileLocked(fileName string) []*Diagnostic {
210+
if !c.fileDiagnosticsSorted.Has(fileName) {
211+
slices.SortStableFunc(c.fileDiagnostics[fileName], CompareDiagnostics)
212+
c.fileDiagnosticsSorted.Add(fileName)
213+
}
214+
return slices.Clone(c.fileDiagnostics[fileName])
178215
}
179216

180217
func (c *DiagnosticsCollection) GetDiagnostics() []*Diagnostic {
181-
fileNames := slices.Collect(maps.Keys(c.fileDiagnostics))
182-
slices.Sort(fileNames)
183-
diagnostics := slices.Clip(c.nonFileDiagnostics)
184-
for _, fileName := range fileNames {
185-
diagnostics = append(diagnostics, c.fileDiagnostics[fileName]...)
218+
c.mu.Lock()
219+
defer c.mu.Unlock()
220+
221+
diagnostics := make([]*Diagnostic, 0, c.count)
222+
diagnostics = append(diagnostics, c.nonFileDiagnostics...)
223+
for _, diags := range c.fileDiagnostics {
224+
diagnostics = append(diagnostics, diags...)
186225
}
226+
slices.SortFunc(diagnostics, CompareDiagnostics)
187227
return diagnostics
188228
}
189229

pkg/astnav/tokens.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,18 @@ func getTokenAtPosition(
187187
tokenFullStart := scanner.TokenFullStart()
188188
tokenStart := core.IfElse(allowPositionInLeadingTrivia, tokenFullStart, scanner.TokenStart())
189189
tokenEnd := scanner.TokenEnd()
190+
flags := scanner.TokenFlags()
190191
if tokenStart <= position && (position < tokenEnd) {
191192
if token == ast.KindIdentifier || !ast.IsTokenKind(token) {
192193
if ast.IsJSDocKind(current.Kind) {
193194
return current
194195
}
195196
panic(fmt.Sprintf("did not expect %s to have %s in its trivia", current.Kind.String(), token.String()))
196197
}
197-
return sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, current)
198+
return sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, current, flags)
198199
}
199200
if includePrecedingTokenAtEndPosition != nil && tokenEnd == position {
200-
prevToken := sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, current)
201+
prevToken := sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, current, flags)
201202
if includePrecedingTokenAtEndPosition(prevToken) {
202203
return prevToken
203204
}
@@ -514,7 +515,8 @@ func findRightmostValidToken(endPos int, sourceFile *ast.SourceFile, containingN
514515
tokenFullStart := scanner.TokenFullStart()
515516
tokenEnd := scanner.TokenEnd()
516517
startPos = tokenEnd
517-
tokens = append(tokens, sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, n))
518+
flags := scanner.TokenFlags()
519+
tokens = append(tokens, sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, n, flags))
518520
scanner.Scan()
519521
}
520522
startPos = visitedNode.End()
@@ -531,7 +533,8 @@ func findRightmostValidToken(endPos int, sourceFile *ast.SourceFile, containingN
531533
tokenFullStart := scanner.TokenFullStart()
532534
tokenEnd := scanner.TokenEnd()
533535
startPos = tokenEnd
534-
tokens = append(tokens, sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, n))
536+
flags := scanner.TokenFlags()
537+
tokens = append(tokens, sourceFile.GetOrCreateToken(token, tokenFullStart, tokenEnd, n, flags))
535538
scanner.Scan()
536539
}
537540

@@ -616,8 +619,9 @@ func FindNextToken(previousToken *ast.Node, parent *ast.Node, file *ast.SourceFi
616619
tokenFullStart := scanner.TokenFullStart()
617620
tokenStart := scanner.TokenStart()
618621
tokenEnd := scanner.TokenEnd()
622+
flags := scanner.TokenFlags()
619623
if tokenStart == previousToken.End() {
620-
return file.GetOrCreateToken(token, tokenFullStart, tokenEnd, n)
624+
return file.GetOrCreateToken(token, tokenFullStart, tokenEnd, n, flags)
621625
}
622626
panic(fmt.Sprintf("Expected to find next token at %d, got token %s at %d", previousToken.End(), token, tokenStart))
623627
}
@@ -690,7 +694,8 @@ func FindChildOfKind(containingNode *ast.Node, kind ast.Kind, sourceFile *ast.So
690694
tokenKind := scan.Token()
691695
tokenFullStart := scan.TokenFullStart()
692696
tokenEnd := scan.TokenEnd()
693-
token := sourceFile.GetOrCreateToken(tokenKind, tokenFullStart, tokenEnd, containingNode)
697+
flags := scan.TokenFlags()
698+
token := sourceFile.GetOrCreateToken(tokenKind, tokenFullStart, tokenEnd, containingNode, flags)
694699
if tokenKind == kind {
695700
foundChild = token
696701
return true
@@ -720,7 +725,8 @@ func FindChildOfKind(containingNode *ast.Node, kind ast.Kind, sourceFile *ast.So
720725
tokenKind := scan.Token()
721726
tokenFullStart := scan.TokenFullStart()
722727
tokenEnd := scan.TokenEnd()
723-
token := sourceFile.GetOrCreateToken(tokenKind, tokenFullStart, tokenEnd, containingNode)
728+
flags := scan.TokenFlags()
729+
token := sourceFile.GetOrCreateToken(tokenKind, tokenFullStart, tokenEnd, containingNode, flags)
724730
if tokenKind == kind {
725731
return token
726732
}

pkg/checker/checker.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ type Program interface {
540540
GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
541541
GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
542542
SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmit bool) bool
543-
IsSourceFromProjectReference(path tspath.Path) bool
544543
IsSourceFileDefaultLibrary(path tspath.Path) bool
545544
GetProjectReferenceFromOutputDts(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
546545
GetRedirectForResolution(file ast.HasFileName) *tsoptions.ParsedCommandLine
@@ -930,8 +929,6 @@ func NewChecker(program Program) (*Checker, *sync.Mutex) {
930929
c.unionTypes = make(map[string]*Type)
931930
c.unionOfUnionTypes = make(map[UnionOfUnionKey]*Type)
932931
c.intersectionTypes = make(map[string]*Type)
933-
c.diagnostics = ast.DiagnosticsCollection{}
934-
c.suggestionDiagnostics = ast.DiagnosticsCollection{}
935932
c.mergedSymbols = make(map[*ast.Symbol]*ast.Symbol)
936933
c.patternForType = make(map[*Type]*ast.Node)
937934
c.contextFreeTypes = make(map[*ast.Node]*Type)
@@ -2094,13 +2091,6 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy
20942091
return nil
20952092
}
20962093

2097-
func (c *Checker) CheckSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
2098-
if SkipTypeChecking(sourceFile, c.compilerOptions, c.program, false) {
2099-
return
2100-
}
2101-
c.checkSourceFile(ctx, sourceFile)
2102-
}
2103-
21042094
func (c *Checker) checkSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
21052095
c.checkNotCanceled()
21062096
links := c.sourceFileLinks.Get(sourceFile)
@@ -13507,30 +13497,20 @@ func (c *Checker) getDiagnostics(ctx context.Context, sourceFile *ast.SourceFile
1350713497
c.checkNotCanceled()
1350813498
isSuggestionDiagnostics := collection == &c.suggestionDiagnostics
1350913499

13510-
files := c.files
13511-
if sourceFile != nil {
13512-
files = []*ast.SourceFile{sourceFile}
13500+
c.checkSourceFile(ctx, sourceFile)
13501+
if c.wasCanceled {
13502+
return nil
1351313503
}
1351413504

13515-
for _, file := range files {
13516-
c.CheckSourceFile(ctx, file)
13517-
if c.wasCanceled {
13518-
return nil
13519-
}
13520-
13521-
// Check unused identifiers as suggestions if we're collecting suggestion diagnostics
13522-
// and they are not configured as errors
13523-
if isSuggestionDiagnostics && !file.IsDeclarationFile &&
13524-
!(c.compilerOptions.NoUnusedLocals.IsTrue() || c.compilerOptions.NoUnusedParameters.IsTrue()) {
13525-
links := c.sourceFileLinks.Get(file)
13526-
c.checkUnusedIdentifiers(links.identifierCheckNodes)
13527-
}
13505+
// Check unused identifiers as suggestions if we're collecting suggestion diagnostics
13506+
// and they are not configured as errors
13507+
if isSuggestionDiagnostics && !sourceFile.IsDeclarationFile &&
13508+
!(c.compilerOptions.NoUnusedLocals.IsTrue() || c.compilerOptions.NoUnusedParameters.IsTrue()) {
13509+
links := c.sourceFileLinks.Get(sourceFile)
13510+
c.checkUnusedIdentifiers(links.identifierCheckNodes)
1352813511
}
1352913512

13530-
if sourceFile != nil {
13531-
return collection.GetDiagnosticsForFile(sourceFile.FileName())
13532-
}
13533-
return collection.GetDiagnostics()
13513+
return collection.GetDiagnosticsForFile(sourceFile.FileName())
1353413514
}
1353513515

1353613516
func (c *Checker) GetGlobalDiagnostics() []*ast.Diagnostic {
@@ -15800,7 +15780,7 @@ func (c *Checker) resolveAlias(symbol *ast.Symbol) *ast.Symbol {
1580015780
}
1580115781

1580215782
func (c *Checker) resolveIndirectionAlias(source *ast.Symbol, target *ast.Symbol) *ast.Symbol {
15803-
result := c.resolveAlias(target)
15783+
result := c.getMergedSymbol(c.resolveAlias(target))
1580415784
if targetLinks := c.aliasSymbolLinks.Get(target); targetLinks.typeOnlyDeclaration != nil {
1580515785
if sourceLinks := c.aliasSymbolLinks.Get(source); sourceLinks.typeOnlyDeclaration == nil {
1580615786
sourceLinks.typeOnlyDeclaration = targetLinks.typeOnlyDeclaration
@@ -27691,7 +27671,7 @@ func (c *Checker) markJsxAliasReferenced(node *ast.Node /*JsxOpeningLikeElement
2769127671
// Mark local symbol as referenced here because it might not have been marked
2769227672
// if jsx emit was not jsxFactory as there wont be error being emitted
2769327673
c.symbolReferenced(jsxFactorySym, ast.SymbolFlagsAll)
27694-
// If react/jsxFactory symbol is alias, mark it as refereced
27674+
// If react/jsxFactory symbol is alias, mark it as referenced
2769527675
if c.canCollectSymbolAliasAccessibilityData && jsxFactorySym.Flags&ast.SymbolFlagsAlias != 0 && c.getTypeOnlyAliasDeclaration(jsxFactorySym) == nil {
2769627676
c.markAliasSymbolAsReferenced(jsxFactorySym)
2769727677
}

pkg/checker/jsx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ func (c *Checker) getJsxManagedAttributesFromLocatedAttributes(context *ast.Node
10301030

10311031
func (c *Checker) instantiateAliasOrInterfaceWithDefaults(managedSym *ast.Symbol, typeArguments []*Type, inJavaScript bool) *Type {
10321032
declaredManagedType := c.getDeclaredTypeOfSymbol(managedSym)
1033-
// fetches interface type, or initializes symbol links type parmaeters
1033+
// fetches interface type, or initializes symbol links type parameters
10341034
if managedSym.Flags&ast.SymbolFlagsTypeAlias != 0 {
10351035
params := c.typeAliasLinks.Get(managedSym).typeParameters
10361036
if len(params) >= len(typeArguments) {

pkg/checker/nodebuilderimpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (b *NodeBuilderImpl) appendReferenceToType(root *ast.TypeNode, ref *ast.Typ
155155
imprt := root.AsImportTypeNode()
156156
// then move qualifiers
157157
ids := getAccessStack(ref)
158-
var qualifier *ast.Node
158+
qualifier := root.AsImportTypeNode().Qualifier
159159
for _, id := range ids {
160160
if qualifier != nil {
161161
qualifier = b.f.NewQualifiedName(qualifier, id)

0 commit comments

Comments
 (0)