UNPKG

930 BJavaScriptView Raw
1/* eslint no-param-reassign: off */
2
3const afterPattern = /:$/;
4const beforePattern = /^:(\s+)?/;
5// const bracketsPattern = /\{/;
6
7module.exports = (node) => {
8 const { name, params = '' } = node;
9
10 // situations like @page :last { color: red } should default to the built-in AtRule
11 // LESS variables are @name : value; < note that for them to be valid LESS vars, they must end in
12 // a semicolon.
13
14 if (node.name.slice(-1) !== ':') {
15 return;
16 }
17
18 if (afterPattern.test(name)) {
19 const [match] = name.match(afterPattern);
20
21 node.name = name.replace(match, '');
22 node.raws.afterName = match + (node.raws.afterName || '');
23 node.variable = true;
24 node.value = node.params;
25 }
26
27 if (beforePattern.test(params)) {
28 const [match] = params.match(beforePattern);
29
30 node.value = params.replace(match, '');
31 node.raws.afterName = (node.raws.afterName || '') + match;
32 node.variable = true;
33 }
34};