postcss-syntax
Advanced tools
Comparing version 0.30.0 to 0.31.0
"use strict"; | ||
// https://github.com/Microsoft/vscode/blob/master/extensions/markdown-basics/package.json | ||
// https://github.com/Microsoft/vscode/blob/master/extensions/html/package.json | ||
// 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/Microsoft/vscode/blob/master/extensions/xml/package.json | ||
// https://github.com/Microsoft/vscode/blob/master/extensions/css/package.json | ||
// https://github.com/Microsoft/vscode/blob/master/extensions/less/package.json | ||
// https://github.com/vuejs/vetur/blob/master/package.json | ||
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 | ||
// 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, | ||
@@ -25,10 +22,18 @@ }; | ||
const extracts = { | ||
jsx: /^(?:m?[jt]sx?|es\d*|pac)$/i, | ||
// 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 | ||
// *.wpy WePY https://github.com/Tencent/wepy/blob/master/docs/md/doc.md#wpy文件说明 | ||
html: /^(?:\w*html?|xht|mdoc|jsp|aspx?|volt|ejs|php|vue|ux|wpy)$/i, | ||
// *.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 | ||
html: /^(?:\w*html?|xht|xslt?|mdoc|jsp|aspx?|volt|ejs|vue|wpy|ux|php\d*|ctp|twig|liquid)$/i, | ||
// https://github.com/Microsoft/vscode/blob/master/extensions/markdown-basics/package.json | ||
markdown: /^(?:m(?:ark)?d(?:ow)?n|mk?d)$/i, | ||
xsl: /^xslt?$/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, | ||
@@ -43,8 +48,15 @@ }; | ||
let extract; | ||
if ((/^#!([^\r\n]+)/.test(source) && /(?:^|\s+)(?:ts-)?node(?:\.\w+)?(?:\s+|$)$/.test(RegExp.$1)) || /^("|')use strict\1;*\s*(\r?\n|$)/.test(source) || /^import(?:\s+[^;]+\s+from)?\s+("|')[^'"]+?\1;*\s*(\r?\n|$)/.test(source) || /^(?:(?:var|let|const)\s+[^;]+\s*=)?\s*(?:require|import)\(.+\)/.test(source)) { | ||
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)\s*(;|\r?\n|$)|(?:(?:var|let|const)\s+[^;]+\s*=\s*)?(?:require|import)\(.+\))/.test(source) || | ||
// https://en.wikipedia.org/wiki/Shebang_(Unix) | ||
// or start with strict mode | ||
// or start with import code | ||
(/^#!([^\r\n]+)/.test(source) && /(?:^|\s+|\/)(?:ts-)?node(?:\.\w+)?(?:\s+|$)$/.test(RegExp.$1)) | ||
) { | ||
extract = "jsx"; | ||
} else if (/^<(?:!DOCTYPE\s+)?html(\s+[^<>]*)?>/i.test(source)) { | ||
} else if ( | ||
/^(?:<\?.*?\?>\s*)*<(?:!DOCTYPE\s+)?html(\s+[^<>]*)?>/i.test(source) || | ||
/^<\?php(?:\s+[\s\S]*)?(?:\?>|$)/.test(source) | ||
) { | ||
extract = "html"; | ||
@@ -54,7 +66,7 @@ } else if (/^<\?xml(\s+[^<>]*)?\?>/i.test(source)) { | ||
if (/<xsl:\w+\b[^<>]*>/.test(source) || /<\/xsl:\w+>/i.test(source)) { | ||
extract = "xsl"; | ||
extract = "html"; | ||
} else { | ||
extract = "xml"; | ||
} | ||
} else if (/^#+\s+\S+/.test(source) || /^\S+[^\r\n]*\r?\n=+(\r?\n|$)/.test(source)) { | ||
} else if (/^(?:#+\s+\S+|\S+[^\r\n]*\r?\n=+(\r?\n|$))/.test(source)) { | ||
extract = "markdown"; | ||
@@ -97,12 +109,6 @@ } else if (/<(\w+)(?:\s+[^<>]*)?>[\s\S]*?<\/\1>/.test(source)) { | ||
function getLang (opts, source) { | ||
const file = opts.from; | ||
const rules = opts.syntax.config.rules; | ||
return (rules && rules.find( | ||
rule => rule.test.test ? rule.test.test(file) : rule.test(file, source) | ||
)) || fileType(file) || sourceType(source) || { | ||
lang: "css", | ||
}; | ||
function getLang (file, source) { | ||
return fileType(file) || sourceType(source); | ||
} | ||
module.exports = getLang; |
@@ -10,3 +10,2 @@ "use strict"; | ||
xml: "html", | ||
xsl: "html", | ||
}; | ||
@@ -13,0 +12,0 @@ |
{ | ||
"name": "postcss-syntax", | ||
"version": "0.30.0", | ||
"version": "0.31.0", | ||
"description": "Automatically switch PostCSS syntax by file extensions", | ||
@@ -33,2 +33,50 @@ "repository": { | ||
}, | ||
"extensions": [ | ||
".css", | ||
".pcss", | ||
".postcss", | ||
".acss", | ||
".wxss", | ||
".sass", | ||
".scss", | ||
".less", | ||
".sss", | ||
".js", | ||
".es6", | ||
".mjs", | ||
".pac", | ||
".jsx", | ||
".ts", | ||
".tsx", | ||
".babel", | ||
".flow", | ||
".html", | ||
".htm", | ||
".shtml", | ||
".xhtml", | ||
".mdoc", | ||
".jsp", | ||
".asp", | ||
".aspx", | ||
".jshtm", | ||
".volt", | ||
".ejs", | ||
".rhtml", | ||
".xsl", | ||
".xslt", | ||
".vue", | ||
".wpy", | ||
".ux", | ||
".php", | ||
".php4", | ||
".php5", | ||
".phtml", | ||
".ctp", | ||
".twig", | ||
".liquid", | ||
".md", | ||
".mdown", | ||
".markdown", | ||
".markdn" | ||
], | ||
"peerDependencies": { | ||
@@ -42,9 +90,9 @@ "postcss": ">=5.0.0" | ||
"nyc": "^12.0.2", | ||
"postcss": "^6.0.22", | ||
"postcss-html": ">=0.30.0", | ||
"postcss-jsx": ">=0.30.0", | ||
"postcss": "^6.0.23", | ||
"postcss-html": ">=0.31.0", | ||
"postcss-jsx": ">=0.31.0", | ||
"postcss-less": "^2.0.0", | ||
"postcss-markdown": ">=0.30.0", | ||
"postcss-markdown": ">=0.31.0", | ||
"postcss-safe-parser": "^3.0.1", | ||
"postcss-scss": "^1.0.5", | ||
"postcss-scss": "^1.0.6", | ||
"proxyquire": "^2.0.1", | ||
@@ -51,0 +99,0 @@ "sugarss": "^1.0.1" |
21
parse.js
@@ -6,13 +6,18 @@ "use strict"; | ||
const getLang = require("./get-lang"); | ||
const normalOpts = require("./normal-opts"); | ||
function getSyntax (opts, source) { | ||
const rules = opts.syntax && opts.syntax.config && opts.syntax.config.rules; | ||
const file = opts.from || ""; | ||
return (rules && rules.find( | ||
rule => rule.test.test ? rule.test.test(file) : rule.test(file, source) | ||
)) || getLang(file, source) || { | ||
lang: "css", | ||
}; | ||
} | ||
function parse (source, opts) { | ||
if (!opts) { | ||
opts = {}; | ||
} | ||
if (!opts.syntax) { | ||
opts.syntax = this; | ||
} | ||
source = source.toString(); | ||
const syntax = getLang(opts, source); | ||
opts = normalOpts(opts, this); | ||
const syntax = getSyntax(opts, source); | ||
const syntaxOpts = Object.assign({}, opts, syntax.opts); | ||
@@ -19,0 +24,0 @@ let root; |
"use strict"; | ||
const stringify = require("./stringify"); | ||
const parseStyle = require("./parse-style"); | ||
const normalOpts = require("./normal-opts"); | ||
@@ -11,12 +12,6 @@ module.exports = (extract, lang) => { | ||
xml: "html", | ||
xsl: "html", | ||
}; | ||
function parse (source, opts) { | ||
source = source.toString(); | ||
if (!opts) { | ||
opts = {}; | ||
} | ||
if (!opts.syntax) { | ||
opts.syntax = this; | ||
} | ||
opts = normalOpts(opts, this); | ||
const document = parseStyle(source, opts, extract(source, opts)); | ||
@@ -23,0 +18,0 @@ document.source.lang = lang; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21359
16
559