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

originalPositionFor returns null if sourcemap does not contains the exact line. #261

Open
yoshiokatsuneo opened this issue May 8, 2017 · 6 comments
Labels
needs-triage Unconfirmed issues

Comments

@yoshiokatsuneo
Copy link

originalPositionFor returns null if sourcemap does not contains the exact line.
It cause the issue with typescript(ts-node) that may not create source map for all the lines,
especially when the source contains multi-line chained function call like below.

let obj:any = null;
obj
.map();

In this case, the error happens on the last line. But, sourcemap does not have information on the line. So, the following code assume the mapping does not found and return null.

if (mapping.generatedLine === needle.generatedLine) {

It is much better to return the nearest source map position, instead of just return null.

@yoshiokatsuneo
Copy link
Author

Related to:
TypeStrong/ts-node#325

@tromey
Copy link
Contributor

tromey commented May 26, 2017

Over in #220 the proposal is to remove "fuzzy mapping" from another API. It would be funny to change that one to be more strict while changing this one to be less so -- but maybe that's even the best thing to do.

@tromey
Copy link
Contributor

tromey commented May 26, 2017

I see now that originalPositionFor is documented as returning the nearest mapping.

@Snipx
Copy link

Snipx commented May 7, 2018

For Kotlin the issue is even more important because the mapping is fuzzier in Kotlin than in TypeScript I believe. See istanbuljs/nyc#818

@ericmorand
Copy link

ericmorand commented May 10, 2018

Any news about this one? The bias property only works with columns. line still has to match exactly for the function to return a position.

@TimHambourger
Copy link

This one would greatly help SourceMapGenerator.prototype.applySourceMap. I'll file a separate issue describing what I'm hitting there, b/c it concerns behaviors in applySourceMap and not just originalPositionFor.

But one suggestion I'll make here is that as in #220, this could work well as an optional argument. It makes sense to me that some cases might call for strict matching and others fuzzy. I don't have strong feelings about what the default should be -- I personally would be fine keeping strict as the default for backwards compatibility. My main interest is to see applySourceMap move to fuzzy matching, for reasons I'll explain in my separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Unconfirmed issues
Projects
None yet
Development

No branches or pull requests

6 participants