support optional output of names in source maps (#3784)

This commit is contained in:
Alex Lam S.L
2020-04-17 00:20:48 +01:00
committed by GitHub
parent 0ce71bbec0
commit 83f42ede36
5 changed files with 115 additions and 27 deletions

View File

@@ -90,14 +90,8 @@ function create_array_map() {
}
function SourceMap(options) {
options = defaults(options, {
content: false,
file: null,
root: null,
orig: null,
}, true);
var sources = create_array_map();
var sources_content = options.content && Object.create(null);
var sources_content = options.includeSources && Object.create(null);
var names = create_array_map();
var mappings = "";
if (options.orig) Object.keys(options.orig).forEach(function(name) {
@@ -155,7 +149,7 @@ function SourceMap(options) {
toString: function() {
return JSON.stringify({
version: 3,
file: options.file || undefined,
file: options.filename || undefined,
sourceRoot: options.root || undefined,
sources: sources,
sourcesContent: sources_content ? sources.map(function(source) {
@@ -188,7 +182,7 @@ function SourceMap(options) {
original_line = orig_line;
mappings += vlq_encode(orig_col - original_column);
original_column = orig_col;
if (name != null) {
if (options.names && name != null) {
var name_idx = names.index(name);
mappings += vlq_encode(name_idx - name_index);
name_index = name_idx;