(nodes, sample)
| 185 | } |
| 186 | |
| 187 | normalize(nodes, sample) { |
| 188 | if (typeof nodes === 'string') { |
| 189 | nodes = cleanSource(parse(nodes).nodes) |
| 190 | } else if (typeof nodes === 'undefined') { |
| 191 | nodes = [] |
| 192 | } else if (Array.isArray(nodes)) { |
| 193 | nodes = nodes.slice(0) |
| 194 | for (let i of nodes) { |
| 195 | if (i.parent) i.parent.removeChild(i, 'ignore') |
| 196 | } |
| 197 | } else if (nodes.type === 'root' && this.type !== 'document') { |
| 198 | nodes = nodes.nodes.slice(0) |
| 199 | for (let i of nodes) { |
| 200 | if (i.parent) i.parent.removeChild(i, 'ignore') |
| 201 | } |
| 202 | } else if (nodes.type) { |
| 203 | nodes = [nodes] |
| 204 | } else if (nodes.prop) { |
| 205 | if (typeof nodes.value === 'undefined') { |
| 206 | throw new Error('Value field is missed in node creation') |
| 207 | } else if (typeof nodes.value !== 'string') { |
| 208 | nodes.value = String(nodes.value) |
| 209 | } |
| 210 | nodes = [new Declaration(nodes)] |
| 211 | } else if (nodes.selector || nodes.selectors) { |
| 212 | nodes = [new Rule(nodes)] |
| 213 | } else if (nodes.name) { |
| 214 | nodes = [new AtRule(nodes)] |
| 215 | } else if (nodes.text) { |
| 216 | nodes = [new Comment(nodes)] |
| 217 | } else { |
| 218 | throw new Error('Unknown node type in node creation') |
| 219 | } |
| 220 | |
| 221 | let processed = nodes.map(i => { |
| 222 | /* c8 ignore next */ |
| 223 | if (!i[my]) Container.rebuild(i) |
| 224 | i = i.proxyOf |
| 225 | if (i.parent) i.parent.removeChild(i) |
| 226 | if (i[isClean]) markTreeDirty(i) |
| 227 | |
| 228 | if (!i.raws) i.raws = {} |
| 229 | if (typeof i.raws.before === 'undefined') { |
| 230 | if (sample && typeof sample.raws.before !== 'undefined') { |
| 231 | i.raws.before = sample.raws.before.replace(/\S/g, '') |
| 232 | } |
| 233 | } |
| 234 | i.parent = this.proxyOf |
| 235 | return i |
| 236 | }) |
| 237 | |
| 238 | return processed |
| 239 | } |
| 240 | |
| 241 | prepend(...children) { |
| 242 | children = children.reverse() |
no test coverage detected