MCPcopy
hub / github.com/postcss/postcss / insertBefore

Method insertBefore

lib/container.js:163–185  ·  view source on GitHub ↗
(exist, add)

Source from the content-addressed store, hash-verified

161 }
162
163 insertBefore(exist, add) {
164 let existIndex = this.index(exist)
165 let type = existIndex === 0 ? 'prepend' : false
166 let nodes = this.normalize(
167 add,
168 this.proxyOf.nodes[existIndex],
169 type
170 ).reverse()
171 existIndex = this.index(exist)
172 for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
173
174 let index
175 for (let id in this.indexes) {
176 index = this.indexes[id]
177 if (existIndex <= index) {
178 this.indexes[id] = index + nodes.length
179 }
180 }
181
182 this.markDirty()
183
184 return this
185 }
186
187 normalize(nodes, sample) {
188 if (typeof nodes === 'string') {

Callers 4

beforeMethod · 0.80
cloneBeforeMethod · 0.80
replaceWithMethod · 0.80
container.test.tsFile · 0.80

Calls 3

indexMethod · 0.95
normalizeMethod · 0.95
markDirtyMethod · 0.80

Tested by

no test coverage detected