Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
chore(type-utils): reuse newly added "is builtin symbol like" logic#8287
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -69,6 +69,18 @@ export function isReadonlyTypeLike( | ||||||||||||||||||
| ); | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
| /** | ||||||||||||||||||
| * let F = new Function("foo"); | ||||||||||||||||||
| * ^ FunctionSimilar | ||||||||||||||||||
| * let I = (callback: Function) => {} | ||||||||||||||||||
| * ^ FunctionSimilar | ||||||||||||||||||
| */ | ||||||||||||||||||
| export function isFunctionSimilar(program: ts.Program, type: ts.Type): boolean { | ||||||||||||||||||
| return ( | ||||||||||||||||||
| isBuiltinSymbolLike(program, type, 'Function') || | ||||||||||||||||||
| isBuiltinSymbolLike(program, type, 'FunctionConstructor') | ||||||||||||||||||
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. The original rule didn't check for symbols with name ContributorAuthor
| ||||||||||||||||||
| code:"const fn = new Function('a', 'b', 'return a + b');", | |
| errors:[ | |
| { | |
| messageId:'noFunctionConstructor', | |
| line:1, | |
| column:12, | |
| }, | |
| ], |
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.
You're rightFunction here hasFunctionConstructor type. I missed this because in the source code of rule both symbol name and callee identifier's name are compared toFUNCTION_CONSTRUCTOR
Then +1 on renamingisFunctionLike... Not sure what's the best name for it. MaybeisFunctionTypeLike or something like this?
Also we should consider that#8094 most likely will introduce changes toisBuiltinSymbolLike.
As per#8094 (comment):isBuiltinSymbolLike(program, type, 'Function') || isBuiltinSymbolLike(program, type, 'FunctionConstructor') recursively visits all subtypes twice, we can optimize to not do the same job twice.#8094 does the following:
isBuiltinSymbolLike(services.program,calleeType,name=>name==='PromiseConstructor'||name==='Promise')
Perhaps we can wait until#8094 is merged and then do the same
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.
Yes, sure.
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.
But that is probably not within the scope of this pr. IMO we shouldn't change the rule logic in this pr
Yeah this is just a refactor (chore). If you want to change how it works that'd be a separate issue.
👍 I'll mark this as blocked on#8094. Thanks :)
JoshuaKGoldbergApr 23, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
#8094 is closed - so we can now pretend it doesn't exist*. cc @arka1002, I'm un-blocking this PR. Sorry for the long wait!
*(though if you end up taking in code from it, we'll need aCo-authored-by: Timothy Moore <mtimothy984@gmail.com> in the PR description)