Skip to content

Commit 287e1ec

Browse files
committed
Merge branch 'main' into jabaile/staticcheck
2 parents fe4db02 + 9953b71 commit 287e1ec

File tree

256 files changed

+8682
-2158
lines changed

Some content is hidden

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

256 files changed

+8682
-2158
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
# Initializes the CodeQL tools for scanning.
5050
- name: Initialize CodeQL
51-
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
51+
uses: github/codeql-action/init@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1
5252
with:
5353
config-file: ./.github/codeql/codeql-configuration.yml
5454
# Override language selection by uncommenting this and choosing your languages
@@ -58,7 +58,7 @@ jobs:
5858
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5959
# If this step fails, then you should remove it and run the build manually (see below).
6060
- name: Autobuild
61-
uses: github/codeql-action/autobuild@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
61+
uses: github/codeql-action/autobuild@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1
6262

6363
# ℹ️ Command-line programs to run using the OS shell.
6464
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,4 +72,4 @@ jobs:
7272
# make release
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
75+
uses: github/codeql-action/analyze@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1

cmd/tsgo/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func runAPI(args []string) int {
2626
Out: os.Stdout,
2727
Err: os.Stderr,
2828
Cwd: *cwd,
29-
NewLine: "\n",
3029
DefaultLibraryPath: defaultLibraryPath,
3130
})
3231

cmd/tsgo/sys.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"fmt"
55
"io"
66
"os"
7-
"runtime"
87
"time"
98

109
"github.com/microsoft/typescript-go/internal/bundled"
11-
"github.com/microsoft/typescript-go/internal/core"
1210
"github.com/microsoft/typescript-go/internal/execute"
1311
"github.com/microsoft/typescript-go/internal/tspath"
1412
"github.com/microsoft/typescript-go/internal/vfs"
@@ -19,7 +17,6 @@ type osSys struct {
1917
writer io.Writer
2018
fs vfs.FS
2119
defaultLibraryPath string
22-
newLine string
2320
cwd string
2421
start time.Time
2522
}
@@ -44,10 +41,6 @@ func (s *osSys) GetCurrentDirectory() string {
4441
return s.cwd
4542
}
4643

47-
func (s *osSys) NewLine() string {
48-
return s.newLine
49-
}
50-
5144
func (s *osSys) Writer() io.Writer {
5245
return s.writer
5346
}
@@ -69,7 +62,6 @@ func newSystem() *osSys {
6962
fs: bundled.WrapFS(osvfs.FS()),
7063
defaultLibraryPath: bundled.LibPath(),
7164
writer: os.Stdout,
72-
newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"),
7365
start: time.Now(),
7466
}
7567
}

internal/api/api.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ func (api *API) Trace(s string) {
111111
api.options.Logger.Info(s)
112112
}
113113

114-
// NewLine implements ProjectHost.
115-
func (api *API) NewLine() string {
116-
return api.host.NewLine()
117-
}
118-
119114
// PositionEncoding implements ProjectHost.
120115
func (api *API) PositionEncoding() lsproto.PositionEncodingKind {
121116
return lsproto.PositionEncodingKindUTF8

internal/api/host.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ type APIHost interface {
66
FS() vfs.FS
77
DefaultLibraryPath() string
88
GetCurrentDirectory() string
9-
NewLine() string
109
}

internal/api/server.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type ServerOptions struct {
6161
Out io.Writer
6262
Err io.Writer
6363
Cwd string
64-
NewLine string
6564
DefaultLibraryPath string
6665
}
6766

@@ -98,7 +97,6 @@ func NewServer(options *ServerOptions) *Server {
9897
w: bufio.NewWriter(options.Out),
9998
stderr: options.Err,
10099
cwd: options.Cwd,
101-
newLine: options.NewLine,
102100
fs: bundled.WrapFS(osvfs.FS()),
103101
defaultLibraryPath: options.DefaultLibraryPath,
104102
}
@@ -126,11 +124,6 @@ func (s *Server) GetCurrentDirectory() string {
126124
return s.cwd
127125
}
128126

129-
// NewLine implements APIHost.
130-
func (s *Server) NewLine() string {
131-
return s.newLine
132-
}
133-
134127
func (s *Server) Run() error {
135128
for {
136129
messageType, method, payload, err := s.readRequest("")

internal/checker/checker.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17872,6 +17872,7 @@ func (c *Checker) pushTypeResolution(target TypeSystemEntity, propertyName TypeS
1787217872
func (c *Checker) popTypeResolution() bool {
1787317873
lastIndex := len(c.typeResolutions) - 1
1787417874
result := c.typeResolutions[lastIndex].result
17875+
c.typeResolutions[lastIndex] = TypeResolution{} // Clear the last entry to avoid memory leaks
1787517876
c.typeResolutions = c.typeResolutions[:lastIndex]
1787617877
return result
1787717878
}
@@ -21126,6 +21127,9 @@ func (c *Checker) getDefaultOrUnknownFromTypeParameter(t *Type) *Type {
2112621127
}
2112721128

2112821129
func (c *Checker) getNamedMembers(members ast.SymbolTable) []*ast.Symbol {
21130+
if len(members) == 0 {
21131+
return nil
21132+
}
2112921133
result := make([]*ast.Symbol, 0, len(members))
2113021134
for id, symbol := range members {
2113121135
if c.isNamedMember(symbol, id) {
@@ -29344,7 +29348,9 @@ func (c *Checker) pushContextualType(node *ast.Node, t *Type, isCache bool) {
2934429348
}
2934529349

2934629350
func (c *Checker) popContextualType() {
29347-
c.contextualInfos = c.contextualInfos[:len(c.contextualInfos)-1]
29351+
lastIndex := len(c.contextualInfos) - 1
29352+
c.contextualInfos[lastIndex] = ContextualInfo{}
29353+
c.contextualInfos = c.contextualInfos[:lastIndex]
2934829354
}
2934929355

2935029356
func (c *Checker) findContextualNode(node *ast.Node, includeCaches bool) int {
@@ -29414,7 +29420,9 @@ func (c *Checker) pushInferenceContext(node *ast.Node, context *InferenceContext
2941429420
}
2941529421

2941629422
func (c *Checker) popInferenceContext() {
29417-
c.inferenceContextInfos = c.inferenceContextInfos[:len(c.inferenceContextInfos)-1]
29423+
lastIndex := len(c.inferenceContextInfos) - 1
29424+
c.inferenceContextInfos[lastIndex] = InferenceContextInfo{}
29425+
c.inferenceContextInfos = c.inferenceContextInfos[:lastIndex]
2941829426
}
2941929427

2942029428
func (c *Checker) getInferenceContext(node *ast.Node) *InferenceContext {

internal/checker/checker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ foo.bar;`
3636
fs = bundled.WrapFS(fs)
3737

3838
cd := "/"
39-
host := compiler.NewCompilerHost(nil, cd, fs, bundled.LibPath(), nil)
39+
host := compiler.NewCompilerHost(cd, fs, bundled.LibPath())
4040

4141
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil)
4242
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
@@ -70,7 +70,7 @@ func TestCheckSrcCompiler(t *testing.T) {
7070

7171
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
7272

73-
host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil)
73+
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath())
7474
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
7575
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
7676
p := compiler.NewProgram(compiler.ProgramOptions{
@@ -87,7 +87,7 @@ func BenchmarkNewChecker(b *testing.B) {
8787

8888
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
8989

90-
host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil)
90+
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath())
9191
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
9292
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")
9393
p := compiler.NewProgram(compiler.ProgramOptions{

internal/checker/types.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -297,34 +297,6 @@ const (
297297
AccessFlagsPersistent = AccessFlagsIncludeUndefined
298298
)
299299

300-
type AssignmentDeclarationKind = int32
301-
302-
const (
303-
AssignmentDeclarationKindNone = AssignmentDeclarationKind(iota)
304-
/// exports.name = expr
305-
/// module.exports.name = expr
306-
AssignmentDeclarationKindExportsProperty
307-
/// module.exports = expr
308-
AssignmentDeclarationKindModuleExports
309-
/// className.prototype.name = expr
310-
AssignmentDeclarationKindPrototypeProperty
311-
/// this.name = expr
312-
AssignmentDeclarationKindThisProperty
313-
// F.name = expr
314-
AssignmentDeclarationKindProperty
315-
// F.prototype = { ... }
316-
AssignmentDeclarationKindPrototype
317-
// Object.defineProperty(x, 'name', { value: any, writable?: boolean (false by default) });
318-
// Object.defineProperty(x, 'name', { get: Function, set: Function });
319-
// Object.defineProperty(x, 'name', { get: Function });
320-
// Object.defineProperty(x, 'name', { set: Function });
321-
AssignmentDeclarationKindObjectDefinePropertyValue
322-
// Object.defineProperty(exports || module.exports, 'name', ...);
323-
AssignmentDeclarationKindObjectDefinePropertyExports
324-
// Object.defineProperty(Foo.prototype, 'name', ...);
325-
AssignmentDeclarationKindObjectDefinePrototypeProperty
326-
)
327-
328300
type NodeCheckFlags uint32
329301

330302
const (

internal/compiler/fileloader.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type processedFiles struct {
5454
// List of present unsupported extensions
5555
unsupportedExtensions []string
5656
sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
57+
fileLoadDiagnostics *ast.DiagnosticsCollection
5758
}
5859

5960
type jsxRuntimeImportSpecifier struct {
@@ -132,6 +133,7 @@ func processAllProgramFiles(
132133
var unsupportedExtensions []string
133134
var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
134135
var libFileSet collections.Set[tspath.Path]
136+
fileLoadDiagnostics := &ast.DiagnosticsCollection{}
135137

136138
loader.parseTasks.collect(&loader, loader.rootTasks, func(task *parseTask, _ []tspath.Path) {
137139
if task.isRedirected {
@@ -159,6 +161,7 @@ func processAllProgramFiles(
159161
resolvedModules[path] = task.resolutionsInFile
160162
typeResolutionsInFile[path] = task.typeResolutionsInFile
161163
sourceFileMetaDatas[path] = task.metadata
164+
162165
if task.jsxRuntimeImportSpecifier != nil {
163166
if jsxRuntimeImportSpecifiers == nil {
164167
jsxRuntimeImportSpecifiers = make(map[tspath.Path]*jsxRuntimeImportSpecifier, totalFileCount)
@@ -183,8 +186,28 @@ func processAllProgramFiles(
183186

184187
allFiles := append(libFiles, files...)
185188

189+
for _, resolutions := range resolvedModules {
190+
for _, resolvedModule := range resolutions {
191+
for _, diag := range resolvedModule.ResolutionDiagnostics {
192+
fileLoadDiagnostics.Add(diag)
193+
}
194+
}
195+
}
196+
for _, typeResolutions := range typeResolutionsInFile {
197+
for _, resolvedTypeRef := range typeResolutions {
198+
for _, diag := range resolvedTypeRef.ResolutionDiagnostics {
199+
fileLoadDiagnostics.Add(diag)
200+
}
201+
}
202+
}
203+
186204
loader.pathForLibFileResolutions.Range(func(key tspath.Path, value module.ModeAwareCache[*module.ResolvedModule]) bool {
187205
resolvedModules[key] = value
206+
for _, resolvedModule := range value {
207+
for _, diag := range resolvedModule.ResolutionDiagnostics {
208+
fileLoadDiagnostics.Add(diag)
209+
}
210+
}
188211
return true
189212
})
190213

@@ -201,6 +224,7 @@ func processAllProgramFiles(
201224
unsupportedExtensions: unsupportedExtensions,
202225
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
203226
libFiles: libFileSet,
227+
fileLoadDiagnostics: fileLoadDiagnostics,
204228
}
205229
}
206230

@@ -372,6 +396,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
372396
resolutionMode := getModeForTypeReferenceDirectiveInFile(ref, file, meta, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect))
373397
resolved := p.resolver.ResolveTypeReferenceDirective(ref.FileName, file.FileName(), resolutionMode, redirect)
374398
typeResolutionsInFile[module.ModeAwareCacheKey{Name: ref.FileName, Mode: resolutionMode}] = resolved
399+
375400
if resolved.IsResolved() {
376401
t.addSubTask(resolvedRef{
377402
fileName: resolved.ResolvedFileName,

0 commit comments

Comments
 (0)