Skip to content

Commit 3696ccc

Browse files
committed
Merge remote-tracking branch 'origin/main' into port/jsx-fragment-changes
2 parents 827255f + 14e44b1 commit 3696ccc

File tree

258 files changed

+1659
-4257
lines changed

Some content is hidden

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

258 files changed

+1659
-4257
lines changed

internal/api/encoder/encoder.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,8 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
693693
case ast.KindClassDeclaration:
694694
n := node.AsClassDeclaration()
695695
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Name() != nil) << 1) | (boolToByte(n.TypeParameters != nil) << 2) | (boolToByte(n.HeritageClauses != nil) << 3) | (boolToByte(n.Members != nil) << 4)
696-
case ast.KindJSDocPropertyTag:
697-
n := node.AsJSDocPropertyTag()
698-
if n.IsNameFirst {
699-
return (boolToByte(n.Name() != nil) << 0) | (boolToByte(n.TypeExpression != nil) << 1)
700-
}
701-
return (boolToByte(n.TypeExpression != nil) << 0) | (boolToByte(n.Name() != nil) << 1)
702-
case ast.KindJSDocParameterTag:
703-
n := node.AsJSDocParameterTag()
696+
case ast.KindJSDocParameterTag, ast.KindJSDocPropertyTag:
697+
n := node.AsJSDocParameterOrPropertyTag()
704698
if n.IsNameFirst {
705699
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.Name() != nil) << 1) | (boolToByte(n.TypeExpression != nil) << 2) | (boolToByte(n.Comment != nil) << 3)
706700
}
@@ -745,11 +739,8 @@ func getNodeDefinedData(node *ast.Node) uint32 {
745739
case ast.KindObjectLiteralExpression:
746740
n := node.AsObjectLiteralExpression()
747741
return uint32(boolToByte(n.MultiLine)) << 24
748-
case ast.KindJSDocPropertyTag:
749-
n := node.AsJSDocPropertyTag()
750-
return uint32(boolToByte(n.IsBracketed))<<24 | uint32(boolToByte(n.IsNameFirst))<<25
751-
case ast.KindJSDocParameterTag:
752-
n := node.AsJSDocParameterTag()
742+
case ast.KindJSDocParameterTag, ast.KindJSDocPropertyTag:
743+
n := node.AsJSDocParameterOrPropertyTag()
753744
return uint32(boolToByte(n.IsBracketed))<<24 | uint32(boolToByte(n.IsNameFirst))<<25
754745
case ast.KindJsxText:
755746
n := node.AsJsxText()

internal/ast/ast.go

Lines changed: 37 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ func (n *Node) Type() *Node {
548548
return n.AsTemplateLiteralTypeSpan().Type
549549
case KindJSDocTypeExpression:
550550
return n.AsJSDocTypeExpression().Type
551-
case KindJSDocPropertyTag:
552-
return n.AsJSDocPropertyTag().TypeExpression
551+
case KindJSDocParameterTag, KindJSDocPropertyTag:
552+
return n.AsJSDocParameterOrPropertyTag().TypeExpression
553553
case KindJSDocNullableType:
554554
return n.AsJSDocNullableType().Type
555555
case KindJSDocNonNullableType:
@@ -623,8 +623,8 @@ func (n *Node) TagName() *Node {
623623
return n.AsJSDocCallbackTag().TagName
624624
case KindJSDocOverloadTag:
625625
return n.AsJSDocOverloadTag().TagName
626-
case KindJSDocParameterTag:
627-
return n.AsJSDocParameterTag().TagName
626+
case KindJSDocParameterTag, KindJSDocPropertyTag:
627+
return n.AsJSDocParameterOrPropertyTag().TagName
628628
case KindJSDocReturnTag:
629629
return n.AsJSDocReturnTag().TagName
630630
case KindJSDocThisTag:
@@ -637,8 +637,6 @@ func (n *Node) TagName() *Node {
637637
return n.AsJSDocTypedefTag().TagName
638638
case KindJSDocSeeTag:
639639
return n.AsJSDocSeeTag().TagName
640-
case KindJSDocPropertyTag:
641-
return n.AsJSDocPropertyTag().TagName
642640
case KindJSDocSatisfiesTag:
643641
return n.AsJSDocSatisfiesTag().TagName
644642
case KindJSDocImportTag:
@@ -709,8 +707,8 @@ func (n *Node) CommentList() *NodeList {
709707
return n.AsJSDocCallbackTag().Comment
710708
case KindJSDocOverloadTag:
711709
return n.AsJSDocOverloadTag().Comment
712-
case KindJSDocParameterTag:
713-
return n.AsJSDocParameterTag().Comment
710+
case KindJSDocParameterTag, KindJSDocPropertyTag:
711+
return n.AsJSDocParameterOrPropertyTag().Comment
714712
case KindJSDocReturnTag:
715713
return n.AsJSDocReturnTag().Comment
716714
case KindJSDocThisTag:
@@ -723,8 +721,6 @@ func (n *Node) CommentList() *NodeList {
723721
return n.AsJSDocTypedefTag().Comment
724722
case KindJSDocSeeTag:
725723
return n.AsJSDocSeeTag().Comment
726-
case KindJSDocPropertyTag:
727-
return n.AsJSDocPropertyTag().Comment
728724
case KindJSDocSatisfiesTag:
729725
return n.AsJSDocSatisfiesTag().Comment
730726
case KindJSDocImportTag:
@@ -1520,12 +1516,8 @@ func (n *Node) AsJSDocTemplateTag() *JSDocTemplateTag {
15201516
return n.data.(*JSDocTemplateTag)
15211517
}
15221518

1523-
func (n *Node) AsJSDocPropertyTag() *JSDocPropertyTag {
1524-
return n.data.(*JSDocPropertyTag)
1525-
}
1526-
1527-
func (n *Node) AsJSDocParameterTag() *JSDocParameterTag {
1528-
return n.data.(*JSDocParameterTag)
1519+
func (n *Node) AsJSDocParameterOrPropertyTag() *JSDocParameterOrPropertyTag {
1520+
return n.data.(*JSDocParameterOrPropertyTag)
15291521
}
15301522

15311523
func (n *Node) AsJSDocReturnTag() *JSDocReturnTag {
@@ -1846,7 +1838,7 @@ func IsDeclarationNode(node *Node) bool {
18461838
return node.DeclarationData() != nil
18471839
}
18481840

1849-
// DeclarationBase
1841+
// ExportableBase
18501842

18511843
type ExportableBase struct {
18521844
LocalSymbol *Symbol // Local symbol declared by node (initialized by binding only for exported nodes)
@@ -5529,6 +5521,10 @@ func (node *RegularExpressionLiteral) Clone(f NodeFactoryCoercible) *Node {
55295521
return cloneNode(f.AsNodeFactory().NewRegularExpressionLiteral(node.Text), node.AsNode(), f.AsNodeFactory().hooks)
55305522
}
55315523

5524+
func IsRegularExpressionLiteral(node *Node) bool {
5525+
return node.Kind == KindRegularExpressionLiteral
5526+
}
5527+
55325528
// NoSubstitutionTemplateLiteral
55335529

55345530
type NoSubstitutionTemplateLiteral struct {
@@ -9194,112 +9190,70 @@ func (node *JSDocTemplateTag) Clone(f NodeFactoryCoercible) *Node {
91949190
return cloneNode(f.AsNodeFactory().NewJSDocTemplateTag(node.TagName, node.Constraint, node.TypeParameters, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
91959191
}
91969192

9197-
// JSDocPropertyTag
9198-
type JSDocPropertyTag struct {
9193+
// JSDocParameterOrPropertyTag
9194+
type JSDocParameterOrPropertyTag struct {
91999195
JSDocTagBase
92009196
name *EntityName
92019197
IsBracketed bool
92029198
TypeExpression *TypeNode
92039199
IsNameFirst bool
92049200
}
92059201

9206-
func (f *NodeFactory) NewJSDocPropertyTag(tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9207-
data := &JSDocPropertyTag{}
9202+
type (
9203+
JSDocParameterTag = JSDocParameterOrPropertyTag
9204+
JSDocPropertyTag = JSDocParameterOrPropertyTag
9205+
)
9206+
9207+
func (f *NodeFactory) newJSDocParameterOrPropertyTag(kind Kind, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9208+
data := &JSDocParameterOrPropertyTag{}
92089209
data.TagName = tagName
92099210
data.name = name
92109211
data.IsBracketed = isBracketed
92119212
data.TypeExpression = typeExpression
92129213
data.IsNameFirst = isNameFirst
92139214
data.Comment = comment
9214-
return f.newNode(KindJSDocPropertyTag, data)
9215-
}
9216-
9217-
func (f *NodeFactory) UpdateJSDocPropertyTag(node *JSDocPropertyTag, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9218-
if tagName != node.TagName || name != node.name || isBracketed != node.IsBracketed || typeExpression != node.TypeExpression || isNameFirst != node.IsNameFirst || comment != node.Comment {
9219-
return updateNode(f.NewJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node.AsNode(), f.hooks)
9220-
}
9221-
return node.AsNode()
9222-
}
9223-
9224-
func (node *JSDocPropertyTag) ForEachChild(v Visitor) bool {
9225-
if node.IsNameFirst {
9226-
return visit(v, node.TagName) || visit(v, node.name) || visit(v, node.TypeExpression) || visitNodeList(v, node.Comment)
9227-
} else {
9228-
return visit(v, node.TagName) || visit(v, node.TypeExpression) || visit(v, node.name) || visitNodeList(v, node.Comment)
9229-
}
9230-
}
9231-
9232-
func (node *JSDocPropertyTag) VisitEachChild(v *NodeVisitor) *Node {
9233-
tagName := v.visitNode(node.TagName)
9234-
var name, typeExpression *Node
9235-
if node.IsNameFirst {
9236-
name, typeExpression = v.visitNode(node.name), v.visitNode(node.TypeExpression)
9237-
} else {
9238-
typeExpression, name = v.visitNode(node.TypeExpression), v.visitNode(node.name)
9239-
}
9240-
return v.Factory.UpdateJSDocPropertyTag(node, tagName, name, node.IsBracketed, typeExpression, node.IsNameFirst, v.visitNodes(node.Comment))
9241-
}
9242-
9243-
func (node *JSDocPropertyTag) Clone(f NodeFactoryCoercible) *Node {
9244-
return cloneNode(f.AsNodeFactory().NewJSDocPropertyTag(node.TagName, node.Name(), node.IsBracketed, node.TypeExpression, node.IsNameFirst, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
9215+
return f.newNode(kind, data)
92459216
}
92469217

9247-
func (node *JSDocPropertyTag) Name() *EntityName { return node.name }
9248-
9249-
// JSDocParameterTag
9250-
type JSDocParameterTag struct {
9251-
JSDocTagBase
9252-
name *EntityName
9253-
IsBracketed bool
9254-
TypeExpression *TypeNode
9255-
IsNameFirst bool
9218+
func (f *NodeFactory) NewJSDocParameterTag(tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9219+
return f.newJSDocParameterOrPropertyTag(KindJSDocParameterTag, tagName, name, isBracketed, typeExpression, isNameFirst, comment)
92569220
}
92579221

9258-
func (f *NodeFactory) NewJSDocParameterTag(tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9259-
data := &JSDocParameterTag{}
9260-
data.TagName = tagName
9261-
data.name = name
9262-
data.IsBracketed = isBracketed
9263-
data.TypeExpression = typeExpression
9264-
data.IsNameFirst = isNameFirst
9265-
data.Comment = comment
9266-
return f.newNode(KindJSDocParameterTag, data)
9222+
func (f *NodeFactory) NewJSDocPropertyTag(tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9223+
return f.newJSDocParameterOrPropertyTag(KindJSDocPropertyTag, tagName, name, isBracketed, typeExpression, isNameFirst, comment)
92679224
}
92689225

9269-
func (f *NodeFactory) UpdateJSDocParameterTag(node *JSDocParameterTag, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
9226+
func (f *NodeFactory) UpdateJSDocParameterOrPropertyTag(kind Kind, node *JSDocParameterOrPropertyTag, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {
92709227
if tagName != node.TagName || name != node.name || isBracketed != node.IsBracketed || typeExpression != node.TypeExpression || isNameFirst != node.IsNameFirst || comment != node.Comment {
9271-
return updateNode(f.NewJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node.AsNode(), f.hooks)
9228+
return updateNode(f.newJSDocParameterOrPropertyTag(kind, tagName, name, isBracketed, typeExpression, isNameFirst, comment), node.AsNode(), f.hooks)
92729229
}
92739230
return node.AsNode()
92749231
}
92759232

9276-
func (node *JSDocParameterTag) ForEachChild(v Visitor) bool {
9277-
if visit(v, node.TagName) {
9278-
return true
9279-
}
9233+
func (node *JSDocParameterOrPropertyTag) ForEachChild(v Visitor) bool {
92809234
if node.IsNameFirst {
9281-
return visit(v, node.name) || visit(v, node.TypeExpression) || visitNodeList(v, node.Comment)
9235+
return visit(v, node.TagName) || visit(v, node.name) || visit(v, node.TypeExpression) || visitNodeList(v, node.Comment)
92829236
} else {
9283-
return visit(v, node.TypeExpression) || visit(v, node.name) || visitNodeList(v, node.Comment)
9237+
return visit(v, node.TagName) || visit(v, node.TypeExpression) || visit(v, node.name) || visitNodeList(v, node.Comment)
92849238
}
92859239
}
92869240

9287-
func (node *JSDocParameterTag) VisitEachChild(v *NodeVisitor) *Node {
9241+
func (node *JSDocParameterOrPropertyTag) VisitEachChild(v *NodeVisitor) *Node {
92889242
tagName := v.visitNode(node.TagName)
92899243
var name, typeExpression *Node
92909244
if node.IsNameFirst {
92919245
name, typeExpression = v.visitNode(node.name), v.visitNode(node.TypeExpression)
92929246
} else {
92939247
typeExpression, name = v.visitNode(node.TypeExpression), v.visitNode(node.name)
92949248
}
9295-
return v.Factory.UpdateJSDocParameterTag(node, tagName, name, node.IsBracketed, typeExpression, node.IsNameFirst, v.visitNodes(node.Comment))
9249+
return v.Factory.UpdateJSDocParameterOrPropertyTag(node.Kind, node, tagName, name, node.IsBracketed, typeExpression, node.IsNameFirst, v.visitNodes(node.Comment))
92969250
}
92979251

9298-
func (node *JSDocParameterTag) Clone(f NodeFactoryCoercible) *Node {
9299-
return cloneNode(f.AsNodeFactory().NewJSDocParameterTag(node.TagName, node.Name(), node.IsBracketed, node.TypeExpression, node.IsNameFirst, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
9252+
func (node *JSDocParameterOrPropertyTag) Clone(f NodeFactoryCoercible) *Node {
9253+
return cloneNode(f.AsNodeFactory().newJSDocParameterOrPropertyTag(node.Kind, node.TagName, node.Name(), node.IsBracketed, node.TypeExpression, node.IsNameFirst, node.Comment), node.AsNode(), f.AsNodeFactory().hooks)
93009254
}
93019255

9302-
func (node *JSDocParameterTag) Name() *EntityName { return node.name }
9256+
func (node *JSDocParameterOrPropertyTag) Name() *EntityName { return node.name }
93039257

93049258
// JSDocReturnTag
93059259
type JSDocReturnTag struct {

internal/ast/utilities.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ func newParentInChildrenSetter() func(node *Node) bool {
885885
}
886886

887887
state.visit = func(node *Node) bool {
888-
if state.parent != nil {
888+
if state.parent != nil && node.Parent != state.parent {
889+
// Avoid data races on no-ops
889890
node.Parent = state.parent
890891
}
891892
saveParent := state.parent
@@ -3472,3 +3473,13 @@ func IndexOfNode(nodes []*Node, node *Node) int {
34723473
func compareNodePositions(n1, n2 *Node) int {
34733474
return n1.Pos() - n2.Pos()
34743475
}
3476+
3477+
func IsUnterminatedNode(node *Node) bool {
3478+
return IsLiteralKind(node.Kind) && IsUnterminatedLiteral(node)
3479+
}
3480+
3481+
// Gets a value indicating whether a class element is either a static or an instance property declaration with an initializer.
3482+
func IsInitializedProperty(member *ClassElement) bool {
3483+
return member.Kind == KindPropertyDeclaration &&
3484+
member.Initializer() != nil
3485+
}

internal/binder/binder.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ func (b *Binder) bind(node *ast.Node) bool {
762762
func (b *Binder) setJSDocParents(node *ast.Node) {
763763
for _, jsdoc := range node.JSDoc(b.file) {
764764
setParent(jsdoc, node)
765-
ast.SetParentInChildren(jsdoc)
765+
if jsdoc.Kind != ast.KindJSDocImportTag {
766+
// JSDocImportTag children have parents set during parsing for module resolution purposes.
767+
ast.SetParentInChildren(jsdoc)
768+
}
766769
}
767770
}
768771

@@ -1892,13 +1895,16 @@ func (b *Binder) bindForStatement(node *ast.Node) {
18921895
stmt := node.AsForStatement()
18931896
preLoopLabel := b.setContinueTarget(node, b.createLoopLabel())
18941897
preBodyLabel := b.createBranchLabel()
1898+
preIncrementorLabel := b.createBranchLabel()
18951899
postLoopLabel := b.createBranchLabel()
18961900
b.bind(stmt.Initializer)
18971901
topFlow := b.currentFlow
18981902
b.currentFlow = preLoopLabel
18991903
b.bindCondition(stmt.Condition, preBodyLabel, postLoopLabel)
19001904
b.currentFlow = b.finishFlowLabel(preBodyLabel)
1901-
b.bindIterativeStatement(stmt.Statement, postLoopLabel, preLoopLabel)
1905+
b.bindIterativeStatement(stmt.Statement, postLoopLabel, preIncrementorLabel)
1906+
b.addAntecedent(preIncrementorLabel, b.currentFlow)
1907+
b.currentFlow = b.finishFlowLabel(preIncrementorLabel)
19021908
b.bind(stmt.Incrementor)
19031909
b.addAntecedent(preLoopLabel, b.currentFlow)
19041910
b.addAntecedent(preLoopLabel, topFlow)
@@ -2686,9 +2692,11 @@ func isNarrowingBinaryExpression(expr *ast.BinaryExpression) bool {
26862692
case ast.KindEqualsToken, ast.KindBarBarEqualsToken, ast.KindAmpersandAmpersandEqualsToken, ast.KindQuestionQuestionEqualsToken:
26872693
return containsNarrowableReference(expr.Left)
26882694
case ast.KindEqualsEqualsToken, ast.KindExclamationEqualsToken, ast.KindEqualsEqualsEqualsToken, ast.KindExclamationEqualsEqualsToken:
2689-
return isNarrowableOperand(expr.Left) || isNarrowableOperand(expr.Right) ||
2690-
isNarrowingTypeOfOperands(expr.Right, expr.Left) || isNarrowingTypeOfOperands(expr.Left, expr.Right) ||
2691-
(ast.IsBooleanLiteral(expr.Right) && isNarrowingExpression(expr.Left) || ast.IsBooleanLiteral(expr.Left) && isNarrowingExpression(expr.Right))
2695+
left := ast.SkipParentheses(expr.Left)
2696+
right := ast.SkipParentheses(expr.Right)
2697+
return isNarrowableOperand(left) || isNarrowableOperand(right) ||
2698+
isNarrowingTypeOfOperands(right, left) || isNarrowingTypeOfOperands(left, right) ||
2699+
(ast.IsBooleanLiteral(right) && isNarrowingExpression(left) || ast.IsBooleanLiteral(left) && isNarrowingExpression(right))
26922700
case ast.KindInstanceOfKeyword:
26932701
return isNarrowableOperand(expr.Left)
26942702
case ast.KindInKeyword:
@@ -2876,9 +2884,15 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR
28762884
}
28772885
return scanner.GetRangeOfTokenAtPosition(sourceFile, pos)
28782886
// This list is a work in progress. Add missing node kinds to improve their error spans
2887+
case ast.KindFunctionDeclaration, ast.KindMethodDeclaration:
2888+
if node.Flags&ast.NodeFlagsReparsed != 0 {
2889+
errorNode = node
2890+
break
2891+
}
2892+
fallthrough
28792893
case ast.KindVariableDeclaration, ast.KindBindingElement, ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration,
2880-
ast.KindModuleDeclaration, ast.KindEnumDeclaration, ast.KindEnumMember, ast.KindFunctionDeclaration, ast.KindFunctionExpression,
2881-
ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindPropertyDeclaration,
2894+
ast.KindModuleDeclaration, ast.KindEnumDeclaration, ast.KindEnumMember, ast.KindFunctionExpression,
2895+
ast.KindGetAccessor, ast.KindSetAccessor, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindPropertyDeclaration,
28822896
ast.KindPropertySignature, ast.KindNamespaceImport:
28832897
errorNode = ast.GetNameOfDeclaration(node)
28842898
case ast.KindArrowFunction:
@@ -2898,6 +2912,10 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR
28982912
pos := scanner.SkipTrivia(sourceFile.Text(), node.AsSatisfiesExpression().Expression.End())
28992913
return scanner.GetRangeOfTokenAtPosition(sourceFile, pos)
29002914
case ast.KindConstructor:
2915+
if node.Flags&ast.NodeFlagsReparsed != 0 {
2916+
errorNode = node
2917+
break
2918+
}
29012919
scanner := scanner.GetScannerForSourceFile(sourceFile, node.Pos())
29022920
start := scanner.TokenStart()
29032921
for scanner.Token() != ast.KindConstructorKeyword && scanner.Token() != ast.KindStringLiteral && scanner.Token() != ast.KindEndOfFile {

0 commit comments

Comments
 (0)