Skip to content

Commit 919bb23

Browse files
bouncemebounceme
authored and
bounceme
committed
Detect on common react patterns, This is a combination of 12 commits.
1 parent eb656ed commit 919bb23

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ftdetect/javascript.vim

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ if g:jsx_pragma_required
2323
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
2424
endif
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.
2734
fu! <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
3141
endfu
3242

0 commit comments

Comments
 (0)