How to use pug-walk - 1 common examples

To help you get started, we’ve selected a few pug-walk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JPeer264 / node-rcs-core / lib / replace / pug.js View on Github external
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 }
        ))
      ))();

pug-walk

Walk and transform a pug AST

MIT
Latest version published 4 years ago

Package Health Score

77 / 100
Full package analysis

Popular pug-walk functions