-
Notifications
You must be signed in to change notification settings - Fork 671
fix(1374): support declaration emit for expando functions #1399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
e5d6bde
8e203e7
21c11bc
7e20f09
9eb36b8
37935cf
b6977b5
789cfc8
c81d99f
64d9add
df829b5
cf9bae5
cd93375
d1c76ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1348,7 +1348,7 @@ func IsBindableStaticElementAccessExpression(node *Node, excludeThisKeyword bool | |
return IsLiteralLikeElementAccess(node) && | ||
((!excludeThisKeyword && node.Expression().Kind == KindThisKeyword) || | ||
IsEntityNameExpression(node.Expression()) || | ||
IsBindableStaticAccessExpression(node.Expression() /*excludeThisKeyword*/, true)) | ||
IsBindableStaticAccessExpression(node.Expression(), true /*excludeThisKeyword*/)) | ||
} | ||
|
||
func IsLiteralLikeElementAccess(node *Node) bool { | ||
|
@@ -2817,10 +2817,6 @@ func IsModuleExportsAccessExpression(node *Node) bool { | |
return false | ||
} | ||
|
||
func isLiteralLikeElementAccess(node *Node) bool { | ||
return node.Kind == KindElementAccessExpression && IsStringOrNumericLiteralLike(node.AsElementAccessExpression().ArgumentExpression) | ||
} | ||
|
||
func IsCheckJSEnabledForFile(sourceFile *SourceFile, compilerOptions *core.CompilerOptions) bool { | ||
if sourceFile.CheckJsDirective != nil { | ||
return sourceFile.CheckJsDirective.Enabled | ||
|
@@ -2924,6 +2920,14 @@ func IsContextualKeyword(token Kind) bool { | |
return KindFirstContextualKeyword <= token && token <= KindLastContextualKeyword | ||
} | ||
|
||
func IsKeyword(token Kind) bool { | ||
return KindFirstKeyword <= token && token <= KindLastKeyword | ||
} | ||
|
||
func IsNonContextualKeyword(token Kind) bool { | ||
return IsKeyword(token) && !IsContextualKeyword(token) | ||
} | ||
|
||
func IsThisInTypeQuery(node *Node) bool { | ||
if !IsThisIdentifier(node) { | ||
return false | ||
|
@@ -3633,3 +3637,79 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild { | |
} | ||
}) | ||
} | ||
|
||
func IsExpandoPropertyDeclaration(node *Node) bool { | ||
if node == nil { | ||
return false | ||
} | ||
return IsPropertyAccessExpression(node) || IsElementAccessExpression(node) || IsBinaryExpression(node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expando declarations should only be binary expressions now. /** @type {string} */
f.p is no longer supported by Corsa, and access expressions don't have a Symbol field. |
||
} | ||
|
||
func GetExpandoInitializer(initializer *Node, isPrototypeAssignment bool) *Node { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prototype assignments aren't supported in Corsa |
||
if initializer.Kind == KindCallExpression { | ||
expr := SkipParentheses(initializer.Expression()) | ||
if expr.Kind == KindFunctionExpression || expr.Kind == KindArrowFunction { | ||
return initializer | ||
} | ||
return nil | ||
} | ||
|
||
if initializer.Kind == KindFunctionExpression || initializer.Kind == KindCallExpression || initializer.Kind == KindArrowFunction { | ||
return initializer | ||
} | ||
|
||
if initializer.Kind == KindObjectLiteralExpression && (len(initializer.Properties()) == 0 || isPrototypeAssignment) { | ||
return initializer | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func GetEffectiveInitializer(node *Node) *Expression { | ||
if IsInJSFile(node) && node.Initializer() != nil && IsBinaryExpression(node.Initializer()) { | ||
initializer := node.Initializer().AsBinaryExpression() | ||
if initializer.OperatorToken.Kind == KindBarBarToken || initializer.OperatorToken.Kind == KindQuestionQuestionToken { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaulting assignments with |
||
if node.Name() != nil && IsEntityNameExpressionEx(node.Name(), IsInJSFile(node)) && IsSameEntityName(node.Name(), initializer.Left) { | ||
return initializer.Right | ||
} | ||
} | ||
} | ||
return node.Initializer() | ||
} | ||
|
||
func GetDeclaredExpandoInitializer(node *Node) *Expression { | ||
a-tarasyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
initializer := GetEffectiveInitializer(node) | ||
if initializer == nil { | ||
return nil | ||
} | ||
return GetExpandoInitializer(initializer, IsPrototypeAccess(node.Name())) | ||
} | ||
|
||
func IsPrototypeAccess(node *Node) bool { | ||
return IsBindableStaticAccessExpression(node, false /*excludeThisKeyword*/) | ||
} | ||
|
||
func IsLiteralLikeAccess(node *Node) bool { | ||
return IsPropertyAccessExpression(node) || IsLiteralLikeElementAccess(node) | ||
} | ||
|
||
func GetNameOrArgument(node *Expression) *Expression { | ||
if IsPropertyAccessExpression(node) { | ||
return node.Name() | ||
} | ||
return node.AsElementAccessExpression().ArgumentExpression | ||
} | ||
|
||
func IsSameEntityName(name *Expression, initializer *Expression) bool { | ||
if IsPropertyNameLiteral(name) && IsPropertyNameLiteral(initializer) { | ||
return name.Text() == initializer.Text() | ||
} | ||
if IsMemberName(name) && IsLiteralLikeAccess(initializer) && (initializer.Expression().Kind == KindThisKeyword || IsIdentifier(initializer.Expression()) && | ||
(initializer.Expression().Text() == "window" || initializer.Expression().Text() == "self" || initializer.Expression().Text() == "global")) { | ||
return IsSameEntityName(name, GetNameOrArgument(initializer)) | ||
} | ||
if IsLiteralLikeAccess(name) && IsLiteralLikeAccess(initializer) { | ||
return GetElementOrPropertyAccessName(name) == GetElementOrPropertyAccessName(initializer) && IsSameEntityName(name.Expression(), initializer.Expression()) | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the binder already has to detect these patterns, so you shouldn't need to port anything new.
edit: your explanation of why these are needed makes sense, but much of it can be simplified given how much less Corsa supports.