MCPcopy
hub / github.com/postcss/postcss / prepareVisitors

Method prepareVisitors

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

Source from the content-addressed store, hash-verified

246 }
247
248 prepareVisitors() {
249 this.listeners = {}
250 let add = (plugin, type, cb) => {
251 if (!this.listeners[type]) this.listeners[type] = []
252 this.listeners[type].push([plugin, cb])
253 }
254 for (let plugin of this.plugins) {
255 if (typeof plugin === 'object') {
256 for (let event in plugin) {
257 if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
258 throw new Error(
259 `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
260 `Try to update PostCSS (${this.processor.version} now).`
261 )
262 }
263 if (!NOT_VISITORS[event]) {
264 if (typeof plugin[event] === 'object') {
265 for (let filter in plugin[event]) {
266 if (filter === '*') {
267 add(plugin, event, plugin[event][filter])
268 } else {
269 add(
270 plugin,
271 event + '-' + filter.toLowerCase(),
272 plugin[event][filter]
273 )
274 }
275 }
276 } else if (typeof plugin[event] === 'function') {
277 add(plugin, event, plugin[event])
278 }
279 }
280 }
281 }
282 }
283 this.hasListener = Object.keys(this.listeners).length > 0
284 }
285
286 async runAsync() {
287 this.plugin = 0

Callers 2

runAsyncMethod · 0.95
syncMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected