Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const replacePug = (code, opts = {}) => {
const lexed = lex(code);
const ast = parser(lexed);
const defaultOptions = {
espreeOptions: {},
triggerClassAttributes: [],
triggerIdAttributes: [],
};
const options = merge(opts, defaultOptions);
walk(ast, (node) => {
if (node.name === 'script' || node.name === 'style') {
const modifiedBlockNodes = node.block.nodes.map((block) => {
if (block.type === 'Code') {
// eslint-disable-next-line no-param-reassign
block.type = 'Text';
// eslint-disable-next-line no-param-reassign
block.val = `#{${block.val}}`;
}
return block;
});
const newCode = wrap((
generateCode((
{ ...node.block, nodes: modifiedBlockNodes }
))
))();