Skip to content

Commit 9573cfc

Browse files
Implement ResolveTypeReferenceDirective (microsoft#98)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent 2dd1a1a commit 9573cfc

File tree

206 files changed

+1970
-40022
lines changed

Some content is hidden

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

206 files changed

+1970
-40022
lines changed

internal/ast/diagnostic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ast
33
import (
44
"github.com/microsoft/typescript-go/internal/compiler/diagnostics"
55
"github.com/microsoft/typescript-go/internal/core"
6+
"github.com/microsoft/typescript-go/internal/stringutil"
67
)
78

89
// Diagnostic
@@ -58,7 +59,7 @@ func (d *Diagnostic) AddRelatedInfo(relatedInformation *Diagnostic) *Diagnostic
5859
func NewDiagnostic(file *SourceFile, loc core.TextRange, message *diagnostics.Message, args ...any) *Diagnostic {
5960
text := message.Message()
6061
if len(args) != 0 {
61-
text = core.FormatStringFromArgs(text, args)
62+
text = stringutil.Format(text, args)
6263
}
6364
return &Diagnostic{
6465
file: file,
@@ -106,7 +107,7 @@ func (m *MessageChain) AddMessageChain(messageChain *MessageChain) *MessageChain
106107
func NewMessageChain(message *diagnostics.Message, args ...any) *MessageChain {
107108
text := message.Message()
108109
if len(args) != 0 {
109-
text = core.FormatStringFromArgs(text, args)
110+
text = stringutil.Format(text, args)
110111
}
111112
return &MessageChain{
112113
code: message.Code(),

internal/compiler/checker.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/microsoft/typescript-go/internal/compiler/diagnostics"
1414
"github.com/microsoft/typescript-go/internal/core"
1515
"github.com/microsoft/typescript-go/internal/scanner"
16+
"github.com/microsoft/typescript-go/internal/stringutil"
1617
"github.com/microsoft/typescript-go/internal/tspath"
1718
)
1819

@@ -2098,7 +2099,7 @@ func (c *Checker) checkExpressionWorker(node *ast.Node, checkMode CheckMode) *Ty
20982099
return c.getFreshTypeOfLiteralType(c.getStringLiteralType(node.Text()))
20992100
case ast.KindNumericLiteral:
21002101
// !!! checkGrammarNumericLiteral(node as NumericLiteral)
2101-
return c.getFreshTypeOfLiteralType(c.getNumberLiteralType(core.StringToNumber(node.Text())))
2102+
return c.getFreshTypeOfLiteralType(c.getNumberLiteralType(stringutil.ToNumber(node.Text())))
21022103
case ast.KindBigIntLiteral:
21032104
// !!! checkGrammarBigIntLiteral(node as BigIntLiteral);
21042105
return c.getFreshTypeOfLiteralType(c.getBigIntLiteralType(PseudoBigInt{
@@ -10926,7 +10927,7 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) EvaluatorRe
1092610927
// Technically we resolved a global lib file here, but the decision to treat this as numeric
1092710928
// is more predicated on the fact that the single-file resolution *didn't* resolve to a
1092810929
// different meaning of `Infinity` or `NaN`. Transpilers handle this no problem.
10929-
return evaluatorResult(core.StringToNumber(expr.Text()), false, false, false)
10930+
return evaluatorResult(stringutil.ToNumber(expr.Text()), false, false, false)
1093010931
}
1093110932
}
1093210933
if symbol.Flags&ast.SymbolFlagsEnumMember != 0 {
@@ -13076,7 +13077,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy
1307613077
}
1307713078
}
1307813079
if everyType(objectType, isTupleType) && isNumericLiteralName(propName) {
13079-
index := core.StringToNumber(propName)
13080+
index := stringutil.ToNumber(propName)
1308013081
if accessNode != nil && everyType(objectType, func(t *Type) bool {
1308113082
return t.TargetTupleType().combinedFlags&ElementFlagsVariable == 0
1308213083
}) && accessFlags&AccessFlagsAllowMissing == 0 {
@@ -13320,7 +13321,7 @@ func indexTypeLessThan(indexType *Type, limit int) bool {
1332013321
if t.flags&TypeFlagsStringOrNumberLiteral != 0 {
1332113322
propName := getPropertyNameFromType(t)
1332213323
if isNumericLiteralName(propName) {
13323-
index := core.StringToNumber(propName)
13324+
index := stringutil.ToNumber(propName)
1332413325
return index >= 0 && index < float64(limit)
1332513326
}
1332613327
}

internal/compiler/diagnostics/diagnostics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Package diagnostics contains generated localizable diagnostic messages.
22
package diagnostics
33

4-
import "github.com/microsoft/typescript-go/internal/core"
4+
import "github.com/microsoft/typescript-go/internal/stringutil"
55

66
//go:generate go run generate.go -output ./diagnostics_generated.go
77
//go:generate go run golang.org/x/tools/cmd/stringer -type=Category -output=stringer_generated.go
@@ -50,7 +50,7 @@ func (m *Message) ReportsDeprecated() bool { return m.reportsDeprecat
5050
func (m *Message) Format(args ...any) string {
5151
text := m.Message()
5252
if len(args) != 0 {
53-
text = core.FormatStringFromArgs(text, args)
53+
text = stringutil.Format(text, args)
5454
}
5555
return text
5656
}

0 commit comments

Comments
 (0)