Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lines
.slice(Math.max(0, lineNumber - 3), lineNumber + 2)
.join("\n| ");
}
throw err;
}
const scopeManager = eslintScope.analyze(ast, {
ecmaVersion: 6,
sourceType: "module",
optimistic: true,
ignoreEval: true,
impliedStrict: true
});
const globalScope = scopeManager.acquire(ast);
const moduleScope = globalScope.childScopes[0];
const resultSource = new ReplaceSource(source);
info.ast = ast;
info.internalSource = source;
info.source = resultSource;
info.globalScope = globalScope;
info.moduleScope = moduleScope;
}
}
// List of all used names to avoid conflicts
const allUsedNames = new Set([
"__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name
"abstract",
"arguments",
"async",
"await",
function buildInjector(polyfills, src) {
const injectorRaw = loadFileAsSource('./injector.js');
const injector = new ReplaceSource(injectorRaw);
// Replace __TEST__
const testPosition = injectorRaw.source().indexOf('__TEST__');
injector.replace(testPosition, testPosition + 7,
polyfills.map(polyfill =>
`/* ${polyfill.replace(/\//g, '.')} */!(` +
loadFileAsString(`polyfill-service/polyfills/${polyfill}/detect.js`) +
')'
).join('\n || ')
);
// Replace __SRC__
const srcPosition = injectorRaw.source().indexOf('__SRC__');
injector.replace(srcPosition, srcPosition + 6, JSON.stringify(src));
return injector;
// Less accurate fallback
// parse5 4.x does not provide locations if malformed html is present
scriptInsertionPoint = params.inputContent.indexOf('');
}
let styleInsertionPoint;
if (headElement.__location && headElement.__location.endTag) {
styleInsertionPoint = headElement.__location.endTag.startOffset;
} else {
// Less accurate fallback
// parse5 4.x does not provide locations if malformed html is present
styleInsertionPoint = params.inputContent.indexOf('');
}
// Inject into the html
const indexSource = new ReplaceSource(
new RawSource(params.inputContent),
params.input
);
let scriptElements = '';
for (const script of scripts) {
const attrs: { name: string; value: string | null }[] = [
{ name: 'src', value: (params.deployUrl || '') + script }
];
if (crossOrigin !== 'none') {
attrs.push({ name: 'crossorigin', value: crossOrigin });
}
// We want to include nomodule or module when a file is not common amongs all
// such as runtime.js
expressionSource(dependencyTemplates, runtimeTemplate) {
const source = new ReplaceSource(new RawSource(this.expression));
for (const dep of this.dependencies) {
const template = dependencyTemplates.get(dep.constructor);
if (!template) {
throw new Error(`No template for dependency: ${dep.constructor.name}`);
}
template.apply(dep, source, runtimeTemplate, dependencyTemplates);
}
return source;
}
generate(module, dependencyTemplates, runtimeTemplate) {
const originalSource = module.originalSource();
if (!originalSource) {
return new RawSource("throw new Error('No source available');");
}
const source = new ReplaceSource(originalSource);
this.sourceBlock(
module,
module,
[],
dependencyTemplates,
source,
runtimeTemplate
);
return source;
}
function replaceAll(source, name, oldStr, newStr) {
const transformedSource = new ReplaceSource(source, name);
const reTester = new RegExp(oldStr, 'g');
let reResult = reTester.exec(source.source());
if (reResult == null) {
return source;
}
while (reResult != null) {
transformedSource.replace(
reResult.index,
reTester.lastIndex - 1,
newStr
);
reResult = reTester.exec(source.source());
}
expressionSource(dependencyTemplates, outputOptions, requestShortener) {
const source = new ReplaceSource(new RawSource(this.expression));
this.dependencies.forEach(dep => {
const template = dependencyTemplates.get(dep.constructor);
if(!template) throw new Error(`No template for dependency: ${dep.constructor.name}`);
template.apply(dep, source, outputOptions, requestShortener, dependencyTemplates);
});
return source;
}
module.buildInfo.optimize.minify
)
: `""`;
this.reportDiagnostics(meta);
const depth = module.buildInfo.runtimeInfo.depth;
const id =
this.options.runtimeStylesheetId === 'namespace'
? JSON.stringify(module.buildInfo.stylableMeta.namespace)
: runtimeTemplate.moduleId({
module,
request: module.request
});
return new ReplaceSource(
this.createModuleSource(
module,
id,
stylableResult,
css,
depth,
!isImportedByNonStylable
)
);
}
public transform(module: StylableModule) {
function purify(content) {
const rawSource = new webpack_sources_1.RawSource(content);
const replaceSource = new webpack_sources_1.ReplaceSource(rawSource, 'file.js');
const inserts = purifyReplacements(content);
inserts.forEach((insert) => {
replaceSource.insert(insert.pos, insert.content);
});
return replaceSource.source();
}
exports.purify = purify;