Files
react-native-devtools-frontend/node_modules/postcss-syntax/get-lang.js
T
Alex Rudenko 6c0f161c95 Revert "Update stylelint to 14.0.1"
This reverts commit 1e08ee816b.

Reason for revert: tree is closed due to errors https://ci.chromium.org/ui/p/devtools-frontend/builders/ci/Stand-alone%20Linux/8169/overview

Original change's description:
> Update stylelint to 14.0.1
>
> This also upgrades PostCSS to 8.3.11.
>
> DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration
> R=​szuend@chromium.org
>
> Bug: none
> Change-Id: I606540b03509d7c6e73f3d490327cd4174e03d31
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3259541
> Reviewed-by: Simon Zünd <szuend@chromium.org>
> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>

Bug: none
Change-Id: Icb1c02b41dbccc3b4fc5760f5dd0b78eca078b61
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3263399
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Alex Rudenko <alexrudenko@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
2021-11-05 06:32:31 +00:00

112 lines
4.3 KiB
JavaScript

"use strict";
const languages = {
sass: /^sass$/i,
// https://github.com/Microsoft/vscode/blob/master/extensions/scss/package.json
scss: /^scss$/i,
// https://github.com/Microsoft/vscode/blob/master/extensions/less/package.json
less: /^less$/i,
// https://github.com/MhMadHamster/vscode-postcss-language/blob/master/package.json
sugarss: /^s(?:ugar)?ss$/i,
// https://github.com/d4rkr00t/language-stylus/blob/master/package.json
stylus: /^styl(?:us)?$/i,
// WXSS(WeiXin Style Sheets) See: https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html
// acss(AntFinancial Style Sheet) See: https://docs.alipay.com/mini/framework/acss
// `*.pcss`, `*.postcss`
// https://github.com/Microsoft/vscode/blob/master/extensions/css/package.json
// https://github.com/rcsole/postcss-syntax/blob/master/package.json
css: /^(?:wx|\w*c)ss$/i,
};
const extracts = {
// https://github.com/Microsoft/vscode/blob/master/extensions/javascript/package.json
// https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/package.json
// https://github.com/michaelgmcd/vscode-language-babel/blob/master/package.json
jsx: /^(?:m?[jt]sx?|es\d*|pac|babel|flow)$/i,
// *.*html? HTML https://github.com/Microsoft/vscode/blob/master/extensions/html/package.json
// *.xslt? XSLT https://msdn.microsoft.com/en-us/library/ms764661(v=vs.85).aspx
// *.vue VUE https://vue-loader.vuejs.org/spec.html
// *.wpy WePY https://github.com/Tencent/wepy/blob/master/docs/md/doc.md#wpy文件说明
// *.ux quickapp https://doc.quickapp.cn/framework/source-file.html
// *.php* PHP https://github.com/Microsoft/vscode/blob/master/extensions/php/package.json
// *.twig Twig https://github.com/mblode/vscode-twig-language/blob/master/package.json
// *.liquid Liquid https://github.com/GingerBear/vscode-liquid/blob/master/package.json
// *.svelte Svelte https://github.com/UnwrittenFun/svelte-vscode/blob/master/package.json
html: /^(?:\w*html?|xht|xslt?|mdoc|jsp|aspx?|volt|ejs|vue|wpy|ux|php\d*|ctp|twig|liquid|svelte)$/i,
// https://github.com/Microsoft/vscode/blob/master/extensions/markdown-basics/package.json
markdown: /^(?:m(?:ark)?d(?:ow)?n|mk?d)$/i,
// https://github.com/Microsoft/vscode/blob/master/extensions/xml/package.json
xml: /^(?:xml|xsd|ascx|atom|axml|bpmn|config|cpt|csl|csproj|csproj|user|dita|ditamap|dtd|dtml|fsproj|fxml|iml|isml|jmx|launch|menu|mxml|nuspec|opml|owl|proj|props|pt|publishsettings|pubxml|pubxml|user|rdf|rng|rss|shproj|storyboard|svg|targets|tld|tmx|vbproj|vbproj|user|vcxproj|vcxproj|filters|wsdl|wxi|wxl|wxs|xaml|xbl|xib|xlf|xliff|xpdl|xul|xoml)$/i,
};
function sourceType (source) {
source = source && source.trim();
if (!source) {
return;
}
let extract;
if (
// start with strict mode
// start with import code
// start with require code
/^(?:(?:\/\/[^\r\n]*\r?\n|\/\*.*?\*\/)\s*)*(?:(?:("|')use strict\1|import(?:\s+[^;]+\s+from)?\s+("|')[^'"]+?\2|export\s+[^;]+\s+[^;]+)\s*(;|\r?\n|$)|(?:(?:var|let|const)\s+[^;]+\s*=\s*)?(?:require|import)\(.+\))/.test(source) ||
// https://en.wikipedia.org/wiki/Shebang_(Unix)
(/^#!([^\r\n]+)/.test(source) && /(?:^|\s+|\/)(?:ts-)?node(?:\.\w+)?(?:\s+|$)$/.test(RegExp.$1))
) {
extract = "jsx";
} else if (
/^(?:<\?.*?\?>\s*)*<(?:!DOCTYPE\s+)?html(\s+[^<>]*)?>/i.test(source) ||
/^<\?php(?:\s+[\s\S]*)?(?:\?>|$)/.test(source)
) {
extract = "html";
} else if (/^<\?xml(\s+[^<>]*)?\?>/i.test(source)) {
// https://msdn.microsoft.com/en-us/library/ms764661(v=vs.85).aspx
if (/<xsl:\w+\b[^<>]*>/.test(source) || /<\/xsl:\w+>/i.test(source)) {
extract = "html";
} else {
extract = "xml";
}
} else if (/^(?:#+\s+\S+|\S+[^\r\n]*\r?\n=+(\r?\n|$))/.test(source)) {
extract = "markdown";
} else if (/<(\w+)(?:\s+[^<>]*)?>[\s\S]*?<\/\1>/.test(source)) {
extract = "html";
} else {
return;
}
return {
extract,
};
}
function extType (extName, languages) {
for (const langName in languages) {
if (languages[langName].test(extName)) {
return langName;
}
}
}
function fileType (file) {
if (file && /\.(\w+)(?:[?#].*?)?$/.test(file)) {
const extName = RegExp.$1;
const extract = extType(extName, extracts);
if (extract) {
return {
extract,
};
}
const lang = extType(extName, languages);
if (lang) {
return {
lang,
};
}
}
}
function getLang (file, source) {
return fileType(file) || sourceType(source);
}
module.exports = getLang;