Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (p *fileLoader) loadSourceFileMetaData(fileName string) *ast.SourceFileMeta

func (p *fileLoader) parseSourceFile(t *parseTask) *ast.SourceFile {
path := p.toPath(t.normalizedFilePath)
sourceFile := p.opts.Host.GetSourceFile(t.normalizedFilePath, path, p.projectReferenceFileMapper.getCompilerOptionsForFile(t).SourceFileAffecting(), t.metadata) // TODO(jakebailey): cache :(
sourceFile := p.opts.Host.GetSourceFile(t.normalizedFilePath, path, p.projectReferenceFileMapper.getCompilerOptionsForFile(t).SourceFileAffecting(), t.metadata)
return sourceFile
}

Expand Down
14 changes: 2 additions & 12 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ type Program struct {
nodeModules map[string]*ast.SourceFile
checkerPool CheckerPool

sourceAffectingCompilerOptionsOnce sync.Once
sourceAffectingCompilerOptions *core.SourceFileAffectingCompilerOptions

comparePathsOptions tspath.ComparePathsOptions

processedFiles
Expand Down Expand Up @@ -302,19 +299,12 @@ func (p *Program) singleThreaded() bool {
return p.opts.SingleThreaded.DefaultIfUnknown(p.Options().SingleThreaded).IsTrue()
}

func (p *Program) getSourceAffectingCompilerOptions() *core.SourceFileAffectingCompilerOptions {
p.sourceAffectingCompilerOptionsOnce.Do(func() {
p.sourceAffectingCompilerOptions = p.Options().SourceFileAffecting()
})
return p.sourceAffectingCompilerOptions
}

func (p *Program) BindSourceFiles() {
wg := core.NewWorkGroup(p.singleThreaded())
for _, file := range p.files {
if !file.IsBound() {
wg.Queue(func() {
binder.BindSourceFile(file, p.getSourceAffectingCompilerOptions())
binder.BindSourceFile(file, p.Options().SourceFileAffecting())
})
}
}
Expand Down Expand Up @@ -605,7 +595,7 @@ func compactAndMergeRelatedInfos(diagnostics []*ast.Diagnostic) []*ast.Diagnosti
func (p *Program) getDiagnosticsHelper(ctx context.Context, sourceFile *ast.SourceFile, ensureBound bool, ensureChecked bool, getDiagnostics func(context.Context, *ast.SourceFile) []*ast.Diagnostic) []*ast.Diagnostic {
if sourceFile != nil {
if ensureBound {
binder.BindSourceFile(sourceFile, p.getSourceAffectingCompilerOptions())
binder.BindSourceFile(sourceFile, p.Options().SourceFileAffecting())
}
return SortAndDeduplicateDiagnostics(getDiagnostics(ctx, sourceFile))
}
Expand Down
29 changes: 18 additions & 11 deletions internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"reflect"
"strings"
"sync"

"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/tspath"
Expand Down Expand Up @@ -146,6 +147,9 @@ type CompilerOptions struct {
PprofDir string `json:"pprofDir,omitzero"`
SingleThreaded Tristate `json:"singleThreaded,omitzero"`
Quiet Tristate `json:"quiet,omitzero"`

sourceFileAffectingCompilerOptionsOnce sync.Once
sourceFileAffectingCompilerOptions *SourceFileAffectingCompilerOptions
}

// noCopy may be embedded into structs which must not be copied
Expand Down Expand Up @@ -360,17 +364,20 @@ type SourceFileAffectingCompilerOptions struct {
}

func (options *CompilerOptions) SourceFileAffecting() *SourceFileAffectingCompilerOptions {
return &SourceFileAffectingCompilerOptions{
AllowUnreachableCode: options.AllowUnreachableCode,
AllowUnusedLabels: options.AllowUnusedLabels,
BindInStrictMode: options.AlwaysStrict.IsTrue() || options.Strict.IsTrue(),
EmitModuleDetectionKind: options.GetEmitModuleDetectionKind(),
EmitModuleKind: options.GetEmitModuleKind(),
EmitScriptTarget: options.GetEmitScriptTarget(),
JsxEmit: options.Jsx,
NoFallthroughCasesInSwitch: options.NoFallthroughCasesInSwitch,
ShouldPreserveConstEnums: options.ShouldPreserveConstEnums(),
}
options.sourceFileAffectingCompilerOptionsOnce.Do(func() {
options.sourceFileAffectingCompilerOptions = &SourceFileAffectingCompilerOptions{
AllowUnreachableCode: options.AllowUnreachableCode,
AllowUnusedLabels: options.AllowUnusedLabels,
BindInStrictMode: options.AlwaysStrict.IsTrue() || options.Strict.IsTrue(),
EmitModuleDetectionKind: options.GetEmitModuleDetectionKind(),
EmitModuleKind: options.GetEmitModuleKind(),
EmitScriptTarget: options.GetEmitScriptTarget(),
JsxEmit: options.Jsx,
NoFallthroughCasesInSwitch: options.NoFallthroughCasesInSwitch,
ShouldPreserveConstEnums: options.ShouldPreserveConstEnums(),
}
})
return options.sourceFileAffectingCompilerOptions
}

type ModuleDetectionKind int32
Expand Down
3 changes: 2 additions & 1 deletion internal/tsoptions/commandlineparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
Expand Down Expand Up @@ -173,7 +174,7 @@ func (f commandLineSubScenario) assertParseResult(t *testing.T) {
newParsedCompilerOptions := &core.CompilerOptions{}
e := json.Unmarshal(o, newParsedCompilerOptions)
assert.NilError(t, e)
assert.DeepEqual(t, tsBaseline.options, newParsedCompilerOptions)
assert.DeepEqual(t, tsBaseline.options, newParsedCompilerOptions, cmpopts.IgnoreUnexported(core.CompilerOptions{}))

newParsedWatchOptions := core.WatchOptions{}
e = json.Unmarshal(o, &newParsedWatchOptions)
Expand Down
3 changes: 2 additions & 1 deletion internal/tsoptions/tsconfigparsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
"github.com/microsoft/typescript-go/internal/parser"
Expand Down Expand Up @@ -863,7 +864,7 @@ func TestParseSrcCompiler(t *testing.T) {
SourceMap: core.TSTrue,
UseUnknownInCatchVariables: core.TSFalse,
Pretty: core.TSTrue,
})
}, cmpopts.IgnoreUnexported(core.CompilerOptions{}))

fileNames := parseConfigFileContent.ParsedConfig.FileNames
relativePaths := make([]string, 0, len(fileNames))
Expand Down