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
Add missing source-map methods #2
Conversation
allGeneratedPositionsFor( | ||
originalPosition: Parameters<typeof generatedPositionFor>[1], | ||
): ReturnType<typeof generatedPositionFor>[] { | ||
// This doesn't map exactly to the same feature | ||
return [generatedPositionFor(this._map, originalPosition)]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is no equivalent in trace-mapping
I'm not sure to know how important it is or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, but the instanbul project might want to use it eventually to fix their coverage cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented for now that it only returns one mapping
src/source-map.ts
Outdated
const sourceContent = sourceContentFor(this._map, aSource); | ||
if (sourceContent != null) { | ||
return sourceContent; | ||
} | ||
|
||
const resolvedSource = resolve(aSource, this.sourceRoot); | ||
if (this.sources.indexOf(resolvedSource) > -1) { | ||
return this.sourcesContent[this.sources.indexOf(resolvedSource)]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this logic be moved to trace-mapping
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already there. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only partially though.
the implementation in trace-mapping
looks up a static list of sources, whereas the original Mozilla implementation resolves the sourceFile and accepts some relative paths.
Removed the extended part for now and will look into a future PR for trace-mapping
|
||
eachMapping( | ||
aCallback: Parameters<typeof eachMapping>[1], | ||
aContext?: any /*, aOrder?: number*/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how important that order
argument is, should it be implemented ? is it even possible in trace-mapping
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is possible in trace-mapping, but it's not implemented. We generate the "original order" in generatedPositionFor
, and you would need to walk that. Rather than adding a parameter to trace-mapping
, I would expose a new function that did eachMappingBySource
, and call the appropriate function here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented that this isn't supported for now
allGeneratedPositionsFor( | ||
originalPosition: Parameters<typeof generatedPositionFor>[1], | ||
): ReturnType<typeof generatedPositionFor>[] { | ||
// This doesn't map exactly to the same feature | ||
return [generatedPositionFor(this._map, originalPosition)]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, but the instanbul project might want to use it eventually to fix their coverage cases.
this._map = new GenMapping(opts); | ||
constructor(opts: ConstructorParameters<typeof GenMapping>[0] | GenMapping) { | ||
// TODO :: should this be duck-typed ? | ||
this._map = opts instanceof GenMapping ? opts : new GenMapping(opts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does SourceMapGenerator
support this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't but I use this as a workaround to make it possible to call the constructor in the fromSourceMap
below that is using fromMap()
and passing that to SourceMapGenerator
's constructor
} | ||
|
||
// This is a fallback for `source-map` and `source-map-js` | ||
return new SourceMapConsumer(map.toJSON() as SectionedSourceMapInput, mapUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to support the old consumer instances? I'd think most would be from the JSON string/Object forms that are serialized into a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do, I honestly don't know in which contexts this package is used and sometimes compilation processes go through multiple libraries which could use any source map library
Hello @onigoetz and @jridgewell! Just came across these packages and this PR and just wanted to thank you both for doing amazing work to dramatically improve the codebase and size of source-map! It's a lot harder to justify the bundle size of source-map in the browser for small features like enhancing error messages as I'm keen to do, and this seems incredibly promising. Please let me know if I can be of any help |
@TylorS from you're comment, I imagine you're doing unminification of stack trace line/columns using the sourcemap? I'd suggest using |
Thanks for the advice @jridgewell! I'll have to poke around at it. I was initially going to use github.com/xpl/stacktracey, but it has a direct dep on |
Hi @jridgewell I've been fairly inactive on my JS projects lately but would like to pick up where I left off. I'm still very motivated to get this PR merged and get more tools over to your implementation of source-map to make JS tooling faster. |
Hi @jridgewell I think I addressed all comments from the PR except the ones that I left unresolved. I'm ready to make adjustments wherever is needed |
I'll take a look at this this weekend. |
Hi,
As said in #1 This PR adds some missing methods to source-map, I'm opening it as Draft as it's not yet complete but I would love some feedback on a few things.
Added Methods and fields
static SourceMapConsumer.fromSourceMap()
will transform aSourceMapGenerator
into aSourceMapConsumer
. is optimized to usetoDecodedMap
when availableSourceMapConsumer.version
SourceMapConsumer.mappings
: computes the mappings on demandSourceMapConsumer.generatedPositionFor()
SourceMapConsumer.allGeneratedPositionsFor()
: Will only return one value fromgeneratedPositionFor
SourceMapConsumer.hasContentsOfAllSources()
SourceMapConsumer.sourceContentFor()
trace-mapping
source-map-js
does a resolution of the path as well: https://github.com/7rulnik/source-map-js/blob/patch-0.6.1/lib/source-map-consumer.js#L750-L794, can be done later as a PR totrace-mapping
directlySourceMapConsumer.eachMapping()
static SourceMapGenerator.fromSourceMap()
SourceMapGenerator.applySourceMap
src/utils
: neededTests
Tests come from the
source-map-js
repository, I've been testing these changes on a PR I'm preparing forpostcss
I will probably add more tests and examples as I discover and fix issues.Tests Runtime
I configured the tests to use
ts-mocha
instead ofmocha
and changed the paths in the tests to use the source file, as it didn't show the coverage properly. This PR currently has 85% coverage.Build
This PR also introduces changes in the build process. It now has three outputs instead of two :
source-map.umd.js
: For browsers, still same as beforesource-map.mjs.js
: For node with imports, does not include dependenciessource-map.cjs
: For node with requires, does not include dependenciesI also changed the
package.json
accordingly.If you have any early feedback before I go in a wrong direction I'd love to hear it