How to use the postcss.stringify function in postcss

To help you get started, we’ve selected a few postcss 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 salesforce / lwc / packages / @lwc / style-compiler / src / serialize.ts View on Github external
function serializeCss(
    result: postcss.LazyResult,
    collectVarFunctions: boolean,
    minify: boolean
): string {
    const tokens: Token[] = [];
    let currentRuleTokens: Token[] = [];
    let tmpHostExpression: string | null;

    // Walk though all nodes in the CSS...
    postcss.stringify(result.root, (part, node, nodePosition) => {
        // When consuming the beggining of a rule, first we tokenize the selector
        if (node && node.type === 'rule' && nodePosition === 'start') {
            currentRuleTokens.push(...tokenizeCssSelector(normalizeString(part)));

            // When consuming the end of a rule we normalize it and produce a new one
        } else if (node && node.type === 'rule' && nodePosition === 'end') {
            currentRuleTokens.push({ type: TokenType.text, value: part });
            currentRuleTokens = reduceTokens(currentRuleTokens);

            // If we are in fakeShadow we dont want to have :host selectors
            if ((node as any)._isHostNative) {
                // create an expression for all the tokens (concatenation of strings)
                // Save it so in the next rule we can apply a ternary
                tmpHostExpression = generateExpressionFromTokens(currentRuleTokens);
            } else if ((node as any)._isFakeNative) {
                const exprToken = generateExpressionFromTokens(currentRuleTokens);
github salesforce / lwc / packages / lwc-style-compiler / src / serialize.ts View on Github external
function serializeCss(result: postcss.LazyResult, collectVarFunctions: boolean, minify: boolean): string {
    const tokens: Token[] = [];
    let currentRuleTokens: Token[] = [];
    let tmpHostExpression: string | null;

    // Walk though all nodes in the CSS...
    postcss.stringify(result.root, (part, node, nodePosition) => {

        // When consuming the beggining of a rule, first we tokenize the selector
        if (node && node.type === 'rule' && nodePosition === 'start') {
            currentRuleTokens.push(...tokenizeCssSelector(normalizeString(part)));

        // When consuming the end of a rule we normalize it and produce a new one
        } else if (node && node.type === 'rule' && nodePosition === 'end') {
            currentRuleTokens.push({ type: TokenType.text, value: part });
            currentRuleTokens = reduceTokens(currentRuleTokens);

            // If we are in fakeShadow we dont want to have :host selectors
            if ((node as any)._isHostNative) {
                // create an expression for all the tokens (concatenation of strings)
                // Save it so in the next rule we can apply a ternary
                tmpHostExpression = generateExpressionFromTokens(currentRuleTokens);
            } else if ((node as any)._isFakeNative) {
github SerkanSipahi / app-decorators / packages / postcss-parse-atrule-events / src / index.js View on Github external
let stringifyAstNode = node => {

    if(!node || (node && !node.type)) {
        throw new Error('Failed: please pass AST node!');
    }

    let result = '';
    compiler.stringify(node, i => result += i);
    return result;
};
github parcel-bundler / parcel / packages / transformers / css / src / CSSTransformer.js View on Github external
async generate({asset}) {
    let code;
    if (!asset.ast || !asset.ast.isDirty) {
      code = await asset.getCode();
    } else {
      code = '';
      postcss.stringify(asset.ast.program, c => (code += c));
    }

    return {
      code
    };
  }
});
github parcel-bundler / parcel / src / transforms / css / src / CSSAsset.js View on Github external
render() {
    if (this.dirty) {
      this.css = '';
      postcss.stringify(this.root, c => (this.css += c));
    }

    return this.css;
  }
}
github uncss / uncss / src / uncss.js View on Github external
return uncss(pages, pcss, options.ignore).then(([css, rep]) => {
        let newCssStr = '';
        postcss.stringify(css, (result) => {
            newCssStr += result;
        });

        if (options.report) {
            report = {
                original: cssStr,
                selectors: rep
            };
        }
        return [newCssStr, report];
    });
}
github parcel-bundler / parcel / packages / transformers / postcss / src / PostCSSTransformer.js View on Github external
generate({asset}) {
    let ast = nullthrows(asset.ast);

    let code = '';
    postcss.stringify(ast.program, c => (code += c));

    return {
      code,
    };
  },
});