Skip to content

Commit dc5ba19

Browse files
author
Timothy Lindvall
committed
fix: Addl. block-interface-index error case.
It's an error if a given rule in a definition file with a block-interface-index declared has more than one selector.
1 parent 92a5b25 commit dc5ba19

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/@css-blocks/core/src/BlockParser/features/add-interface-indexes.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ export function addInterfaceIndexes(configuration: Configuration, root: postcss.
5959

6060
// Set the index on the related style node.
6161
const parsedSelectors = block.getParsedSelectors(rule);
62-
parsedSelectors.forEach(sel => {
62+
if (parsedSelectors.length > 1) {
63+
// It's an error if there's more than one selector on a node that has block-interface-index.
64+
block.addError(
65+
new CssBlockError(
66+
"A rule that has a defined block-interface-index can't have more than one selector.",
67+
sourceRange(configuration, root, file, rule),
68+
),
69+
);
70+
} else {
71+
const sel = parsedSelectors[0];
6372
const styleTarget = getStyleTargets(block, sel.key);
6473
if (styleTarget.blockAttrs.length > 0) {
6574
styleTarget.blockAttrs[0].index = parsedIndex;
@@ -68,7 +77,7 @@ export function addInterfaceIndexes(configuration: Configuration, root: postcss.
6877
} else {
6978
throw new Error(`Couldn\'t find style node corresponding to selector ${sel}. This shouldn't happen.`);
7079
}
71-
});
80+
}
7281
});
7382
});
7483

0 commit comments

Comments
 (0)