-
Notifications
You must be signed in to change notification settings - Fork 12.9k
only search require calls in JS files #28168
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
Conversation
This change uncovered some pretty surprising behavior: if you have |
@DanielRosenwasser and I had a long discussion about Specifically, Adding @DanielRosenwasser to the review for signoff on the error message change. [1] Note that the behaviour has existed for longer in JS, but is probably a good idea there. |
There's also a number of new "Cannot find module 'x'" messages in the prettier user test. Mind checking those out? |
There are baseline changes, but they are the same in this branch an in master.
I agree the proposed error message makes more sense, but I don't think it's strictly related to this PR. There are a few more error messages suggesting installing Note that this change will not only break code that implicitly relies on |
if ((file.flags & NodeFlags.PossiblyContainsDynamicImport)) { | ||
collectDynamicImports(); | ||
} | ||
if (isJavaScriptFile) { |
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.
I think we can still keep this a single pass by passing regexp instead.
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.
It's possible, but IMO not very useful. It would save around 4 lines of code just to add new code to get determine the correct regexp to use. It also adds complexity by moving the regexp out of the function where its matches are used.
I doubt having a single pass of a complex regexp outperforms two passes with a simple regex each (also considering potential inlining).
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.
It will save pass I think.
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.
Like I already said: I don't think there will be a noticeable difference in performance because of optimizations in the VM (like inlining). It's not like we are walking the whole AST twice.
What's the observable breaking change here? |
Having This occurred to me in this PR because there is |
Dont think its worth taking this at point given people might be depending on this behavior by now. |
require('foo')
in TypeScript files has no special meaning. Therefore we don't need to look it up and treat it like an import. It used to be in the same function as the lookup of dynamic imports to find both in one full AST walk.Followup on #28104 /cc @sandersn