MCPcopy Create free account
hub / github.com/antonk52/cssmodules-language-server / concatSelectors

Function concatSelectors

src/utils.ts:202–229  ·  view source on GitHub ↗
(
    parentSelectors: string[],
    nodeSelectors: string[],
)

Source from the content-addressed store, hash-verified

200const PostcssInst = postcss([]);
201
202const concatSelectors = (
203 parentSelectors: string[],
204 nodeSelectors: string[],
205): string[] => {
206 // if parent is AtRule
207 if (parentSelectors.length === 0) return nodeSelectors;
208
209 return ([] as string[]).concat(
210 ...parentSelectors.map(ps =>
211 nodeSelectors.map(
212 /**
213 * No need to replace for children separated by spaces
214 *
215 * .parent {
216 * color: red;
217 *
218 * & .child {
219 * ^^^^^^^^ no need to do the replace here,
220 * since no new classnames are created
221 * color: pink;
222 * }
223 * }
224 */
225 s => (/&[a-z0-1-_]/i.test(s) ? s.replace('&', ps) : s),
226 ),
227 ),
228 );
229};
230
231function getParentRule(node: Node): undefined | Node {
232 const {parent} = node;

Callers 1

filePathToClassnameDictFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected