Skip to content

Commit 6f17800

Browse files
committed
Merge branch 'main' into guyllian.gomez/yarn-pnp
2 parents f8dd02f + 3d247ef commit 6f17800

File tree

939 files changed

+1673
-8238
lines changed

Some content is hidden

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

939 files changed

+1673
-8238
lines changed

.custom-gcl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/custom-gcl.jsonschema.json
22

3-
version: v2.5.0
3+
version: v2.6.0
44

55
destination: ./_tools
66

.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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
51+
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
61+
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
75+
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ linters:
3333
- makezero
3434
- mirror
3535
- misspell
36+
- modernize
3637
- musttag
3738
- nakedret
3839
- nolintlint

internal/ast/ast.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func visit(v Visitor, node *Node) bool {
2424
}
2525

2626
func visitNodes(v Visitor, nodes []*Node) bool {
27-
for _, node := range nodes {
27+
for _, node := range nodes { //nolint:modernize
2828
if v(node) {
2929
return true
3030
}
@@ -4845,6 +4845,10 @@ func IsImportDeclaration(node *Node) bool {
48454845
return node.Kind == KindImportDeclaration
48464846
}
48474847

4848+
func IsJSImportDeclaration(node *Node) bool {
4849+
return node.Kind == KindJSImportDeclaration
4850+
}
4851+
48484852
func IsImportDeclarationOrJSImportDeclaration(node *Node) bool {
48494853
return node.Kind == KindImportDeclaration || node.Kind == KindJSImportDeclaration
48504854
}

internal/binder/binder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ func isNarrowableReference(node *ast.Node) bool {
26402640

26412641
func hasNarrowableArgument(expr *ast.Node) bool {
26422642
call := expr.AsCallExpression()
2643-
for _, argument := range call.Arguments.Nodes {
2643+
for _, argument := range call.Arguments.Nodes { //nolint:modernize
26442644
if containsNarrowableReference(argument) {
26452645
return true
26462646
}

internal/checker/checker.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6781,10 +6781,26 @@ func (c *Checker) reportUnusedVariable(location *ast.Node, diagnostic *ast.Diagn
67816781
}
67826782

67836783
func (c *Checker) reportUnused(location *ast.Node, kind UnusedKind, diagnostic *ast.Diagnostic) {
6784-
if location.Flags&(ast.NodeFlagsAmbient|ast.NodeFlagsThisNodeOrAnySubNodesHasError) == 0 &&
6785-
(kind == UnusedKindLocal && c.compilerOptions.NoUnusedLocals.IsTrue() ||
6786-
(kind == UnusedKindParameter && c.compilerOptions.NoUnusedParameters.IsTrue())) {
6787-
c.diagnostics.Add(diagnostic)
6784+
if location.Flags&(ast.NodeFlagsAmbient|ast.NodeFlagsThisNodeOrAnySubNodesHasError) == 0 {
6785+
isError := c.unusedIsError(kind)
6786+
if isError {
6787+
c.diagnostics.Add(diagnostic)
6788+
} else {
6789+
suggestion := *diagnostic
6790+
suggestion.SetCategory(diagnostics.CategorySuggestion)
6791+
c.suggestionDiagnostics.Add(&suggestion)
6792+
}
6793+
}
6794+
}
6795+
6796+
func (c *Checker) unusedIsError(kind UnusedKind) bool {
6797+
switch kind {
6798+
case UnusedKindLocal:
6799+
return c.compilerOptions.NoUnusedLocals.IsTrue()
6800+
case UnusedKindParameter:
6801+
return c.compilerOptions.NoUnusedParameters.IsTrue()
6802+
default:
6803+
panic("Unhandled case in unusedIsError")
67886804
}
67896805
}
67906806

@@ -13401,18 +13417,30 @@ func (c *Checker) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast.
1340113417

1340213418
func (c *Checker) getDiagnostics(ctx context.Context, sourceFile *ast.SourceFile, collection *ast.DiagnosticsCollection) []*ast.Diagnostic {
1340313419
c.checkNotCanceled()
13420+
isSuggestionDiagnostics := collection == &c.suggestionDiagnostics
13421+
13422+
files := c.files
1340413423
if sourceFile != nil {
13405-
c.CheckSourceFile(ctx, sourceFile)
13406-
if c.wasCanceled {
13407-
return nil
13408-
}
13409-
return collection.GetDiagnosticsForFile(sourceFile.FileName())
13424+
files = []*ast.SourceFile{sourceFile}
1341013425
}
13411-
for _, file := range c.files {
13426+
13427+
for _, file := range files {
1341213428
c.CheckSourceFile(ctx, file)
1341313429
if c.wasCanceled {
1341413430
return nil
1341513431
}
13432+
13433+
// Check unused identifiers as suggestions if we're collecting suggestion diagnostics
13434+
// and they are not configured as errors
13435+
if isSuggestionDiagnostics && !file.IsDeclarationFile &&
13436+
!(c.compilerOptions.NoUnusedLocals.IsTrue() || c.compilerOptions.NoUnusedParameters.IsTrue()) {
13437+
links := c.sourceFileLinks.Get(file)
13438+
c.checkUnusedIdentifiers(links.identifierCheckNodes)
13439+
}
13440+
}
13441+
13442+
if sourceFile != nil {
13443+
return collection.GetDiagnosticsForFile(sourceFile.FileName())
1341613444
}
1341713445
return collection.GetDiagnostics()
1341813446
}

internal/checker/grammarchecks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ func (c *Checker) checkGrammarHeritageClause(node *ast.HeritageClause) bool {
900900
return c.grammarErrorAtPos(node.AsNode(), types.Pos(), 0, diagnostics.X_0_list_cannot_be_empty, listType)
901901
}
902902

903-
for _, node := range types.Nodes {
903+
for _, node := range types.Nodes { //nolint:modernize
904904
if c.checkGrammarExpressionWithTypeArguments(node) {
905905
return true
906906
}

internal/checker/mapper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package checker
22

3-
import "github.com/microsoft/typescript-go/internal/core"
3+
import (
4+
"slices"
5+
6+
"github.com/microsoft/typescript-go/internal/core"
7+
)
48

59
// TypeMapperKind
610

@@ -158,10 +162,8 @@ func newArrayToSingleTypeMapper(sources []*Type, target *Type) *TypeMapper {
158162
}
159163

160164
func (m *ArrayToSingleTypeMapper) Map(t *Type) *Type {
161-
for _, s := range m.sources {
162-
if t == s {
163-
return m.target
164-
}
165+
if slices.Contains(m.sources, t) {
166+
return m.target
165167
}
166168
return t
167169
}

internal/checker/nodebuilderimpl.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,10 +2034,8 @@ func (b *NodeBuilderImpl) shouldUsePlaceholderForProperty(propertySymbol *ast.Sy
20342034
return false
20352035
}
20362036
// (1)
2037-
for _, elem := range b.ctx.reverseMappedStack {
2038-
if elem == propertySymbol {
2039-
return true
2040-
}
2037+
if slices.Contains(b.ctx.reverseMappedStack, propertySymbol) {
2038+
return true
20412039
}
20422040
// (2)
20432041
if len(b.ctx.reverseMappedStack) > 0 {

internal/compiler/fileloader.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ type processedFiles struct {
6464
importHelpersImportSpecifiers map[tspath.Path]*ast.Node
6565
libFiles map[tspath.Path]*LibFile
6666
// List of present unsupported extensions
67-
unsupportedExtensions []string
6867
sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
6968
includeProcessor *includeProcessor
7069
// if file was included using source file and its output is actually part of program
@@ -152,7 +151,6 @@ func processAllProgramFiles(
152151
sourceFileMetaDatas := make(map[tspath.Path]ast.SourceFileMetaData, totalFileCount)
153152
var jsxRuntimeImportSpecifiers map[tspath.Path]*jsxRuntimeImportSpecifier
154153
var importHelpersImportSpecifiers map[tspath.Path]*ast.Node
155-
var unsupportedExtensions []string
156154
var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
157155
libFilesMap := make(map[tspath.Path]*LibFile, libFileCount)
158156

@@ -217,10 +215,6 @@ func processAllProgramFiles(
217215
}
218216
importHelpersImportSpecifiers[path] = task.importHelpersImportSpecifier
219217
}
220-
extension := tspath.TryGetExtensionFromPath(file.FileName())
221-
if slices.Contains(tspath.SupportedJSExtensionsFlat, extension) {
222-
unsupportedExtensions = core.AppendIfUnique(unsupportedExtensions, extension)
223-
}
224218
if task.fromExternalLibrary {
225219
sourceFilesFoundSearchingNodeModules.Add(path)
226220
}
@@ -251,7 +245,6 @@ func processAllProgramFiles(
251245
sourceFileMetaDatas: sourceFileMetaDatas,
252246
jsxRuntimeImportSpecifiers: jsxRuntimeImportSpecifiers,
253247
importHelpersImportSpecifiers: importHelpersImportSpecifiers,
254-
unsupportedExtensions: unsupportedExtensions,
255248
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
256249
libFiles: libFilesMap,
257250
missingFiles: missingFiles,
@@ -638,16 +631,22 @@ func getLibraryNameFromLibFileName(libFileName string) string {
638631
// lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
639632
// lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
640633
components := strings.Split(libFileName, ".")
641-
var path string
634+
var path strings.Builder
635+
path.WriteString("@typescript/lib-")
642636
if len(components) > 1 {
643-
path = components[1]
637+
path.WriteString(components[1])
644638
}
645639
i := 2
646640
for i < len(components) && components[i] != "" && components[i] != "d" {
647-
path += core.IfElse(i == 2, "/", "-") + components[i]
641+
if i == 2 {
642+
path.WriteByte('/')
643+
} else {
644+
path.WriteByte('-')
645+
}
646+
path.WriteString(components[i])
648647
i++
649648
}
650-
return "@typescript/lib-" + path
649+
return path.String()
651650
}
652651

653652
func getInferredLibraryNameResolveFrom(options *core.CompilerOptions, currentDirectory string, libFileName string) string {

0 commit comments

Comments
 (0)