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
Switch to TraceMap for sourcemap's originalPositionFor API #1181
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,11 @@ | |
"use strict"; | ||
|
||
import MOZ_SourceMap from "source-map"; | ||
import { | ||
defaults, | ||
} from "./utils/index.js"; | ||
import {AnyMap, originalPositionFor} from "@jridgewell/trace-mapping"; | ||
import {defaults} from "./utils/index.js"; | ||
|
||
// a small wrapper around fitzgen's source-map library | ||
async function SourceMap(options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the only reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I don't need to wonder much, it was the one thing people asked for when Terser 5 was released. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like me to go through and remove all asyncs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR :) Also if the minify function becomes sync, it would break people who are calling .then directly. It should be a new function |
||
// a small wrapper around source-map and @jridgewell/trace-mapping | ||
function SourceMap(options) { | ||
options = defaults(options, { | ||
file : null, | ||
root : null, | ||
|
@@ -66,18 +65,20 @@ async function SourceMap(options) { | |
}); | ||
|
||
if (options.orig) { | ||
orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig); | ||
orig_map.sources.forEach(function(source) { | ||
var sourceContent = orig_map.sourceContentFor(source, true); | ||
if (sourceContent) { | ||
generator.setSourceContent(source, sourceContent); | ||
} | ||
}); | ||
orig_map = new AnyMap(options.orig); | ||
if (orig_map.sourcesContent) { | ||
orig_map.resolvedSources.forEach(function(source, i) { | ||
var sourceContent = orig_map.sourcesContent[i]; | ||
if (sourceContent) { | ||
generator.setSourceContent(source, sourceContent); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function add(source, gen_line, gen_col, orig_line, orig_col, name) { | ||
if (orig_map) { | ||
var info = orig_map.originalPositionFor({ | ||
var info = originalPositionFor(orig_map, { | ||
line: orig_line, | ||
column: orig_col | ||
}); | ||
|
@@ -101,11 +102,7 @@ async function SourceMap(options) { | |
add : add, | ||
get : function() { return generator; }, | ||
toString : function() { return generator.toString(); }, | ||
destroy : function () { | ||
if (orig_map && orig_map.destroy) { | ||
orig_map.destroy(); | ||
} | ||
} | ||
destroy : function() {} | ||
}; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
We still use the
SourceMapGenerator
API to generate a new sourcemap for the minified output.TraceMap
(andAnyMap
) are only for consuming and tracing an already existing sourcemap.