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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,21 +1764,15 @@ func GetThisContainer(node *Node, includeArrowFunctions bool, includeClassComput
}

func GetSuperContainer(node *Node, stopOnFunctions bool) *Node {
for {
node = node.Parent
if node == nil {
return nil
}
for node = node.Parent; node != nil; node = node.Parent {
switch node.Kind {
case KindComputedPropertyName:
node = node.Parent
break
case KindFunctionDeclaration, KindFunctionExpression, KindArrowFunction:
if !stopOnFunctions {
continue
}
// falls through

return node
case KindPropertyDeclaration, KindPropertySignature, KindMethodDeclaration, KindMethodSignature, KindConstructor, KindGetAccessor, KindSetAccessor, KindClassStaticBlockDeclaration:
return node
case KindDecorator:
Expand All @@ -1792,9 +1786,9 @@ func GetSuperContainer(node *Node, stopOnFunctions bool) *Node {
// from the parent class declaration.
node = node.Parent
}
break
}
}
return nil
}

func GetImmediatelyInvokedFunctionExpression(fn *Node) *Node {
Expand Down
10 changes: 4 additions & 6 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14476,13 +14476,11 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
} else if ast.IsVariableDeclaration(location) && location.AsVariableDeclaration().Initializer != nil && ast.IsRequireCall(location.AsVariableDeclaration().Initializer, true /*requireStringLiteralLikeArgument*/) {
contextSpecifier = location.AsVariableDeclaration().Initializer.AsCallExpression().Arguments.Nodes[0]
} else {
var ancestor *ast.Node
if ancestor == nil {
ancestor = ast.FindAncestor(location, ast.IsImportCall)
if ancestor != nil {
contextSpecifier = ancestor.AsCallExpression().Arguments.Nodes[0]
}
ancestor := ast.FindAncestor(location, ast.IsImportCall)
if ancestor != nil {
contextSpecifier = ancestor.AsCallExpression().Arguments.Nodes[0]
}

if ancestor == nil {
ancestor = ast.FindAncestor(location, ast.IsImportDeclarationOrJSImportDeclaration)
if ancestor != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func (r *emitResolver) requiresAddingImplicitUndefined(declaration *ast.Node, sy
}
t := r.checker.getTypeOfSymbol(symbol)
r.checker.mappedSymbolLinks.Has(symbol)
return !!((symbol.Flags&ast.SymbolFlagsProperty != 0) && (symbol.Flags&ast.SymbolFlagsOptional != 0) && isOptionalDeclaration(declaration) && r.checker.ReverseMappedSymbolLinks.Has(symbol) && r.checker.ReverseMappedSymbolLinks.Get(symbol).mappedType != nil && containsNonMissingUndefinedType(r.checker, t))
return (symbol.Flags&ast.SymbolFlagsProperty != 0) && (symbol.Flags&ast.SymbolFlagsOptional != 0) && isOptionalDeclaration(declaration) && r.checker.ReverseMappedSymbolLinks.Has(symbol) && r.checker.ReverseMappedSymbolLinks.Get(symbol).mappedType != nil && containsNonMissingUndefinedType(r.checker, t)
case ast.KindParameter, ast.KindJSDocParameterTag:
return r.requiresAddingImplicitUndefinedWorker(declaration, enclosingDeclaration)
default:
Expand Down
15 changes: 7 additions & 8 deletions internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,13 @@ func (c *Checker) getJSXFragmentType(node *ast.Node) *Type {
if jsxFactorySymbol.Flags&ast.SymbolFlagsAlias != 0 {
resolvedAlias = c.resolveAlias(jsxFactorySymbol)
}
if jsxFactorySymbol != nil {
reactExports := c.getExportsOfSymbol(resolvedAlias)
typeSymbol := c.getSymbol(reactExports, ReactNames.Fragment, ast.SymbolFlagsBlockScopedVariable)
if typeSymbol != nil {
links.jsxFragmentType = c.getTypeOfSymbol(typeSymbol)
} else {
links.jsxFragmentType = c.errorType
}

reactExports := c.getExportsOfSymbol(resolvedAlias)
typeSymbol := c.getSymbol(reactExports, ReactNames.Fragment, ast.SymbolFlagsBlockScopedVariable)
if typeSymbol != nil {
links.jsxFragmentType = c.getTypeOfSymbol(typeSymbol)
} else {
links.jsxFragmentType = c.errorType
}
return links.jsxFragmentType
}
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ func (b *nodeBuilderImpl) getSymbolChain(symbol *ast.Symbol, meaning ast.SymbolF
// If a parent symbol is an anonymous type, don't write it.
(symbol.Flags&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsObjectLiteral) == 0) {
// If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.)
if !endOfChain && !yieldModuleSymbol && !!core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) {
if !endOfChain && !yieldModuleSymbol && core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) {
return nil
}
return []*ast.Symbol{symbol}
Expand Down Expand Up @@ -1740,7 +1740,7 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa
typeParamList = b.f.NewNodeList(typeParameters)
}
var modifierList *ast.ModifierList
if modifiers != nil && len(modifiers) > 0 {
if len(modifiers) > 0 {
modifierList = b.f.NewModifierList(modifiers)
}
var name *ast.Node
Expand Down
5 changes: 3 additions & 2 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,10 @@ func (l *LanguageService) getCompletionData(
}

var importAttributes *ast.ImportAttributesNode
if contextToken.Kind == ast.KindOpenBraceToken || contextToken.Kind == ast.KindCommaToken {
switch contextToken.Kind {
case ast.KindOpenBraceToken, ast.KindCommaToken:
importAttributes = core.IfElse(ast.IsImportAttributes(contextToken.Parent), contextToken.Parent, nil)
} else if contextToken.Kind == ast.KindColonToken {
case ast.KindColonToken:
importAttributes = core.IfElse(ast.IsImportAttributes(contextToken.Parent.Parent), contextToken.Parent.Parent, nil)
}

Expand Down
11 changes: 4 additions & 7 deletions internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,12 @@ func getContextNodeForNodeEntry(node *ast.Node) *ast.Node {
}

// Jsx Tags
if node.Parent.Kind == ast.KindJsxOpeningElement || node.Parent.Kind == ast.KindJsxClosingElement {
switch node.Parent.Kind {
case ast.KindJsxOpeningElement, ast.KindJsxClosingElement:
return node.Parent.Parent
} else if node.Parent.Kind == ast.KindJsxSelfClosingElement ||
node.Parent.Kind == ast.KindLabeledStatement ||
node.Parent.Kind == ast.KindBreakStatement ||
node.Parent.Kind == ast.KindContinueStatement {
case ast.KindJsxSelfClosingElement, ast.KindLabeledStatement, ast.KindBreakStatement, ast.KindContinueStatement:
return node.Parent
} else if node.Parent.Kind == ast.KindStringLiteral || node.Parent.Kind == ast.KindNoSubstitutionTemplateLiteral {
case ast.KindStringLiteral, ast.KindNoSubstitutionTemplateLiteral:
if validImport := tryGetImportFromModuleSpecifier(node); validImport != nil {
declOrStatement := ast.FindAncestor(validImport, func(*ast.Node) bool {
return ast.IsDeclaration(node) || ast.IsStatement(node) || ast.IsJSDocTag(node)
Expand Down Expand Up @@ -865,7 +863,6 @@ func getReferencesForSuperKeyword(superKeyword *ast.Node) []*SymbolAndEntries {
case ast.KindPropertyDeclaration, ast.KindPropertySignature, ast.KindMethodDeclaration, ast.KindMethodSignature, ast.KindConstructor, ast.KindGetAccessor, ast.KindSetAccessor:
staticFlag &= searchSpaceNode.ModifierFlags()
searchSpaceNode = searchSpaceNode.Parent // re-assign to be the owning class
break
default:
return nil
}
Expand Down
37 changes: 16 additions & 21 deletions internal/ls/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,55 +287,45 @@ func getPossibleTypeArgumentsInfo(tokenIn *ast.Node, sourceFile *ast.SourceFile)
}
}
remainingLessThanTokens--
break
case ast.KindGreaterThanGreaterThanGreaterThanToken:
remainingLessThanTokens = +3
break
case ast.KindGreaterThanGreaterThanToken:
remainingLessThanTokens = +2
break
case ast.KindGreaterThanToken:
remainingLessThanTokens++
break
case ast.KindCloseBraceToken:
// This can be object type, skip until we find the matching open brace token
// Skip until the matching open brace token
token = findPrecedingMatchingToken(token, ast.KindOpenBraceToken, sourceFile)
if token == nil {
return nil
}
break
case ast.KindCloseParenToken:
// This can be object type, skip until we find the matching open brace token
// Skip until the matching open brace token
token = findPrecedingMatchingToken(token, ast.KindOpenParenToken, sourceFile)
if token == nil {
return nil
}
break
case ast.KindCloseBracketToken:
// This can be object type, skip until we find the matching open brace token
// Skip until the matching open brace token
token = findPrecedingMatchingToken(token, ast.KindOpenBracketToken, sourceFile)
if token == nil {
return nil
}
break

// Valid tokens in a type name. Skip.
case ast.KindCommaToken:
// Valid tokens in a type name. Skip.
nTypeArguments++
break
case ast.KindEqualsGreaterThanToken, ast.KindIdentifier, ast.KindStringLiteral, ast.KindNumericLiteral,
ast.KindBigIntLiteral, ast.KindTrueKeyword, ast.KindFalseKeyword, ast.KindTypeOfKeyword, ast.KindExtendsKeyword,
ast.KindKeyOfKeyword, ast.KindDotToken, ast.KindBarToken, ast.KindQuestionToken, ast.KindColonToken:
break
// do nothing
default:
if ast.IsTypeNode(token) {
break
if !ast.IsTypeNode(token) {
// Invalid token in type
return nil
}
// Invalid token in type
return nil
}
token = astnav.FindPrecedingToken(sourceFile, token.Pos())
}
Expand Down Expand Up @@ -1215,15 +1205,18 @@ func getAdjustedLocationForImportDeclaration(node *ast.ImportDeclaration, forRen
// import /**/type { propertyName as [|name|] } from ...;
// import /**/type * as [|name|] from ...;
if namedBindings := node.ImportClause.AsImportClause().NamedBindings; namedBindings != nil {
if namedBindings.Kind == ast.KindNamedImports {
switch namedBindings.Kind {
case ast.KindNamedImports:
// do nothing if there is more than one binding
elements := namedBindings.AsNamedImports().Elements
if len(elements.Nodes) != 1 {
return nil
}
return elements.Nodes[0].Name()
} else if namedBindings.Kind == ast.KindNamespaceImport {

case ast.KindNamespaceImport:
return namedBindings.Name()

}
}
}
Expand All @@ -1244,14 +1237,15 @@ func getAdjustedLocationForExportDeclaration(node *ast.ExportDeclaration, forRen
// export /**/type { [|name|] } from ...
// export /**/type { propertyName as [|name|] } from ...
// export /**/type * as [|name|] ...
if node.ExportClause.Kind == ast.KindNamedExports {
switch node.ExportClause.Kind {
case ast.KindNamedExports:
// do nothing if there is more than one binding
elements := node.ExportClause.AsNamedExports().Elements
if len(elements.Nodes) != 1 {
return nil
}
return elements.Nodes[0].Name()
} else if node.ExportClause.Kind == ast.KindNamespaceExport {
case ast.KindNamespaceExport:
return node.ExportClause.Name()
}
}
Expand Down Expand Up @@ -1641,12 +1635,13 @@ func findPrecedingMatchingToken(token *ast.Node, matchingTokenKind ast.Kind, sou
return nil
}
token = preceding
if token.Kind == matchingTokenKind {
switch token.Kind {
case matchingTokenKind:
if remainingMatchingTokens == 0 {
return token
}
remainingMatchingTokens--
} else if token.Kind == tokenKind {
case tokenKind:
remainingMatchingTokens++
}
}
Expand Down
Loading