Skip to content

Commit a76671b

Browse files
committed
merged main
2 parents c0fac1d + 0522ac5 commit a76671b

File tree

1,612 files changed

+37554
-25149
lines changed

Some content is hidden

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

1,612 files changed

+37554
-25149
lines changed

Herebyfile.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ export const buildNativePreviewPackages = task({
10771077
const inputPackageJson = JSON.parse(fs.readFileSync(path.join(inputDir, "package.json"), "utf8"));
10781078
inputPackageJson.version = getVersion();
10791079
delete inputPackageJson.private;
1080+
delete inputPackageJson.engines;
10801081

10811082
const { stdout: gitHead } = await $pipe`git rev-parse HEAD`;
10821083
inputPackageJson.gitHead = gitHead;

internal/ast/ast.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9665,6 +9665,10 @@ func IsJSDocParameterTag(node *Node) bool {
96659665
return node.Kind == KindJSDocParameterTag
96669666
}
96679667

9668+
func IsJSDocPropertyTag(node *Node) bool {
9669+
return node.Kind == KindJSDocPropertyTag
9670+
}
9671+
96689672
// JSDocReturnTag
96699673
type JSDocReturnTag struct {
96709674
JSDocTagBase
@@ -10141,6 +10145,8 @@ func (node *JSDocCallbackTag) Clone(f NodeFactoryCoercible) *Node {
1014110145
return cloneNode(f.AsNodeFactory().NewJSDocCallbackTag(node.TagName, node.TypeExpression, node.FullName, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
1014210146
}
1014310147

10148+
func (node *JSDocCallbackTag) Name() *DeclarationName { return node.FullName }
10149+
1014410150
func IsJSDocCallbackTag(node *Node) bool {
1014510151
return node.Kind == KindJSDocCallbackTag
1014610152
}
@@ -10290,6 +10296,10 @@ func (node *JSDocSignature) Clone(f NodeFactoryCoercible) *Node {
1029010296
return cloneNode(f.AsNodeFactory().NewJSDocSignature(node.TypeParameters, node.Parameters, node.Type), node.AsNode(), f.AsNodeFactory().hooks)
1029110297
}
1029210298

10299+
func IsJSDocSignature(node *Node) bool {
10300+
return node.Kind == KindJSDocSignature
10301+
}
10302+
1029310303
// JSDocNameReference
1029410304
type JSDocNameReference struct {
1029510305
TypeNodeBase
@@ -10323,6 +10333,10 @@ func (node *JSDocNameReference) Clone(f NodeFactoryCoercible) *Node {
1032310333

1032410334
func (node *JSDocNameReference) Name() *EntityName { return node.name }
1032510335

10336+
func IsJSDocNameReference(node *Node) bool {
10337+
return node.Kind == KindJSDocNameReference
10338+
}
10339+
1032610340
// PatternAmbientModule
1032710341

1032810342
type PatternAmbientModule struct {

internal/ast/utilities.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ func IsClassLike(node *Node) bool {
552552
return node.Kind == KindClassDeclaration || node.Kind == KindClassExpression
553553
}
554554

555+
func IsClassOrInterfaceLike(node *Node) bool {
556+
return node.Kind == KindClassDeclaration || node.Kind == KindClassExpression || node.Kind == KindInterfaceDeclaration
557+
}
558+
555559
func IsClassElement(node *Node) bool {
556560
switch node.Kind {
557561
case KindConstructor,
@@ -1899,13 +1903,11 @@ func IsExpressionNode(node *Node) bool {
18991903
for node.Parent.Kind == KindQualifiedName {
19001904
node = node.Parent
19011905
}
1902-
return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || isJSXTagName(node)
1903-
case KindJSDocMemberName:
1904-
return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || isJSXTagName(node)
1906+
return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) || isJSXTagName(node)
19051907
case KindPrivateIdentifier:
19061908
return IsBinaryExpression(node.Parent) && node.Parent.AsBinaryExpression().Left == node && node.Parent.AsBinaryExpression().OperatorToken.Kind == KindInKeyword
19071909
case KindIdentifier:
1908-
if IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || isJSXTagName(node) {
1910+
if IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) || isJSXTagName(node) {
19091911
return true
19101912
}
19111913
fallthrough
@@ -2045,7 +2047,9 @@ func isPartOfTypeNodeInParent(node *Node) bool {
20452047

20462048
func isPartOfTypeExpressionWithTypeArguments(node *Node) bool {
20472049
parent := node.Parent
2048-
return IsHeritageClause(parent) && (!IsClassLike(parent.Parent) || parent.AsHeritageClause().Token == KindImplementsKeyword)
2050+
return IsHeritageClause(parent) && (!IsClassLike(parent.Parent) || parent.AsHeritageClause().Token == KindImplementsKeyword) ||
2051+
IsJSDocImplementsTag(parent) ||
2052+
IsJSDocAugmentsTag(parent)
20492053
}
20502054

20512055
func IsJSDocLinkLike(node *Node) bool {
@@ -2620,12 +2624,12 @@ func IsParseTreeNode(node *Node) bool {
26202624
return node.Flags&NodeFlagsSynthesized == 0
26212625
}
26222626

2623-
// Returns a token if position is in [start-of-leading-trivia, end), includes JSDoc only in JS files
2624-
func GetNodeAtPosition(file *SourceFile, position int, isJavaScriptFile bool) *Node {
2627+
// Returns a token if position is in [start-of-leading-trivia, end), includes JSDoc only if requested
2628+
func GetNodeAtPosition(file *SourceFile, position int, includeJSDoc bool) *Node {
26252629
current := file.AsNode()
26262630
for {
26272631
var child *Node
2628-
if isJavaScriptFile {
2632+
if includeJSDoc {
26292633
for _, jsdoc := range current.JSDoc(file) {
26302634
if nodeContainsPosition(jsdoc, position) {
26312635
child = jsdoc
@@ -3867,3 +3871,9 @@ func GetRestIndicatorOfBindingOrAssignmentElement(bindingElement *Node) *Node {
38673871
}
38683872
return nil
38693873
}
3874+
3875+
func IsJSDocNameReferenceContext(node *Node) bool {
3876+
return node.Flags&NodeFlagsJSDoc != 0 && FindAncestor(node, func(node *Node) bool {
3877+
return IsJSDocNameReference(node) || IsJSDocLinkLike(node)
3878+
}) != nil
3879+
}

internal/astnav/tokens.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,27 @@ import (
99
)
1010

1111
func GetTouchingPropertyName(sourceFile *ast.SourceFile, position int) *ast.Node {
12-
return getTokenAtPosition(sourceFile, position, false /*allowPositionInLeadingTrivia*/, func(node *ast.Node) bool {
12+
return getReparsedNodeForNode(getTokenAtPosition(sourceFile, position, false /*allowPositionInLeadingTrivia*/, func(node *ast.Node) bool {
1313
return ast.IsPropertyNameLiteral(node) || ast.IsKeywordKind(node.Kind) || ast.IsPrivateIdentifier(node)
14-
})
14+
}))
15+
}
16+
17+
// If the given node is a declaration name node in a JSDoc comment that is subject to reparsing, return the declaration name node
18+
// for the corresponding reparsed construct. Otherwise, just return the node.
19+
func getReparsedNodeForNode(node *ast.Node) *ast.Node {
20+
if node.Flags&ast.NodeFlagsJSDoc != 0 && (ast.IsIdentifier(node) || ast.IsPrivateIdentifier(node)) {
21+
parent := node.Parent
22+
if (ast.IsJSDocTypedefTag(parent) || ast.IsJSDocCallbackTag(parent) || ast.IsJSDocPropertyTag(parent) || ast.IsJSDocParameterTag(parent) || ast.IsImportClause(parent) || ast.IsImportSpecifier(parent)) && parent.Name() == node {
23+
// Reparsing preserves the location of the name. Thus, a search at the position of the name with JSDoc excluded
24+
// finds the containing reparsed declaration node.
25+
if reparsed := ast.GetNodeAtPosition(ast.GetSourceFileOfNode(node), node.Pos(), false); reparsed != nil {
26+
if name := reparsed.Name(); name != nil && name.Pos() == node.Pos() {
27+
return name
28+
}
29+
}
30+
}
31+
}
32+
return node
1533
}
1634

1735
func GetTouchingToken(sourceFile *ast.SourceFile, position int) *ast.Node {

internal/checker/checker.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,10 +2368,11 @@ func (c *Checker) checkJSDocComment(node *ast.Node, location *ast.Node) {
23682368
func (c *Checker) resolveJSDocMemberName(name *ast.Node, location *ast.Node) *ast.Symbol {
23692369
if name != nil && ast.IsEntityName(name) {
23702370
meaning := ast.SymbolFlagsType | ast.SymbolFlagsNamespace | ast.SymbolFlagsValue
2371-
symbol := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, location)
2372-
if symbol == nil && ast.IsQualifiedName(name) {
2373-
symbol := c.resolveJSDocMemberName(name.AsQualifiedName().Left, location)
2374-
if symbol != nil {
2371+
if symbol := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, location); symbol != nil {
2372+
return symbol
2373+
}
2374+
if ast.IsQualifiedName(name) {
2375+
if symbol := c.resolveJSDocMemberName(name.AsQualifiedName().Left, location); symbol != nil {
23752376
var t *Type
23762377
if symbol.Flags&ast.SymbolFlagsValue != 0 {
23772378
proto := c.getPropertyOfType(c.getTypeOfSymbol(symbol), "prototype")
@@ -30203,19 +30204,15 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
3020330204
return c.getSymbolOfDeclaration(grandParent)
3020430205
}
3020530206

30206-
if node.Kind == ast.KindIdentifier {
30207+
if ast.IsIdentifier(node) {
3020730208
if isInRightSideOfImportOrExportAssignment(node) {
3020830209
return c.getSymbolOfNameOrPropertyAccessExpression(node)
30209-
} else if parent.Kind == ast.KindBindingElement &&
30210-
grandParent.Kind == ast.KindObjectBindingPattern &&
30211-
node == parent.AsBindingElement().PropertyName {
30210+
} else if ast.IsBindingElement(parent) && ast.IsObjectBindingPattern(grandParent) && node == parent.PropertyName() {
3021230211
typeOfPattern := c.getTypeOfNode(grandParent)
30213-
propertyDeclaration := c.getPropertyOfType(typeOfPattern, node.Text())
30214-
30215-
if propertyDeclaration != nil {
30212+
if propertyDeclaration := c.getPropertyOfType(typeOfPattern, node.Text()); propertyDeclaration != nil {
3021630213
return propertyDeclaration
3021730214
}
30218-
} else if ast.IsMetaProperty(parent) && parent.AsMetaProperty().Name() == node {
30215+
} else if ast.IsMetaProperty(parent) && parent.Name() == node {
3021930216
metaProp := parent.AsMetaProperty()
3022030217
if metaProp.KeywordToken == ast.KindNewKeyword && node.Text() == "target" {
3022130218
// `target` in `new.target`
@@ -30230,6 +30227,14 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
3023030227
}
3023130228
// no other meta properties are valid syntax, thus no others should have symbols
3023230229
return nil
30230+
} else if ast.IsJSDocParameterTag(parent) && parent.Name() == node {
30231+
if fn := ast.GetNodeAtPosition(ast.GetSourceFileOfNode(node), node.Pos(), false); fn != nil && ast.IsFunctionLike(fn) {
30232+
for _, param := range fn.Parameters() {
30233+
if param.Name().Text() == node.Text() {
30234+
return c.getSymbolOfNode(param)
30235+
}
30236+
}
30237+
}
3023330238
}
3023430239
}
3023530240

@@ -30418,28 +30423,32 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast
3041830423
// Missing entity name.
3041930424
return nil
3042030425
}
30421-
30422-
if name.Kind == ast.KindIdentifier {
30426+
isJSDoc := ast.IsJSDocNameReferenceContext(name)
30427+
if ast.IsIdentifier(name) {
3042330428
if ast.IsJsxTagName(name) && isJsxIntrinsicTagName(name) {
3042430429
symbol := c.getIntrinsicTagSymbol(name.Parent)
3042530430
return core.IfElse(symbol == c.unknownSymbol, nil, symbol)
3042630431
}
30427-
result := c.resolveEntityName(
30428-
name,
30429-
ast.SymbolFlagsValue, /*meaning*/
30430-
true, /*ignoreErrors*/
30431-
true, /*dontResolveAlias*/
30432-
nil /*location*/)
30432+
meaning := core.IfElse(isJSDoc, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, ast.SymbolFlagsValue)
30433+
result := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, nil /*location*/)
30434+
if result == nil && isJSDoc {
30435+
if container := ast.FindAncestor(name, ast.IsClassOrInterfaceLike); container != nil {
30436+
symbol := c.getSymbolOfDeclaration(container)
30437+
// Handle unqualified references to class static members and class or interface instance members
30438+
if result = c.getMergedSymbol(c.getSymbol(c.getExportsOfSymbol(symbol), name.Text(), meaning)); result == nil {
30439+
result = c.getPropertyOfType(c.getDeclaredTypeOfSymbol(symbol), name.Text())
30440+
}
30441+
}
30442+
}
3043330443
return result
3043430444
} else if ast.IsPrivateIdentifier(name) {
3043530445
return c.getSymbolForPrivateIdentifierExpression(name)
30436-
} else if name.Kind == ast.KindPropertyAccessExpression || name.Kind == ast.KindQualifiedName {
30446+
} else if ast.IsPropertyAccessExpression(name) || ast.IsQualifiedName(name) {
3043730447
links := c.symbolNodeLinks.Get(name)
3043830448
if links.resolvedSymbol != nil {
3043930449
return links.resolvedSymbol
3044030450
}
30441-
30442-
if name.Kind == ast.KindPropertyAccessExpression {
30451+
if ast.IsPropertyAccessExpression(name) {
3044330452
c.checkPropertyAccessExpression(name, CheckModeNormal, false /*writeOnly*/)
3044430453
if links.resolvedSymbol == nil {
3044530454
links.resolvedSymbol = c.getApplicableIndexSymbol(
@@ -30450,7 +30459,9 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast
3045030459
} else {
3045130460
c.checkQualifiedName(name, CheckModeNormal)
3045230461
}
30453-
30462+
if links.resolvedSymbol == nil && isJSDoc && ast.IsQualifiedName(name) {
30463+
return c.resolveJSDocMemberName(name, nil)
30464+
}
3045430465
return links.resolvedSymbol
3045530466
}
3045630467
} else if ast.IsEntityName(name) && isTypeReferenceIdentifier(name) {

internal/compiler/fileloader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ func processAllProgramFiles(
254254
unsupportedExtensions: unsupportedExtensions,
255255
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
256256
libFiles: libFilesMap,
257+
missingFiles: missingFiles,
257258
includeProcessor: loader.includeProcessor,
258259
outputFileToProjectReferenceSource: outputFileToProjectReferenceSource,
259260
}
@@ -356,7 +357,7 @@ func (p *fileLoader) addProjectReferenceTasks(singleThreaded bool) {
356357
})
357358
}
358359
} else {
359-
for outputDts := range resolved.GetOutputDeclarationFileNames() {
360+
for outputDts := range resolved.GetOutputDeclarationAndSourceFileNames() {
360361
if outputDts != "" {
361362
p.rootTasks = append(p.rootTasks, &parseTask{
362363
normalizedFilePath: outputDts,

internal/compiler/filesparser.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,15 @@ func (w *filesParser) collect(loader *fileLoader, tasks []*parseTask, iterate fu
240240

241241
func (w *filesParser) collectWorker(loader *fileLoader, tasks []*parseTask, iterate func(*parseTask), seen collections.Set[*parseTask]) {
242242
for _, task := range tasks {
243-
if task.redirectedParseTask == nil {
243+
// Exclude automatic type directive tasks from include reason processing,
244+
// as these are internal implementation details and should not contribute
245+
// to the reasons for including files.
246+
if task.redirectedParseTask == nil && !task.isForAutomaticTypeDirective {
244247
includeReason := task.includeReason
245248
if task.loadedTask != nil {
246249
task = task.loadedTask
247250
}
248-
if existing, ok := loader.includeProcessor.fileIncludeReasons[task.path]; ok {
249-
loader.includeProcessor.fileIncludeReasons[task.path] = append(existing, includeReason)
250-
} else {
251-
loader.includeProcessor.fileIncludeReasons[task.path] = []*fileIncludeReason{includeReason}
252-
}
251+
w.addIncludeReason(loader, task, includeReason)
253252
}
254253
// ensure we only walk each task once
255254
if !task.loaded || !seen.AddIfAbsent(task) {
@@ -267,3 +266,15 @@ func (w *filesParser) collectWorker(loader *fileLoader, tasks []*parseTask, iter
267266
iterate(task)
268267
}
269268
}
269+
270+
func (w *filesParser) addIncludeReason(loader *fileLoader, task *parseTask, reason *fileIncludeReason) {
271+
if task.redirectedParseTask != nil {
272+
w.addIncludeReason(loader, task.redirectedParseTask, reason)
273+
} else if task.loaded {
274+
if existing, ok := loader.includeProcessor.fileIncludeReasons[task.path]; ok {
275+
loader.includeProcessor.fileIncludeReasons[task.path] = append(existing, reason)
276+
} else {
277+
loader.includeProcessor.fileIncludeReasons[task.path] = []*fileIncludeReason{reason}
278+
}
279+
}
280+
}

internal/compiler/program.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,18 @@ func (p *Program) GetSourceFiles() []*ast.SourceFile {
15411541
return p.files
15421542
}
15431543

1544+
// Testing only
1545+
func (p *Program) GetIncludeReasons() map[tspath.Path][]*fileIncludeReason {
1546+
return p.includeProcessor.fileIncludeReasons
1547+
}
1548+
1549+
// Testing only
1550+
func (p *Program) IsMissingPath(path tspath.Path) bool {
1551+
return slices.ContainsFunc(p.missingFiles, func(missingPath string) bool {
1552+
return p.toPath(missingPath) == path
1553+
})
1554+
}
1555+
15441556
func (p *Program) ExplainFiles(w io.Writer) {
15451557
toRelativeFileName := func(fileName string) string {
15461558
return tspath.GetRelativePathFromDirectory(p.GetCurrentDirectory(), fileName, p.comparePathsOptions)

internal/execute/incremental/program.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler
320320
len(program.GetConfigFileParsingDiagnostics()) > 0 ||
321321
len(program.GetSyntacticDiagnostics(ctx, nil)) > 0 ||
322322
len(program.GetProgramDiagnostics()) > 0 ||
323-
len(program.GetBindDiagnostics(ctx, nil)) > 0 ||
324323
len(program.GetOptionsDiagnostics(ctx)) > 0 ||
325324
len(program.GetGlobalDiagnostics(ctx)) > 0 {
326325
p.snapshot.hasErrors = core.TSTrue

internal/execute/tsctests/runner.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func (test *tscInput) run(t *testing.T, scenario string) {
8080
sys.baselineFSwithDiff(baselineBuilder)
8181
result := test.executeCommand(sys, baselineBuilder, test.commandLineArgs)
8282
sys.serializeState(baselineBuilder)
83-
sys.baselinePrograms(baselineBuilder)
84-
var unexpectedDiff string
83+
unexpectedDiff := sys.baselinePrograms(baselineBuilder, "Initial build")
8584

8685
for index, do := range test.edits {
8786
sys.clearOutput()
@@ -101,7 +100,7 @@ func (test *tscInput) run(t *testing.T, scenario string) {
101100
result.Watcher.DoCycle()
102101
}
103102
sys.serializeState(baselineBuilder)
104-
sys.baselinePrograms(baselineBuilder)
103+
unexpectedDiff += sys.baselinePrograms(baselineBuilder, fmt.Sprintf("Edit [%d]:: %s\n", index, do.caption))
105104
})
106105
wg.Queue(func() {
107106
// Compute build with all the edits

0 commit comments

Comments
 (0)