Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
end = function () {
if(self.opts.minify === false) {
this.queue(null)
return
}
var thisStream = this
, unminCode = buffs.join('')
, originalCode = false
, existingMap = convertSM.fromSource(unminCode)
, finish;
existingMap = existingMap ? existingMap.toObject() : false;
if(existingMap && existingMap.sourcesContent && existingMap.sourcesContent.length) {
originalCode = convertSM.removeComments(existingMap.sourcesContent[0]);
existingMap = JSON.stringify(existingMap);
}
// Only accept existing maps with sourcesContent
else {
existingMap = false;
}
finish = function (tempExistingMapFile, cleanupCallback) {
// Don't minify JSON!
if(file.match(/\.json$/)) {
try {
thisStream.queue(JSON.stringify(JSON.parse(unminCode)))
}
catch(e) {
console.error('failed to parse JSON in ' + file)
thisStream.queue(unminCode)
private async preprocess(dep: DepsInfo): Promise {
// Get sourcemaps created by pretransform
const rawMap = convert.fromSource(dep.source);
const consumer = rawMap
? await new sourceMap.SourceMapConsumer(rawMap.toObject())
: null;
if (consumer) {
dep.source = convert.removeComments(dep.source); // eslint-disable-line
}
const tokens = tokenize(dep.source);
const imports = [];
let exports = null;
depth(tokens);
scope(tokens);
// Note: tokens must be sorted by position
let lastLine = 1;
let lastColumn = 1;
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (body.indexOf(key) !== -1) {
matches = true;
break;
}
}
if (!matches) {
// just pass it through
output.end(buf);
return;
}
if (opts.sourceMap) {
inputMap = convertSourceMap.fromSource(body);
if (inputMap) inputMap = inputMap.toObject();
body = convertSourceMap.removeComments(body);
sourcemapper = new MagicString(body);
}
falafel(body, parserOpts, walk);
}
catch (err) { return error(err) }
finish(body);
}), output);
function extractSourceMaps (sourceCode) {
const converter = convertSourceMap.fromSource(sourceCode)
// if (!converter) throw new Error('Unable to find original inlined sourcemap')
const maps = converter && converter.toObject()
const sourceContent = maps && maps.sourcesContent[0]
const code = convertSourceMap.removeComments(sourceCode)
return { code, maps }
}
function evaluate(js, ctx) {
if (!ctx) ctx = { window: {}, document: {} };
js = convert.removeComments(js);
vm.runInNewContext('main =' + js + '(1)', ctx, 'main.vm');
vm.runInNewContext('require =' + js + '', ctx, 'require.vm');
return ctx;
}
parseInputSourceMap(code: string): string {
const opts = this.opts;
if (opts.inputSourceMap !== false) {
const inputMap = convertSourceMap.fromSource(code);
if (inputMap) {
opts.inputSourceMap = inputMap.toObject();
code = convertSourceMap.removeComments(code);
}
}
return code;
}
.then( () => {
/*
Angular compiler with 'flatModuleOutFile' turned on creates an entry JS file with a matching d.ts
file and an aggregated metadata.json file.
This is done by creating a corresponding TS file (to the output JS file).
The side-effect is a source map reference to the TS file.
Since the TS is virtual and does not exists we need to remove the comment so the source maps
will not break.
*/
const flatModuleJsPath = Path.join(copyInst.toSrc, `${util.getMainOutputFileName(util.currentPackage())}.js`);
const withoutComments = convert.removeComments(fs.readFileSync(flatModuleJsPath, 'utf-8'));
fs.writeFileSync(flatModuleJsPath, withoutComments, 'utf-8');
});
});
}, function(done) {
var self = this;
var source = pieces.join('');
var inputMapCV = convert.fromSource(source);
var inputMap;
if (inputMapCV) {
inputMap = inputMapCV.toObject();
source = convert.removeComments(source);
}
reactHotLoader.call({
resourcePath: file,
callback: function(err, source, map) {
if (err) {
done(err);
} else {
if (map) {
source = source + '\n' + convert.fromJSON(map).toComment();
}
self.push(source);
done();
}
}
}, source, inputMap);
});
parseInputSourceMap(code): string {
let inputMap = convertSourceMap.fromSource(code);
if (inputMap) {
this.inputSourceMap = inputMap.toObject();
code = convertSourceMap.removeComments(code);
}
return code;
}
bundler.bundle(function (err, buf) {
if (err) {
return cb(err)
}
var src = buf.toString()
var srcmap = convert.fromSource(src)
var map
src = convert.removeComments(src)
if (srcmap) {
map = srcmap.toObject()
}
debug('test files took %s to bundle', humanizeDuration(Date.now() - start))
cb(null, src, map)
})
}