Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async load () {
const rawSource = this.sources.source || await readFile(this.path, 'utf8')
const rawSourceMap = this.sources.sourceMap ||
// if we find a source-map (either inline, or a .map file) we load
// both the transpiled and original source, both of which are used during
// the backflips we perform to remap absolute to relative positions.
convertSourceMap.fromSource(rawSource) || convertSourceMap.fromMapFileSource(rawSource, dirname(this.path))
if (rawSourceMap) {
if (rawSourceMap.sourcemap.sources.length > 1) {
console.warn('v8-to-istanbul: source-mappings from one to many files not yet supported')
this.source = new CovSource(rawSource, this.wrapperLength)
} else {
this._rewritePath(rawSourceMap)
this.sourceMap = await new SourceMapConsumer(rawSourceMap.sourcemap)
let originalRawSource
if (this.sources.originalSource) {
originalRawSource = this.sources.originalSource
} else {
originalRawSource = await readFile(this.path, 'utf8')
}
script = debugExpr + script;
}
// bail early if we don't have a path
if (!currentWrapFile || !useSourceMaps) return moduleWrap(script);
var sourceFile = path.relative(basedir, currentWrapFile).replace(/\\/g, '/');
var sourceFileName = path.basename(sourceFile);
var sourceFileDir = path.dirname(sourceFile);
var hasComment = convertSourceMap.commentRegex.test(script);
var hasMapFile = convertSourceMap.mapFileCommentRegex.test(script);
// if we have a map pointing to a file, inline it as base64
if (!hasComment && hasMapFile) {
try {
var sm = convertSourceMap.fromMapFileSource(original, sourceFileDir);
script = [
combineSourceMap.removeComments(script),
convertSourceMap.fromObject(sm.sourcemap).toComment()
].join('\n');
hasComment = true; // now we have base64 comment
} catch (err) {
// Don't attempt to handle source maps for this file,
// it is most likely a comment about source maps and not
// a *real* source map comment!
}
}
var wrapScript = moduleWrap(script);
// do not make any more alterations to the source maps
if (hasComment || hasMapFile) return wrapScript;
function resolveSourceFile(file) {
const testDir = path.dirname(file);
const buffer = tryRead(file);
if (!buffer) {
return file; // Assume the file is stubbed in our test suite.
}
const source = buffer.toString();
const converter = convertSourceMap.fromSource(source) || convertSourceMap.fromMapFileSource(source, testDir);
if (converter) {
const map = converter.toObject();
const firstSource = `${map.sourceRoot || ''}${map.sources[0]}`;
return path.resolve(testDir, firstSource);
}
return file;
}
try {
let base64SourceMap = Convert.fromSource(file.contents.toString());
if (base64SourceMap) {
return null;
}
} catch (error) {
// we don't want the build to fail when a sourcemap file can't be parsed
return null;
}
let converter;
try {
converter = Convert.fromMapFileSource(file.contents.toString(), parsedPath.dir);
} catch (e) {
logger.error(e);
return null;
}
sourceMap = converter
? converter.sourcemap
: null;
return sourceMap;
}
_.forOwn(covered, function (fixture) {
var source = fixture.contentSync()
var sourceMap = convertSourceMap.fromSource(source) || convertSourceMap.fromMapFileSource(source, fixture.absPath)
if (sourceMap) {
sourceMapCache.addMap(fixture.absPath, sourceMap.sourcemap)
}
})
fs.readFile(target, {encoding:'utf8'}, function(e, data) {
if (e) throw e;
js = data;
var sourceMap = convert.fromMapFileSource(js, command.outdir);
sourceMap.setProperty('sources', [rel]);
js = convert.removeMapFileComments(js);
js += '\n' + sourceMap.toComment() + '\n';
fs.writeFile(target, js, function() {
queue = queue.slice(1);
if (queue.length == 0) done();
});
});
});
function getSourceMap(filePath, code) {
let sourceMap = convertSourceMap.fromSource(code);
if (!sourceMap) {
const dirPath = path.dirname(filePath);
sourceMap = convertSourceMap.fromMapFileSource(code, dirPath);
}
return sourceMap ? sourceMap.toObject() : undefined;
}
const sourceMap = (() => {
try {
let converter = convert.fromSource(contents);
if (converter) return converter.sourcemap;
if (filePath) {
converter = convert.fromMapFileSource(contents, dir);
if (converter) return converter.sourcemap;
}
} catch (err) {
return;
}
})();
function getSourceMap(filePath, code) {
let sourceMap = convertSourceMap.fromSource(code);
if (!sourceMap) {
const dirPath = path.dirname(filePath);
sourceMap = convertSourceMap.fromMapFileSource(code, dirPath);
}
return sourceMap ? sourceMap.toObject() : undefined;
}
function espowerSource(grunt, jsCode, filepath, dest, options) {
var jsAst, espowerOptions, modifiedAst, escodegenOutput, resolved;
jsAst = esprima.parse(jsCode, {
tolerant: true,
loc: true,
raw: true,
source: filepath
});
var inMap = convert.fromSource(jsCode) || convert.fromMapFileSource(jsCode, path.dirname(filepath));
espowerOptions = extend(espower.defaultOptions(), options, {
destructive: true,
path: filepath,
sourceMap: inMap ? inMap.sourcemap : void 0
});
modifiedAst = estraverse.replace(jsAst, mergeVisitors([
{
enter: empowerAssert.enter
},
espower.createVisitor(jsAst, espowerOptions)
]));
escodegenOutput = escodegen.generate(modifiedAst, {
sourceMap: true,
sourceMapWithCode: true
});
var outMap = convert.fromJSON(escodegenOutput.map.toString());