MCPcopy
hub / github.com/postcss/postcss / runAsync

Method runAsync

lib/lazy-result.js:286–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

284 }
285
286 async runAsync() {
287 this.plugin = 0
288 for (let i = 0; i < this.plugins.length; i++) {
289 let plugin = this.plugins[i]
290 let promise = this.runOnRoot(plugin)
291 if (isPromise(promise)) {
292 try {
293 await promise
294 } catch (error) {
295 throw this.handleError(error)
296 }
297 }
298 }
299
300 this.prepareVisitors()
301 if (this.hasListener) {
302 let root = this.result.root
303 while (!root[isClean]) {
304 root[isClean] = true
305 let stack = [toStack(root)]
306 while (stack.length > 0) {
307 let promise = this.visitTick(stack)
308 if (isPromise(promise)) {
309 try {
310 await promise
311 } catch (e) {
312 let node = stack[stack.length - 1].node
313 throw this.handleError(e, node)
314 }
315 }
316 }
317 }
318
319 if (this.listeners.OnceExit) {
320 for (let [plugin, visitor] of this.listeners.OnceExit) {
321 this.result.lastPlugin = plugin
322 try {
323 if (root.type === 'document') {
324 let roots = root.nodes.map(subRoot =>
325 visitor(subRoot, this.helpers)
326 )
327
328 await Promise.all(roots)
329 } else {
330 await visitor(root, this.helpers)
331 }
332 } catch (e) {
333 throw this.handleError(e)
334 }
335 }
336 }
337 }
338
339 this.processed = true
340 return this.stringify()
341 }
342
343 runOnRoot(plugin) {

Callers 1

asyncMethod · 0.95

Calls 8

runOnRootMethod · 0.95
handleErrorMethod · 0.95
prepareVisitorsMethod · 0.95
visitTickMethod · 0.95
stringifyMethod · 0.95
isPromiseFunction · 0.85
toStackFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected