Skip to content
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

--source-maps=false generates empty, double stringified sourcemaps. #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xnuk
Copy link
Contributor

@xnuk xnuk commented Dec 25, 2021

$ echo > file.ts # empty file

$ npx swc file.ts --source-maps=false
Successfully compiled 1 file with swc.


//#sourceMappingURL=data:application/json;charset=utf-8;base64,IntcInZlcnNpb25cIjozLFwic291cmNlc1wiOltdLFwibmFtZXNcIjpbXSxcIm1hcHBpbmdzXCI6XCJcIixcImZpbGVcIjpcInN0ZG91dFwifSI=

$ npx swc file.ts --source-maps=inline
Successfully compiled 1 file with swc.

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9

//#sourceMappingURL=data:application/json;charset=utf-8;base64,IntcInZlcnNpb25cIjozLFwic291cmNlc1wiOltdLFwibmFtZXNcIjpbXSxcIm1hcHBpbmdzXCI6XCJcIixcImZpbGVcIjpcInN0ZG91dFwifSI=

$ npx swc --version

@swc/cli: 0.1.55
@swc/core: 1.2.122

And unsurprisingly:

atob('IntcInZlcnNpb25cIjozLFwic291cmNlc1wiOltdLFwibmFtZXNcIjpbXSxcIm1hcHBpbmdzXCI6XCJcIixcImZpbGVcIjpcInN0ZG91dFwifSI')
=== '"{\\"version\\":3,\\"sources\\":[],\\"names\\":[],\\"mappings\\":\\"\\",\\"file\\":\\"stdout\\"}"';

atob('eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9')
=== '{"version":3,"sources":[],"names":[],"mappings":""}';

This PR tries to fix these thing by touching async function concatResults in src/swc/file with:

  • not JSON.stringifiying source maps
  • not generating empty sourcemaps, by lazily creating new SourceMapGenerator.

Merry... Christmas?

@xnuk
Copy link
Contributor Author

xnuk commented Dec 4, 2022

It's about a year, and still reproducible in @swc/cli v0.1.57 + @swc/core v1.3.21. Could someone review this one? @swc-project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant