@@ -5759,6 +5759,13 @@ function* tokenize(stream) {
57595759 buffer = '';
57605760 }
57615761 break;
5762+ case '&':
5763+ if (buffer.length > 0) {
5764+ yield pushToken(buffer, parseInfo);
5765+ buffer = '';
5766+ }
5767+ yield pushToken(value, parseInfo);
5768+ break;
57625769 case '<':
57635770 if (buffer.length > 0) {
57645771 yield pushToken(buffer, parseInfo);
@@ -60871,7 +60878,67 @@ function expandRule(node) {
6087160878 }
6087260879 }
6087360880 else {
60874- rule.sel = replaceCompound(rule.sel, ast.sel);
60881+ let childSelectorCompund = [];
60882+ let withCompound = [];
60883+ let withoutCompound = [];
60884+ const rules = splitRule(ast.sel);
60885+ for (const sel of (rule.raw ?? splitRule(rule.sel))) {
60886+ const s = sel.join('');
60887+ if (s.includes('&')) {
60888+ if (s.indexOf('&', 1) == -1) {
60889+ if (s.at(0) == '&') {
60890+ if (s.at(1) == ' ') {
60891+ childSelectorCompund.push(s.slice(2));
60892+ }
60893+ else {
60894+ if (s == '&') {
60895+ withCompound.push(s);
60896+ }
60897+ else {
60898+ withoutCompound.push(s.slice(1));
60899+ }
60900+ }
60901+ }
60902+ }
60903+ else {
60904+ withCompound.push(s);
60905+ }
60906+ }
60907+ else {
60908+ withoutCompound.push(s);
60909+ }
60910+ }
60911+ const selectors = [];
60912+ const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
60913+ if (childSelectorCompund.length > 0) {
60914+ if (childSelectorCompund.length == 1) {
60915+ selectors.push(replaceCompound('& ' + childSelectorCompund[0].trim(), selector));
60916+ }
60917+ else {
60918+ selectors.push(replaceCompound('& :is(' + childSelectorCompund.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.trim(), '') + ')', selector));
60919+ }
60920+ }
60921+ if (withoutCompound.length > 0) {
60922+ if (withoutCompound.length == 1) {
60923+ const useIs = rules.length == 1 && selector.match(/^[a-zA-Z.:]/) != null && selector.includes(' ') && withoutCompound.length == 1 && withoutCompound[0].match(/^[a-zA-Z]+$/) != null;
60924+ const compound = useIs ? ':is(&)' : '&';
60925+ selectors.push(replaceCompound(rules.length == 1 ? (useIs ? withoutCompound[0] + ':is(&)' : (selector.match(/^[.:]/) && withoutCompound[0].match(/^[a-zA-Z]+$/) ? withoutCompound[0] + compound : compound + withoutCompound[0])) : (withoutCompound[0].match(/^[a-zA-Z:]+$/) ? withoutCompound[0].trim() + compound : '&' + (withoutCompound[0].match(/^\S+$/) ? withoutCompound[0].trim() : ':is(' + withoutCompound[0].trim() + ')')), selector));
60926+ }
60927+ else {
60928+ selectors.push(replaceCompound('&:is(' + withoutCompound.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.trim(), '') + ')', selector));
60929+ }
60930+ }
60931+ if (withCompound.length > 0) {
60932+ if (withCompound.length == 1) {
60933+ selectors.push(replaceCompound(withCompound[0], selector));
60934+ }
60935+ else {
60936+ for (const w of withCompound) {
60937+ selectors.push(replaceCompound(w, selector));
60938+ }
60939+ }
60940+ }
60941+ rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
6087560942 }
6087660943 ast.chi.splice(i--, 1);
6087760944 result.push(...expandRule(rule));
@@ -63343,12 +63410,25 @@ async function load(url, currentFile) {
6334363410 return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : promises.readFile(resolved.absolute, { encoding: 'utf-8' });
6334463411}
6334563412
63413+ /**
63414+ * entry point for node and other runtimes
63415+ * @module
63416+ */
63417+ /**
63418+ * render ast node
63419+ */
6334663420function render(data, options = {}) {
6334763421 return doRender(data, Object.assign(options, { load, resolve, dirname, cwd: options.cwd ?? process.cwd() }));
6334863422}
63423+ /**
63424+ * parse css
63425+ */
6334963426async function parse(iterator, opt = {}) {
6335063427 return doParse(iterator, Object.assign(opt, { load, resolve, dirname, cwd: opt.cwd ?? process.cwd() }));
6335163428}
63429+ /**
63430+ * parse and render css
63431+ */
6335263432async function transform(css, options = {}) {
6335363433 options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
6335463434 const startTime = performance.now();
0 commit comments