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

Input source maps #26843

Open
4 tasks done
rtm opened this issue Sep 2, 2018 · 0 comments
Open
4 tasks done

Input source maps #26843

rtm opened this issue Sep 2, 2018 · 0 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@rtm
Copy link

rtm commented Sep 2, 2018

Suggestion

Support input source maps, for the case where a TS file is generated programatically from some other source file, in order to permit end-to-end mapping.

Such source maps could either be specified in the .ts file using the //# SourceMappingURL=foo.ts.map notation, searched for under the name *.ts.map, or found in-line in the .ts sources, etc., depending on various options.

The effect would be that the *.js.map file generated (or inlined) would be the equivalent of what is known as "applying" the input source map to the tsc-generated sourcemap. In other words, the sourcemap would map lines in the *.js file all the way back to the original file(s) from which the *.ts file was generated.

Use Cases

This issue has come up in the context of some literate programming hacking I am doing. The programmer works on "literate programming documents" (actually, a flavor of Markdown), and then "tangles" (to use Knuth's terminology) that into a TS file.

My tangler generates the *.ts.map file. Currently, what I am doing is to provide an extra utility which the programmer can use to "apply" the map I create to the one created by tsc to get lines in the *.js all the way back to the literate programming document. However, this is a bit clumsy, and requires some setup. It would be nicer if tsc could take in source maps, apply them itself, and output *.js.map files reflecting that mapping.

Examples

Currently, the user does something like the following:

modernlit --sourcemap foo.lit.md # creates foo.ts and foo.ts.map
tsc --sourcemap foo.ts # creates foo.js and foo.js.map
mlsourcemap foo.ts.map foo.js.map # rewrites foo.js.map by "applying" foo.ts.map

("modernlit" is the name I am currently using for my literate programming system.)

With the feature I am proposing, the call to mlsourcemap could be eliminated. tsc would find foo.ts.map, and perform the mapping, generating a foo.js.map which reflected it having been "applied" to the JS-to-TS sourcemap. This would avoid the user having to remember to call mlsourcemap, and avoid me having to write it, maintain, and document it.

For information on "applying" (remapping) sourcemaps, as implemented in the Mozilla source-maps library, see here.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants