Skip to content

Commit 6ec2fe6

Browse files
committed
Merge branch 'main' into gabritto/blockcompletion
2 parents 4014311 + db8c64e commit 6ec2fe6

File tree

946 files changed

+12782
-15693
lines changed

Some content is hidden

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

946 files changed

+12782
-15693
lines changed

internal/api/encoder/encoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
635635
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.Comment != nil) << 1)
636636
case ast.KindJSDocTemplateTag:
637637
n := node.AsJSDocTemplateTag()
638-
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.Constraint != nil) << 1) | (boolToByte(n.TypeParameters() != nil) << 2) | (boolToByte(n.Comment != nil) << 3)
638+
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.Constraint != nil) << 1) | (boolToByte(n.TypeParameters != nil) << 2) | (boolToByte(n.Comment != nil) << 3)
639639
case ast.KindJSDocReturnTag:
640640
n := node.AsJSDocReturnTag()
641641
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.TypeExpression != nil) << 1) | (boolToByte(n.Comment != nil) << 2)

internal/ast/ast.go

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ func (n *Node) Text() string {
289289
return n.AsJsxNamespacedName().Namespace.Text() + ":" + n.AsJsxNamespacedName().name.Text()
290290
case KindRegularExpressionLiteral:
291291
return n.AsRegularExpressionLiteral().Text
292+
case KindJSDocText:
293+
return n.AsJSDocText().Text
292294
}
293295
panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data))
294296
}
@@ -429,6 +431,8 @@ func (n *Node) TypeParameterList() *NodeList {
429431
return n.AsInterfaceDeclaration().TypeParameters
430432
case KindTypeAliasDeclaration, KindJSTypeAliasDeclaration:
431433
return n.AsTypeAliasDeclaration().TypeParameters
434+
case KindJSDocTemplateTag:
435+
return n.AsJSDocTemplateTag().TypeParameters
432436
default:
433437
funcLike := n.FunctionLikeData()
434438
if funcLike != nil {
@@ -4180,6 +4184,10 @@ func IsImportDeclaration(node *Node) bool {
41804184
return node.Kind == KindImportDeclaration
41814185
}
41824186

4187+
func IsImportDeclarationOrJSImportDeclaration(node *Node) bool {
4188+
return node.Kind == KindImportDeclaration || node.Kind == KindJSImportDeclaration
4189+
}
4190+
41834191
// ImportSpecifier
41844192

41854193
type ImportSpecifier struct {
@@ -7532,6 +7540,53 @@ func IsImportAttributes(node *Node) bool {
75327540
return node.Kind == KindImportAttributes
75337541
}
75347542

7543+
func (node *ImportAttributesNode) GetResolutionModeOverride( /* !!! grammarErrorOnNode?: (node: Node, diagnostic: DiagnosticMessage) => void*/ ) (core.ResolutionMode, bool) {
7544+
if node == nil {
7545+
return core.ResolutionModeNone, false
7546+
}
7547+
7548+
attributes := node.AsImportAttributes().Attributes
7549+
7550+
if len(attributes.Nodes) != 1 {
7551+
// !!!
7552+
// grammarErrorOnNode?.(
7553+
// node,
7554+
// node.token === SyntaxKind.WithKeyword
7555+
// ? Diagnostics.Type_import_attributes_should_have_exactly_one_key_resolution_mode_with_value_import_or_require
7556+
// : Diagnostics.Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require,
7557+
// );
7558+
return core.ResolutionModeNone, false
7559+
}
7560+
7561+
elem := attributes.Nodes[0].AsImportAttribute()
7562+
if !IsStringLiteralLike(elem.Name()) {
7563+
return core.ResolutionModeNone, false
7564+
}
7565+
if elem.Name().Text() != "resolution-mode" {
7566+
// !!!
7567+
// grammarErrorOnNode?.(
7568+
// elem.name,
7569+
// node.token === SyntaxKind.WithKeyword
7570+
// ? Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_attributes
7571+
// : Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_assertions,
7572+
// );
7573+
return core.ResolutionModeNone, false
7574+
}
7575+
if !IsStringLiteralLike(elem.Value) {
7576+
return core.ResolutionModeNone, false
7577+
}
7578+
if elem.Value.Text() != "import" && elem.Value.Text() != "require" {
7579+
// !!!
7580+
// grammarErrorOnNode?.(elem.value, Diagnostics.resolution_mode_should_be_either_require_or_import);
7581+
return core.ResolutionModeNone, false
7582+
}
7583+
if elem.Value.Text() == "import" {
7584+
return core.ResolutionModeESM, true
7585+
} else {
7586+
return core.ModuleKindCommonJS, true
7587+
}
7588+
}
7589+
75357590
// TypeQueryNode
75367591

75377592
type TypeQueryNode struct {
@@ -9112,39 +9167,37 @@ func IsJSDocUnknownTag(node *Node) bool {
91129167
type JSDocTemplateTag struct {
91139168
JSDocTagBase
91149169
Constraint *Node
9115-
typeParameters *TypeParameterList
9170+
TypeParameters *TypeParameterList
91169171
}
91179172

91189173
func (f *NodeFactory) NewJSDocTemplateTag(tagName *IdentifierNode, constraint *Node, typeParameters *TypeParameterList, comment *NodeList) *Node {
91199174
data := &JSDocTemplateTag{}
91209175
data.TagName = tagName
91219176
data.Constraint = constraint
9122-
data.typeParameters = typeParameters
9177+
data.TypeParameters = typeParameters
91239178
data.Comment = comment
91249179
return f.newNode(KindJSDocTemplateTag, data)
91259180
}
91269181

91279182
func (f *NodeFactory) UpdateJSDocTemplateTag(node *JSDocTemplateTag, tagName *IdentifierNode, constraint *Node, typeParameters *TypeParameterList, comment *NodeList) *Node {
9128-
if tagName != node.TagName || constraint != node.Constraint || typeParameters != node.typeParameters || comment != node.Comment {
9183+
if tagName != node.TagName || constraint != node.Constraint || typeParameters != node.TypeParameters || comment != node.Comment {
91299184
return updateNode(f.NewJSDocTemplateTag(tagName, constraint, typeParameters, comment), node.AsNode(), f.hooks)
91309185
}
91319186
return node.AsNode()
91329187
}
91339188

91349189
func (node *JSDocTemplateTag) ForEachChild(v Visitor) bool {
9135-
return visit(v, node.TagName) || visit(v, node.Constraint) || visitNodeList(v, node.typeParameters) || visitNodeList(v, node.Comment)
9190+
return visit(v, node.TagName) || visit(v, node.Constraint) || visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Comment)
91369191
}
91379192

91389193
func (node *JSDocTemplateTag) VisitEachChild(v *NodeVisitor) *Node {
9139-
return v.Factory.UpdateJSDocTemplateTag(node, v.visitNode(node.TagName), v.visitNode(node.Constraint), v.visitNodes(node.typeParameters), v.visitNodes(node.Comment))
9194+
return v.Factory.UpdateJSDocTemplateTag(node, v.visitNode(node.TagName), v.visitNode(node.Constraint), v.visitNodes(node.TypeParameters), v.visitNodes(node.Comment))
91409195
}
91419196

91429197
func (node *JSDocTemplateTag) Clone(f NodeFactoryCoercible) *Node {
9143-
return cloneNode(f.AsNodeFactory().NewJSDocTemplateTag(node.TagName, node.Constraint, node.TypeParameters(), node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
9198+
return cloneNode(f.AsNodeFactory().NewJSDocTemplateTag(node.TagName, node.Constraint, node.TypeParameters, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
91449199
}
91459200

9146-
func (node *JSDocTemplateTag) TypeParameters() *TypeParameterList { return node.typeParameters }
9147-
91489201
// JSDocPropertyTag
91499202
type JSDocPropertyTag struct {
91509203
JSDocTagBase
@@ -9922,8 +9975,9 @@ type CommentDirective struct {
99229975
// SourceFile
99239976

99249977
type SourceFileMetaData struct {
9925-
PackageJsonType string
9926-
ImpliedNodeFormat core.ResolutionMode
9978+
PackageJsonType string
9979+
PackageJsonDirectory string
9980+
ImpliedNodeFormat core.ResolutionMode
99279981
}
99289982

99299983
type CheckJsDirective struct {

internal/ast/utilities.go

Lines changed: 156 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,10 @@ func IsComputedNonLiteralName(name *Node) bool {
19481948
}
19491949

19501950
func IsQuestionToken(node *Node) bool {
1951-
return node != nil && node.Kind == KindQuestionToken
1951+
if node == nil {
1952+
return false
1953+
}
1954+
return node.Kind == KindQuestionToken
19521955
}
19531956

19541957
func GetTextOfPropertyName(name *Node) string {
@@ -2403,7 +2406,7 @@ func GetImpliedNodeFormatForFile(path string, packageJsonType string) core.Modul
24032406
impliedNodeFormat = core.ResolutionModeESM
24042407
} else if tspath.FileExtensionIsOneOf(path, []string{tspath.ExtensionDcts, tspath.ExtensionCts, tspath.ExtensionCjs}) {
24052408
impliedNodeFormat = core.ResolutionModeCommonJS
2406-
} else if packageJsonType != "" && tspath.FileExtensionIsOneOf(path, []string{tspath.ExtensionDts, tspath.ExtensionTs, tspath.ExtensionTsx, tspath.ExtensionJs, tspath.ExtensionJsx}) {
2409+
} else if tspath.FileExtensionIsOneOf(path, []string{tspath.ExtensionDts, tspath.ExtensionTs, tspath.ExtensionTsx, tspath.ExtensionJs, tspath.ExtensionJsx}) {
24072410
impliedNodeFormat = core.IfElse(packageJsonType == "module", core.ResolutionModeESM, core.ResolutionModeCommonJS)
24082411
}
24092412

@@ -2739,6 +2742,22 @@ func IsTypeOnlyImportOrExportDeclaration(node *Node) bool {
27392742
return IsTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node)
27402743
}
27412744

2745+
func IsExclusivelyTypeOnlyImportOrExport(node *Node) bool {
2746+
switch node.Kind {
2747+
case KindExportDeclaration:
2748+
return node.AsExportDeclaration().IsTypeOnly
2749+
case KindImportDeclaration, KindJSImportDeclaration:
2750+
if importClause := node.AsImportDeclaration().ImportClause; importClause != nil {
2751+
return importClause.AsImportClause().IsTypeOnly
2752+
}
2753+
case KindJSDocImportTag:
2754+
if importClause := node.AsJSDocImportTag().ImportClause; importClause != nil {
2755+
return importClause.AsImportClause().IsTypeOnly
2756+
}
2757+
}
2758+
return false
2759+
}
2760+
27422761
func GetClassLikeDeclarationOfSymbol(symbol *Symbol) *Node {
27432762
return core.Find(symbol.Declarations, IsClassLike)
27442763
}
@@ -2941,6 +2960,59 @@ func GetPropertyNameForPropertyNameNode(name *Node) string {
29412960
panic("Unhandled case in getPropertyNameForPropertyNameNode")
29422961
}
29432962

2963+
func IsPartOfTypeOnlyImportOrExportDeclaration(node *Node) bool {
2964+
return FindAncestor(node, IsTypeOnlyImportOrExportDeclaration) != nil
2965+
}
2966+
2967+
func IsPartOfExclusivelyTypeOnlyImportOrExportDeclaration(node *Node) bool {
2968+
return FindAncestor(node, IsExclusivelyTypeOnlyImportOrExport) != nil
2969+
}
2970+
2971+
func IsEmittableImport(node *Node) bool {
2972+
switch node.Kind {
2973+
case KindImportDeclaration:
2974+
return node.AsImportDeclaration().ImportClause == nil || !node.AsImportDeclaration().ImportClause.IsTypeOnly()
2975+
case KindExportDeclaration:
2976+
return !node.AsExportDeclaration().IsTypeOnly
2977+
case KindImportEqualsDeclaration:
2978+
return !node.AsImportEqualsDeclaration().IsTypeOnly
2979+
case KindCallExpression:
2980+
return IsImportCall(node)
2981+
}
2982+
return false
2983+
}
2984+
2985+
func IsResolutionModeOverrideHost(node *Node) bool {
2986+
if node == nil {
2987+
return false
2988+
}
2989+
switch node.Kind {
2990+
case KindImportType, KindExportDeclaration, KindImportDeclaration, KindJSImportDeclaration:
2991+
return true
2992+
}
2993+
return false
2994+
}
2995+
2996+
func HasResolutionModeOverride(node *Node) bool {
2997+
if node == nil {
2998+
return false
2999+
}
3000+
var attributes *ImportAttributesNode
3001+
switch node.Kind {
3002+
case KindImportType:
3003+
attributes = node.AsImportTypeNode().Attributes
3004+
case KindImportDeclaration, KindJSImportDeclaration:
3005+
attributes = node.AsImportDeclaration().Attributes
3006+
case KindExportDeclaration:
3007+
attributes = node.AsExportDeclaration().Attributes
3008+
}
3009+
if attributes != nil {
3010+
_, ok := attributes.GetResolutionModeOverride()
3011+
return ok
3012+
}
3013+
return false
3014+
}
3015+
29443016
func IsStringTextContainingNode(node *Node) bool {
29453017
return node.Kind == KindStringLiteral || IsTemplateLiteralKind(node.Kind)
29463018
}
@@ -3304,6 +3376,87 @@ func IsTypeDeclarationName(name *Node) bool {
33043376
GetNameOfDeclaration(name.Parent) == name
33053377
}
33063378

3379+
func IsRightSideOfQualifiedNameOrPropertyAccess(node *Node) bool {
3380+
parent := node.Parent
3381+
switch parent.Kind {
3382+
case KindQualifiedName:
3383+
return parent.AsQualifiedName().Right == node
3384+
case KindPropertyAccessExpression:
3385+
return parent.AsPropertyAccessExpression().Name() == node
3386+
case KindMetaProperty:
3387+
return parent.AsMetaProperty().Name() == node
3388+
}
3389+
return false
3390+
}
3391+
3392+
func HasQuestionToken(node *Node) bool {
3393+
switch node.Kind {
3394+
case KindParameter:
3395+
return node.AsParameterDeclaration().QuestionToken != nil
3396+
case KindMethodDeclaration:
3397+
return IsQuestionToken(node.AsMethodDeclaration().PostfixToken)
3398+
case KindShorthandPropertyAssignment:
3399+
return IsQuestionToken(node.AsShorthandPropertyAssignment().PostfixToken)
3400+
case KindMethodSignature:
3401+
return IsQuestionToken(node.AsMethodSignatureDeclaration().PostfixToken)
3402+
case KindPropertySignature:
3403+
return IsQuestionToken(node.AsPropertySignatureDeclaration().PostfixToken)
3404+
case KindPropertyAssignment:
3405+
return IsQuestionToken(node.AsPropertyAssignment().PostfixToken)
3406+
case KindPropertyDeclaration:
3407+
return IsQuestionToken(node.AsPropertyDeclaration().PostfixToken)
3408+
}
3409+
return false
3410+
}
3411+
3412+
func GetInvokedExpression(node *Node) *Node {
3413+
switch node.Kind {
3414+
case KindTaggedTemplateExpression:
3415+
return node.AsTaggedTemplateExpression().Tag
3416+
case KindJsxOpeningElement, KindJsxSelfClosingElement:
3417+
return node.TagName()
3418+
case KindBinaryExpression:
3419+
return node.AsBinaryExpression().Right
3420+
default:
3421+
return node.Expression()
3422+
}
3423+
}
3424+
3425+
func IsCallOrNewExpression(node *Node) bool {
3426+
return IsCallExpression(node) || IsNewExpression(node)
3427+
}
3428+
3429+
func CanHaveSymbol(node *Node) bool {
3430+
switch node.Kind {
3431+
case KindArrowFunction, KindBinaryExpression, KindBindingElement, KindCallExpression, KindCallSignature,
3432+
KindClassDeclaration, KindClassExpression, KindClassStaticBlockDeclaration, KindConstructor, KindConstructorType,
3433+
KindConstructSignature, KindElementAccessExpression, KindEnumDeclaration, KindEnumMember, KindExportAssignment, KindJSExportAssignment,
3434+
KindExportDeclaration, KindExportSpecifier, KindFunctionDeclaration, KindFunctionExpression, KindFunctionType,
3435+
KindGetAccessor, KindIdentifier, KindImportClause, KindImportEqualsDeclaration, KindImportSpecifier,
3436+
KindIndexSignature, KindInterfaceDeclaration, KindJSDocSignature, KindJSDocTypeLiteral,
3437+
KindJsxAttribute, KindJsxAttributes, KindJsxSpreadAttribute, KindMappedType, KindMethodDeclaration,
3438+
KindMethodSignature, KindModuleDeclaration, KindNamedTupleMember, KindNamespaceExport, KindNamespaceExportDeclaration,
3439+
KindNamespaceImport, KindNewExpression, KindNoSubstitutionTemplateLiteral, KindNumericLiteral, KindObjectLiteralExpression,
3440+
KindParameter, KindPropertyAccessExpression, KindPropertyAssignment, KindPropertyDeclaration, KindPropertySignature,
3441+
KindSetAccessor, KindShorthandPropertyAssignment, KindSourceFile, KindSpreadAssignment, KindStringLiteral,
3442+
KindTypeAliasDeclaration, KindJSTypeAliasDeclaration, KindTypeLiteral, KindTypeParameter, KindVariableDeclaration:
3443+
return true
3444+
}
3445+
return false
3446+
}
3447+
3448+
func IndexOfNode(nodes []*Node, node *Node) int {
3449+
index, ok := slices.BinarySearchFunc(nodes, node, compareNodePositions)
3450+
if ok {
3451+
return index
3452+
}
3453+
return -1
3454+
}
3455+
3456+
func compareNodePositions(n1, n2 *Node) int {
3457+
return n1.Pos() - n2.Pos()
3458+
}
3459+
33073460
func IsUnterminatedNode(node *Node) bool {
33083461
return IsLiteralKind(node.Kind) && IsUnterminatedLiteral(node)
33093462
}
@@ -3316,4 +3469,4 @@ func IsInitializedProperty(member *ClassElement) bool {
33163469

33173470
func IsJsxOpeningLikeElement(node *Node) bool {
33183471
return IsJsxOpeningElement(node) || IsJsxSelfClosingElement(node)
3319-
}
3472+
}

internal/binder/binder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,8 @@ func (b *Binder) bindChildren(node *ast.Node) {
15621562
// and set it before we descend into nodes that could actually be part of an assignment pattern.
15631563
b.inAssignmentPattern = false
15641564
if b.checkUnreachable(node) {
1565-
b.bindEachChild(node)
15661565
b.setJSDocParents(node)
1566+
b.bindEachChild(node)
15671567
b.inAssignmentPattern = saveInAssignmentPattern
15681568
return
15691569
}
@@ -1574,6 +1574,7 @@ func (b *Binder) bindChildren(node *ast.Node) {
15741574
hasFlowNodeData.FlowNode = b.currentFlow
15751575
}
15761576
}
1577+
b.setJSDocParents(node)
15771578
switch node.Kind {
15781579
case ast.KindWhileStatement:
15791580
b.bindWhileStatement(node)
@@ -1653,7 +1654,6 @@ func (b *Binder) bindChildren(node *ast.Node) {
16531654
default:
16541655
b.bindEachChild(node)
16551656
}
1656-
b.setJSDocParents(node)
16571657
b.inAssignmentPattern = saveInAssignmentPattern
16581658
}
16591659

0 commit comments

Comments
 (0)