Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lib/process-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}