Skip to content

Commit 24985b7

Browse files
authored
Merge branch 'main' into main
2 parents bab6338 + 55cbead commit 24985b7

File tree

140 files changed

+1195
-1648
lines changed

Some content is hidden

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

140 files changed

+1195
-1648
lines changed

.github/workflows/create-cache.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ defaults:
2020

2121
jobs:
2222
cache:
23+
if: github.repository == 'microsoft/typescript-go'
24+
2325
strategy:
2426
fail-fast: false
2527
matrix:

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- errname
2323
- errorlint
2424
- fatcontext
25+
- forbidigo
2526
- gocheckcompilerdirectives
2627
- goprintffuncname
2728
- govet
@@ -70,11 +71,30 @@ linters:
7071
- pkg: 'encoding/json$'
7172
desc: 'Use "github.com/go-json-experiment/json" instead.'
7273

74+
forbidigo:
75+
analyze-types: true
76+
forbid:
77+
- pattern: '.*'
78+
msg: tspath should likely be used instead
79+
pkg: ^(path|path/filepath)$
80+
- pattern: '.*'
81+
msg: a host implementation should likely be used instead
82+
pkg: ^os/
83+
- pattern: 'GOOS'
84+
msg: a host implementation should likely be used instead
85+
pkg: ^runtime$
86+
7387
exclusions:
7488
rules:
7589
- path: internal/fourslash/tests/gen/
7690
linters:
7791
- misspell
92+
- path: 'internal/(repo|testutil|testrunner|vfs|pprof|execute/tsctests|bundled)|cmd/tsgo'
93+
text: should likely be used instead
94+
- path: '(.+)_test\.go$'
95+
text: should likely be used instead
96+
- path: '_tools'
97+
text: should likely be used instead
7898

7999
presets:
80100
- comments

_submodules/TypeScript

Submodule TypeScript updated 774 files

cmd/tsgo/lsp.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"os"
8+
"os/exec"
9+
"os/signal"
710
"runtime"
11+
"syscall"
812

913
"github.com/microsoft/typescript-go/internal/bundled"
1014
"github.com/microsoft/typescript-go/internal/core"
@@ -49,9 +53,17 @@ func runLSP(args []string) int {
4953
FS: fs,
5054
DefaultLibraryPath: defaultLibraryPath,
5155
TypingsLocation: typingsLocation,
56+
NpmInstall: func(cwd string, args []string) ([]byte, error) {
57+
cmd := exec.Command("npm", args...)
58+
cmd.Dir = cwd
59+
return cmd.Output()
60+
},
5261
})
5362

54-
if err := s.Run(); err != nil {
63+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
64+
defer stop()
65+
66+
if err := s.Run(ctx); err != nil {
5567
return 1
5668
}
5769
return 0

internal/ast/symbol.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const (
4343
InternalSymbolNameClass = InternalSymbolNamePrefix + "class" // Unnamed class expression
4444
InternalSymbolNameFunction = InternalSymbolNamePrefix + "function" // Unnamed function expression
4545
InternalSymbolNameComputed = InternalSymbolNamePrefix + "computed" // Computed property name declaration with dynamic name
46-
InternalSymbolNameResolving = InternalSymbolNamePrefix + "resolving" // Indicator symbol used to mark partially resolved type aliases
4746
InternalSymbolNameInstantiationExpression = InternalSymbolNamePrefix + "instantiationExpression" // Instantiation expressions
4847
InternalSymbolNameImportAttributes = InternalSymbolNamePrefix + "importAttributes"
4948
InternalSymbolNameExportEquals = "export=" // Export assignment symbol

internal/checker/checker.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const (
6161
TypeSystemPropertyNameResolvedBaseTypes
6262
TypeSystemPropertyNameWriteType
6363
TypeSystemPropertyNameInitializerIsUndefined
64+
TypeSystemPropertyNameAliasTarget
6465
)
6566

6667
type TypeResolution struct {
@@ -618,7 +619,6 @@ type Checker struct {
618619
argumentsSymbol *ast.Symbol
619620
requireSymbol *ast.Symbol
620621
unknownSymbol *ast.Symbol
621-
resolvingSymbol *ast.Symbol
622622
unresolvedSymbols map[string]*ast.Symbol
623623
errorTypes map[string]*Type
624624
globalThisSymbol *ast.Symbol
@@ -915,7 +915,6 @@ func NewChecker(program Program) *Checker {
915915
c.argumentsSymbol = c.newSymbol(ast.SymbolFlagsProperty, "arguments")
916916
c.requireSymbol = c.newSymbol(ast.SymbolFlagsProperty, "require")
917917
c.unknownSymbol = c.newSymbol(ast.SymbolFlagsProperty, "unknown")
918-
c.resolvingSymbol = c.newSymbol(ast.SymbolFlagsNone, ast.InternalSymbolNameResolving)
919918
c.unresolvedSymbols = make(map[string]*ast.Symbol)
920919
c.errorTypes = make(map[string]*Type)
921920
c.globalThisSymbol = c.newSymbolEx(ast.SymbolFlagsModule, "globalThis", ast.CheckFlagsReadonly)
@@ -15652,29 +15651,25 @@ func (c *Checker) resolveAlias(symbol *ast.Symbol) *ast.Symbol {
1565215651
}
1565315652
links := c.aliasSymbolLinks.Get(symbol)
1565415653
if links.aliasTarget == nil {
15655-
links.aliasTarget = c.resolvingSymbol
15654+
if !c.pushTypeResolution(symbol, TypeSystemPropertyNameAliasTarget) {
15655+
return c.unknownSymbol
15656+
}
1565615657
node := c.getDeclarationOfAliasSymbol(symbol)
1565715658
if node == nil {
1565815659
panic("Unexpected nil in resolveAlias for symbol: " + c.symbolToString(symbol))
1565915660
}
15660-
target := c.getTargetOfAliasDeclaration(node, false /*dontRecursivelyResolve*/)
15661-
if links.aliasTarget == c.resolvingSymbol {
15662-
if target == nil {
15663-
target = c.unknownSymbol
15664-
}
15665-
links.aliasTarget = target
15666-
} else {
15661+
links.aliasTarget = core.OrElse(c.getTargetOfAliasDeclaration(node, false /*dontRecursivelyResolve*/), c.unknownSymbol)
15662+
if !c.popTypeResolution() {
1566715663
c.error(node, diagnostics.Circular_definition_of_import_alias_0, c.symbolToString(symbol))
15664+
links.aliasTarget = c.unknownSymbol
1566815665
}
15669-
} else if links.aliasTarget == c.resolvingSymbol {
15670-
links.aliasTarget = c.unknownSymbol
1567115666
}
1567215667
return links.aliasTarget
1567315668
}
1567415669

1567515670
func (c *Checker) tryResolveAlias(symbol *ast.Symbol) *ast.Symbol {
1567615671
links := c.aliasSymbolLinks.Get(symbol)
15677-
if links.aliasTarget != c.resolvingSymbol {
15672+
if links.aliasTarget != nil || c.findResolutionCycleStartIndex(symbol, TypeSystemPropertyNameAliasTarget) < 0 {
1567815673
return c.resolveAlias(symbol)
1567915674
}
1568015675
return nil
@@ -18097,6 +18092,8 @@ func (c *Checker) typeResolutionHasProperty(r *TypeResolution) bool {
1809718092
return c.nodeLinks.Get(r.target.(*ast.Node)).flags&NodeCheckFlagsInitializerIsUndefinedComputed != 0
1809818093
case TypeSystemPropertyNameWriteType:
1809918094
return c.valueSymbolLinks.Get(r.target.(*ast.Symbol)).writeType != nil
18095+
case TypeSystemPropertyNameAliasTarget:
18096+
return c.aliasSymbolLinks.Get(r.target.(*ast.Symbol)).aliasTarget != nil
1810018097
}
1810118098
panic("Unhandled case in typeResolutionHasProperty")
1810218099
}

internal/diagnostics/diagnostics_generated.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ TestCompletionEntryClassMembersWithInferredFunctionReturnType1
1616
TestCompletionEntryForArgumentConstrainedToString
1717
TestCompletionEntryForArrayElementConstrainedToString
1818
TestCompletionEntryForArrayElementConstrainedToString2
19-
TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved
2019
TestCompletionEntryForUnionProperty
2120
TestCompletionEntryForUnionProperty2
2221
TestCompletionForComputedStringProperties

internal/fourslash/fourslash.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fourslash
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"maps"
@@ -164,7 +165,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
164165
defer func() {
165166
outputWriter.Close()
166167
}()
167-
err := server.Run()
168+
err := server.Run(context.TODO())
168169
if err != nil {
169170
t.Error("server error:", err)
170171
}

internal/fourslash/tests/gen/completionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved_test.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,9 @@ import (
1010

1111
func TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15-
const content = `// @Filename: /node_modules/@types/react/index.d.ts
16-
export = React;
17-
export as namespace React;
18-
declare namespace React {
19-
function createElement(): any;
20-
interface Component<P = {}, S = {}, SS = any> { }
21-
class Component<P, S> {
22-
static contextType?: any;
23-
context: any;
24-
constructor(props: Readonly<P>);
25-
setState<K extends keyof S>(
26-
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
27-
callback?: () => void
28-
): void;
29-
}
30-
}
31-
// @Filename: /a.ts
15+
const content = `// @Filename: /a.ts
3216
import React from 'react'
3317
class Slider extends React.Component {
3418
static defau/**/ltProps = {

0 commit comments

Comments
 (0)