| 341 | } |
| 342 | |
| 343 | runOnRoot(plugin) { |
| 344 | this.result.lastPlugin = plugin |
| 345 | try { |
| 346 | if (typeof plugin === 'object' && plugin.Once) { |
| 347 | if (this.result.root.type === 'document') { |
| 348 | let roots = this.result.root.nodes.map(root => |
| 349 | plugin.Once(root, this.helpers) |
| 350 | ) |
| 351 | |
| 352 | if (isPromise(roots[0])) { |
| 353 | return Promise.all(roots) |
| 354 | } |
| 355 | |
| 356 | return roots |
| 357 | } |
| 358 | |
| 359 | return plugin.Once(this.result.root, this.helpers) |
| 360 | } else if (typeof plugin === 'function') { |
| 361 | return plugin(this.result.root, this.result) |
| 362 | } |
| 363 | } catch (error) { |
| 364 | throw this.handleError(error) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | stringify() { |
| 369 | if (this.error) throw this.error |