2 failing tests

pull/9549/head
Albert 3 years ago
parent 0708f16f3c
commit eef0b3bf6c
No known key found for this signature in database
GPG Key ID: 639EBA2F18800B0E

@ -988,7 +988,7 @@ function group_selectors(selector, parent_blocks_group) {
// If it isn't a nested rule, then we add an empty block group // If it isn't a nested rule, then we add an empty block group
if (parent_blocks_group === null) { if (parent_blocks_group === null) {
return [ return [
selector_to_blocks(selector, null, false).map((block) => new BlockUse(block, true)) selector_to_blocks(selector, false).map((block) => new BlockUse(block, true))
]; ];
} }
@ -996,6 +996,10 @@ function group_selectors(selector, parent_blocks_group) {
// or at the front if there is no `&` selector // or at the front if there is no `&` selector
// TODO: handle multiple `&` selectors // TODO: handle multiple `&` selectors
let nested_rule_index = selector.children.findIndex((child) => child.type === 'NestingSelector'); let nested_rule_index = selector.children.findIndex((child) => child.type === 'NestingSelector');
let is_next_combinator = selector.children[nested_rule_index + 1]?.type === 'Combinator';
console.log("selector", JSON.stringify(selector, null, 2))
console.log("=========")
// if there is no `&` selector, we need to add a fake combinator at the start // if there is no `&` selector, we need to add a fake combinator at the start
if (nested_rule_index === -1) { if (nested_rule_index === -1) {
@ -1009,8 +1013,7 @@ function group_selectors(selector, parent_blocks_group) {
// Create the new blocks for the nested rule, visible by default // Create the new blocks for the nested rule, visible by default
const blocks = selector_to_blocks( const blocks = selector_to_blocks(
selector, selector,
nested_rule_index === 0 ? null : FakeCombinator, true
false
); );
return parent_blocks_group.map(parent_blocks => { return parent_blocks_group.map(parent_blocks => {
@ -1023,6 +1026,8 @@ function group_selectors(selector, parent_blocks_group) {
// insert the parent blocks at the position of the `&` selector // insert the parent blocks at the position of the `&` selector
block_uses.splice(nested_rule_index, 0, ...parent_block_uses); block_uses.splice(nested_rule_index, 0, ...parent_block_uses);
console.log(JSON.stringify(block_uses.map(b => b.block), null, 2))
return block_uses; return block_uses;
}) })
} }
@ -1030,13 +1035,14 @@ function group_selectors(selector, parent_blocks_group) {
/** /**
* @param {import('#compiler').Css.Selector} selector * @param {import('#compiler').Css.Selector} selector
* @param {import('../../../types/css.js').Combinator | null} combinator
* @param {boolean} allow_nesting * @param {boolean} allow_nesting
*/ */
function selector_to_blocks(selector, combinator, allow_nesting) { function selector_to_blocks(selector, allow_nesting) {
let block = new Block(combinator); const is_next_combinator = selector.children[0]?.type === 'Combinator';
const combinator = is_next_combinator ? selector.children.shift() : null;
let block = new Block(/** @type {import('#compiler').Css.Combinator | null} */ (combinator));
const blocks = [block]; const blocks = [block];
selector.children.forEach((child) => { selector.children.map(child => {
if (child.type === 'Combinator') { if (child.type === 'Combinator') {
block = new Block(child); block = new Block(child);
blocks.push(block); blocks.push(block);

Loading…
Cancel
Save