Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
file.sourceMap = JSON.parse(file.sourceMap);
}
// check source map properties
assertProperty(sourceMap, "file");
assertProperty(sourceMap, "mappings");
assertProperty(sourceMap, "sources");
// fix paths if Windows style paths
sourceMap.file = sourceMap.file.replace(/\\/g, '/');
sourceMap.sources = sourceMap.sources.map(function(filePath) {
return filePath.replace(/\\/g, '/');
});
if (file.sourceMap && file.sourceMap.mappings !== '') {
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
generator.applySourceMap(new SourceMapConsumer(file.sourceMap));
file.sourceMap = JSON.parse(generator.toString());
} else {
file.sourceMap = sourceMap;
}
};
const outSourceMap = new UglifyJS.SourceMap({
file: `${id}.js`,
root: sourceRoot
})
const stream = new UglifyJS.OutputStream({
ascii_only: true,
screw_ie8: false,
source_map: outSourceMap
})
/* eslint-enable camelcase */
compressed.print(stream)
const js = stream.toString()
const map = JSON.parse(outSourceMap.toString())
const generator = new SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map))
sourceMaps.forEach(function(sourceMap) {
generator.applySourceMap(new SourceMapConsumer(sourceMap), sourceMap.sources[0], sourceRoot)
})
return {
js,
map: JSON.stringify(generator.toJSON(), function(k, v) {
if (k != 'sourcesContent') return v
})
}
}
var filename = normalizePath(this.resourcePath);
this.cacheable && this.cacheable();
if (sourceMapEnabled && !inputSourceMap && annotateMap) {
outputSourceMap = annotateMap;
}
// Using BabelJS as an example,
// https://github.com/babel/babel/blob/d3a73b87e9007104cb4fec343f0cfb9e1c67a4ec/packages/babel/src/transformation/file/index.js#L465
// See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com/floridoo/vinyl-sourcemaps-apply/blob/master/index.js
if (sourceMapEnabled && inputSourceMap) {
inputSourceMap.sourceRoot = '';
inputSourceMap.sources[0] = filename;
if (annotateMap) {
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap));
generator.applySourceMap(new SourceMapConsumer(inputSourceMap), filename);
outputSourceMap = generator.toJSON();
//Should be set to avoid '../../file is not in SourceMap error https://github.com/huston007/ng-annotate-loader/pull/11'
outputSourceMap.sourceRoot = '';
//Copy file name from incoming file because it is empty by some unknown reaon
outputSourceMap.file = normalizePath(this.resourcePath);
} else {
outputSourceMap = inputSourceMap;
}
}
return outputSourceMap;
}
if (doubleRoastedCoffee != null &&
doubleRoastedCoffee.data != null) {
output.js = doubleRoastedCoffee.data;
const coffeeSourceMap = doubleRoastedCoffee.sourceMap;
if (coffeeSourceMap) {
// Reference the compiled CoffeeScript file so that `applySourceMap`
// below can match it with the source map produced by the CoffeeScript
// compiler.
coffeeSourceMap.sources[0] = '/' + this._outputFilePath(inputFile);
// Combine the original CoffeeScript source map with the one
// produced by this.babelCompiler.processOneFileForTarget.
const smg = SourceMapGenerator.fromSourceMap(
new SourceMapConsumer(coffeeSourceMap)
);
smg.applySourceMap(new SourceMapConsumer(sourceMap));
sourceMap = smg.toJSON();
} else {
// If the .coffee file is contained by a node_modules directory,
// then BabelCompiler will not transpile it, and there will be
// no sourceMap, but that's fine because the original
// CoffeeScript sourceMap will still be valid.
}
}
return addSharedHeader(output.js, sourceMap);
}
SourceMapConcatHelper.prototype._write = function() {
// ensure we're using forward slashes, because these are URLs
var file = path.relative(path.dirname(this.dest), this.files.dest);
file = file.replace(/\\/g, '/');
var code_map = this.node.toStringWithSourceMap({
file: file
});
// Consume the new sourcemap.
var generator = SourceMapGenerator.fromSourceMap(
new SourceMapConsumer(code_map.map.toJSON())
);
// Consume sourcemaps for source files.
this.maps.forEach(Function.apply.bind(generator.applySourceMap, generator));
// New sourcemap.
var newSourceMap = generator.toJSON();
// Return a string for inline use or write the map.
if (this.options.sourceMapStyle === 'inline') {
grunt.log.writeln(
'Source map for ' + chalk.cyan(this.files.dest) + ' inlined.'
);
return JSON.stringify(newSourceMap, null, '');
} else {
grunt.file.write(
this.dest,
JSON.stringify(newSourceMap, null, '')
return {type, line, column, source, desc: item.description};
};
throw {
errors: [
...closureResult.errors.map(remap('error')),
...closureResult.warnings.map(remap('warning')),
],
};
} else {
// Currently, closure compiler doesn't support applying its generated
// source map to an existing source map, so we do it manually.
const fromMap = JSON.parse(closureResult.sourceMap);
const toMap = rollupResult.map;
const generator = SourceMapGenerator.fromSourceMap(
await new SourceMapConsumer(fromMap));
generator.applySourceMap(
await new SourceMapConsumer(toMap), path.basename(output));
const sourceMap = generator.toString();
return {
code: closureResult.compiledCode,
map: sourceMap,
};
}
};
SourceMapSource.prototype.node = function(options) {
var innerSourceMap = this._innerSourceMap;
var sourceMap = this._sourceMap;
if(innerSourceMap) {
innerSourceMap = new SourceMapConsumer(innerSourceMap);
sourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
sourceMap.setSourceContent(this._name, this._originalSource);
sourceMap.applySourceMap(innerSourceMap, this._name);
sourceMap = sourceMap.toJSON();
}
return SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
};
mergeSourceMap(orginSourceMap, sourceMap){
let {SourceMapGenerator, SourceMapConsumer} = require('source-map');
sourceMap.file = sourceMap.file.replace(/\\/g, '/');
sourceMap.sources = sourceMap.sources.map(filePath => {
return filePath.replace(/\\/g, '/');
});
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
generator.applySourceMap(new SourceMapConsumer(orginSourceMap));
sourceMap = JSON.parse(generator.toString());
return sourceMap;
}
/**
});
if (!code) {
return {
code: '',
};
}
const mapFilenameToFile = files.reduce((obj, file) => ({
...obj,
[file.getPathInBundle()]: file,
}), {});
map.sourcesContent = map.sources.map((filename) => mapFilenameToFile[filename].getContentsAsString());
const newMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map));
files.filter((file) => file.getSourceMap())
.forEach((file) => {
newMap.applySourceMap(new SourceMapConsumer(file.getSourceMap()), file.getPathInBundle());
});
return {
code,
sourceMap: newMap.toString(),
};
};