Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import test from 'ava';
import uglify from 'uglify-js';
import sinon from 'sinon';
import tmpFile from '../../lib/tmp-file';
import cache from '../../lib/cache';
import { RawSource, OriginalSource } from 'webpack-sources';
const codeSource = 'function test () { void(0); }';
const rawSource = new RawSource(codeSource);
const originalSource = new OriginalSource(codeSource);
const sourceAndMap = rawSource.sourceAndMap();
const options = {
uglifyJS: { },
};
const originalContent = JSON.stringify({
source: sourceAndMap.source,
map: sourceAndMap.map,
options,
});
const minifiedContent = uglify.minify(codeSource, { });
// ava is multi process and uses process.on,
// so we stub it to be sure it doesn't get in the way.
const stubbedOn = sinon.stub(process, 'on');
const worker = require('../../lib/worker');
const { minify, processMessage } = worker;
render(hash, chunk, moduleTemplate, dependencyTemplates) {
const buf = [];
buf.push(this.applyPluginsWaterfall("bootstrap", "", chunk, hash, moduleTemplate, dependencyTemplates));
buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
buf.push("");
buf.push("// The require function");
buf.push(`function ${this.requireFn}(moduleId) {`);
buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
buf.push("}");
buf.push("");
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
buf.push("");
buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
if(chunk.hasEntryModule()) {
source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
}
if(!source) throw new Error("Compiler error: MainTemplate plugin 'render' should return something");
chunk.rendered = true;
return new ConcatSource(source, ";");
}
render(hash, chunk, moduleTemplate, dependencyTemplates) {
const buf = this.renderBootstrap(
hash,
chunk,
moduleTemplate,
dependencyTemplates
);
let source = this.hooks.render.call(
new OriginalSource(
Template.prefix(buf, " \t") + "\n",
"webpack/bootstrap"
),
chunk,
hash,
moduleTemplate,
dependencyTemplates
);
if (chunk.hasEntryModule()) {
source = this.hooks.renderWithEntry.call(source, chunk, hash);
}
if (!source) {
throw new Error(
"Compiler error: MainTemplate plugin 'render' should return something"
);
}
}
let amdFactory;
if(optionalExternals.length > 0) {
const wrapperArguments = externalsArguments(requiredExternals);
const factoryArguments = requiredExternals.length > 0 ?
externalsArguments(requiredExternals) + ", " + externalsRootArray(optionalExternals) :
externalsRootArray(optionalExternals);
amdFactory = `function webpackLoadOptionalExternalModuleAmd(${wrapperArguments}) {\n` +
` return factory(${factoryArguments});\n` +
" }";
} else {
amdFactory = "factory";
}
return new ConcatSource(new OriginalSource(
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
(this.auxiliaryComment &&
typeof this.auxiliaryComment === "string" ?
" //" + this.auxiliaryComment + "\n" :
this.auxiliaryComment.commonjs2 ?
" //" + this.auxiliaryComment.commonjs2 + "\n" :
""
) +
" if(typeof exports === 'object' && typeof module === 'object')\n" +
" module.exports = factory(" + externalsRequireArray("commonjs2") + ");\n" +
(this.auxiliaryComment &&
typeof this.auxiliaryComment === "string" ?
" //" + this.auxiliaryComment + "\n" :
this.auxiliaryComment.amd ?
" //" + this.auxiliaryComment.amd + "\n" :
""
getSource(sourceString) {
if(this.useSourceMap) {
return new OriginalSource(sourceString, this.identifier());
}
return new RawSource(sourceString);
}
getSource(sourceString) {
if(this.useSourceMap) {
return new OriginalSource(sourceString, this.identifier());
}
return new RawSource(sourceString);
}
createSourceForAsset(name, content, sourceMap) {
if (!sourceMap) {
return new RawSource(content);
}
if (typeof sourceMap === "string") {
return new OriginalSource(content, sourceMap);
}
return new SourceMapSource(content, name, sourceMap);
}
getSource(sourceString) {
if(this.useSourceMap) {
return new OriginalSource(sourceString, this.identifier());
}
return new RawSource(sourceString);
}
return new LineToLineMappedSource(
source,
identifier,
asString(resourceBuffer)
);
}
if (this.useSourceMap && sourceMap) {
return new SourceMapSource(source, identifier, sourceMap);
}
if (Buffer.isBuffer(source)) {
return new RawSource(source);
}
return new OriginalSource(source, identifier);
}