Files
react-native-devtools-frontend/node_modules/postcss-syntax/get-syntax.js
T
Mathias Bynens 79e2cf0633 Add stylelint dependency
This also adds CC-BY-4.0 to the list of accepted licenses.

DISABLE_THIRD_PARTY_CHECK=update dependencies

Bug: chromium:1083142
Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
2020-06-11 06:20:04 +00:00

64 lines
1.4 KiB
JavaScript

"use strict";
const path = require("path");
const reSyntaxCSS = /^(?:post)?css$/i;
function cssSyntax () {
return {
stringify: require("postcss/lib/stringify"),
parse: require("postcss/lib/parse"),
};
}
function normalize (syntax) {
if (!syntax.parse) {
syntax = {
parse: syntax,
};
}
return syntax;
}
function requireSyntax (syntax) {
if (reSyntaxCSS.test(syntax)) {
return cssSyntax();
} else if (/^sugarss$/i.test(syntax)) {
syntax = "sugarss";
} else if (path.isAbsolute(syntax) || syntax[0] === ".") {
syntax = path.resolve(syntax);
} else {
syntax = syntax.toLowerCase().replace(/^(?:postcss-)?(\w+)/i, "postcss-$1");
}
return normalize(require(syntax));
}
function getSyntax (lang, opts) {
let syntax;
lang = lang || "css";
if (opts.syntax.config[lang]) {
syntax = opts.syntax.config[lang];
if (typeof syntax === "string") {
if (syntax !== lang && opts.syntax.config[syntax]) {
return getSyntax(syntax, opts);
}
syntax = requireSyntax(syntax);
} else {
syntax = normalize(syntax);
}
} else if (reSyntaxCSS.test(lang)) {
syntax = cssSyntax();
} else {
return requireSyntax(lang);
}
if (!syntax.stringify) {
if (reSyntaxCSS.test(lang)) {
syntax.stringify = require("postcss/lib/stringify");
} else {
syntax.stringify = getSyntax(null, opts).stringify;
}
}
opts.syntax.config[lang] = syntax;
return syntax;
}
module.exports = getSyntax;