UNPKG

@tbela99/css-parser

Version:

CSS parser for node and the browser

42 lines (39 loc) 1.3 kB
import { EnumToken } from '../../ast/types.js'; import '../../ast/minify.js'; import '../../ast/walk.js'; import '../../parser/parse.js'; import '../../renderer/color/utils/constants.js'; import '../../renderer/sourcemap/lib/encode.js'; import '../../parser/utils/config.js'; function stripCommaToken(tokenList) { let result = []; let last = null; for (let i = 0; i < tokenList.length; i++) { if (tokenList[i].typ == EnumToken.CommaTokenType && last != null && last.typ == EnumToken.CommaTokenType) { return null; } if (tokenList[i].typ != EnumToken.WhitespaceTokenType) { last = tokenList[i]; } if (tokenList[i].typ == EnumToken.CommentTokenType || tokenList[i].typ == EnumToken.CommaTokenType) { continue; } result.push(tokenList[i]); } return result; } function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) { return tokenList.reduce((acc, curr) => { if (curr.typ == EnumToken.CommentTokenType) { return acc; } if (split.includes(curr.typ)) { acc.push([]); } else { acc[acc.length - 1].push(curr); } return acc; }, [[]]); } export { splitTokenList, stripCommaToken };