mirror of
https://github.com/jehna/humanify.git
synced 2026-04-28 01:55:56 +03:00
[GH-ISSUE #182] Instead of rewriting the source, what about creating a sourcemap? #52
Labels
No labels
bug
enhancement
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/humanify#52
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Originally created by @brianjenkins94 on GitHub (Oct 26, 2024).
Original GitHub issue: https://github.com/jehna/humanify/issues/182
@jehna commented on GitHub (Oct 27, 2024):
A great idea! Do you know anything about creating sourcemaps with Babel or similar tools? I think usually Babel creates sourcemaps that start from the original file and you end up with a sourcemap mapping from the end result (e.g. a minified file) to the original file.
In Humanify's case we'd need to do the reverse: Start with a minified file, apply Prettier, Webcrack and Babel transformations, and end up with a source map mapping from the original (minified) file to the end result (un-minified file).
If anybody has ideas on how to do this with any existing tools, I'd be happy to give it a look
@j4k0xb commented on GitHub (Oct 29, 2024):
Renaming itself has many edge cases (
const { a } = b->const { a: foo } = b), and there are also other transformations in humanify.It would be simpler to rewrite the source and make babel generate a source-map additionally.
Here's a snippet to reverse it: https://gist.github.com/j4k0xb/0d76d103db9696b515ce9c51c45b76b8
and you probably need a way to combine multiple source-maps
@0xdevalias commented on GitHub (Dec 10, 2024):
^Big agree on this.
I haven't looked deeply into this, but I switched from
prettiertobiomein my RE project; I wonder if it can generate sourcemaps for it's formatting? (ChatGPT seems to think it can't)Even if neither of these tools can; I wonder if it would be possible to take the 'before formatting' and 'after formatting' code, and then generate a sourcemap based on the diff between them?
See also:
@pionxzh commented on GitHub (Dec 11, 2024):
It will be challenging to compare before and after to generate the sourcemap. I didn't look into humanity's source code detailly, but you should be able to let babel generate the sourcemap since most of the operation is renaming. Prettier does not support sourcemap, but I have no idea what other alternatives provide this functionality.
@pionxzh commented on GitHub (Dec 11, 2024):
I have tried using https://github.com/Rich-Harris/magic-string to do some code transformation with source map support, but I'm not sure if it fits into the use case here.