-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
feat: migrate from source-map
to @jridgewell/trace-mapping
#12692
Conversation
@@ -456,7 +450,7 @@ export default class CoverageReporter extends BaseReporter { | |||
originalSource: fileTransform.originalCode, | |||
source: fileTransform.code, | |||
sourceMap: { | |||
sourcemap: {file: res.url, ...sourcemapContent}, | |||
sourcemap: {file: res.url, ...sourcemapContent} as any, |
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.
https://github.com/istanbuljs/v8-to-istanbul/blob/1f357fa2e994385b56ba505ca199eda46b233a89/index.d.ts#L14
https://github.com/mozilla/source-map/blob/58819f09018d56ef84dc41ba9c93f554e0645169/source-map.d.ts#L17
vs
https://github.com/jridgewell/trace-mapping/blob/d4ead19a18c805bd3af657f71ea72c48809f61db/src/types.ts#L7
packages/jest-transform/src/types.ts
Outdated
@@ -26,8 +26,8 @@ export interface Options | |||
isInternalModule?: boolean; | |||
} | |||
|
|||
// This is fixed in [email protected], but we can't upgrade yet since it's async | |||
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> { | |||
// `babel` and `@jridgewell/trace-mapping` disagrees |
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.
However, you don't really need a generator for this simple usecase. You can just take advantage of a import { AllMap, encodedMappings } from '@jridgewell/trace-map';
const output = [
'const Handlebars = require("handlebars/dist/cjs/handlebars.runtime.js");\n',
'module.exports = Handlebars.template(',
code,
');\n',
];
const map = new AllMap({
version: 3,
sections: [
{
offset: {
// 0-index, so count of newlines before `code`
line: 1,
// column offset of the injected code on its first line
column: output[1].length,
},
map: pc.map,
},
],
});
// map is now a regular, non-sectioned sourcemap that can be used everywhere.
// You need to manually JSONify the map from here, but I could add an export to do that for you.
const json = JSON.stringify({
version: 3,
file: map.file,
names: map.names,
sources: map.sources,
sourcesContent: map.sourcesContent,
// Depending on where this is going, you could use decodedMappings to avoid an encode->decode round trip.
mappings: encodedMappings(map),
}); |
Thanks @jridgewell! keeping the current code in this case seems fine, it's just an integration test. Happy to switch over if/when you release a generator package, though! 🙂 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Same motivation as istanbuljs/v8-to-istanbul#185.
@jridgewell hi again! 😀 If this PR lands, there's only a single (non-transitive) usage of
source-map
in this repo, and that's https://github.com/facebook/jest/blob/5183c15a8e14089351d6403f4fdb72a6705aa379/e2e/coverage-handlebars/transform-handlebars.js. Would that use case be something you support as well?Test plan
Green CI