11"use strict" ;
22
3- // https://github.com/Microsoft/vscode/blob/master/extensions/markdown-basics/package.json
4- // https://github.com/Microsoft/vscode/blob/master/extensions/html/package.json
5- // https://github.com/Microsoft/vscode/blob/master/extensions/javascript/package.json
6- // https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/package.json
7- // https://github.com/Microsoft/vscode/blob/master/extensions/xml/package.json
8- // https://github.com/Microsoft/vscode/blob/master/extensions/css/package.json
9- // https://github.com/Microsoft/vscode/blob/master/extensions/less/package.json
10- // https://github.com/vuejs/vetur/blob/master/package.json
11-
123const languages = {
134 sass : / ^ s a s s $ / i,
5+ // https://github.com/Microsoft/vscode/blob/master/extensions/scss/package.json
146 scss : / ^ s c s s $ / i,
7+ // https://github.com/Microsoft/vscode/blob/master/extensions/less/package.json
158 less : / ^ l e s s $ / i,
9+ // https://github.com/MhMadHamster/vscode-postcss-language/blob/master/package.json
1610 sugarss : / ^ s (?: u g a r ) ? s s $ / i,
11+ // https://github.com/d4rkr00t/language-stylus/blob/master/package.json
1712 stylus : / ^ s t y l (?: u s ) ? $ / i,
18- // WXSS(WeiXin Style Sheets) See: https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html
19- // acss(AntFinancial Style Sheet) See: https://docs.alipay.com/mini/framework/acss
13+ // WXSS(WeiXin Style Sheets) See: https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html
14+ // acss(AntFinancial Style Sheet) See: https://docs.alipay.com/mini/framework/acss
2015 // `*.pcss`, `*.postcss`
16+ // https://github.com/Microsoft/vscode/blob/master/extensions/css/package.json
17+ // https://github.com/rcsole/postcss-syntax/blob/master/package.json
2118 css : / ^ (?: w x | \w * c ) s s $ / i,
2219} ;
2320
2421const extracts = {
25- jsx : / ^ (?: m ? [ j t ] s x ? | e s \d * | p a c ) $ / i,
22+ // https://github.com/Microsoft/vscode/blob/master/extensions/javascript/package.json
23+ // https://github.com/Microsoft/vscode/blob/master/extensions/typescript-basics/package.json
24+ // https://github.com/michaelgmcd/vscode-language-babel/blob/master/package.json
25+ jsx : / ^ (?: m ? [ j t ] s x ? | e s \d * | p a c | b a b e l | f l o w ) $ / i,
26+ // *.*html? HTML https://github.com/Microsoft/vscode/blob/master/extensions/html/package.json
2627 // *.xslt? XSLT https://msdn.microsoft.com/en-us/library/ms764661(v=vs.85).aspx
2728 // *.vue VUE https://vue-loader.vuejs.org/spec.html
28- // *.ux quickapp https://doc.quickapp.cn/framework/source-file.html
2929 // *.wpy WePY https://github.com/Tencent/wepy/blob/master/docs/md/doc.md#wpy文件说明
30- html : / ^ (?: \w * h t m l ? | x h t | m d o c | j s p | a s p x ? | v o l t | e j s | p h p | v u e | u x | w p y ) $ / i,
30+ // *.ux quickapp https://doc.quickapp.cn/framework/source-file.html
31+ // *.php* PHP https://github.com/Microsoft/vscode/blob/master/extensions/php/package.json
32+ // *.twig Twig https://github.com/mblode/vscode-twig-language/blob/master/package.json
33+ // *.liquid Liquid https://github.com/GingerBear/vscode-liquid/blob/master/package.json
34+ html : / ^ (?: \w * h t m l ? | x h t | x s l t ? | m d o c | j s p | a s p x ? | v o l t | e j s | v u e | w p y | u x | p h p \d * | c t p | t w i g | l i q u i d ) $ / i,
35+ // https://github.com/Microsoft/vscode/blob/master/extensions/markdown-basics/package.json
3136 markdown : / ^ (?: m (?: a r k ) ? d (?: o w ) ? n | m k ? d ) $ / i,
32- xsl : / ^ x s l t ? $ / i ,
37+ // https://github.com/Microsoft/vscode/blob/master/extensions/xml/package.json
3338 xml : / ^ (?: x m l | x s d | a s c x | a t o m | a x m l | b p m n | c o n f i g | c p t | c s l | c s p r o j | c s p r o j | u s e r | d i t a | d i t a m a p | d t d | d t m l | f s p r o j | f x m l | i m l | i s m l | j m x | l a u n c h | m e n u | m x m l | n u s p e c | o p m l | o w l | p r o j | p r o p s | p t | p u b l i s h s e t t i n g s | p u b x m l | p u b x m l | u s e r | r d f | r n g | r s s | s h p r o j | s t o r y b o a r d | s v g | t a r g e t s | t l d | t m x | v b p r o j | v b p r o j | u s e r | v c x p r o j | v c x p r o j | f i l t e r s | w s d l | w x i | w x l | w x s | x a m l | x b l | x i b | x l f | x l i f f | x p d l | x u l | x o m l ) $ / i,
3439} ;
3540
@@ -39,21 +44,28 @@ function sourceType (source) {
3944 return ;
4045 }
4146 let extract ;
42- if ( ( / ^ # ! ( [ ^ \r \n ] + ) / . test ( source ) && / (?: ^ | \s + ) (?: t s - ) ? n o d e (?: \. \w + ) ? (?: \s + | $ ) $ / . test ( RegExp . $1 ) ) || / ^ ( " | ' ) u s e s t r i c t \1; * \s * ( \r ? \n | $ ) / . test ( source ) || / ^ i m p o r t (?: \s + [ ^ ; ] + \s + f r o m ) ? \s + ( " | ' ) [ ^ ' " ] + ?\1; * \s * ( \r ? \n | $ ) / . test ( source ) || / ^ (?: (?: v a r | l e t | c o n s t ) \s + [ ^ ; ] + \s * = ) ? \s * (?: r e q u i r e | i m p o r t ) \( .+ \) / . test ( source ) ) {
47+ if (
48+ // start with strict mode
49+ // start with import code
50+ // start with require code
51+ / ^ (?: (?: \/ \/ [ ^ \r \n ] * \r ? \n | \/ \* .* ?\* \/ ) \s * ) * (?: (?: ( " | ' ) u s e s t r i c t \1| i m p o r t (?: \s + [ ^ ; ] + \s + f r o m ) ? \s + ( " | ' ) [ ^ ' " ] + ?\2) \s * ( ; | \r ? \n | $ ) | (?: (?: v a r | l e t | c o n s t ) \s + [ ^ ; ] + \s * = \s * ) ? (?: r e q u i r e | i m p o r t ) \( .+ \) ) / . test ( source ) ||
4352 // https://en.wikipedia.org/wiki/Shebang_(Unix)
44- // or start with strict mode
45- // or start with import code
53+ ( / ^ # ! ( [ ^ \r \n ] + ) / . test ( source ) && / (?: ^ | \s + | \/ ) (?: t s - ) ? n o d e (?: \. \w + ) ? (?: \s + | $ ) $ / . test ( RegExp . $1 ) )
54+ ) {
4655 extract = "jsx" ;
47- } else if ( / ^ < (?: ! D O C T Y P E \s + ) ? h t m l ( \s + [ ^ < > ] * ) ? > / i. test ( source ) ) {
56+ } else if (
57+ / ^ (?: < \? .* ?\? > \s * ) * < (?: ! D O C T Y P E \s + ) ? h t m l ( \s + [ ^ < > ] * ) ? > / i. test ( source ) ||
58+ / ^ < \? p h p (?: \s + [ \s \S ] * ) ? (?: \? > | $ ) / . test ( source )
59+ ) {
4860 extract = "html" ;
4961 } else if ( / ^ < \? x m l ( \s + [ ^ < > ] * ) ? \? > / i. test ( source ) ) {
5062 // https://msdn.microsoft.com/en-us/library/ms764661(v=vs.85).aspx
5163 if ( / < x s l : \w + \b [ ^ < > ] * > / . test ( source ) || / < \/ x s l : \w + > / i. test ( source ) ) {
52- extract = "xsl " ;
64+ extract = "html " ;
5365 } else {
5466 extract = "xml" ;
5567 }
56- } else if ( / ^ # + \s + \S + / . test ( source ) || / ^ \S + [ ^ \r \n ] * \r ? \n = + ( \r ? \n | $ ) / . test ( source ) ) {
68+ } else if ( / ^ (?: # + \s + \S + | \S + [ ^ \r \n ] * \r ? \n = + ( \r ? \n | $ ) ) / . test ( source ) ) {
5769 extract = "markdown" ;
5870 } else if ( / < ( \w + ) (?: \s + [ ^ < > ] * ) ? > [ \s \S ] * ?< \/ \1> / . test ( source ) ) {
5971 extract = "html" ;
@@ -92,8 +104,8 @@ function fileType (file) {
92104}
93105
94106function getLang ( opts , source ) {
95- const file = opts . from ;
96- const rules = opts . syntax . config . rules ;
107+ const file = opts . from || opts ;
108+ const rules = opts . syntax && opts . syntax . config && opts . syntax . config . rules ;
97109 return ( rules && rules . find (
98110 rule => rule . test . test ? rule . test . test ( file ) : rule . test ( file , source )
99111 ) ) || fileType ( file ) || sourceType ( source ) || {
0 commit comments