diff --git a/lib/process-content.js b/lib/process-content.js index a048403..4ce6cc9 100644 --- a/lib/process-content.js +++ b/lib/process-content.js @@ -43,18 +43,20 @@ module.exports = function processContent( return runPostcss(postcss, content, filename, plugins, parserList) } -function runPostcss(postcss, content, filename, plugins, parsers, index) { - if (!index) index = 0 - return postcss(plugins) - .process(content, { - from: filename, - parser: parsers[index], - }) - .catch(err => { - // If there's an error, try the next parser - index++ - // If there are no parsers left, throw it - if (index === parsers.length) throw err - return runPostcss(postcss, content, filename, plugins, parsers, index) - }) +async function runPostcss(postcss, content, filename, plugins, parsers) { + let lastError + const processor = postcss(plugins) + + for (const parser of parsers) { + try { + return await processor.process(content, { + from: filename, + parser, + }) + } catch (err) { + lastError = err + } + } + + throw lastError }