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 map stripping breaks with source map comments in middle of file #389

Closed
4 of 5 tasks
nwalters512 opened this issue Nov 14, 2023 · 1 comment · Fixed by #392
Closed
4 of 5 tasks

Source map stripping breaks with source map comments in middle of file #389

nwalters512 opened this issue Nov 14, 2023 · 1 comment · Fixed by #392
Labels
bug Something isn't working outdated released

Comments

@nwalters512
Copy link
Contributor

Precheck

  • I searched existing issues before opening this one to avoid duplicates
  • I'm able to reproduce this issue and prove it with a minimal reproduction
  • I understand this is not a place to ask for free debugging support

Problem

The source map stripping added in #374 can change the behavior of files if the source map comment happens to be in the middle of the file. For instance:

type Name = string;

function sayHello(name: string) {
  console.log('Hello', name);
}

//# sourceMappingURL=index.js.map

sayHello('World');

For this code, Hello World will not be printed.

For better or worse, this kind of thing shows up in real-world code: https://github.com/drudru/ansi_up/blob/a30bb48417c9d67d8743ea30937b3b432b7648ec/ansi_up.js#L448. You can see how stripping the final lines along with the source map comment will result in unrunnable code that fails to parse.

Expected behavior

I would expect source map stripping to not change the runtime behavior of files, even if the file happens to be malformed. Note that I am not trying to make the argument that this comment should be interpreted as a source map or otherwise handled by tsx.

I'd be happy to open a PR for this if we can decide on what the behavior should be. I'm thinking that we should only strip this comment if it's the last line of the file.

Minimal reproduction URL

https://github.com/nwalters512/tsx-source-maps-parse-error-repro

Version

v4.1.2

Node.js version

v20.7.0

Package manager

npm

Operating system

macOS

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@privatenumber
Copy link
Owner

🎉 This issue has been resolved in v4.1.3

If you appreciate this project, please consider supporting this project by sponsoring ❤️ 🙏

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants