Fix error importing *.grammar.terms from vitest #21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-vitest-terms-import-errors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
vitestdev server callsresolveIda second time with the initially resolved\0${id}.termsmodule id.When this happens
resolveIdattempts to resolve the module id a second time, but produces an invalid path which looks like\0${basePath}\0${id}.terms. This results in an error when the second invalid path gets later passed toload(id) {}.Checking for a leading null byte (
\0) which is used to identify virtual modules prevents this second module id resolution attempt.I created a small reproduction repo which demonstrates the issue: https://github.com/epfremmer/lezer-vitest-repro-1
Hopefully this is helpful 🎉
Could this be a bug in the test server? Neither Rollup nor Vite will resolve these twice.
TBH I'm not sure... I was having a hard time debugging where in the test server was causing this to happen. It does seem pretty strange that it happens which makes me think it's not intended.
I've opened an issue on vitest and see if anyone can shed some light on this behavior?
In the meantime, I've pushed a patch that does something similar to this, using the already present regexp match instead of an extra line.
Awesome, thank you! Your patch looks much nicer than what I had 👍
Pull request closed