You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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');
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.
Precheck
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:
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
The text was updated successfully, but these errors were encountered: