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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps missing end range #1796

Closed
smcenlly opened this issue Jun 7, 2021 · 1 comment 路 Fixed by #1832
Closed

Source maps missing end range #1796

smcenlly opened this issue Jun 7, 2021 · 1 comment 路 Fixed by #1832
Labels
Milestone

Comments

@smcenlly
Copy link

smcenlly commented Jun 7, 2021

Issue Description / Background

Firstly - great job on swc, today was the first time we had used it and it really is very very fast! 馃槉

Today we discovered that swc source maps are missing end ranges for multi-line blocks, which causes problems for various developer tooling the relies on source maps, including istanbul.js and our product, Wallaby.js.

While source maps are lossy by nature, most source maps include a mapping for the end range of certain types of ast nodes (e.g. ExpressionStatements). These appear to be missing for swc source maps which breaks JavaScript developer tooling that relies on these.

After identifying the problem, we have used https://sokra.github.io/source-map-visualization/#custom to visualize the problem for you and have compared swc, Babel and TypeScript (see below). You will see in the swc source maps, there is no mapping after throw new Error('boom'); while there is for TypeScript and Babel.

swc

image

TypeScript

image

Babel

image

We have also provide the sample repo that you can use to generate the transformed files and their source maps (refer to package.json scripts).


Is this by design or a bug? If it is by design, what is your guidance to determine source-code mapping for end-of-range for swc transformed files (e.g. we have the original source file + line + column after at the end of the file)? From a development tooling perspective, it would be ideal if the source maps would behave similarly to either Babel or TypeScript if at all possible.

@smcenlly smcenlly added the C-bug label Jun 7, 2021
@kdy1 kdy1 added this to the v1.2.61 milestone Jun 8, 2021
@kdy1 kdy1 modified the milestones: v1.2.61, v1.2.62 Jun 16, 2021
@kdy1 kdy1 mentioned this issue Jun 18, 2021
10 tasks
kdy1 added a commit to kdy1/swc that referenced this issue Jun 18, 2021
kdy1 added a commit that referenced this issue Jun 18, 2021
swc_common:
 - `SourceMap`: Don't panic for dummy spans.

swc_ecma_codegen:
 - Use span for `throw`. (#1685)
 - Use span for `var` / `let` / `const`.
 - Use span for `new`.
 - Use span for `if`.
 - Add spans to braces of a block statement. (#1796)

swc_ecma_transforms_compat:
 - `parameters`: Don't drop the span of block statements. (#1796)

swc:
 - Allow specifying input source map in `.swcrc`.
 - Ensure that the inline source map works properly. (#1713)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants