UNPKG

@tbela99/css-parser

Version:

CSS parser for node and the browser

47 lines (44 loc) 1.41 kB
import { PropertyList } from '../../parser/declaration/list.js'; import { EnumToken } from '../types.js'; import '../minify.js'; import '../walk.js'; import '../../parser/parse.js'; import '../../renderer/color/utils/constants.js'; import '../../renderer/sourcemap/lib/encode.js'; import '../../parser/utils/config.js'; class ComputeShorthandFeature { static get ordering() { return 2; } static register(options) { if (options.computeShorthand) { for (const feature of options.features) { if (feature instanceof ComputeShorthandFeature) { return; } } // @ts-ignore options.features.push(new ComputeShorthandFeature(options)); } } run(ast, options = {}, parent, context) { // @ts-ignore const j = ast.chi.length; let k = 0; let properties = new PropertyList(options); // @ts-ignore for (; k < j; k++) { // @ts-ignore const node = ast.chi[k]; if (node.typ == EnumToken.CommentNodeType || node.typ == EnumToken.DeclarationNodeType) { properties.add(node); continue; } break; } // @ts-ignore ast.chi = [...properties].concat(ast.chi.slice(k)); return ast; } } export { ComputeShorthandFeature };