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

Ingesting a sourcemap containing blank/unmapped files leads to inaccurate sourcemap output. (T7583) #4474

Closed
babel-bot opened this issue Sep 6, 2016 · 3 comments
Labels
area: sourcemaps i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@babel-bot
Copy link
Collaborator

babel-bot commented Sep 6, 2016

Issue originally made by @pkovac

Bug information

  • Babel version: 6.14.0
  • Node version: 6.3.0
  • npm version: 3.10.5

Description

Using the inputSourceMap option, providing a mapping which contains files with no corresponding line mappings will produce a sourcemap with mappings offset by the number of blank files.

A repo which demonstrates the problem can be seen here: WeaveTeam/blank-file-bug. I've attempted to make the test-case as minimal as possible. In addition to the dependencies listed, you'll also need to install node-debug globally to easily test it, or other sourcemap-enabled Node debugger.

Steps to reproduce:

  1. run 'npm run start' after checking out and 'npm install'ing the above repo.
  2. go into bin/js/ and 'node-debug main.js' or other debugger which supports sourcemaps.
  3. Attempt to set a breakpoint in c.ts, line 1.

Result:
No breakpoint will be set.

You can get the expected behavior from bin/es6/main.js, as the code provided contains no ES6-isms and can run without crosscompilation. By performing the above steps, you can confirm that the input sourcemaps generated by typescript are correct.

An examination of the two main.js.map files reveals the problem; in the babel output, all the 'mappings' have a 0 ('A') source file offset, therefore pointing to the first (blank) entry in the sources list, which is not accurate, while in the input generated by Typescript, the first mapping contains a source offset of 2 ('C')

References:
Source Map Revision 3 Proposal

@babel-bot
Copy link
Collaborator Author

Comment originally made by @pkovac

It should also be noted that in TS, files containing nothing but an interface will also generate a source with no mapping, so this isn't a problem only with blank input files from the start. Additionally, disabling output of comments seems to produce a similar problem when there are files composed entirely of comments, though it's a bit more difficult to reproduce. I haven't added either of these examples to the test case above because they make the output sourcemap harder to read as a human to validate that the offsets are incorrect.

@necolas
Copy link

necolas commented Nov 17, 2016

This appears to be the same issue we're having at Twitter using any version of babel-core@>=6.14.0 to compile our JS (via webpack and babel-loader)

@loganfsmyth
Copy link
Member

This appears to be working now since I can set a breakpoint. I'm going to guess that #7761 fixed it. If there are still issues, feel free to file a new issue though.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 11, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: sourcemaps i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants