source: frontend/node_modules/postcss/lib/no-work-result.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.6 KB
Line 
1'use strict'
2
3let MapGenerator = require('./map-generator')
4let parse = require('./parse')
5let Result = require('./result')
6let stringify = require('./stringify')
7let warnOnce = require('./warn-once')
8
9class NoWorkResult {
10 get content() {
11 return this.result.css
12 }
13
14 get css() {
15 return this.result.css
16 }
17
18 get map() {
19 return this.result.map
20 }
21
22 get messages() {
23 return []
24 }
25
26 get opts() {
27 return this.result.opts
28 }
29
30 get processor() {
31 return this.result.processor
32 }
33
34 get root() {
35 if (this._root) {
36 return this._root
37 }
38
39 let root
40 let parser = parse
41
42 try {
43 root = parser(this._css, this._opts)
44 } catch (error) {
45 this.error = error
46 }
47
48 if (this.error) {
49 throw this.error
50 } else {
51 this._root = root
52 return root
53 }
54 }
55
56 get [Symbol.toStringTag]() {
57 return 'NoWorkResult'
58 }
59
60 constructor(processor, css, opts) {
61 css = css.toString()
62 this.stringified = false
63
64 this._processor = processor
65 this._css = css
66 this._opts = opts
67 this._map = undefined
68
69 let str = stringify
70 this.result = new Result(this._processor, undefined, this._opts)
71 this.result.css = css
72
73 let self = this
74 Object.defineProperty(this.result, 'root', {
75 get() {
76 return self.root
77 }
78 })
79
80 let map = new MapGenerator(str, undefined, this._opts, css)
81 if (map.isMap()) {
82 let [generatedCSS, generatedMap] = map.generate()
83 if (generatedCSS) {
84 this.result.css = generatedCSS
85 }
86 if (generatedMap) {
87 this.result.map = generatedMap
88 }
89 } else {
90 map.clearAnnotation()
91 this.result.css = map.css
92 }
93 }
94
95 async() {
96 if (this.error) return Promise.reject(this.error)
97 return Promise.resolve(this.result)
98 }
99
100 catch(onRejected) {
101 return this.async().catch(onRejected)
102 }
103
104 finally(onFinally) {
105 return this.async().then(onFinally, onFinally)
106 }
107
108 sync() {
109 if (this.error) throw this.error
110 return this.result
111 }
112
113 then(onFulfilled, onRejected) {
114 if (process.env.NODE_ENV !== 'production') {
115 if (!('from' in this._opts)) {
116 warnOnce(
117 'Without `from` option PostCSS could generate wrong source map ' +
118 'and will not find Browserslist config. Set it to CSS file path ' +
119 'or to `undefined` to prevent this warning.'
120 )
121 }
122 }
123
124 return this.async().then(onFulfilled, onRejected)
125 }
126
127 toString() {
128 return this._css
129 }
130
131 warnings() {
132 return []
133 }
134}
135
136module.exports = NoWorkResult
137NoWorkResult.default = NoWorkResult
Note: See TracBrowser for help on using the repository browser.