(s: string)
| 82 | } |
| 83 | |
| 84 | function parse(s: string) { |
| 85 | let properties = new Map<string, string>(); |
| 86 | let i = 0; |
| 87 | while (i < s.length) { |
| 88 | while (i < s.length && s[i] === ' ') { |
| 89 | i++; |
| 90 | } |
| 91 | |
| 92 | let start = i; |
| 93 | readValue(); // property index |
| 94 | |
| 95 | // read conditions (up to the last segment) |
| 96 | let condition = i; |
| 97 | while (i < s.length && s[i] !== ' ') { |
| 98 | readValue(); |
| 99 | } |
| 100 | |
| 101 | let property = s.slice(start, condition); |
| 102 | if (process.env.NODE_ENV !== 'production' && property.startsWith('-macro-')) { |
| 103 | let value = s.slice(start, i); |
| 104 | properties.set(value, ' ' + value); |
| 105 | } else { |
| 106 | properties.set(property, (properties.get(property) || '') + ' ' + s.slice(start, i)); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | function readValue() { |
| 111 | if (s[i] === '-') { |
| 112 | // the beginning and end of arbitrary values are marked with - |
| 113 | while (i < s.length && s[i] !== ' ') { |
| 114 | i++; |
| 115 | if (s[i] === '-') { |
| 116 | i++; |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | } else { |
| 121 | while (i < s.length) { |
| 122 | if (s[i] === '_') { |
| 123 | i++; |
| 124 | } else { |
| 125 | i++; |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return properties; |
| 133 | } |
no test coverage detected