Skip to content

Commit 56232e7

Browse files
feat(index): pass AST (result.root) && Messages (result.messages) as metadata to other loaders (#322)
1 parent 4e8e20c commit 56232e7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const SyntaxError = require('./Error')
3939
*
4040
* @return {cb} cb Result
4141
*/
42-
module.exports = function loader (css, map) {
42+
module.exports = function loader (css, map, meta) {
4343
const options = Object.assign({}, loaderUtils.getOptions(this))
4444

4545
validateOptions(require('./options.json'), options, 'PostCSS Loader')
@@ -160,6 +160,11 @@ module.exports = function loader (css, map) {
160160
map.sources = map.sources.map((src) => path.resolve(src))
161161
}
162162

163+
if (!meta) meta = {}
164+
165+
meta.ast = { 'type': 'postcss', root: result.root }
166+
meta.messages = result.messages
167+
163168
if (this.loaderIndex === 0) {
164169
/**
165170
* @memberof loader
@@ -173,6 +178,7 @@ module.exports = function loader (css, map) {
173178

174179
return null
175180
}
181+
176182
/**
177183
* @memberof loader
178184
* @callback cb
@@ -181,12 +187,13 @@ module.exports = function loader (css, map) {
181187
* @param {String} css Result (Raw Module)
182188
* @param {Object} map Source Map
183189
*/
184-
cb(null, css, map)
190+
cb(null, css, map, meta)
185191

186192
return null
187193
})
188194
}).catch((err) => {
189195
if (err.file) this.addDependency(err.file)
196+
190197
return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
191198
})
192199
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy