Skip to content
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

Parsing function and method *bodies* for constant declarations #20

Open
szepeviktor opened this issue Mar 16, 2023 · 2 comments
Open

Parsing function and method *bodies* for constant declarations #20

szepeviktor opened this issue Mar 16, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@szepeviktor
Copy link
Member

Moved here from README.

@szepeviktor szepeviktor added the help wanted Extra attention is needed label Mar 16, 2023
@tfrommen
Copy link

tfrommen commented Feb 29, 2024

👋 Hi there,

I just implemented parsing nested define expressions in a library that is using php-stubs/generator internally:
-> inpsyde/wp-stubs#7

We are extending the default NodeVisitor class, so my approach was to parse for any nested define expressions inside functions and class methods, and then add them back into the function/method body after it was emptied (by the default/parent enterNode method).

Now, should parsing nested define constants (and maybe also const constants?) be made possible in the generator itself? I am happy to help implement this, if yes.

We would need to define how this would happen. That is, should it happen by default if the StubsGenerator::CONSTANTS symbol is passed? Or should it be turned on explicitly with a dedicated symbol, for example, StubsGenerator::NESTED_CONSTANTS? If the latter, should the StubsGenerator::CONSTANTS symbol have to be defined as well, or does the new StubsGenerator::NESTED_CONSTANTS symbol imply the existing one?

Regarding the implementation, is replacing the function/method body with the define (and const?) expressions what you have in mind?
This would then, of course, be implemented in the current Function_ || ClassMethod case in the enterNode method.

cc @GiacoCorsiglia

@szepeviktor
Copy link
Member Author

Hello @tfrommen!

Thank you for your comment.
I raise my voice against using legacy technologies (even in WordPress plugins)

❌ Global constants

https://github.com/szepeviktor/starter-plugin/blob/master/README.md#what-to-avoid

This repo exists as I need a working tool to generate stubs.
3e3f6f4...master

I would like WordPress to have a class autoloader, so it would need no stubs.
e.g. https://core.trac.wordpress.org/ticket/60414

If you force me to accept your PR I will merge it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants