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

Empty template spans break sourcemaps #825

Open
Septh opened this issue Feb 4, 2024 · 1 comment
Open

Empty template spans break sourcemaps #825

Septh opened this issue Feb 4, 2024 · 1 comment

Comments

@Septh
Copy link

Septh commented Feb 4, 2024

I have set up a repro here: https://github.com/Septh/sucrase-broken-sourcemaps.

After cloning and installing, run node sucrase.js to compile the TypeScript code; you can then upload the resulting index.js file to Evan Wallace's excellent source-map-visualization tool.

Here's what I get:

image
(permalink)

As you can see, the original column number stays 'stuck' at the end of the first template string.

@Septh
Copy link
Author

Septh commented Feb 6, 2024

I did some digging and I think i figured out what's going on.

The issue arises only when the tokenizer generates zero-length tt.template tokens:

`foo ${var} bar`  // <- sourcemaps are correct
`foo ${var}`      // <- sourcemaps are wrong (last tt.template is 2:10-2:10)
`${var} bar`      // <- sourcemaps are wrong (first tt.template is 3:2-3:2)

(the line:column values come from the playground).

When a token is empty, the computeSourceColumns function in /src/computeSourceMap.ts fails to map the following tokens to their original source code positions because the condition at line 79 will never be true again.

Septh added a commit to Septh/sucrase that referenced this issue Feb 6, 2024
Septh added a commit to Septh/sucrase that referenced this issue Feb 17, 2024
@Septh Septh changed the title Template strings break sourcemaps Empty template spans break sourcemaps Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant