FES throws an error when non globally exposed function's name used in other context#6055
Conversation
| } | ||
| } | ||
| const keyArray = Object.keys(p5Constructors); | ||
| const globalFunctions = ['Renderer', 'Renderer2D', 'RendererGL']; |
There was a problem hiding this comment.
- more classes can be added as per need.
- I think the name of identifier
globalFunctionsis not accurate, should it be changed ?
There was a problem hiding this comment.
right, maybe something like classesWithGlobalFunctions would be more accurate?
|
Hi @aditya-shrivastavv, thank you for submitting this PR. |
|
Thanks for making this change @aditya-shrivastavv! Agreed with @almchung, let's copy that unit test they linked and pick a few example functions to check for (maybe a fill-related one, a typography-related one, a shape-related one?) |
|
Thanks, @davepagurek and @almchung for your feedback, I have read #5753 and understood what problems my approach can cause in different situations. |
|
@aditya-shrivastavv: it would be great to have the unit tests related to this issue, as @davepagurek also mentioned. |
|
I think there is a similar test already written for this, which detects the reassignment of the p5.js functions outside setup. |
|
The previous tests didn't catch the false positive cases discussed in #5753 so we need new tests for those. |
davepagurek
left a comment
There was a problem hiding this comment.
Thanks for adding some tests! I think my only remaining comments are about naming things in the code, after that I think this is good to go!
| ); | ||
|
|
||
| testUnMinified( | ||
| 'detects reassignment of p5.js function (size from TypedDict or Dom) outside setup', |
There was a problem hiding this comment.
We should probably name this test something like "does not detect ..." to make it clear that we don't want it catching this false positive.
|
done ! |
davepagurek
left a comment
There was a problem hiding this comment.
Looks great, thanks @aditya-shrivastavv!
|
hey, @davepagurek I think we should rename the identifier |
|
@aditya-shrivastavv if you want to make another PR renaming the variable that sounds good to me! |
Resolves #5753
Changes:
Previously we were adding all the methods of all p5 classes as reserved functions in the
functionArray, but all p5 classes do not have their functions added to the global scope.So, as suggested by @davepagurek that only the methods/functions inside
p5,p5.Renderer,p5.RendererGL, andp5.Renderer2Dare available in the global scope, so only those should be added tofunctionArrayso that FES do not throw an error when a function's name (which is not exposed or defined by p5.js in the global scope) is used as a variable or any other way.PR Checklist
npm run lintpasses