@@ -1348,7 +1348,7 @@ func IsBindableStaticElementAccessExpression(node *Node, excludeThisKeyword bool
1348
1348
return IsLiteralLikeElementAccess (node ) &&
1349
1349
((! excludeThisKeyword && node .Expression ().Kind == KindThisKeyword ) ||
1350
1350
IsEntityNameExpression (node .Expression ()) ||
1351
- IsBindableStaticAccessExpression (node .Expression () /*excludeThisKeyword*/ , true ))
1351
+ IsBindableStaticAccessExpression (node .Expression (), true /*excludeThisKeyword*/ ))
1352
1352
}
1353
1353
1354
1354
func IsLiteralLikeElementAccess (node * Node ) bool {
@@ -2817,10 +2817,6 @@ func IsModuleExportsAccessExpression(node *Node) bool {
2817
2817
return false
2818
2818
}
2819
2819
2820
- func isLiteralLikeElementAccess (node * Node ) bool {
2821
- return node .Kind == KindElementAccessExpression && IsStringOrNumericLiteralLike (node .AsElementAccessExpression ().ArgumentExpression )
2822
- }
2823
-
2824
2820
func IsCheckJSEnabledForFile (sourceFile * SourceFile , compilerOptions * core.CompilerOptions ) bool {
2825
2821
if sourceFile .CheckJsDirective != nil {
2826
2822
return sourceFile .CheckJsDirective .Enabled
@@ -2924,6 +2920,14 @@ func IsContextualKeyword(token Kind) bool {
2924
2920
return KindFirstContextualKeyword <= token && token <= KindLastContextualKeyword
2925
2921
}
2926
2922
2923
+ func IsKeyword (token Kind ) bool {
2924
+ return KindFirstKeyword <= token && token <= KindLastKeyword
2925
+ }
2926
+
2927
+ func IsNonContextualKeyword (token Kind ) bool {
2928
+ return IsKeyword (token ) && ! IsContextualKeyword (token )
2929
+ }
2930
+
2927
2931
func IsThisInTypeQuery (node * Node ) bool {
2928
2932
if ! IsThisIdentifier (node ) {
2929
2933
return false
@@ -3633,3 +3637,79 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild {
3633
3637
}
3634
3638
})
3635
3639
}
3640
+
3641
+ func IsExpandoPropertyDeclaration (node * Node ) bool {
3642
+ if node == nil {
3643
+ return false
3644
+ }
3645
+ return IsPropertyAccessExpression (node ) || IsElementAccessExpression (node ) || IsBinaryExpression (node )
3646
+ }
3647
+
3648
+ func GetExpandoInitializer (initializer * Node , isPrototypeAssignment bool ) * Node {
3649
+ if initializer .Kind == KindCallExpression {
3650
+ expr := SkipParentheses (initializer .Expression ())
3651
+ if expr .Kind == KindFunctionExpression || expr .Kind == KindArrowFunction {
3652
+ return initializer
3653
+ }
3654
+ return nil
3655
+ }
3656
+
3657
+ if initializer .Kind == KindFunctionExpression || initializer .Kind == KindCallExpression || initializer .Kind == KindArrowFunction {
3658
+ return initializer
3659
+ }
3660
+
3661
+ if initializer .Kind == KindObjectLiteralExpression && (len (initializer .Properties ()) == 0 || isPrototypeAssignment ) {
3662
+ return initializer
3663
+ }
3664
+
3665
+ return nil
3666
+ }
3667
+
3668
+ func GetEffectiveInitializer (node * Node ) * Expression {
3669
+ if IsInJSFile (node ) && node .Initializer () != nil && IsBinaryExpression (node .Initializer ()) {
3670
+ initializer := node .Initializer ().AsBinaryExpression ()
3671
+ if initializer .OperatorToken .Kind == KindBarBarToken || initializer .OperatorToken .Kind == KindQuestionQuestionToken {
3672
+ if node .Name () != nil && IsEntityNameExpressionEx (node .Name (), IsInJSFile (node )) && IsSameEntityName (node .Name (), initializer .Left ) {
3673
+ return initializer .Right
3674
+ }
3675
+ }
3676
+ }
3677
+ return node .Initializer ()
3678
+ }
3679
+
3680
+ func GetDeclaredExpandoInitializer (node * Node ) * Expression {
3681
+ initializer := GetEffectiveInitializer (node )
3682
+ if initializer == nil {
3683
+ return nil
3684
+ }
3685
+ return GetExpandoInitializer (initializer , IsPrototypeAccess (node .Name ()))
3686
+ }
3687
+
3688
+ func IsPrototypeAccess (node * Node ) bool {
3689
+ return IsBindableStaticAccessExpression (node , false /*excludeThisKeyword*/ )
3690
+ }
3691
+
3692
+ func IsLiteralLikeAccess (node * Node ) bool {
3693
+ return IsPropertyAccessExpression (node ) || IsLiteralLikeElementAccess (node )
3694
+ }
3695
+
3696
+ func GetNameOrArgument (node * Expression ) * Expression {
3697
+ if IsPropertyAccessExpression (node ) {
3698
+ return node .Name ()
3699
+ }
3700
+ return node .AsElementAccessExpression ().ArgumentExpression
3701
+ }
3702
+
3703
+ func IsSameEntityName (name * Expression , initializer * Expression ) bool {
3704
+ if IsPropertyNameLiteral (name ) && IsPropertyNameLiteral (initializer ) {
3705
+ return name .Text () == initializer .Text ()
3706
+ }
3707
+ if IsMemberName (name ) && IsLiteralLikeAccess (initializer ) && (initializer .Expression ().Kind == KindThisKeyword || IsIdentifier (initializer .Expression ()) &&
3708
+ (initializer .Expression ().Text () == "window" || initializer .Expression ().Text () == "self" || initializer .Expression ().Text () == "global" )) {
3709
+ return IsSameEntityName (name , GetNameOrArgument (initializer ))
3710
+ }
3711
+ if IsLiteralLikeAccess (name ) && IsLiteralLikeAccess (initializer ) {
3712
+ return GetElementOrPropertyAccessName (name ) == GetElementOrPropertyAccessName (initializer ) && IsSameEntityName (name .Expression (), initializer .Expression ())
3713
+ }
3714
+ return false
3715
+ }
0 commit comments