Skip to content

Commit 0fc83aa

Browse files
dependabot[bot]github-actions[bot]buke
authored
deps(deps): bump microsoft/typescript-go from dcebe53 to 20bf4fc (#55)
* deps(deps): bump microsoft/typescript-go from `dcebe53` to `20bf4fc` Bumps [microsoft/typescript-go](https://github.com/microsoft/typescript-go) from `dcebe53` to `20bf4fc`. - [Commits](microsoft/typescript-go@dcebe53...20bf4fc) --- updated-dependencies: - dependency-name: microsoft/typescript-go dependency-version: 20bf4fc90d3d38016f07fda1fb972eedc715bb02 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(sync): mirror internal packages into pkg/ (auto) (#56) Co-authored-by: buke <1013738+buke@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: buke <1013738+buke@users.noreply.github.com>
1 parent b1212f1 commit 0fc83aa

File tree

3,761 files changed

+11973
-12996
lines changed

Some content is hidden

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

3,761 files changed

+11973
-12996
lines changed

microsoft/typescript-go

Submodule typescript-go updated 3761 files

pkg/ast/ast.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ func (n *Node) TemplateLiteralLikeData() *TemplateLiteralLikeBase {
263263
}
264264
func (n *Node) KindString() string { return n.Kind.String() }
265265
func (n *Node) KindValue() int16 { return int16(n.Kind) }
266+
func (n *Node) Decorators() []*Node {
267+
if n.Modifiers() == nil {
268+
return nil
269+
}
270+
return core.Filter(n.Modifiers().Nodes, IsDecorator)
271+
}
266272

267273
type MutableNode Node
268274

@@ -6300,7 +6306,7 @@ func (node *BinaryExpression) computeSubtreeFacts() SubtreeFacts {
63006306
propagateSubtreeFacts(node.Type) |
63016307
propagateSubtreeFacts(node.OperatorToken) |
63026308
propagateSubtreeFacts(node.Right) |
6303-
core.IfElse(node.OperatorToken.Kind == KindInKeyword && IsPrivateIdentifier(node.Left), SubtreeContainsClassFields, SubtreeFactsNone)
6309+
core.IfElse(node.OperatorToken.Kind == KindInKeyword && IsPrivateIdentifier(node.Left), SubtreeContainsClassFields|SubtreeContainsPrivateIdentifierInExpression, SubtreeFactsNone)
63046310
}
63056311

63066312
func (node *BinaryExpression) setModifiers(modifiers *ModifierList) { node.modifiers = modifiers }
@@ -6753,9 +6759,13 @@ func (node *PropertyAccessExpression) Clone(f NodeFactoryCoercible) *Node {
67536759
func (node *PropertyAccessExpression) Name() *DeclarationName { return node.name }
67546760

67556761
func (node *PropertyAccessExpression) computeSubtreeFacts() SubtreeFacts {
6762+
privateName := SubtreeFactsNone
6763+
if !IsIdentifier(node.name) {
6764+
privateName = SubtreeContainsPrivateIdentifierInExpression
6765+
}
67566766
return propagateSubtreeFacts(node.Expression) |
67576767
propagateSubtreeFacts(node.QuestionDotToken) |
6758-
propagateSubtreeFacts(node.name)
6768+
propagateSubtreeFacts(node.name) | privateName
67596769
}
67606770

67616771
func (node *PropertyAccessExpression) propagateSubtreeFacts() SubtreeFacts {
@@ -10791,6 +10801,8 @@ type SourceFile struct {
1079110801
tokenFactory *NodeFactory
1079210802
declarationMapMu sync.Mutex
1079310803
declarationMap map[string][]*Node
10804+
nameTableOnce sync.Once
10805+
nameTable map[string]int
1079410806
}
1079510807

1079610808
func (f *NodeFactory) NewSourceFile(opts SourceFileParseOptions, text string, statements *NodeList, endOfFileToken *TokenNode) *Node {
@@ -10934,6 +10946,39 @@ func (node *SourceFile) ECMALineMap() []core.TextPos {
1093410946
return lineMap
1093510947
}
1093610948

10949+
// GetNameTable returns a map of all names in the file to their positions.
10950+
// If the name appears more than once, the value is -1.
10951+
func (file *SourceFile) GetNameTable() map[string]int {
10952+
file.nameTableOnce.Do(func() {
10953+
nameTable := make(map[string]int, file.IdentifierCount)
10954+
10955+
var walk func(node *Node) bool
10956+
walk = func(node *Node) bool {
10957+
if IsIdentifier(node) && !isTagName(node) && node.Text() != "" ||
10958+
IsStringOrNumericLiteralLike(node) && literalIsName(node) ||
10959+
IsPrivateIdentifier(node) {
10960+
text := node.Text()
10961+
if _, ok := nameTable[text]; ok {
10962+
nameTable[text] = -1
10963+
} else {
10964+
nameTable[text] = node.Pos()
10965+
}
10966+
}
10967+
10968+
node.ForEachChild(walk)
10969+
jsdocNodes := node.JSDoc(file)
10970+
for _, jsdoc := range jsdocNodes {
10971+
jsdoc.ForEachChild(walk)
10972+
}
10973+
return false
10974+
}
10975+
file.ForEachChild(walk)
10976+
10977+
file.nameTable = nameTable
10978+
})
10979+
return file.nameTable
10980+
}
10981+
1093710982
func (node *SourceFile) IsBound() bool {
1093810983
return node.isBound.Load()
1093910984
}

pkg/ast/subtreefacts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
SubtreeContainsClassFields
3838
SubtreeContainsDecorators
3939
SubtreeContainsIdentifier
40+
SubtreeContainsPrivateIdentifierInExpression
4041

4142
SubtreeFactsComputed // NOTE: This should always be last
4243
SubtreeFactsNone SubtreeFacts = 0

pkg/ast/utilities.go

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,3 +3941,242 @@ func IsPotentiallyExecutableNode(node *Node) bool {
39413941
}
39423942
return IsClassDeclaration(node) || IsEnumDeclaration(node) || IsModuleDeclaration(node)
39433943
}
3944+
3945+
func HasAbstractModifier(node *Node) bool {
3946+
return HasSyntacticModifier(node, ModifierFlagsAbstract)
3947+
}
3948+
3949+
func HasAmbientModifier(node *Node) bool {
3950+
return HasSyntacticModifier(node, ModifierFlagsAmbient)
3951+
}
3952+
3953+
func NodeCanBeDecorated(useLegacyDecorators bool, node *Node, parent *Node, grandparent *Node) bool {
3954+
// private names cannot be used with decorators yet
3955+
if useLegacyDecorators && node.Name() != nil && IsPrivateIdentifier(node.Name()) {
3956+
return false
3957+
}
3958+
switch node.Kind {
3959+
case KindClassDeclaration:
3960+
// class declarations are valid targets
3961+
return true
3962+
case KindClassExpression:
3963+
// class expressions are valid targets for native decorators
3964+
return !useLegacyDecorators
3965+
case KindPropertyDeclaration:
3966+
// property declarations are valid if their parent is a class declaration.
3967+
return parent != nil && (useLegacyDecorators && IsClassDeclaration(parent) ||
3968+
!useLegacyDecorators && IsClassLike(parent) && !HasAbstractModifier(node) && !HasAmbientModifier(node))
3969+
case KindGetAccessor, KindSetAccessor, KindMethodDeclaration:
3970+
// if this method has a body and its parent is a class declaration, this is a valid target.
3971+
return parent != nil && node.Body() != nil && (useLegacyDecorators && IsClassDeclaration(parent) ||
3972+
!useLegacyDecorators && IsClassLike(parent))
3973+
case KindParameter:
3974+
// TODO(rbuckton): Parameter decorator support for ES decorators must wait until it is standardized
3975+
if !useLegacyDecorators {
3976+
return false
3977+
}
3978+
// if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target.
3979+
return parent != nil && parent.Body() != nil &&
3980+
(parent.Kind == KindConstructor || parent.Kind == KindMethodDeclaration || parent.Kind == KindSetAccessor) &&
3981+
GetThisParameter(parent) != node && grandparent != nil && grandparent.Kind == KindClassDeclaration
3982+
}
3983+
3984+
return false
3985+
}
3986+
3987+
func ClassOrConstructorParameterIsDecorated(useLegacyDecorators bool, node *Node) bool {
3988+
if nodeIsDecorated(useLegacyDecorators, node, nil, nil) {
3989+
return true
3990+
}
3991+
constructor := GetFirstConstructorWithBody(node)
3992+
return constructor != nil && ChildIsDecorated(useLegacyDecorators, constructor, node)
3993+
}
3994+
3995+
func ClassElementOrClassElementParameterIsDecorated(useLegacyDecorators bool, node *Node, parent *Node) bool {
3996+
var parameters *NodeList
3997+
if IsAccessor(node) {
3998+
decls := GetAllAccessorDeclarations(parent.Members(), node)
3999+
var firstAccessorWithDecorators *Node
4000+
if HasDecorators(decls.FirstAccessor) {
4001+
firstAccessorWithDecorators = decls.FirstAccessor
4002+
} else if HasDecorators(decls.SecondAccessor) {
4003+
firstAccessorWithDecorators = decls.SecondAccessor
4004+
}
4005+
if firstAccessorWithDecorators == nil || node != firstAccessorWithDecorators {
4006+
return false
4007+
}
4008+
if decls.SetAccessor != nil {
4009+
parameters = decls.SetAccessor.Parameters
4010+
}
4011+
} else if IsMethodDeclaration(node) {
4012+
parameters = node.ParameterList()
4013+
}
4014+
if nodeIsDecorated(useLegacyDecorators, node, parent, nil) {
4015+
return true
4016+
}
4017+
if parameters != nil && len(parameters.Nodes) > 0 {
4018+
for _, parameter := range parameters.Nodes {
4019+
if IsThisParameter(parameter) {
4020+
continue
4021+
}
4022+
if nodeIsDecorated(useLegacyDecorators, parameter, node, parent) {
4023+
return true
4024+
}
4025+
}
4026+
}
4027+
return false
4028+
}
4029+
4030+
func nodeIsDecorated(useLegacyDecorators bool, node *Node, parent *Node, grandparent *Node) bool {
4031+
return HasDecorators(node) && NodeCanBeDecorated(useLegacyDecorators, node, parent, grandparent)
4032+
}
4033+
4034+
func NodeOrChildIsDecorated(useLegacyDecorators bool, node *Node, parent *Node, grandparent *Node) bool {
4035+
return nodeIsDecorated(useLegacyDecorators, node, parent, grandparent) || ChildIsDecorated(useLegacyDecorators, node, parent)
4036+
}
4037+
4038+
func ChildIsDecorated(useLegacyDecorators bool, node *Node, parent *Node) bool {
4039+
switch node.Kind {
4040+
case KindClassDeclaration, KindClassExpression:
4041+
return core.Some(node.Members(), func(m *Node) bool {
4042+
return NodeOrChildIsDecorated(useLegacyDecorators, m, node, parent)
4043+
})
4044+
case KindMethodDeclaration,
4045+
KindSetAccessor,
4046+
KindConstructor:
4047+
return core.Some(node.Parameters(), func(p *Node) bool {
4048+
return nodeIsDecorated(useLegacyDecorators, p, node, parent)
4049+
})
4050+
default:
4051+
return false
4052+
}
4053+
}
4054+
4055+
type AllAccessorDeclarations struct {
4056+
FirstAccessor *AccessorDeclaration
4057+
SecondAccessor *AccessorDeclaration
4058+
SetAccessor *SetAccessorDeclaration
4059+
GetAccessor *GetAccessorDeclaration
4060+
}
4061+
4062+
func GetAllAccessorDeclarationsForDeclaration(accessor *AccessorDeclaration, declarationsOfSymbol []*Node) AllAccessorDeclarations {
4063+
var otherKind Kind
4064+
if accessor.Kind == KindSetAccessor {
4065+
otherKind = KindGetAccessor
4066+
} else if accessor.Kind == KindGetAccessor {
4067+
otherKind = KindSetAccessor
4068+
} else {
4069+
panic(fmt.Sprintf("Unexpected node kind %q", accessor.Kind))
4070+
}
4071+
// otherAccessor := ast.GetDeclarationOfKind(c.getSymbolOfDeclaration(accessor), otherKind)
4072+
var otherAccessor *AccessorDeclaration
4073+
for _, d := range declarationsOfSymbol {
4074+
if d.Kind == otherKind {
4075+
otherAccessor = d
4076+
break
4077+
}
4078+
}
4079+
4080+
var firstAccessor *AccessorDeclaration
4081+
var secondAccessor *AccessorDeclaration
4082+
if otherAccessor != nil && (otherAccessor.Pos() < accessor.Pos()) {
4083+
firstAccessor = otherAccessor
4084+
secondAccessor = accessor
4085+
} else {
4086+
firstAccessor = accessor
4087+
secondAccessor = otherAccessor
4088+
}
4089+
4090+
var setAccessor *SetAccessorDeclaration
4091+
var getAccessor *GetAccessorDeclaration
4092+
if accessor.Kind == KindSetAccessor {
4093+
setAccessor = accessor.AsSetAccessorDeclaration()
4094+
if otherAccessor != nil {
4095+
getAccessor = otherAccessor.AsGetAccessorDeclaration()
4096+
}
4097+
} else {
4098+
getAccessor = accessor.AsGetAccessorDeclaration()
4099+
if otherAccessor != nil {
4100+
setAccessor = otherAccessor.AsSetAccessorDeclaration()
4101+
}
4102+
}
4103+
4104+
return AllAccessorDeclarations{
4105+
FirstAccessor: firstAccessor,
4106+
SecondAccessor: secondAccessor,
4107+
SetAccessor: setAccessor,
4108+
GetAccessor: getAccessor,
4109+
}
4110+
}
4111+
4112+
func GetAllAccessorDeclarations(parentDeclarations []*Node, accessor *AccessorDeclaration) AllAccessorDeclarations {
4113+
if HasDynamicName(accessor) {
4114+
// dynamic names can only be match up via checker symbol lookup, just return an object with just this accessor
4115+
return GetAllAccessorDeclarationsForDeclaration(accessor, []*Node{accessor})
4116+
}
4117+
4118+
accessorName := GetPropertyNameForPropertyNameNode(accessor.Name())
4119+
accessorStatic := IsStatic(accessor)
4120+
var matches []*Node
4121+
for _, member := range parentDeclarations {
4122+
if !IsAccessor(member) || IsStatic(member) != accessorStatic {
4123+
continue
4124+
}
4125+
memberName := GetPropertyNameForPropertyNameNode(member.Name())
4126+
if memberName == accessorName {
4127+
matches = append(matches, member)
4128+
}
4129+
}
4130+
return GetAllAccessorDeclarationsForDeclaration(accessor, matches)
4131+
}
4132+
4133+
func IsAsyncFunction(node *Node) bool {
4134+
switch node.Kind {
4135+
case KindFunctionDeclaration, KindFunctionExpression, KindArrowFunction, KindMethodDeclaration:
4136+
data := node.BodyData()
4137+
return data.Body != nil && data.AsteriskToken == nil && HasSyntacticModifier(node, ModifierFlagsAsync)
4138+
}
4139+
return false
4140+
}
4141+
4142+
/**
4143+
* Gets the most likely element type for a TypeNode. This is not an exhaustive test
4144+
* as it assumes a rest argument can only be an array type (either T[], or Array<T>).
4145+
*
4146+
* @param node The type node.
4147+
*
4148+
* @internal
4149+
*/
4150+
func GetRestParameterElementType(node *ParameterDeclarationNode) *Node {
4151+
if node == nil {
4152+
return node
4153+
}
4154+
if node.Kind == KindArrayType {
4155+
return node.AsArrayTypeNode().ElementType
4156+
}
4157+
if node.Kind == KindTypeReference && node.AsTypeReferenceNode().TypeArguments != nil {
4158+
return core.FirstOrNil(node.AsTypeReferenceNode().TypeArguments.Nodes)
4159+
}
4160+
return nil
4161+
}
4162+
4163+
func isTagName(node *Node) bool {
4164+
return node.Parent != nil && IsJSDocTag(node.Parent) && node.Parent.TagName() == node
4165+
}
4166+
4167+
// We want to store any numbers/strings if they were a name that could be
4168+
// related to a declaration. So, if we have 'import x = require("something")'
4169+
// then we want 'something' to be in the name table. Similarly, if we have
4170+
// "a['propname']" then we want to store "propname" in the name table.
4171+
func literalIsName(node *Node) bool {
4172+
return IsDeclarationName(node) ||
4173+
node.Parent.Kind == KindExternalModuleReference ||
4174+
isArgumentOfElementAccessExpression(node) ||
4175+
IsLiteralComputedPropertyDeclarationName(node)
4176+
}
4177+
4178+
func isArgumentOfElementAccessExpression(node *Node) bool {
4179+
return node != nil && node.Parent != nil &&
4180+
node.Parent.Kind == KindElementAccessExpression &&
4181+
node.Parent.AsElementAccessExpression().ArgumentExpression == node
4182+
}

pkg/binder/binder.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,15 +2648,6 @@ func getOptionalSymbolFlagForNode(node *ast.Node) ast.SymbolFlags {
26482648
return core.IfElse(postfixToken != nil && postfixToken.Kind == ast.KindQuestionToken, ast.SymbolFlagsOptional, ast.SymbolFlagsNone)
26492649
}
26502650

2651-
func isAsyncFunction(node *ast.Node) bool {
2652-
switch node.Kind {
2653-
case ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindMethodDeclaration:
2654-
data := node.BodyData()
2655-
return data.Body != nil && data.AsteriskToken == nil && ast.HasSyntacticModifier(node, ast.ModifierFlagsAsync)
2656-
}
2657-
return false
2658-
}
2659-
26602651
func isFunctionSymbol(symbol *ast.Symbol) bool {
26612652
d := symbol.ValueDeclaration
26622653
if d != nil {

0 commit comments

Comments
 (0)