How to use the css-tree/data.types 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 prometheusresearch-archive / react-stylesheet / scripts / make-CSSType.js View on Github external
function buildType(syntax, key) {
  if (syntax.type === 'Sequence') {
    let types = syntax.terms.map(p => buildType(p, key));
    return t.unionTypeAnnotation(types);
  } else if (syntax.type === 'Keyword') {
    return t.stringLiteral(syntax.name);
  } else if (syntax.type === 'Function') {
    return t.identifier('string');
  } else if (syntax.type === 'Type') {
    let type = TYPE[syntax.name];
    if (type != null) {
      return type;
    } else if (cssData.types[syntax.name] != null) {
      return t.identifier(typeName(syntax.name));
    } else {
      console.log(key, syntax);
      throw new Error('Unknown type: ' + syntax.type);
    }
  } else if (syntax.type === 'Property') {
    return t.identifier(propertyName(syntax.name));
  } else if (syntax.type === 'Group') {
    return t.identifier('string');
  } else if (syntax.type === 'Parentheses') {
    return t.identifier('string');
  } else if (syntax.type === 'String') {
    return t.identifier('string');
  } else if (syntax.type === 'Percent') {
    return t.identifier('string');
  } else if (syntax.type === 'Comma') {