How to use pug-lexer - 5 common examples

To help you get started, we’ve selected a few pug-lexer 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
}

        return block;
      });
      const newCode = wrap((
        generateCode((
          { ...node.block, nodes: modifiedBlockNodes }
        ))
      ))();
      const replacedCode = node.name === 'script'
        ? replaceJs(newCode, merge(options.espreeOptions, { sourceFile: opts.sourceFile }))
        : replaceCss(newCode, { sourceFile: opts.sourceFile });

      // add one tab after each new line
      const pugCode = `${node.name}.\n${replacedCode}`.replace(/\n/g, '\n\t');
      const astReplaced = parser(lex(pugCode));
      const scriptBlock = astReplaced.nodes[0].block;

      // do not change entire scriptBlock
      // this might be look like the correct ast,
      // but the begin and end loc numbers are wrong
      // eslint-disable-next-line no-param-reassign
      node.block.nodes = node.block.nodes.map((n, i) => {
        const { val, type } = scriptBlock.nodes[i];

        return { ...n, val, type };
      });
    }

    if (Array.isArray(node.attrs) && node.attrs.length >= 0) {
      node.attrs.forEach((attr) => {
        let selectorType;
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
github shidhincr / pug-to-html / src / api.js View on Github external
export function compilePugTemplate(str = '', locals = {}) {
  try {
    let funcStr = generateCode(parse(lex(str)), {
      compileDebug: false,
      pretty: true,
      inlineRuntimeFunctions: false,
      templateName: '_parse'
    });
    let func = wrap(funcStr, '_parse');
    return func(locals);
  } catch (e) {
    return `Compile Error: ${e.message}`;
  }
}
github FullHuman / purgecss / packages / purgecss-from-pug / lib / purgecss-from-pug.esm.js View on Github external
export default e => {
  const s = a(e),
    t = [];
  for (const a of s)
    switch (a.type) {
      case "tag":
      case "id":
      case "class":
        t.push(a.val);
        break;
      case "attribute":
        ("class" !== a.name && "id" !== a.name) ||
          t.push(a.mustEscape ? a.val.replace(/"/g, "") : a.val);
    }
  return t;
};
github pugjs / babel-plugin-transform-react-pug / src / parse-pug.js View on Github external
export default function(str) {
  return filters.handleFilters(
    parse(
      stripComments(lex(str), {stripUnbuffered: true, stripBuffered: true}),
    ),
  );
}

pug-lexer

The pug lexer (takes a string and converts it to an array of tokens)

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis

Popular pug-lexer functions