1 |
|
2 | import getArrayedString from './get-arrayed-string';
|
3 | import getClosestVariable from './get-closest-variable';
|
4 |
|
5 |
|
6 | export default function setVariable(node, name, value, opts) {
|
7 |
|
8 | if (!isDefault(value) || getClosestVariable(name, node, opts) === undefined) {
|
9 |
|
10 | const undefaultedValue = 'string' === typeof value ? getArrayedString(value.replace(matchDefault, ''), true) : value;
|
11 |
|
12 |
|
13 | node.variables = node.variables || {};
|
14 |
|
15 |
|
16 | node.variables[name] = undefaultedValue;
|
17 | }
|
18 | }
|
19 |
|
20 |
|
21 | const isDefault = value => matchDefault.test(value);
|
22 |
|
23 |
|
24 | const matchDefault = /\s+!default$/;
|