MCPcopy
hub / github.com/postcss/postcss / constructor

Method constructor

lib/lazy-result.js:140–186  ·  view source on GitHub ↗
(processor, css, opts)

Source from the content-addressed store, hash-verified

138 }
139
140 constructor(processor, css, opts) {
141 this.stringified = false
142 this.processed = false
143
144 let root
145 if (
146 typeof css === 'object' &&
147 css !== null &&
148 (css.type === 'root' || css.type === 'document')
149 ) {
150 root = cleanMarks(css)
151 } else if (css instanceof LazyResult || css instanceof Result) {
152 root = cleanMarks(css.root)
153 if (css.map) {
154 if (typeof opts.map === 'undefined') opts.map = {}
155 if (!opts.map.inline) opts.map.inline = false
156 opts.map.prev = css.map
157 }
158 } else {
159 let parser = parse
160 if (opts.syntax) parser = opts.syntax.parse
161 if (opts.parser) parser = opts.parser
162 if (parser.parse) parser = parser.parse
163
164 try {
165 root = parser(css, opts)
166 } catch (error) {
167 this.processed = true
168 this.error = error
169 }
170
171 if (root && !root[my]) {
172 /* c8 ignore next 2 */
173 Container.rebuild(root)
174 }
175 }
176
177 this.result = new Result(processor, root, opts)
178 this.helpers = { ...postcss, postcss, result: this.result }
179 this.plugins = this.processor.plugins.map(plugin => {
180 if (typeof plugin === 'object' && plugin.prepare) {
181 return { ...plugin, ...plugin.prepare(this.result) }
182 } else {
183 return plugin
184 }
185 })
186 }
187
188 async() {
189 if (this.error) return Promise.reject(this.error)

Callers

nothing calls this directly

Calls 2

cleanMarksFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected