-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Suggestion: Preserve line numbers #3142
Comments
@CyrusNajmabadi can probably chime in with the specifics around how and why we do this |
The reason we do things in the current manner is that preservation of source code formatting was not a goal with the new compiler rewrite. So, the emitter acts as more of a pretty-printer than a true tree rewrite (i.e. one preserving as much of the original tree as possible). We do attempt, in very specialized situations, to have our pretty-printing be informed by the original code. For example, we'll try to preserve certain single line constructs. Or we try to keep some newlines in complex expressions to help make the outputted code more readable. Right now though, we don't do much additional work with keeping newline information around. If you're interested in improving things here, feel free to contribute a PR. Thanks! |
Though we can do this for simple transformations, with an added complexity bear in mind; we can not do that for all transformations. consider something like async/await. SourceMaps has been the standard for JS community to deal with these transformations. The TypeScript compiler supports soruce map generation with |
Sadly we can not have this feature. I implemented a log util to log the message together with the file name and line number. It's work great with babel since babel supports preserve line number. But not typescript. |
+1, there are many cases of develper tools that do not support courcemaps (for instance often hosted online logs of Functions As A Service providers) |
Currently, this TypeScript code
is transpiled to this JavaScript code
However, you could reformat the code, so that the main code pieces keep the same lines, to something like this:
P.S. I know about the source maps.
The text was updated successfully, but these errors were encountered: