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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion microsoft/typescript-go
Submodule typescript-go updated 2866 files
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (api *API) ParseConfigFile(configFileName string) (*ConfigFileResponse, err
api.session,
configDir,
nil, /*existingOptions*/
nil, /*existingOptionsRaw*/
configFileName,
nil, /*resolutionStack*/
nil, /*extraFileExtensions*/
Expand Down
16 changes: 11 additions & 5 deletions pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26600,11 +26600,6 @@ func (c *Checker) isAssignmentToReadonlyEntity(expr *ast.Node, symbol *ast.Symbo
if expressionSymbol.Flags&ast.SymbolFlagsModuleExports != 0 {
return false
}
// references through namespace import should be readonly
if expressionSymbol.Flags&ast.SymbolFlagsAlias != 0 {
declaration := c.getDeclarationOfAliasSymbol(expressionSymbol)
return declaration != nil && ast.IsNamespaceImport(declaration)
}
}
}
if c.isReadonlySymbol(symbol) {
Expand All @@ -26627,6 +26622,17 @@ func (c *Checker) isAssignmentToReadonlyEntity(expr *ast.Node, symbol *ast.Symbo
}
return true
}
if ast.IsAccessExpression(expr) {
// references through namespace import should be readonly
node := ast.SkipParentheses(expr.Expression())
if ast.IsIdentifier(node) {
expressionSymbol := c.getResolvedSymbol(node)
if expressionSymbol.Flags&ast.SymbolFlagsAlias != 0 {
declaration := c.getDeclarationOfAliasSymbol(expressionSymbol)
return declaration != nil && ast.IsNamespaceImport(declaration)
}
}
}
return false
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ foo.bar;`
cd := "/"
host := compiler.NewCompilerHost(cd, fs, bundled.LibPath(), nil, nil)

parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, nil, host, nil)
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")

p := compiler.NewProgram(compiler.ProgramOptions{
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestCheckSrcCompiler(t *testing.T) {
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")

host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, nil, host, nil)
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
p := compiler.NewProgram(compiler.ProgramOptions{
Config: parsed,
Expand All @@ -88,7 +88,7 @@ func BenchmarkNewChecker(b *testing.B) {
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")

host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, nil, host, nil)
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")
p := compiler.NewProgram(compiler.ProgramOptions{
Config: parsed,
Expand Down
11 changes: 10 additions & 1 deletion pkg/compiler/checkerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ type checkerPool struct {

var _ CheckerPool = (*checkerPool)(nil)

func newCheckerPool(checkerCount int, program *Program) *checkerPool {
func newCheckerPool(program *Program) *checkerPool {
checkerCount := 4
if program.SingleThreaded() {
checkerCount = 1
} else if c := program.Options().Checkers; c != nil {
checkerCount = *c
}

checkerCount = max(min(checkerCount, len(program.files), 256), 1)

pool := &checkerPool{
program: program,
checkerCount: checkerCount,
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type processedFiles struct {
// if file was included using source file and its output is actually part of program
// this contains mapping from output to source file
outputFileToProjectReferenceSource map[tspath.Path]string
finishedProcessing bool
}

type jsxRuntimeImportSpecifier struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/filesparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
}

return processedFiles{
finishedProcessing: true,
resolver: loader.resolver,
files: allFiles,
filesByPath: filesByPath,
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ func (h *compilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast.Sourc
}

func (h *compilerHost) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine {
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, h, h.extendedConfigCache)
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, nil /*optionsRaw*/, h, h.extendedConfigCache)
return commandLine
}
14 changes: 6 additions & 8 deletions pkg/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.Fi

func NewProgram(opts ProgramOptions) *Program {
p := &Program{opts: opts}
p.initCheckerPool()
p.processedFiles = processAllProgramFiles(p.opts, p.SingleThreaded())
p.initCheckerPool()
p.verifyCompilerOptions()
return p
}
Expand Down Expand Up @@ -259,16 +259,14 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos
}

func (p *Program) initCheckerPool() {
if !p.finishedProcessing {
panic("Program must finish processing files before initializing checker pool")
}

if p.opts.CreateCheckerPool != nil {
p.checkerPool = p.opts.CreateCheckerPool(p)
} else {
checkers := 4
if p.SingleThreaded() {
checkers = 1
} else if p.Options().Checkers != nil {
checkers = min(max(*p.Options().Checkers, 1), 256)
}
p.checkerPool = newCheckerPool(checkers, p)
p.checkerPool = newCheckerPool(p)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func BenchmarkNewProgram(b *testing.B) {

host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)

parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, host, nil)
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, nil, host, nil)
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")

opts := compiler.ProgramOptions{
Expand Down
9 changes: 8 additions & 1 deletion pkg/execute/build/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ func (h *host) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile {
func (h *host) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine {
return h.resolvedReferences.loadOrStoreNew(path, func(path tspath.Path) *tsoptions.ParsedCommandLine {
configStart := h.orchestrator.opts.Sys.Now()
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, h, &h.extendedConfigCache)
// Wrap command line options in "compilerOptions" key to match tsconfig.json structure
var commandLineRaw *collections.OrderedMap[string, any]
if raw, ok := h.orchestrator.opts.Command.Raw.(*collections.OrderedMap[string, any]); ok {
wrapped := &collections.OrderedMap[string, any]{}
wrapped.Set("compilerOptions", raw)
commandLineRaw = wrapped
}
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, commandLineRaw, h, &h.extendedConfigCache)
configTime := h.orchestrator.opts.Sys.Now().Sub(configStart)
h.configTimes.Store(path, configTime)
return commandLine
Expand Down
9 changes: 8 additions & 1 deletion pkg/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
var compileTimes tsc.CompileTimes
if configFileName != "" {
configStart := sys.Now()
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(configFileName, compilerOptionsFromCommandLine, sys, extendedConfigCache)
var commandLineRaw *collections.OrderedMap[string, any]
if raw, ok := commandLine.Raw.(*collections.OrderedMap[string, any]); ok {
// Wrap command line options in a "compilerOptions" key to match tsconfig.json structure
wrapped := &collections.OrderedMap[string, any]{}
wrapped.Set("compilerOptions", raw)
commandLineRaw = wrapped
}
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(configFileName, compilerOptionsFromCommandLine, commandLineRaw, sys, extendedConfigCache)
compileTimes.ConfigTime = sys.Now().Sub(configStart)
if len(errors) != 0 {
// these are unrecoverable errors--exit to report them as diagnostics
Expand Down
2 changes: 1 addition & 1 deletion pkg/execute/tsctests/tscbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ func TestBuildOutputPaths(t *testing.T) {
t.Run("GetOutputFileNames/"+s.subScenario, func(t *testing.T) {
t.Parallel()
sys := newTestSys(input, false)
config, _ := tsoptions.GetParsedCommandLineOfConfigFile("/home/src/workspaces/project/tsconfig.json", &core.CompilerOptions{}, sys, nil)
config, _ := tsoptions.GetParsedCommandLineOfConfigFile("/home/src/workspaces/project/tsconfig.json", &core.CompilerOptions{}, nil, sys, nil)
assert.DeepEqual(t, slices.Collect(config.GetOutputFileNames()), s.expectedDtsNames)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/execute/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (w *Watcher) hasErrorsInTsConfig() bool {
extendedConfigCache := &tsc.ExtendedConfigCache{}
if w.configFileName != "" {
// !!! need to check that this merges compileroptions correctly. This differs from non-watch, since we allow overriding of previous options
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, w.sys, extendedConfigCache)
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, nil, w.sys, extendedConfigCache)
if len(errors) > 0 {
for _, e := range errors {
w.reportDiagnostic(e)
Expand Down
24 changes: 15 additions & 9 deletions pkg/fourslash/_scripts/convertFourslash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ function stringToTristate(s: string): string {
}

function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefined {
const inlayHintPreferences: string[] = [];
const preferences: string[] = [];
for (const prop of arg.properties) {
if (ts.isPropertyAssignment(prop)) {
Expand Down Expand Up @@ -1441,28 +1442,28 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
paramHint = "lsutil.IncludeInlayParameterNameHintsAll";
break;
}
preferences.push(`IncludeInlayParameterNameHints: ${paramHint}`);
inlayHintPreferences.push(`IncludeInlayParameterNameHints: ${paramHint}`);
break;
case "includeInlayParameterNameHintsWhenArgumentMatchesName":
preferences.push(`IncludeInlayParameterNameHintsWhenArgumentMatchesName: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayParameterNameHintsWhenArgumentMatchesName: ${prop.initializer.getText()}`);
break;
case "includeInlayFunctionParameterTypeHints":
preferences.push(`IncludeInlayFunctionParameterTypeHints: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayFunctionParameterTypeHints: ${prop.initializer.getText()}`);
break;
case "includeInlayVariableTypeHints":
preferences.push(`IncludeInlayVariableTypeHints: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayVariableTypeHints: ${prop.initializer.getText()}`);
break;
case "includeInlayVariableTypeHintsWhenTypeMatchesName":
preferences.push(`IncludeInlayVariableTypeHintsWhenTypeMatchesName: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayVariableTypeHintsWhenTypeMatchesName: ${prop.initializer.getText()}`);
break;
case "includeInlayPropertyDeclarationTypeHints":
preferences.push(`IncludeInlayPropertyDeclarationTypeHints: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayPropertyDeclarationTypeHints: ${prop.initializer.getText()}`);
break;
case "includeInlayFunctionLikeReturnTypeHints":
preferences.push(`IncludeInlayFunctionLikeReturnTypeHints: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayFunctionLikeReturnTypeHints: ${prop.initializer.getText()}`);
break;
case "includeInlayEnumMemberValueHints":
preferences.push(`IncludeInlayEnumMemberValueHints: ${prop.initializer.getText()}`);
inlayHintPreferences.push(`IncludeInlayEnumMemberValueHints: ${prop.initializer.getText()}`);
break;
case "interactiveInlayHints":
// Ignore, deprecated
Expand All @@ -1473,6 +1474,10 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
return undefined;
}
}

if (inlayHintPreferences.length > 0) {
preferences.push(`InlayHints: lsutil.InlayHintsPreferences{${inlayHintPreferences.join(",")}}`);
}
if (preferences.length === 0) {
return "nil /*preferences*/";
}
Expand Down Expand Up @@ -2936,7 +2941,8 @@ func Test${testName}(t *testing.T) {
${failingTests.has(testName) ? "t.Skip()" : ""}
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = ${content}
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
${isServer ? `f.MarkTestAsStradaServer()\n` : ""}${commands}
}`;
return template;
Expand Down
Loading