-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
regex based filter in asset-import-meta-url ignores actual code in some cases #7632
Comments
scratch that, it'll mess stuff up even more π, |
Thank you very much for your correction π |
Could be worth a shot, but we had tried something similar (in a different area) in the past, and it opened up more edge cases. But would be nice if you can find a robust regex for it. |
@bluwy on second thought, I do feel it will be quite finicky and hard to get right another idea, maybe we can bank on the
I feel this can work. I had the idea to do this manually, but regex engines seem to do this for ORed expressions anyways |
FYI, I think there is also a problem with this replacement. There will be a matching error if there are sub-strings of the same length in the same string. I also try to solve this problem normally, it's not just assetImportMetaUrl plugins that need to be changed. #7549 |
// "
const a = 1
// " It also bad |
@poyoho really nice idea of having general utils for regexes, should make the code lot nicer to read π
hmm, I don't think I totally understand, can you pls share some example code where it can break?
agreed, improving |
I test my case in your provide regexp is well |
there a error in nested string template https://regex101.com/r/0GKkgF/1 π |
https://regex101.com/r/JSS4XV/1. but javascript regexp don't support nested syntax. |
thanks @poyoho! |
Describe the bug
Hey!
When using
new URL(..., import.meta.url)
, for some cases vite does not transform the URLs to point to bundled assets (only when building though, works fine in dev π§βπ»)Reproduction
Go to repro and in the terminal do
Browser console should show (notice the second URL isn't transformed)
Why?
It seems these regex filters are at fault
vite/packages/vite/src/node/plugins/assetImportMetaUrl.ts
Lines 34 to 37 in 4433df4
More importantly, the order in which they are applied seems to be the problem
i.e. since
singlelineCommentsRE
is quite broad, removing line comments before strings messes the code in weird ways πHow do we fix? π¨
AFAICT removing strings before line comments fixes such problems (shouldn't create new bugs either?)
PS: I stumbled across this when trying to consume Emscripten's release build (
-Oz
) from vite. In release emcc minifies all JS and puts it in single line, that line had//
somewhere in the middle, and everything went kaboom π₯ π€£Reproduction
https://stackblitz.com/edit/vitejs-vite-vc6p2d?file=src%2FApp.tsx&terminal=dev
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: