-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Sourcemaps always report position 0 #8
Comments
It seems adding if condition can fix this: import MagicString from 'magic-string';
const code = `const answer = 42;\n\nconsole.log("The answer is", answer);`;
const generated = code;
const ms = new MagicString(code, { filename: 'test.ts' })
if (code !== generated) {
ms.overwrite(0, code.length, generated);
}
console.log(ms.generateMap({ hires: true })); Returns: SourceMap {
version: 3,
file: undefined,
sources: [ '' ],
sourcesContent: undefined,
names: [],
mappings: 'AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC'
} |
@cookabc - it's not really a fix... it's a fix for the case where the transformed code is the same as the original. I expect in this case, the unplugin processor hasn't done the work it may have needed to do. Regardless, it's probably a good interim fix for when unplugin doesn't modify the code but it doesn't address the issue for when unplugin does modify the code. |
After some investigation, I believe this might be a rather difficult one than a |
Is there any plan to fix this soon? Interestingly enough, a second plugin I found that provides similar functionality, has this problem too: LZS911/vite-plugin-conditional-compile#5 |
In this function the sourcemap positions are always returned as position 0. This breaks mapping back to the original source and coverage reporting.
unplugin-preprocessor-directives/src/core/context/index.ts
Line 88 in 667aca0
A simpler reproducible example (effectively the same code):
Returns:
AAAA
is position 0 for both statements.The text was updated successfully, but these errors were encountered: