How to use the postcss-js/parser function in postcss-js

To help you get started, we’ve selected a few postcss-js 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 emotion-js / emotion / packages / babel-plugin-emotion / src / parser.js View on Github external
export function parseCSS(
  css: string,
  extractStatic: boolean,
  filename: string
): {
  staticCSSRules: Array,
  styles: { [string]: any },
  composesCount: number
} {
  // todo - handle errors
  let root
  if (typeof css === 'object') {
    root = objParse(css, { from: filename })
  } else {
    root = parse(css, { from: filename })
  }
  let vars = 0
  let composes: number = 0

  root.walkDecls((decl: Decl): void => {
    if (decl.prop === 'composes') {
      if (!/xxx(\d+)xxx/gm.exec(decl.value)) {
        throw new Error('composes must be a interpolation')
      }
      if (decl.parent.nodes[0] !== decl) {
        throw new Error('composes must be the first rule')
      }
      if (decl.parent.type !== 'root') {
        throw new Error('composes cannot be on nested selectors')
github maximkoretskiy / postcss-autoreset / src / createResetRule.es6 View on Github external
function createResetRule(selectors, reset) {
  const selector = selectors.map(s => s.trim()).join(',\n');
  const resetRule = postcss.rule({
    selector,
    source,
    raws: {between: ' '}
  });
  const root = jsToCss(reset);
  root.each(node => node.source = resetRule.source);
  resetRule.append(root);
  return resetRule;
}

postcss-js

PostCSS for CSS-in-JS and styles in JS objects

MIT
Latest version published 2 years ago

Package Health Score

72 / 100
Full package analysis