-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
inputSourceMap option has a bug #4578
Comments
This is because I copied the description from babel. |
Ah understood. Is there some other way to pass through a sourcemap that only exists in-memory? |
You can stringify it |
Ah nice! I just gave that a try, and it no longer throws, but the source locations seem to be off. I updated the replit with the simplest repro I could think of: https://replit.com/@lewisl9029/swc-inputSourceMap-repro
test2's stacktrace points to the original source location where the error is thrown, but test's stacktrace seems to be pointing at a completely unrelated location towards the end of the script. |
Extracting all the necessary info here for convenience: This is index.js, the module used to generate the test files: const swc_ = require('@swc/core')
const babel_ = require('@babel/core')
const fs_ = require('fs')
const { code, map } =
babel_.transformSync(fs_.readFileSync('./input.js'), {
sourceMaps: true
})
console.log({ code, map })
const result = swc_.transformSync(code, {
inputSourceMap: JSON.stringify(map),
sourceMaps: 'inline',
jsc: {
minify: {
compress: true,
mangle: true,
},
},
minify: true,
})
fs_.writeFileSync('./test.js', result.code)
const result2 =
babel_.transformSync(fs_.readFileSync('./input.js'), {
sourceMaps: 'inline'
})
fs_.writeFileSync('./test2.js', result2.code) This is input.js, the file used as input to babel: const test = "1234"
/* this should throw on line 3 */ throw new Error('hi')
const test2 = 1 This is test.js, the output of babel then minified by swc: throw new Error("hi")
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInVua25vd24iLCI8YW5vbj4iXSwic291cmNlc0NvbnRlbnQiOlsiY29uc3QgdGVzdCA9IFwiMTIzNFwiXG5cbi8qIHRoaXMgc2hvdWxkIHRocm93IG9uIGxpbmUgMyAqLyB0aHJvdyBuZXcgRXJyb3IoJ2hpJylcblxuY29uc3QgdGVzdDIgPSAxIiwiY29uc3QgdGVzdCA9IFwiMTIzNFwiO1xuLyogdGhpcyBzaG91bGQgdGhyb3cgb24gbGluZSAzICovXG5cbnRocm93IG5ldyBFcnJvcignaGknKTtcbmNvbnN0IHRlc3QyID0gMTsiXSwibmFtZXMiOlsiRXJyb3IiXSwibWFwcGluZ3MiOiJBQUlBLE1BQU0sSUFBQUEsS0FBTixDQUFBLElBQUEsQ0FBQSJ9 This is test2.js, output of just babel: const test = "1234";
/* this should throw on line 3 */
throw new Error('hi');
const test2 = 1;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ0ZXN0IiwiRXJyb3IiLCJ0ZXN0MiJdLCJzb3VyY2VzIjpbInVua25vd24iXSwic291cmNlc0NvbnRlbnQiOlsiY29uc3QgdGVzdCA9IFwiMTIzNFwiXG5cbi8qIHRoaXMgc2hvdWxkIHRocm93IG9uIGxpbmUgMyAqLyB0aHJvdyBuZXcgRXJyb3IoJ2hpJylcblxuY29uc3QgdGVzdDIgPSAxIl0sIm1hcHBpbmdzIjoiQUFBQSxNQUFNQSxJQUFJLEdBQUcsTUFBYjtBQUVBOztBQUFrQyxNQUFNLElBQUlDLEtBQUosQ0FBVSxJQUFWLENBQU47QUFFbEMsTUFBTUMsS0FBSyxHQUFHLENBQWQifQ== Results of running test vs test2:
|
Is this bug fixed ? |
@ChrisCindy - doesn't seem like, I am still experiencing it. Needed to do some work to drop Babel and use only SWC to have source maps correct. |
**Related issue:** - Closes #4578. - Closes #6244. - vercel/next.js#39878. Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
In types.ts, I see the following docs and type defs for inputSourceMap:
The description says that we should be able to pass in the sourcemap as an object, but the types only specify boolean and string, and when I actually try to pass in an object, I get the following error:
Couldn't see a way to repro this in the playground, so I made a quick repro at replit instead, let me know if there's a preferred alternative: https://replit.com/@lewisl9029/swc-inputSourceMap-repro
Curious if this is a bug or was it never supported in the first place? If it's the latter, please consider this a feature request! I have a use case where I'm using swc as a fast minifier for a babel transformed file (I have a lot of custom babel plugins that still need to be rewritten using the new WASM plugin system before I can replace babel completely), and would like to preserve source mapping functionality if possible. Thanks!
Input code
Config
No response
Playground link
https://replit.com/@lewisl9029/swc-inputSourceMap-repro
Expected behavior
SWC uses supplied sourcemap object
Actual behavior
SWC crashes with the following output:
Version
1.2.179
Additional context
No response
The text was updated successfully, but these errors were encountered: