-
Notifications
You must be signed in to change notification settings - Fork 13.1k
fix for 45006 #45020
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
fix for 45006 #45020
Changes from 5 commits
c0ad7a6
d7e8a69
5920993
d8062fb
10f1aff
78b2567
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 |
|---|---|---|
|
|
@@ -1526,10 +1526,12 @@ namespace ts { | |
| return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression; | ||
| } | ||
|
|
||
| export function isObjectLiteralOrClassExpressionMethod(node: Node): node is MethodDeclaration { | ||
| return node.kind === SyntaxKind.MethodDeclaration && | ||
| export function isObjectLiteralOrClassExpressionMethodOrAccessor(node: Node): node is MethodDeclaration { | ||
| return (node.kind === SyntaxKind.MethodDeclaration && | ||
|
||
| (node.parent.kind === SyntaxKind.ObjectLiteralExpression || | ||
| node.parent.kind === SyntaxKind.ClassExpression); | ||
| node.parent.kind === SyntaxKind.ClassExpression)) || | ||
| node.kind === SyntaxKind.GetAccessor || | ||
| node.kind === SyntaxKind.SetAccessor; | ||
| } | ||
|
|
||
| export function isIdentifierTypePredicate(predicate: TypePredicate): predicate is IdentifierTypePredicate { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // @target: es2020 | ||
| // classes | ||
| class C { | ||
| public fooBack = ""; | ||
|
|
@@ -37,3 +38,13 @@ interface I1 { | |
| } | ||
|
|
||
| var i:I1 = function (n) {return n;} | ||
|
|
||
|
Member
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. Please add a
Contributor
Author
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. yes, no problem |
||
| // Repro from #45006 | ||
| const x: string | number = Math.random() < 0.5 ? "str" : 123; | ||
| if (typeof x === "string") { | ||
| let obj = { | ||
| set prop(_: any) { x.toUpperCase(); }, | ||
| get prop() { return x.toUpperCase() }, | ||
| method() { return x.toUpperCase() } | ||
| } | ||
| } | ||
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.
There are only 3 callers of
isObjectLiteralOrClassExpressionMethod. Two of them need this addition, and the third is guarded bycase SyntaxKind.MethodDeclaration. So I'd like to see the new check moved into that function, and the name should be ... uhh ...isObjectLiteralOrClassExpressionMethodOrAccessor???Maybe there's a better name if there's a term that means "method or accessor".
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.
I just went with choice 1,
isObjectLiteralOrClassExpressionMethodOrAccessor; there was also aContainerFlagsby the same name that looked like it could be part of the same renaming effort.