-
Notifications
You must be signed in to change notification settings - Fork 7
/
processor.js
29 lines (23 loc) · 683 Bytes
/
processor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";
const parseStyle = require("./parse-style");
function getSyntax (config, syntax) {
if (typeof syntax !== "string") {
return syntax;
}
let syntaxConfig = config[syntax];
if (syntaxConfig) {
syntaxConfig = getSyntax(config, syntaxConfig);
} else {
syntaxConfig = {
extract: require(syntax.toLowerCase().replace(/^(postcss-)?/i, "postcss-") + "/extract"),
};
config[syntax] = syntaxConfig;
}
return syntaxConfig;
}
function processor (source, lang, opts) {
const syntax = getSyntax(opts.syntax.config, lang);
const styles = (syntax.extract || syntax)(source, opts) || [];
return parseStyle(source, opts, styles);
}
module.exports = processor;