Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion microsoft/typescript-go
Submodule typescript-go updated 353 files
21 changes: 8 additions & 13 deletions pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,14 @@ func (c *Checker) onFailedToResolveSymbol(errorLocation *ast.Node, name string,
c.checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
return
}
declarationName := name
if errorLocation != nil && ast.IsIdentifier(errorLocation) && errorLocation.Text() == name {
declarationName = scanner.DeclarationNameToString(errorLocation) // use escape sequences from original file
}
// Report missing lib first
suggestedLib := c.getSuggestedLibForNonExistentName(name)
if suggestedLib != "" {
c.error(errorLocation, nameNotFoundMessage, name, suggestedLib)
c.error(errorLocation, nameNotFoundMessage, declarationName, suggestedLib)
return
}
// Then spelling suggestions
Expand All @@ -1575,15 +1579,15 @@ func (c *Checker) onFailedToResolveSymbol(errorLocation *ast.Node, name string,
isUncheckedJS := c.isUncheckedJSSuggestion(errorLocation, suggestion, false /*excludeClasses*/)
message := core.IfElse(meaning == ast.SymbolFlagsNamespace, diagnostics.Cannot_find_namespace_0_Did_you_mean_1,
core.IfElse(isUncheckedJS, diagnostics.Could_not_find_name_0_Did_you_mean_1, diagnostics.Cannot_find_name_0_Did_you_mean_1))
diagnostic := NewDiagnosticForNode(errorLocation, message, name, suggestionName)
diagnostic := NewDiagnosticForNode(errorLocation, message, declarationName, suggestionName)
if suggestion.ValueDeclaration != nil {
diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestionName))
}
c.addErrorOrSuggestion(!isUncheckedJS, diagnostic)
return
}
// And then fall back to unspecified "not found"
c.error(errorLocation, nameNotFoundMessage, name)
c.error(errorLocation, nameNotFoundMessage, declarationName)
}

func (c *Checker) checkAndReportErrorForUsingTypeAsNamespace(errorLocation *ast.Node, name string, meaning ast.SymbolFlags) bool {
Expand Down Expand Up @@ -19931,22 +19935,13 @@ func (c *Checker) getAnnotatedAccessorTypeNode(accessor *ast.Node) *ast.Node {
}

func getEffectiveSetAccessorTypeAnnotationNode(node *ast.Node) *ast.Node {
param := getSetAccessorValueParameter(node)
param := GetSetAccessorValueParameter(node)
if param != nil {
return param.Type()
}
return nil
}

func getSetAccessorValueParameter(accessor *ast.Node) *ast.Node {
parameters := accessor.Parameters()
if len(parameters) > 0 {
hasThis := len(parameters) == 2 && ast.IsThisParameter(parameters[0])
return parameters[core.IfElse(hasThis, 1, 0)]
}
return nil
}

func (c *Checker) getReturnTypeFromBody(fn *ast.Node, checkMode CheckMode) *Type {
body := fn.Body()
if body == nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/checker/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func (c *Checker) GetUnionType(types []*Type) *Type {
return c.getUnionType(types)
}

func (c *Checker) GetNameTypeOfSymbol(symbol *ast.Symbol) *Type {
if !c.valueSymbolLinks.Has(symbol) {
return nil
}
return c.valueSymbolLinks.TryGet(symbol).nameType
}

func IsTypeUsableAsPropertyName(t *Type) bool {
return isTypeUsableAsPropertyName(t)
}

func GetPropertyNameFromType(t *Type) string {
return getPropertyNameFromType(t)
}

func (c *Checker) GetGlobalSymbol(name string, meaning ast.SymbolFlags, diagnostic *diagnostics.Message) *ast.Symbol {
return c.getGlobalSymbol(name, meaning, diagnostic)
}
Expand Down Expand Up @@ -263,6 +278,10 @@ func (c *Checker) GetTypeArguments(t *Type) []*Type {
return c.getTypeArguments(t)
}

func (c *Checker) GetIndexInfoOfType(t *Type, keyType *Type) *IndexInfo {
return c.getIndexInfoOfType(t, keyType)
}

func (c *Checker) GetIndexInfosOfType(t *Type) []*IndexInfo {
return c.getIndexInfosOfType(t)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ func (c *Checker) checkGrammarAccessor(accessor *ast.AccessorDeclaration) bool {
return c.grammarErrorOnNode(accessor.Name(), diagnostics.A_set_accessor_cannot_have_a_return_type_annotation)
}

parameterNode := getSetAccessorValueParameter(accessor)
parameterNode := GetSetAccessorValueParameter(accessor)
if parameterNode == nil {
panic("Return value does not match parameter count assertion.")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@ func (b *NodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
if b.checkTruncationLength() {
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
elem := b.f.NewNotEmittedTypeElement()
return b.f.NewNodeList([]*ast.TypeElement{b.e.AddSyntheticLeadingComment(elem, ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)})
return b.f.NewNodeList([]*ast.TypeElement{b.e.AddSyntheticTrailingComment(elem, ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)})
}
return b.f.NewNodeList([]*ast.Node{b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier("..."), nil, nil, nil)})
}
Expand Down Expand Up @@ -2561,7 +2561,7 @@ func (b *NodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
}
if b.checkTruncationLength() && (i+2 < len(properties)-1) {
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
typeElements[len(typeElements)-1] = b.e.AddSyntheticLeadingComment(typeElements[len(typeElements)-1], ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(properties)-i), false /*hasTrailingNewLine*/)
typeElements[len(typeElements)-1] = b.e.AddSyntheticTrailingComment(typeElements[len(typeElements)-1], ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(properties)-i), false /*hasTrailingNewLine*/)
} else {
text := fmt.Sprintf("... %d more ...", len(properties)-i)
typeElements = append(typeElements, b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier(text), nil, nil, nil))
Expand Down
3 changes: 3 additions & 0 deletions pkg/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,9 @@ func (c *Checker) sliceTupleType(t *Type, index int, endSkipCount int) *Type {
}
return c.createTupleType(nil)
}
if index >= endIndex {
return c.createTupleType(nil)
}
return c.createTupleTypeEx(c.getTypeArguments(t)[index:endIndex], target.elementInfos[index:endIndex], false /*readonly*/)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/checker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,10 @@ func (s *Signature) HasRestParameter() bool {
return s.flags&SignatureFlagsHasRestParameter != 0
}

func (s *Signature) MinArgumentCount() int {
return int(s.minArgumentCount)
}

type CompositeSignature struct {
isUnion bool // True for union, false for intersection
signatures []*Signature // Individual signatures
Expand Down
9 changes: 9 additions & 0 deletions pkg/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,3 +1818,12 @@ func walkUpOuterExpressions(node *ast.Node) *ast.Node {
}
return parent
}

func GetSetAccessorValueParameter(accessor *ast.Node) *ast.Node {
parameters := accessor.Parameters()
if len(parameters) > 0 {
hasThis := len(parameters) == 2 && ast.IsThisParameter(parameters[0])
return parameters[core.IfElse(hasThis, 1, 0)]
}
return nil
}
Loading