Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect on common react patterns #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ftdetect/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ if g:jsx_pragma_required
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
endif

" if g:jsx_check_react_import == 1
" parse the first line of js file (skipping comments). When it has a 'react'
" importation, we guess the user writes jsx
" endif
let s:jsx_prevalent_pattern =
\ '\v\C%^\_s*%(%(//.*\_$|/\*\_.{-}\*/)@>\_s*)*%(import\s+\k+\s+from\s+|%(\l+\s+)=\k+\s*\=\s*require\s*\(\s*)[`"'']react>'

" Whether to set the JSX filetype on *.js files.
fu! <SID>EnableJSX()
if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif
if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif
if g:jsx_ext_required && !exists('b:jsx_ext_found') &&
\ !(get(g:,'jsx_check_react_import') && search(s:jsx_prevalent_pattern, 'nw'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's right—I forgot this function was setting the filetype on .js files only, not files in general.

return 0
endif
return 1
endfu

Expand Down