Skip to content

Commit c1b48ea

Browse files
dependabot[bot]github-actions[bot]buke
authored
deps(deps): bump microsoft/typescript-go from 7c2dab6 to fb0c169 (#40)
* deps(deps): bump microsoft/typescript-go from `7c2dab6` to `fb0c169` Bumps [microsoft/typescript-go](https://github.com/microsoft/typescript-go) from `7c2dab6` to `fb0c169`. - [Commits](microsoft/typescript-go@7c2dab6...fb0c169) --- updated-dependencies: - dependency-name: microsoft/typescript-go dependency-version: fb0c16962e82155ac2545f288ed52b2e11f5bff3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(sync): mirror internal packages into pkg/ (auto) (#41) Co-authored-by: buke <1013738+buke@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: buke <1013738+buke@users.noreply.github.com>
1 parent 6065201 commit c1b48ea

File tree

96 files changed

+2138
-882
lines changed

Some content is hidden

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

96 files changed

+2138
-882
lines changed

microsoft/typescript-go

Submodule typescript-go updated 97 files

pkg/ast/diagnostic.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,17 @@ func getDiagnosticPath(d *Diagnostic) string {
195195
}
196196

197197
func EqualDiagnostics(d1, d2 *Diagnostic) bool {
198+
if d1 == d2 {
199+
return true
200+
}
198201
return EqualDiagnosticsNoRelatedInfo(d1, d2) &&
199202
slices.EqualFunc(d1.RelatedInformation(), d2.RelatedInformation(), EqualDiagnostics)
200203
}
201204

202205
func EqualDiagnosticsNoRelatedInfo(d1, d2 *Diagnostic) bool {
206+
if d1 == d2 {
207+
return true
208+
}
203209
return getDiagnosticPath(d1) == getDiagnosticPath(d2) &&
204210
d1.Loc() == d2.Loc() &&
205211
d1.Code() == d2.Code() &&
@@ -208,6 +214,9 @@ func EqualDiagnosticsNoRelatedInfo(d1, d2 *Diagnostic) bool {
208214
}
209215

210216
func equalMessageChain(c1, c2 *Diagnostic) bool {
217+
if c1 == c2 {
218+
return true
219+
}
211220
return c1.Code() == c2.Code() &&
212221
slices.Equal(c1.MessageArgs(), c2.MessageArgs()) &&
213222
slices.EqualFunc(c1.MessageChain(), c2.MessageChain(), equalMessageChain)
@@ -258,6 +267,9 @@ func compareRelatedInfo(r1, r2 []*Diagnostic) int {
258267
}
259268

260269
func CompareDiagnostics(d1, d2 *Diagnostic) int {
270+
if d1 == d2 {
271+
return 0
272+
}
261273
c := strings.Compare(getDiagnosticPath(d1), getDiagnosticPath(d2))
262274
if c != 0 {
263275
return c

pkg/checker/checker_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,6 @@ foo.bar;`
6161
}
6262
}
6363

64-
func TestCheckSrcCompiler(t *testing.T) {
65-
t.Parallel()
66-
67-
repo.SkipIfNoTypeScriptSubmodule(t)
68-
fs := osvfs.FS()
69-
fs = bundled.WrapFS(fs)
70-
71-
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
72-
73-
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
74-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, nil, host, nil)
75-
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
76-
p := compiler.NewProgram(compiler.ProgramOptions{
77-
Config: parsed,
78-
Host: host,
79-
})
80-
p.CheckSourceFiles(t.Context(), nil)
81-
}
82-
8364
func BenchmarkNewChecker(b *testing.B) {
8465
repo.SkipIfNoTypeScriptSubmodule(b)
8566
fs := osvfs.FS()

pkg/checker/nodebuilderimpl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,10 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
12061206
},
12071207
false, /*forAutoImports*/
12081208
)
1209+
if len(allSpecifiers) == 0 {
1210+
links.specifierCache[cacheKey] = ""
1211+
return ""
1212+
}
12091213
specifier := allSpecifiers[0]
12101214
links.specifierCache[cacheKey] = specifier
12111215
return specifier

pkg/compiler/checkerpool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type CheckerPool interface {
1616
GetChecker(ctx context.Context) (*checker.Checker, func())
1717
GetCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())
1818
GetCheckerForFileExclusive(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())
19-
ForEachCheckerParallel(ctx context.Context, cb func(idx int, c *checker.Checker))
2019
Files(checker *checker.Checker) iter.Seq[*ast.SourceFile]
2120
}
2221

@@ -98,7 +97,7 @@ func (p *checkerPool) createCheckers() {
9897

9998
// Runs `cb` for each checker in the pool concurrently, locking and unlocking checker mutexes as it goes,
10099
// making it safe to call `ForEachCheckerParallel` from many threads simultaneously.
101-
func (p *checkerPool) ForEachCheckerParallel(ctx context.Context, cb func(idx int, c *checker.Checker)) {
100+
func (p *checkerPool) ForEachCheckerParallel(cb func(idx int, c *checker.Checker)) {
102101
p.createCheckers()
103102
wg := core.NewWorkGroup(p.program.SingleThreaded())
104103
for idx, checker := range p.checkers {

pkg/compiler/emitHost.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"github.com/buke/typescript-go-internal/pkg/ast"
77
"github.com/buke/typescript-go-internal/pkg/core"
88
"github.com/buke/typescript-go-internal/pkg/module"
9-
"github.com/buke/typescript-go-internal/pkg/modulespecifiers"
109
"github.com/buke/typescript-go-internal/pkg/outputpaths"
10+
"github.com/buke/typescript-go-internal/pkg/packagejson"
1111
"github.com/buke/typescript-go-internal/pkg/printer"
12+
"github.com/buke/typescript-go-internal/pkg/symlinks"
1213
"github.com/buke/typescript-go-internal/pkg/transformers/declarations"
1314
"github.com/buke/typescript-go-internal/pkg/tsoptions"
1415
"github.com/buke/typescript-go-internal/pkg/tspath"
@@ -70,7 +71,7 @@ func (host *emitHost) GetNearestAncestorDirectoryWithPackageJson(dirname string)
7071
return host.program.GetNearestAncestorDirectoryWithPackageJson(dirname)
7172
}
7273

73-
func (host *emitHost) GetPackageJsonInfo(pkgJsonPath string) modulespecifiers.PackageJsonInfo {
74+
func (host *emitHost) GetPackageJsonInfo(pkgJsonPath string) *packagejson.InfoCacheEntry {
7475
return host.program.GetPackageJsonInfo(pkgJsonPath)
7576
}
7677

@@ -126,3 +127,12 @@ func (host *emitHost) GetEmitResolver() printer.EmitResolver {
126127
func (host *emitHost) IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool {
127128
return host.program.IsSourceFileFromExternalLibrary(file)
128129
}
130+
131+
func (host *emitHost) GetSymlinkCache() *symlinks.KnownSymlinks {
132+
return host.program.GetSymlinkCache()
133+
}
134+
135+
func (host *emitHost) ResolveModuleName(moduleName string, containingFile string, resolutionMode core.ResolutionMode) *module.ResolvedModule {
136+
resolved, _ := host.program.resolver.ResolveModuleName(moduleName, containingFile, resolutionMode, nil)
137+
return resolved
138+
}

pkg/compiler/fileloader.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (p *fileLoader) toPath(file string) tspath.Path {
144144

145145
func (p *fileLoader) addRootTask(fileName string, libFile *LibFile, includeReason *FileIncludeReason) {
146146
absPath := tspath.GetNormalizedAbsolutePath(fileName, p.opts.Host.GetCurrentDirectory())
147-
if core.Tristate.IsTrue(p.opts.Config.CompilerOptions().AllowNonTsExtensions) || slices.Contains(p.supportedExtensions, tspath.TryGetExtensionFromPath(absPath)) {
147+
if p.opts.Config.CompilerOptions().AllowNonTsExtensions.IsTrue() || tspath.HasExtension(absPath) {
148148
p.rootTasks = append(p.rootTasks, &parseTask{
149149
normalizedFilePath: absPath,
150150
libFile: libFile,
@@ -278,14 +278,20 @@ func (p *fileLoader) getDefaultLibFilePriority(a *ast.SourceFile) int {
278278
}
279279

280280
func (p *fileLoader) loadSourceFileMetaData(fileName string) ast.SourceFileMetaData {
281-
packageJsonScope := p.resolver.GetPackageJsonScopeIfApplicable(fileName)
281+
packageJsonScope := p.resolver.GetPackageScopeForPath(fileName)
282+
moduleResolutionKind := p.opts.Config.CompilerOptions().GetModuleResolutionKind()
283+
282284
var packageJsonType, packageJsonDirectory string
283285
if packageJsonScope.Exists() {
284286
packageJsonDirectory = packageJsonScope.PackageDirectory
285287
if value, ok := packageJsonScope.Contents.Type.GetValue(); ok {
286-
packageJsonType = value
288+
if !tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMts, tspath.ExtensionCts, tspath.ExtensionMjs, tspath.ExtensionCjs}) &&
289+
core.ModuleResolutionKindNode16 <= moduleResolutionKind && moduleResolutionKind <= core.ModuleResolutionKindNodeNext || strings.Contains(fileName, "/node_modules/") {
290+
packageJsonType = value
291+
}
287292
}
288293
}
294+
289295
impliedNodeFormat := ast.GetImpliedNodeFormatForFile(fileName, packageJsonType)
290296
return ast.SourceFileMetaData{
291297
PackageJsonType: packageJsonType,

pkg/compiler/filesparser.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/buke/typescript-go-internal/pkg/ast"
99
"github.com/buke/typescript-go-internal/pkg/collections"
1010
"github.com/buke/typescript-go-internal/pkg/core"
11+
"github.com/buke/typescript-go-internal/pkg/diagnostics"
1112
"github.com/buke/typescript-go-internal/pkg/module"
1213
"github.com/buke/typescript-go-internal/pkg/tsoptions"
1314
"github.com/buke/typescript-go-internal/pkg/tspath"
@@ -31,6 +32,7 @@ type parseTask struct {
3132
typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
3233
typeResolutionsTrace []module.DiagAndArgs
3334
resolutionDiagnostics []*ast.Diagnostic
35+
processingDiagnostics []*processingDiagnostic
3436
importHelpersImportSpecifier *ast.Node
3537
jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier
3638

@@ -61,6 +63,34 @@ func (t *parseTask) load(loader *fileLoader) {
6163
return
6264
}
6365

66+
if tspath.HasExtension(t.normalizedFilePath) {
67+
compilerOptions := loader.opts.Config.CompilerOptions()
68+
allowNonTsExtensions := compilerOptions.AllowNonTsExtensions.IsTrue()
69+
if !allowNonTsExtensions {
70+
canonicalFileName := tspath.GetCanonicalFileName(t.normalizedFilePath, loader.opts.Host.FS().UseCaseSensitiveFileNames())
71+
supported := false
72+
for _, ext := range loader.supportedExtensions {
73+
if tspath.FileExtensionIs(canonicalFileName, ext) {
74+
supported = true
75+
break
76+
}
77+
}
78+
if !supported {
79+
if tspath.HasJSFileExtension(canonicalFileName) {
80+
t.processingDiagnostics = append(t.processingDiagnostics, &processingDiagnostic{
81+
kind: processingDiagnosticKindExplainingFileInclude,
82+
data: &includeExplainingDiagnostic{
83+
diagnosticReason: t.includeReason,
84+
message: diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option,
85+
args: []any{t.normalizedFilePath},
86+
},
87+
})
88+
}
89+
return
90+
}
91+
}
92+
}
93+
6494
loader.totalFileCount.Add(1)
6595
if t.libFile != nil {
6696
loader.libFileCount.Add(1)
@@ -319,6 +349,11 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
319349
}
320350
file := task.file
321351
path := task.path
352+
353+
if len(task.processingDiagnostics) > 0 {
354+
loader.includeProcessor.processingDiagnostics = append(loader.includeProcessor.processingDiagnostics, task.processingDiagnostics...)
355+
}
356+
322357
if file == nil {
323358
// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
324359
missingFiles = append(missingFiles, task.normalizedFilePath)

pkg/compiler/knownsymlinks.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)