-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
parser.hooks.new
not called for classes within the same file.
#18113
Comments
I found something suspicious which might allow an easy fix:
I see two potential fixes in this code path:
|
Feel free to send a PR, we have a lot of tests, so we will catch potential problems |
Just looked at the reproducible test repo, yeah, we need to fix it, because other plugins can be broken, it can work for the development mode, but broken for the production mode, it is a critical issue... Will you look at this? |
Yes, I will try to open a PR soon. Should be there the next few days latest. Locally solution 1 worked fine for me. But have to check all unit tests first. |
Made a proposal for fixing the problem. I'm willing to contribute the change as an individual developer but I'm a bit reluctant to provide so many personal details (e.g. mailing address) in the EasyCLA to just contribute some code to this project. |
I wanted to resolve this issue |
Bug report
What is the current behavior?
The
parser.hooks.new("Item")
hooks are not called when the classItem
is within the same file/module. It works if the classItem
is imported from another module.If the current behavior is a bug, please provide the steps to reproduce.
npm install && npm run build
new NotWorkingClass
In the
webpack.config.js
you will find a small plugin tapping into theparser.hooks.new
for ESM javascript files. It then expects to be called for all thenew
expressions within input.mjs. But there is no call forNotWorkingClass
What is the expected behavior?
The parser hook should also be called for the
new NotWorkingClass
expression. From what I could see is following path prevents the hook to be called:JavaScriptParser.walkNewExpression
is called for all expressions which callsJavaScriptParser.callHooksForExpression
WorkingClass
andUint8Array
theJavaScriptParser.getMemberExpressionInfo
returns some data which allows the right hooks to be called.NotWorkingClass
undefined is returned. This is because inJavaScriptParser.getFreeInfoFromVariable
thefreeName
is set totrue
instead of a string bailing the whole code path:webpack/lib/javascript/JavascriptParser.js
Line 4535 in 611bded
I'm not sure what
getFreeInfoFromVariable
should return in this case from a low level behavior. Either the parser somehow needs to fillfreeName
to the className or the hook calling might need adoption to work with Identifiers.Other relevant information:
webpack version: 5.90.3
Node.js version: v20.9.0
Operating System: Windows 11 Professional
Additional tools:
The text was updated successfully, but these errors were encountered: