-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add workaround for Function.toString()
to docs
#163
Comments
I like the idea. Thank you for your contribution. I will add it to the README file later. |
Another suggestion that occured to me based on your idea: we may make bytenode extend the The end goal is to make your examples like this: page.waitForSelector((() => document.querySelector("${selector}")).preserveSourceCode(), opts); and class YourClass {}
YourClass.preserveSourceCode(); |
Definitely interesting but my guess is that there isn't gonna be a simple way to approach this and would have to do actual ast parsing - and at that point, it may as well just be comments on top of function declarations that preserve the source code since that seems to be what a lot of people have mentioned in past issues |
You are probably correct. I wrote my previous comment half asleep! |
I think it could be relatively easy though considering how easy it is to parse and walk the js ast tree with modern packages And to be honest, since this feature is ever so rarely actually needed, you could just get away with two comments, one that marks the start of the source that you want to be preserved and one at the end. Do some simple regex matching or even pure js splitting and move those parts to the dummy code |
I added your workaround in the README file. Thank you. |
Check here already a solution. |
Please add an actual implementation of toString(). This approach makes it harder and harder to maintain your codebase when you need to edit the code inside the string. |
Is the |
Here are both attempts: With the AST it's easier to add a |
Lots of libraries rely on
Function.toString()
to function, so I think it's important to provide some sort of "hacky" solution to be able to use bytenode with the lib.Ref: #93
Not only can you not use functions with puppeteer, but puppeteer now wraps all the string options (ex.
waitForSelector("selector")
) in a function, then calls.toString()
on the wrapped function (or one that you've provided) before sending it to the browserRef: #34 (comment)
Framework uses
Function.toString()
to check ifFunction
is a classAs mentioned in #93 (comment) , a workaround could be just importing the function from a plain
.js
file, and while this will work, it may be a little unnecessary and annoying at timesA simple fix that I'd like to propose to get added to the documentation (or at least a reference to this issue) is the ability to override
.toString()
after bytenode breaks itFor example, to make a quick puppeteer fix:
Or a fix for checking if a
Function
is a class:This is in hopes to save people's time figuring out a good solution (because I know it would've saved mine 😅)
The text was updated successfully, but these errors were encountered: