File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,20 @@ if g:jsx_pragma_required
2323 let b: jsx_pragma_found = search (s: jsx_pragma_pattern , ' npw' )
2424endif
2525
26+ " if g:jsx_check_react_import == 1
27+ " parse the first line of js file (skipping comments). When it has a 'react'
28+ " importation, we guess the user writes jsx
29+ " endif
30+ let s: jsx_prevalent_pattern =
31+ \ ' \v\C%^\_s*%(%(//.*\_$|/\*\_.{-}\*/)@>\_s*)*%(import\s+\k+\s+from\s+|%(\l+\s+)=\k+\s*\=\s*require\s*\(\s*)[`"'' ]react>'
32+
2633" Whether to set the JSX filetype on *.js files.
2734fu ! <SID> EnableJSX ()
2835 if g: jsx_pragma_required && ! b: jsx_pragma_found | return 0 | endif
29- if g: jsx_ext_required && ! exists (' b:jsx_ext_found' ) | return 0 | endif
36+ if g: jsx_ext_required && ! exists (' b:jsx_ext_found' ) &&
37+ \ ! (get (g: ,' jsx_check_react_import' ) && search (s: jsx_prevalent_pattern , ' nw' ))
38+ return 0
39+ endif
3040 return 1
3141endfu
3242
You can’t perform that action at this time.
0 commit comments