How to use the css-tree.lexer function in css-tree

To help you get started, we’ve selected a few css-tree 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 pocketjoso / penthouse / src / postformatting / unused-fontface-remover.js View on Github external
enter: function (node) {
      // walker pass through `font-family` declarations inside @font-face too
      // this condition filters them, to walk through declarations inside a rules only
      if (this.rule) {
        csstree.lexer
          .findDeclarationValueFragments(node, 'Type', 'family-name')
          .forEach(entry => {
            const familyName = decodeFontName({
              type: 'Value',
              children: entry.nodes
            })
            if (!fontNameValues.has(familyName)) {
              debuglog('found used font-family: ' + familyName)
              fontNameValues.add(familyName)
            }
          })
      }
    }
  })
github css / csso / lib / replace / Percentage.js View on Github external
var lexer = require('css-tree').lexer;
var packNumber = require('./Number').pack;
var blacklist = new Set([
    // see https://github.com/jakubpawlowicz/clean-css/issues/957
    'width',
    'min-width',
    'max-width',
    'height',
    'min-height',
    'max-height'
]);

module.exports = function compressPercentage(node, item) {
    node.value = packNumber(node.value, item);

    if (node.value === '0' && this.declaration && !blacklist.has(this.declaration.property)) {
        // try to convert a number
github peterbe / minimalcss / src / run.js View on Github external
const postProcessOptimize = ast => {
  // First walk the AST to know which animations are ever mentioned
  // by the remaining rules.
  const activeAnimationNames = new Set(
    csstree.lexer
      .findAllFragments(ast, 'Type', 'keyframes-name')
      .map(entry => csstree.generate(entry.nodes.first()))
  );

  // This is the function we use to filter @keyframes atrules out,
  // if its name is not actively used.
  // It also filters out all `@media print` atrules.
  csstree.walk(ast, {
    visit: 'Atrule',
    enter: (node, item, list) => {
      const basename = csstree.keyword(node.name).basename;
      if (basename === 'keyframes') {
        if (!activeAnimationNames.has(csstree.generate(node.prelude))) {
          list.remove(item);
        }
      } else if (basename === 'media') {
github css / csso / lib / replace / color.js View on Github external
var lexer = require('css-tree').lexer;
var packNumber = require('./Number').pack;

// http://www.w3.org/TR/css3-color/#svg-color
var NAME_TO_HEX = {
    'aliceblue': 'f0f8ff',
    'antiquewhite': 'faebd7',
    'aqua': '0ff',
    'aquamarine': '7fffd4',
    'azure': 'f0ffff',
    'beige': 'f5f5dc',
    'bisque': 'ffe4c4',
    'black': '000',
    'blanchedalmond': 'ffebcd',
    'blue': '00f',
    'blueviolet': '8a2be2',
    'brown': 'a52a2a',
github peterbe / minimalcss / src / run.js View on Github external
enter: function(node) {
      // walker pass through `font-family` declarations inside @font-face too
      // this condition filter them, to walk through declarations
      // inside a rules only.
      if (this.rule) {
        csstree.lexer
          .findDeclarationValueFragments(node, 'Type', 'family-name')
          .forEach(entry => {
            const name = utils.unquoteString(
              csstree.generate({
                type: 'Value',
                children: entry.nodes
              })
            );
            activeFontFamilyNames.add(name);
          });
      }
    }
  });
github csstree / validator / lib / validate.js View on Github external
var fs = require('fs');
var path = require('path');
var csstree = require('css-tree');
var syntax = csstree.lexer;

function defaultShouldBeValidated(filename) {
    return path.extname(filename) === '.css';
}

function collectFiles(testPath, shouldBeValidated) {
    try {
        if (fs.statSync(testPath).isDirectory()) {
            return fs.readdirSync(testPath).reduce(function(result, dirFilename) {
                return result.concat(collectFiles(path.join(testPath, dirFilename), shouldBeValidated));
            }, []);
        } else {
            return shouldBeValidated(testPath) ? [testPath] : [];
        }
    } catch (e) {
        return [testPath];