-
-
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
JSX inline sourcemap issue #1726
Comments
How did you get the valid |
The const foo = () => <h1 />; creates an invalid sourcemap whereas const foo = <h1 />; doesn't, so I'm not exactly sure what is causing this issue. Repro const swc = require('@swc/core');
const code = `
const foo = () => <h1 />;
`;
/** @type {swc.Options} */
const swcConfig = {
jsc: {
target: 'es5',
parser: {
syntax: 'ecmascript',
jsx: true,
},
loose: true,
},
sourceFileName: 'noop.js',
sourceMaps: true,
};
const result = swc.transformSync(code, swcConfig);
// valid
console.log(
`${
result.code
}\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(
result.map,
'utf8'
).toString('base64')}`
);
const resultInline = swc.transformSync(code, {
...swcConfig,
sourceMaps: 'inline',
});
// invalid
console.log(resultInline.code); |
I think there are many things that are causing this issue. I was able to fix the above sample const foo = () => <h1 /> by removing the const foo = () => <h1></h1>; |
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
When transpiling JSX using swc, if the jsx includes dynamic children, then the inline sourcemap generated is invalid.
Input code
Config
Expected behavior
Inline sourcemap generated (invalid):
data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjxhbm9uPiJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBmb28gPSA8aDE-e2Jhcn08L2gxPiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiSUFBTSxHQUFHLHNDQUFJLEVBQUUsU0FBRSxHQUFHIn0=
Sourcemap generated from result object with
Buffer
:`data:application/json;base64,${Buffer.from(map, 'utf8').toString('base64')}`
data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjxhbm9uPiJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBmb28gPSA8aDE+e2Jhcn08L2gxPiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiSUFBTSxHQUFHLHNDQUFJLEVBQUUsU0FBRSxHQUFHIn0=
Both the sourcemaps are different. The one generated with
Buffer
is valid whereas the one generated by swc is invalidVersion
The version of @swc/core: ^1.2.58
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: