source: trip-planner-front/node_modules/postcss/lib/processor.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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