source: imaps-frontend/node_modules/postcss/lib/processor.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1'use strict'
2
3let NoWorkResult = require('./no-work-result')
4let LazyResult = require('./lazy-result')
5let Document = require('./document')
6let Root = require('./root')
7
8class Processor {
9 constructor(plugins = []) {
10 this.version = '8.4.40'
11 this.plugins = this.normalize(plugins)
12 }
13
14 normalize(plugins) {
15 let normalized = []
16 for (let i of plugins) {
17 if (i.postcss === true) {
18 i = i()
19 } else if (i.postcss) {
20 i = i.postcss
21 }
22
23 if (typeof i === 'object' && Array.isArray(i.plugins)) {
24 normalized = normalized.concat(i.plugins)
25 } else if (typeof i === 'object' && i.postcssPlugin) {
26 normalized.push(i)
27 } else if (typeof i === 'function') {
28 normalized.push(i)
29 } else if (typeof i === 'object' && (i.parse || i.stringify)) {
30 if (process.env.NODE_ENV !== 'production') {
31 throw new Error(
32 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
33 'one of the syntax/parser/stringifier options as outlined ' +
34 'in your PostCSS runner documentation.'
35 )
36 }
37 } else {
38 throw new Error(i + ' is not a PostCSS plugin')
39 }
40 }
41 return normalized
42 }
43
44 process(css, opts = {}) {
45 if (
46 !this.plugins.length &&
47 !opts.parser &&
48 !opts.stringifier &&
49 !opts.syntax
50 ) {
51 return new NoWorkResult(this, css, opts)
52 } else {
53 return new LazyResult(this, css, opts)
54 }
55 }
56
57 use(plugin) {
58 this.plugins = this.plugins.concat(this.normalize([plugin]))
59 return this
60 }
61}
62
63module.exports = Processor
64Processor.default = Processor
65
66Root.registerProcessor(Processor)
67Document.registerProcessor(Processor)
Note: See TracBrowser for help on using the repository browser.