AK-21/Graphite-Industrial-Intelligence
0
1'use strict'2 3let Container = require('./container')4 5let LazyResult, Processor6 7class Root extends Container {8 constructor(defaults) {9 super(defaults)10 this.type = 'root'11 if (!this.nodes) this.nodes = []12 }13 14 normalize(child, sample, type) {15 let nodes = super.normalize(child)16 17 if (sample) {18 if (type === 'prepend') {19 if (this.nodes.length > 1) {20 sample.raws.before = this.nodes[1].raws.before21 } else {22 delete sample.raws.before23 }24 } else if (this.first !== sample) {25 for (let node of nodes) {26 node.raws.before = sample.raws.before27 }28 }29 }30 31 return nodes32 }33 34 removeChild(child, ignore) {35 let index = this.index(child)36 37 if (!ignore && index === 0 && this.nodes.length > 1) {38 this.nodes[1].raws.before = this.nodes[index].raws.before39 }40 41 return super.removeChild(child)42 }43 44 toResult(opts = {}) {45 let lazy = new LazyResult(new Processor(), this, opts)46 return lazy.stringify()47 }48}49 50Root.registerLazyResult = dependant => {51 LazyResult = dependant52}53 54Root.registerProcessor = dependant => {55 Processor = dependant56}57 58module.exports = Root59Root.default = Root60 61Container.registerRoot(Root)62 