Skip to content

Commit f3582f0

Browse files
committed
Merge branch 'main' into guyllian.gomez/yarn-pnp
2 parents 68db04a + 746dcca commit f3582f0

File tree

1,196 files changed

+631268
-8729
lines changed

Some content is hidden

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

1,196 files changed

+631268
-8729
lines changed

.github/ISSUE_TEMPLATE/02-behavior-difference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Behavior Difference
3-
about: tsgo produces different results than TypeScript 5.8
3+
about: tsgo produces different results than TypeScript 5.9
44
title: ''
55
labels: ''
66
assignees: ''
@@ -11,6 +11,6 @@ assignees: ''
1111

1212
<!-- Share a repository link or a code sample -->
1313

14-
## Behavior with `typescript@5.8`
14+
## Behavior with `typescript@5.9`
1515

1616
## Behavior with `tsgo`

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ This is still a work in progress and is not yet at full feature parity with Type
2727

2828
| Feature | Status | Notes |
2929
|---------|--------|-------|
30-
| Program creation | done | Same files and module resolution as TS 5.8. Not all resolution modes supported yet. |
31-
| Parsing/scanning | done | Exact same syntax errors as TS 5.8 |
32-
| Commandline and `tsconfig.json` parsing | mostly done | Missing --help, --init. |
33-
| Type resolution | done | Same types as TS 5.8. |
34-
| Type checking | done | Same errors, locations, and messages as TS 5.8. Types printback in errors may display differently. |
30+
| Program creation | done | Same files and module resolution as TS 5.9. Not all resolution modes supported yet. |
31+
| Parsing/scanning | done | Exact same syntax errors as TS 5.9 |
32+
| Commandline and `tsconfig.json` parsing | done | Done, though `tsconfig` errors may not be as helpful. |
33+
| Type resolution | done | Same types as TS 5.9. |
34+
| Type checking | done | Same errors, locations, and messages as TS 5.9. Types printback in errors may display differently. |
3535
| JavaScript-specific inference and JSDoc | in progress | Mostly complete, but intentionally lacking some features. Declaration emit not complete. |
3636
| JSX | done | - |
3737
| Declaration emit | in progress | Most common features are in place, but some edge cases and feature flags are still unhandled. |
3838
| Emit (JS output) | in progress | `target: esnext` well-supported, other targets may have gaps. |
3939
| Watch mode | prototype | Watches files and rebuilds, but no incremental rechecking. Not optimized. |
4040
| Build mode / project references | done | - |
4141
| Incremental build | done | - |
42-
| Language service (LSP) | in progress | Some functionality (errors, hover, go to def, refs, sig help). More features coming soon. |
42+
| Language service (LSP) | in progress | Most functionality. More features coming soon. |
4343
| API | not ready | - |
4444

4545
Definitions:
@@ -54,7 +54,7 @@ Definitions:
5454
Long-term, we expect that this repo and its contents will be merged into `microsoft/TypeScript`.
5555
As a result, the repo and issue tracker for typescript-go will eventually be closed, so treat discussions/issues accordingly.
5656

57-
For a list of intentional changes with respect to TypeScript 5.7, see CHANGES.md.
57+
For a list of intentional changes with respect to TypeScript 5.9, see CHANGES.md.
5858

5959
## Contributing
6060

internal/ast/ast.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10983,7 +10983,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1098310983
result := make(map[string][]*Node)
1098410984

1098510985
addDeclaration := func(declaration *Node) {
10986-
name := getDeclarationName(declaration)
10986+
name := GetDeclarationName(declaration)
1098710987
if name != "" {
1098810988
result[name] = append(result[name], declaration)
1098910989
}
@@ -10993,7 +10993,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1099310993
visit = func(node *Node) bool {
1099410994
switch node.Kind {
1099510995
case KindFunctionDeclaration, KindFunctionExpression, KindMethodDeclaration, KindMethodSignature:
10996-
declarationName := getDeclarationName(node)
10996+
declarationName := GetDeclarationName(node)
1099710997
if declarationName != "" {
1099810998
declarations := result[declarationName]
1099910999
var lastDeclaration *Node
@@ -11025,7 +11025,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1102511025
break
1102611026
}
1102711027
fallthrough
11028-
case KindVariableDeclaration, KindBindingElement:
11028+
case KindVariableDeclaration, KindBindingElement, KindCommonJSExport:
1102911029
name := node.Name()
1103011030
if name != nil {
1103111031
if IsBindingPattern(name) {
@@ -11074,6 +11074,12 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1107411074
}
1107511075
}
1107611076
}
11077+
case KindBinaryExpression:
11078+
switch GetAssignmentDeclarationKind(node.AsBinaryExpression()) {
11079+
case JSDeclarationKindThisProperty, JSDeclarationKindProperty:
11080+
addDeclaration(node)
11081+
}
11082+
node.ForEachChild(visit)
1107711083
default:
1107811084
node.ForEachChild(visit)
1107911085
}
@@ -11083,7 +11089,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1108311089
return result
1108411090
}
1108511091

11086-
func getDeclarationName(declaration *Node) string {
11092+
func GetDeclarationName(declaration *Node) string {
1108711093
name := GetNonAssignedNameOfDeclaration(declaration)
1108811094
if name != nil {
1108911095
if IsComputedPropertyName(name) {

internal/ast/diagnostic.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ import (
77

88
"github.com/microsoft/typescript-go/internal/core"
99
"github.com/microsoft/typescript-go/internal/diagnostics"
10+
"github.com/microsoft/typescript-go/internal/locale"
1011
)
1112

1213
// Diagnostic
1314

1415
type Diagnostic struct {
15-
file *SourceFile
16-
loc core.TextRange
17-
code int32
18-
category diagnostics.Category
19-
message string
16+
file *SourceFile
17+
loc core.TextRange
18+
code int32
19+
category diagnostics.Category
20+
// Original message; may be nil.
21+
message *diagnostics.Message
22+
messageKey diagnostics.Key
23+
messageArgs []string
2024
messageChain []*Diagnostic
2125
relatedInformation []*Diagnostic
2226
reportsUnnecessary bool
@@ -31,7 +35,8 @@ func (d *Diagnostic) Len() int { return d.loc.Len() }
3135
func (d *Diagnostic) Loc() core.TextRange { return d.loc }
3236
func (d *Diagnostic) Code() int32 { return d.code }
3337
func (d *Diagnostic) Category() diagnostics.Category { return d.category }
34-
func (d *Diagnostic) Message() string { return d.message }
38+
func (d *Diagnostic) MessageKey() diagnostics.Key { return d.messageKey }
39+
func (d *Diagnostic) MessageArgs() []string { return d.messageArgs }
3540
func (d *Diagnostic) MessageChain() []*Diagnostic { return d.messageChain }
3641
func (d *Diagnostic) RelatedInformation() []*Diagnostic { return d.relatedInformation }
3742
func (d *Diagnostic) ReportsUnnecessary() bool { return d.reportsUnnecessary }
@@ -72,12 +77,22 @@ func (d *Diagnostic) Clone() *Diagnostic {
7277
return &result
7378
}
7479

75-
func NewDiagnosticWith(
80+
func (d *Diagnostic) Localize(locale locale.Locale) string {
81+
return diagnostics.Localize(locale, d.message, d.messageKey, d.messageArgs...)
82+
}
83+
84+
// For debugging only.
85+
func (d *Diagnostic) String() string {
86+
return diagnostics.Localize(locale.Default, d.message, d.messageKey, d.messageArgs...)
87+
}
88+
89+
func NewDiagnosticFromSerialized(
7690
file *SourceFile,
7791
loc core.TextRange,
7892
code int32,
7993
category diagnostics.Category,
80-
message string,
94+
messageKey diagnostics.Key,
95+
messageArgs []string,
8196
messageChain []*Diagnostic,
8297
relatedInformation []*Diagnostic,
8398
reportsUnnecessary bool,
@@ -89,7 +104,8 @@ func NewDiagnosticWith(
89104
loc: loc,
90105
code: code,
91106
category: category,
92-
message: message,
107+
messageKey: messageKey,
108+
messageArgs: messageArgs,
93109
messageChain: messageChain,
94110
relatedInformation: relatedInformation,
95111
reportsUnnecessary: reportsUnnecessary,
@@ -104,7 +120,9 @@ func NewDiagnostic(file *SourceFile, loc core.TextRange, message *diagnostics.Me
104120
loc: loc,
105121
code: message.Code(),
106122
category: message.Category(),
107-
message: message.Format(args...),
123+
message: message,
124+
messageKey: message.Key(),
125+
messageArgs: diagnostics.StringifyArgs(args),
108126
reportsUnnecessary: message.ReportsUnnecessary(),
109127
reportsDeprecated: message.ReportsDeprecated(),
110128
}
@@ -185,13 +203,13 @@ func EqualDiagnosticsNoRelatedInfo(d1, d2 *Diagnostic) bool {
185203
return getDiagnosticPath(d1) == getDiagnosticPath(d2) &&
186204
d1.Loc() == d2.Loc() &&
187205
d1.Code() == d2.Code() &&
188-
d1.Message() == d2.Message() &&
206+
slices.Equal(d1.MessageArgs(), d2.MessageArgs()) &&
189207
slices.EqualFunc(d1.MessageChain(), d2.MessageChain(), equalMessageChain)
190208
}
191209

192210
func equalMessageChain(c1, c2 *Diagnostic) bool {
193211
return c1.Code() == c2.Code() &&
194-
c1.Message() == c2.Message() &&
212+
slices.Equal(c1.MessageArgs(), c2.MessageArgs()) &&
195213
slices.EqualFunc(c1.MessageChain(), c2.MessageChain(), equalMessageChain)
196214
}
197215

@@ -211,7 +229,7 @@ func compareMessageChainSize(c1, c2 []*Diagnostic) int {
211229

212230
func compareMessageChainContent(c1, c2 []*Diagnostic) int {
213231
for i := range c1 {
214-
c := strings.Compare(c1[i].Message(), c2[i].Message())
232+
c := slices.Compare(c1[i].MessageArgs(), c2[i].MessageArgs())
215233
if c != 0 {
216234
return c
217235
}
@@ -256,7 +274,7 @@ func CompareDiagnostics(d1, d2 *Diagnostic) int {
256274
if c != 0 {
257275
return c
258276
}
259-
c = strings.Compare(d1.Message(), d2.Message())
277+
c = slices.Compare(d1.MessageArgs(), d2.MessageArgs())
260278
if c != 0 {
261279
return c
262280
}

internal/bundled/embed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (vfs *wrappedFS) walkDir(rest string, walkFn vfs.WalkDirFunc) error {
131131
return err
132132
}
133133
if entry.IsDir() {
134-
if err := vfs.walkDir(name, walkFn); err != nil {
134+
if err := vfs.walkDir(strings.TrimPrefix(name, "/"), walkFn); err != nil {
135135
return err
136136
}
137137
}

internal/bundled/generate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/microsoft/typescript-go/internal/ast"
1616
"github.com/microsoft/typescript-go/internal/core"
17+
"github.com/microsoft/typescript-go/internal/locale"
1718
"github.com/microsoft/typescript-go/internal/parser"
1819
"github.com/microsoft/typescript-go/internal/repo"
1920
"github.com/microsoft/typescript-go/internal/tspath"
@@ -150,7 +151,7 @@ func readLibs() []lib {
150151

151152
if len(diags) > 0 {
152153
for _, diag := range diags {
153-
log.Printf("%s", diag.Message())
154+
log.Printf("%s", diag.Localize(locale.Default))
154155
}
155156
log.Fatalf("failed to parse libs.json")
156157
}

internal/checker/checker.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4271,7 +4271,7 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) {
42714271
}
42724272
c.checkIndexConstraints(classType, symbol, false /*isStaticIndex*/)
42734273
c.checkIndexConstraints(staticType, symbol, true /*isStaticIndex*/)
4274-
c.checkTypeForDuplicateIndexSignatures(node)
4274+
c.checkClassOrInterfaceForDuplicateIndexSignatures(node)
42754275
c.checkPropertyInitialization(node)
42764276
}
42774277

@@ -4758,14 +4758,15 @@ func (c *Checker) checkIndexConstraintForIndexSignature(t *Type, checkInfo *Inde
47584758
}
47594759
}
47604760

4761-
func (c *Checker) checkTypeForDuplicateIndexSignatures(node *ast.Node) {
4762-
if ast.IsInterfaceDeclaration(node) {
4763-
// in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration
4764-
// to prevent this run check only for the first declaration of a given kind
4765-
if symbol := c.getSymbolOfDeclaration(node); len(symbol.Declarations) != 0 && symbol.Declarations[0] != node {
4766-
return
4767-
}
4761+
func (c *Checker) checkClassOrInterfaceForDuplicateIndexSignatures(node *ast.Node) {
4762+
// Only check the type once
4763+
if links := c.declaredTypeLinks.Get(c.getSymbolOfDeclaration(node)); !links.indexSignaturesChecked {
4764+
links.indexSignaturesChecked = true
4765+
c.checkTypeForDuplicateIndexSignatures(node)
47684766
}
4767+
}
4768+
4769+
func (c *Checker) checkTypeForDuplicateIndexSignatures(node *ast.Node) {
47694770
// TypeScript 1.0 spec (April 2014)
47704771
// 3.7.4: An object type can contain at most one string index signature and one numeric index signature.
47714772
// 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration
@@ -4865,8 +4866,8 @@ func (c *Checker) checkInterfaceDeclaration(node *ast.Node) {
48654866
symbol := c.getSymbolOfDeclaration(node)
48664867
c.checkTypeParameterListsIdentical(symbol)
48674868
// Only check this symbol once
4868-
firstInterfaceDecl := ast.GetDeclarationOfKind(symbol, ast.KindInterfaceDeclaration)
4869-
if node == firstInterfaceDecl {
4869+
if links := c.declaredTypeLinks.Get(symbol); !links.interfaceChecked {
4870+
links.interfaceChecked = true
48704871
t := c.getDeclaredTypeOfSymbol(symbol)
48714872
typeWithThis := c.getTypeWithThisArgument(t, nil, false)
48724873
// run subsequent checks only if first set succeeded
@@ -4886,7 +4887,7 @@ func (c *Checker) checkInterfaceDeclaration(node *ast.Node) {
48864887
c.checkTypeReferenceNode(heritageElement)
48874888
}
48884889
c.checkSourceElements(node.Members())
4889-
c.checkTypeForDuplicateIndexSignatures(node)
4890+
c.checkClassOrInterfaceForDuplicateIndexSignatures(node)
48904891
c.registerForUnusedIdentifiersCheck(node)
48914892
}
48924893

internal/checker/grammarchecks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool {
21912191

21922192
nodeArguments := nodeAsCall.Arguments
21932193
argumentNodes := nodeArguments.Nodes
2194-
if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindNodeNext && c.moduleKind != core.ModuleKindNode16 && c.moduleKind != core.ModuleKindPreserve {
2194+
if !(core.ModuleKindNode16 <= c.moduleKind && c.moduleKind <= core.ModuleKindNodeNext) && c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindPreserve {
21952195
// We are allowed trailing comma after proposal-import-assertions.
21962196
c.checkGrammarForDisallowedTrailingComma(nodeArguments, diagnostics.Trailing_comma_not_allowed)
21972197

0 commit comments

Comments
 (0)