Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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) {
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;
};
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
};
}
});
render() {
if (this.dirty) {
this.css = '';
postcss.stringify(this.root, c => (this.css += c));
}
return this.css;
}
}
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];
});
}
generate({asset}) {
let ast = nullthrows(asset.ast);
let code = '';
postcss.stringify(ast.program, c => (code += c));
return {
code,
};
},
});