From 56232e7b5824fd2655560175c44eabc2b40351f8 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Fri, 2 Feb 2018 01:51:18 +0100 Subject: [PATCH] feat(index): pass AST (`result.root`) && Messages (`result.messages`) as metadata to other loaders (#322) --- lib/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 95c6a65b..4e035720 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,7 +39,7 @@ const SyntaxError = require('./Error') * * @return {cb} cb Result */ -module.exports = function loader (css, map) { +module.exports = function loader (css, map, meta) { const options = Object.assign({}, loaderUtils.getOptions(this)) validateOptions(require('./options.json'), options, 'PostCSS Loader') @@ -160,6 +160,11 @@ module.exports = function loader (css, map) { map.sources = map.sources.map((src) => path.resolve(src)) } + if (!meta) meta = {} + + meta.ast = { 'type': 'postcss', root: result.root } + meta.messages = result.messages + if (this.loaderIndex === 0) { /** * @memberof loader @@ -173,6 +178,7 @@ module.exports = function loader (css, map) { return null } + /** * @memberof loader * @callback cb @@ -181,12 +187,13 @@ module.exports = function loader (css, map) { * @param {String} css Result (Raw Module) * @param {Object} map Source Map */ - cb(null, css, map) + cb(null, css, map, meta) return null }) }).catch((err) => { if (err.file) this.addDependency(err.file) + return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err) }) }