From c52a22597fc79de69f11d36ea4f9dff66b1fd59d Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Fri, 6 Jan 2017 22:00:15 -0800 Subject: [PATCH] Squashed 'vim/bundle/javascript/' changes from e9a59c877..d2ccd306f d2ccd306f use generic equivalent 3ea6ed6ac Trim optimize (#1024) c03aee798 add 'mjs' extension (#1023) c5e5e2012 refactor, mergeable (#1018) dcb4e4762 cleaning, small optimization? (#1015) 7097cdad8 Small Flow return fix 739562910 more simplify of PCL (#1013) 8ea46f3e6 neater/faster iterating 6ccc1a713 Fix certain flow annotations within classes fc80419fd trivial indent fixes / updates (#1007) 09d7c7051 faster/smaller cache access, SynId function (#1005) 7175ba5e6 missed a condition last time ff851de60 improve conditionals all over (#1002) 37a68c3c7 Add fold to various flow regions dd1f74fb8 Another quick flow patch bc5b02484 A few more fixes 008e98985 Trying out some flow tweaks e4870b4f5 More fixes for flow 0353342bc Fix for jsFlowOperator 243932e58 A ton of flow fixes ff5e284f4 exponentiator, operator things (#1001) f0ce7ffa9 cino-W (#1000) cc84aa380 Merge pull request #999 from wavded/patch-2 ef74079e9 Add @async tag support. 603ec7156 cleaning, indent (#997) be46c1c4d document and improve class cases (#996) 9b2a032c3 fix list size error with setpos() 7684f3cfc magic 1bd80e092 edge case fix: prevcodeline() and c style comments (#994) 72f4a95b2 fix for `[*` failing 43097941a let [] =[], minor formatting (#990) aba8630e2 Making jsModuleGroup foldable 517d37c97 Merge pull request #992 from pangloss/async-fix 97203f192 async/await should be an @jsExpression ebc6fd267 fix expr_col case 14cf98883 remove semicolon flag; flow (#989) e0472fc50 indent file cleaning (#988) 4eac815fa cleaner searcpair workaround e6f514324 IsCont trivial refactor (#986) efd4f1f5e Small fix for Flow class annotations 8d6fbfb41 lex type import (#984) f20659188 small logic reversal 438990878 date, cleaning 271f73123 clean up Syn e14cfb6a0 flowtype requiring (#982) 2b0889fa8 naturalize (#981) 0b44edb6f Pcodeline (#980) 868c15b1c non-interrupting limit info in debugging 42c9451ab more lookbehind needed... classes 1cb44af82 make var naming consistent (#977) 6f880fe81 fix for non-inheriting (#976) 4e3c3c0d6 small logic fix e5cdee7b2 assure switch isn't method (#974) 931dbd5b6 cino-M (#971) a5a9a17d4 add possible ident shorthand (#970) 7ba092739 cleaner generator shorthand fix (#969) 2dfe7cded star shorthand workaround 9ea6e5df1 date 388c9cbc4 Nat is unary 147e50669 remove script-global, range reversal, max (#965) 18cd99029 cino-star behavior; remove s:W references e092e7fce star comment find, as loop (#963) eb5f00f67 Small fix for jsTaggedTemplate beba61e8e trivial reading stuff and date 1d28953b1 clearer -1 check 28281d25a simplify isBlock and doWhile (#962) 4242a4b5f remove function setup 2e24d89cc fix wording f5f32a9f4 Update README.md bb2c6857d cino-= and misc style changes: indent.vim (#959) 89c3d920e variable of current token in functions (#958) 21a8a7ed8 misc:refactor (#957) dc0bb4748 cleaning: indent.vim (#956) d3068263e date d9820f993 remove comment hack 5f0163963 no eval or confusing viml workarounds (#954) e73b32207 deduplication (#953) 809b6beb4 move state out of try block 82b142242 test fix (#952) 9ce4ea852 misc: go back to l:pos only when needed; (#947) d12dc6156 just use dict value 18c2c847e Merge pull request #925 from pangloss/issue-template d33561172 Improve issue template 7d8a2b117 Adding an ISSUE_TEMPLATE.md a898a9780 Merge pull request #942 from pangloss/bounceme-patch-1 c8aa5ed52 fix wrong func call 244985f10 don't use cursor() in conditional 573879c9d Reuse pos restorer, misc cleaning (#943) 0c26c4808 fix #940: ternary expression returning arrow 81166acad cache synID calls (#938) a1f36ff79 move s: vars 5b2f56d75 Fix buffer variables inited only once (#941) 65dbdfc45 Fix variable typo (#939) f7ffea095 Misc: indent (#937) 896bb54d2 configurable syntax skipping (#936) 53b043924 misc: indent.vim (#935) 259f5282f (silent) exception same as within searchpair (#934) 1e59f8488 break at html too fcdacf6f7 break search at col:1 (#933) ac71ceca3 another str2nr() 45d092f65 str2nr() to prevent octal e573aa0b6 unneeded var declare (#932) 317125e18 &cino non-regex (#931) 2bca9c6f6 misc fixes, non-critical stuff (#929) 10492a89d cino-U (#928) 145fdc76d script-tag var access (#927) 3c2923e43 dont depend on loop error handling 2c8733ed7 vim script minify (#924) 021a5ff80 simpler, float less, cino parse (#926) 5511721b1 compiler header 23f5d0ed1 update comments 0d7ad9320 better do -> while "switch" 1a7a8fc8d no pos movement, exit correctly in prevline() d8729f221 string detecting for prevline() a327247d1 add note ceae62037 Merge pull request #921 from pangloss/fix-prototype ff9918c7c Fix prototype matching 431aa0ed1 Merge pull request #920 from pangloss/add-await-js-expression 5e85c21d0 Adding await to @jsExpression 665501ba2 various indent cleanups (#917) 55651ba6d add "es" extension (#916) b6c00a194 move flow detect to ft detect file (#913) f786167f9 Merge pull request #912 from sebcode/master 0cc170159 Allow flowtype annotation for arrow func return val c87bb4345 auto load flow file with comment header (#911) 8fb55c5be minor change to limit 9cbe46c4a limit expr_col b954ab478 ternary assignment 4e64bcff9 cleaner limiting in html bea0e2096 change buffer variable for html 3ca2f636d fix, keep cache valid in tag 10f71931a don't move to scriptTag 87ecc8742 fix html without pangloss repo syntax file (#909) ac4efdca0 indenting for first line after script tag (#908) 1e4ec0aaf also disregard flow bracket as operator 8e51618ba fix embedded js (#907) 63355ea70 fix: add jsImport and jsExport to htmlJavaScript (#906) 3530116b5 builtin optimization, fail condition (#904) d2bc31992 more pattern simplifications (#903) fac43e7d2 explicit match of cino parse (#902) a24f345f4 dot isblock 90cf82a9f Remove a call to trim() in Onescope (#900) afe6b8bf2 do while; experiment (#899) 0034e332b strpart instead of substrings,date (#898) d87476f30 simplify balance optimization (#897) 289eca381 use search() 'e' flag to simplify regex 015004855 case 4a442bade virtual (#894) 669262388 replace tabs shell comment e79107b49 add small note about testing in shell (#890) 2ad6da791 small code style fixes 1f9e29243 Onescope() refining (#889) 688d34b2e fix type as identifier (#887) a2259d32b flow type ob (#886) 5ff6d5071 more prevcodeline improving (#884) 6c2007980 small fix 6007c680e refactor Prevcodeline (#883) d8ffdf71e remove extra func call 867f50038 remove eval in continues() (#881) 95405f8e3 shiftwidth() compat (#879) d79de5b4f expr_col switch? (#878) a35306e0a save_pos instead of try/finally , date (#877) 40c437fd1 reimplement Trim() (#876) 6be84aa6b alternating balanced() (#874) f92f5814e use float support rather than reimplement it (#873) 44b70ce73 remove pointless format flag (#872) 1ad5378d6 cleaning (#870) c3892c40a reverse logic,skipfunc (#869) 57c837045 regex in token (#868) b99793534 optimization in alternatepair() (#867) 0f36d47e8 make search magic 6fad4c536 document cino-w 73a8a137d cino-w (#864) eb0465274 more c-parse fixes ab5f29eee safe list value 6968e93e3 cino-parsing helper (#862) 5824735cd cino-b (#861) c07c72700 unneeded condition d1b6d908d safer check for paren/cino 4b219f6c9 doc 6c0bd6505 cino=( (#860) 53c547bbb extends, isBlock 4dc80ee25 regex explicit case 203126dae remove quote inaccuracy 05e17e4d4 if ptoken fails, restore cursor (#858) 23e5fa204 fix jsx detection (#857) f70263dc6 clean up continues() (#856) 51e0cc54f more likely condition first (#855) 3344f1388 more keywords/operators (#854) 7072eb54a new operator 97a8ab46e cino option 220ce28ee reduce if nesting, isBlock consistency (#853) 6e8811c32 Enabling spell checking on template strings (#834) e3a0e1f55 ternary algorithm simplified c63905600 regex case fixes (#850) 3bb778ee7 faster tern col regex (#849) 9cf48ee3d string group name 18bc58a02 refactor isBlock (#846) 38c2b557b full syntax check if inside jsx (#844) 742f55bf1 syn related indent fixes (#843) 545ab1a90 Merge pull request #842 from pangloss/misc-bugfixes 5c526adcb Fixes to some comment chaining 1f1d5ebf3 unicode regex flag (#840) d993dda7d Merge pull request #838 from pangloss/bugfix/js-func-call 994b78bf7 Fix for jsFuncCall 871ab2959 prevent octal conversion (#835) 9ada8ab92 switch_offset min value (#832) 8d0d45349 template inner code (#830) b7677c924 float-less cino parsing (#828) 307eb850d better zero char solution bf2f6a8e4 do inc/dec/arrow detection in function (#827) 2195ce010 safer GetPair condition (#824) 432d01b2d Merge pull request #823 from pangloss/ret c354c479e Merge pull request #822 from qstrahl/fix-js-class-value-arrow-function 1ec994774 shorten final return 8b55755e9 Remove keepend from jsClassValue region 4e1ec95dc fix 9d24edb47 accurate Trim and prev_token funcs (#817) 8526ce56e Merge pull request #814 from pangloss/feature/js-object-prop 019e523aa combine ind logic (#816) 67b90c737 First pass at `jsObjectProp` 3cf8f3d0b Merge pull request #801 from pangloss/feature/new-bind-syntax 22c7e7b3e jsBlockLabels are not allowed if :: 7c95ee824 First pas at :: support 9f3ecf459 Merge pull request #815 from pangloss/jstemplateexpression 88c85d9ea Renaming jsTemplateVar -> jsTemplateExpression 690f23ea8 fix for inc/dec operators and blocks (#811) 18cbb4bde cleaning (#810) 0367cb5d5 add compiler plugin (#808) f54c861a8 remove search call (#809) 96a5b5ec6 remove z flag 53dea7aff cleaning,search flags (#807) 56f6fbbe4 improve regex at skip_func (#806) f8e9c1a7f check for lines which contain at least 2 `/` (#804) cfaa6e4ef Merge pull request #789 from wavded/patch-1 7050c3ad9 Merge pull request #802 from pangloss/bugfix/template-var-keepend cb7d5aeae Attempted fix for jsTemplateVar ce415c397 Merge pull request #778 from pangloss/feature/block-support 9148cd38d Add extend to jsTernaryIf 659cbf3de Fix switch cases from being detected as labels f11f948c0 Adding support for block statement labels 4839870f2 Fix jsTernaryIf and jsObjects fe92d4991 First pass at Block support 9e9e2c4f3 remove added s:Trim arg bd9b70af0 remove html comment faa1a4bf4 cleaning (#799) 685219245 Fix Function capitalization in Flow annotations b3a1e8a87 add await d817bd4f1 re-add throw bba35b25c change a keyword 58fdba82d cleaning 3ee5de406 fix keywords 043bb4aa0 fix destruct dce5a10a0 remove check of keyword 2f182a1f4 generic search function (#795) 0b9c46e46 remove flow cases 006f889b4 exact object indent (#793) 2c44678d3 Merge pull request #791 from pangloss/fix-empty-arrow-args d8a6fef99 Bugfix for jsArrowFuncArgs aa3a16993 various fixes (#790) 17bbd02c1 ternary function (#788) ff1fc56de Improve @typedef syntax for namepath. ad3261e92 magic portability (#786) a584a283b Merge pull request #787 from pangloss/add-comments-to-destructuring-blocks 364309983 Adding jsComment to destructuring blocks 8e3ae21c3 fix case block logic 36ebd9f8a rename,refactor, jump label support for isblock() (#775) c2f65cd3f Merge pull request #782 from pangloss/fix-async 1a7632e6c Fixing how async is used 2f8d1fe2e Merge pull request #781 from pangloss/misc-flow-tweaks 7cb3abf71 Misc flow fixes 799274716 Merge pull request #780 from pangloss/flow-fix ddefa30d1 Adding Flow wildcard support 3ef7bfd18 Merge pull request #779 from pangloss/misc-bugfixes 431e22926 Fix require in jsGlobalNodeObjects c347e2da1 Adds __dirname & __filename to jsGlobalNodeObjects f60eb29ea Merge pull request #777 from pangloss/bugfix/add-spread-to-jsblock 6f01baa66 Adding jsSpreadExpression to jsBlock 28732ef1a Merge pull request #776 from pangloss/bugfix/js-class-value c12ae7609 An attempted fix for jsClassValue region end 521f4eda7 jump label support (#772) a6176945c add other comments 8043c4bc0 detect string, prevline (#771) ccc9f3017 improvements to prevcodeline() (#769) da1eee445 odd comments, shebang (#768) ce0f529bb refactor s:OneScope() (#766) 1cb6f1094 cleaner loop (#765) f33b9ed81 cleaning, edge case with keyword (#764) 117c72721 more edge case accuracy,refactoring (#761) 294563c61 &cino format 63daab731 better &cino parsing (#759) 8e17e2330 Detect .es6 files as JavaScript (#199) 25cff858e don't move cursor at default label 3583822da reflow comment 4149f1d30 cleaning continued braceless statement (#758) 9db487d00 add option in s:prev_token() (#757) 1a17ce8c6 Merge pull request #756 from pangloss/array-destructuring-default-value-support 0dd9ad3b4 Fix array destructuring as func arg definitions 0bf390d9c optimize indent with basic syntax file (#753) afecff2b5 v:lnum cleaning 3cc3ef7c1 cleaning (#751) e80725868 Revert "match isk in token regex" (#750) 82f064a12 match isk in token regex (#749) 039c611e1 refactor v:lnum cleaning (#748) d81b076b5 make regex for token() more intuitive (#746) a210f3916 fix code comment 554ae9b24 package-manager info (#744) d377f45bd regex simplified in trim() (#745) d2bc5d49e remove conditional 9e0aa00b6 clarify readme ba9501bfc markdown fixes 41a3bceb4 more readme fixes df14847ad fix readme 9f4772175 Added conceal for no-argument arrow functions - either `()=>` or `_=>` (#735) 6d81ec817 only Trim() if in a block (#743) 66b25d97c Indent: use previous Trim, with new interface (#741) 14919946c date, code documenting 7ceb23304 misc indent changes (#739) 982f699de small optimization (#738) 1bc948137 date, minor regex c1d4b3b07 keywords used as props (#737) 25ceb5578 cleaning, Rework prevcodeline() (#736) edf962fb5 Merge pull request #734 from pangloss/fix-flow-import-type 3dd27d631 Adding support for Flow type imports 18ff935c9 optimization: no continuation at block start (#733) 8265877f7 indentkeys (#732) 1801887f2 operator cleaning (#729) 5e024dc2e Merge pull request #731 from pangloss/refactor-import-export 66f120cb0 Improve default handling 3873adbff Completely refactored how import/export work 894e26d85 Merge pull request #727 from pangloss/fix-import-region 91b0a0da0 Fix end pattern for import region c92a0cad8 paren start line as baseline in blocks (#725) a87c94438 unneeded token call (#722) 209b57f9d remove dead code, rename function, date (#721) ae9324a61 improve ptoken (#719) bac863e62 Merge pull request #718 from pangloss/fix-spread-in-brackets 3efcf3111 Adds jsSpreadExpression to jsBracket 7b9c64f15 Merge pull request #717 from pangloss/improve-class-definition b18c6b88a Basic improvement to jsClassDefinition f4245c4f7 more correct comment match (#714) 737c23845 faster prevline (#713) b8c62023d add operators, regex experiment (#711) 540d3a572 improve regex for s:Trim (#710) b3b85e34b trim from start of comment sequence (#709) f177220eb regex prettify bbabf9d67 syntax aware previous token (#705) c938b83e2 Update README.md (#702) 22b9f0f8e consider regex when matching '/' (#703) git-subtree-dir: vim/bundle/javascript git-subtree-split: d2ccd306f2c11f061c5284ff5d315c7cf257e32a --- CONTRIBUTING.md | 18 -- ISSUE_TEMPLATE.md | 12 + README.md | 81 +++---- compiler/eslint.vim | 16 ++ extras/flow.vim | 54 +++-- extras/jsdoc.vim | 6 +- ftdetect/javascript.vim | 13 +- indent/javascript.vim | 518 +++++++++++++++++++++++++++++----------- syntax/javascript.vim | 186 ++++++++------- 9 files changed, 588 insertions(+), 316 deletions(-) delete mode 100644 CONTRIBUTING.md create mode 100644 ISSUE_TEMPLATE.md create mode 100644 compiler/eslint.vim diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index c47cbc8..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,18 +0,0 @@ -## Contributing - -This project uses the [git -flow](http://nvie.com/posts/a-successful-git-branching-model/) model for -development. There's [a handy git module for git -flow](//github.com/nvie/gitflow). If you'd like to be added as a contributor, -the price of admission is 1 pull request. Please follow the general code style -guides (read the code) and in your pull request explain the reason for the -proposed change and how it is valuable. - -## Pull Requests - -Please make your pull requests against the `develop` branch; we stage changes -for testing there to avoid unexpected breakages for our users. :) - -## Bug report - -Report a bug on [GitHub Issues](https://github.com/pangloss/vim-javascript/issues). diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..155ea8d --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,12 @@ +If you are reporting an issue that involves any JSX (e.g. +
{`${example}`}
), PLEASE PLEASE PLEASE make sure you have properly +setup and are sourcing this plugin https://github.com/mxw/vim-jsx + +WE DO NOT support JSX automatically, you need another plugin to add get this +functionality. + +If applicable, include a snippet of code that we can easily copy and paste that +replicates your bug. + +Make sure the bug still exists if you disable all other javascript plugins +except the one noted above, mxw/vim-jsx diff --git a/README.md b/README.md index 1cd79f4..b60614f 100644 --- a/README.md +++ b/README.md @@ -6,32 +6,12 @@ improved indentation. ## Installation -### Install with [Vundle](https://github.com/gmarik/vundle) - -Add to vimrc: - - Plugin 'pangloss/vim-javascript' - -And install it: - - :so ~/.vimrc - :PluginInstall - -### Install with [vim-plug](https://github.com/junegunn/vim-plug) - -Add to vimrc: - - Plug 'pangloss/vim-javascript' - -And install it: - - :so ~/.vimrc - :PlugInstall - ### Install with [pathogen](https://github.com/tpope/vim-pathogen) git clone https://github.com/pangloss/vim-javascript.git ~/.vim/bundle/vim-javascript +alternatively, use a package manager like [vim-plug](https://github.com/junegunn/vim-plug) + ## Configuration Variables @@ -83,38 +63,53 @@ global vim option, we do not set it ourselves. ## Concealing Characters -You can customize concealing characters by defining one or more of the following +You can customize concealing characters, if your font provides the glyph you want, by defining one or more of the following variables: - let g:javascript_conceal_function = "ƒ" - let g:javascript_conceal_null = "ø" - let g:javascript_conceal_this = "@" - let g:javascript_conceal_return = "⇚" - let g:javascript_conceal_undefined = "¿" - let g:javascript_conceal_NaN = "ℕ" - let g:javascript_conceal_prototype = "¶" - let g:javascript_conceal_static = "•" - let g:javascript_conceal_super = "Ω" - let g:javascript_conceal_arrow_function = "⇒" + let g:javascript_conceal_function = "ƒ" + let g:javascript_conceal_null = "ø" + let g:javascript_conceal_this = "@" + let g:javascript_conceal_return = "⇚" + let g:javascript_conceal_undefined = "¿" + let g:javascript_conceal_NaN = "ℕ" + let g:javascript_conceal_prototype = "¶" + let g:javascript_conceal_static = "•" + let g:javascript_conceal_super = "Ω" + let g:javascript_conceal_arrow_function = "⇒" + let g:javascript_conceal_noarg_arrow_function = "🞅" + let g:javascript_conceal_underscore_arrow_function = "🞅" + + +You can enable concealing within VIM with: + + set conceallevel=1 + +OR if you wish to toggle concealing you may wish to bind a command such as the following which will map `l` (leader is usually the `\` key) to toggling conceal mode: + + map l :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1" + ## Indentation Specific * `:h cino-:` +* `:h cino-=` +* `:h cino-star` +* `:h cino-(` +* `:h cino-w` +* `:h cino-W` +* `:h cino-U` +* `:h cino-m` +* `:h cino-M` +* `:h 'indentkeys'` ## Contributing -This project uses the [git -flow](http://nvie.com/posts/a-successful-git-branching-model/) model for -development. There's [a handy git module for git -flow](//github.com/nvie/gitflow). If you'd like to be added as a contributor, -the price of admission is 1 pull request. Please follow the general code style +Please follow the general code style guides (read the code) and in your pull request explain the reason for the -proposed change and how it is valuable. - - -## Bug Reports +proposed change and how it is valuable. All p.r.'s will be reviewed by a +maintainer(s) then, hopefully, merged. -Report a bug on [GitHub Issues](https://github.com/pangloss/vim-javascript/issues). +Thank you! ## License diff --git a/compiler/eslint.vim b/compiler/eslint.vim new file mode 100644 index 0000000..7695a07 --- /dev/null +++ b/compiler/eslint.vim @@ -0,0 +1,16 @@ +" Vim compiler plugin +" Language: JavaScript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript + +if exists("current_compiler") + finish +endif +let current_compiler = "eslint" + +if exists(":CompilerSet") != 2 + command! -nargs=* CompilerSet setlocal +endif + +CompilerSet makeprg=eslint\ -f\ compact\ % +CompilerSet errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m diff --git a/extras/flow.vim b/extras/flow.vim index 028ea3f..204fdbe 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -1,33 +1,38 @@ syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\|=>\@!\)\@=/ contains=@jsFlowCluster -syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster -syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster -syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster +syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowExactObject contained matchgroup=jsFlowNoise start=/{|/ end=/|}/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster keepend fold syntax match jsFlowNoise contained /[:;,<>]/ -syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object array bool class +syntax keyword jsFlowType contained boolean number string null void any mixed JSON array Function object array bool class syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType syntax match jsFlowTypeCustom contained /[0-9a-zA-Z_.]*/ skipwhite skipempty nextgroup=jsFlowGroup syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens -syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject syntax match jsFlowOrOperator contained /|/ skipwhite skipempty nextgroup=@jsFlowCluster +syntax keyword jsFlowImportType contained type skipwhite skipempty nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup +syntax match jsFlowWildcard contained /*/ -syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster -syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp -syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp -syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster,jsFlowArrow,jsFlowReturnParens +syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold +syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold +syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp,jsFlowReturnArrow fold +syntax match jsFlowReturnArrow contained /=>/ skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock,jsFlowReturnOrOp -syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword +syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword,jsFlowReturnObject syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp syntax match jsFlowReturnOrOp contained /\s*|\s*/ skipwhite skipempty nextgroup=@jsFlowReturnCluster +syntax match jsFlowWildcardReturn contained /*/ skipwhite skipempty nextgroup=jsFuncBlock syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncArgs syntax region jsFlowClassGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock -syntax region jsFlowTypeStatement start=/type/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend -syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression,jsFlowGroup,jsFlowMaybe +syntax region jsFlowTypeStatement start=/type\%(\s\+\k\)\@=/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend +syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/=/ end=/[\n;]/ contains=@jsFlowCluster,jsFlowGroup,jsFlowMaybe +syntax match jsFlowTypeOperator contained /=/ containedin=jsFlowTypeValue syntax match jsFlowTypeOperator contained /=/ syntax keyword jsFlowTypeKeyword contained type @@ -37,12 +42,18 @@ syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\) syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster -syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise +syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise fold -syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend +" NOTE: It appears the nextgroup was causing a ton of breakages... testing it +" witout a nextgroup, but keeping this arround for reference incase something breaks +" syntax match jsFlowMaybe contained /?/ nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject extend keepend +syntax match jsFlowMaybe contained /?/ +syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend fold -syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp -syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator +syntax region jsFlowParenAnnotation contained start=/:/ end=/[,=)]\@=/ containedin=jsParen contains=@jsFlowCluster + +syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn,jsFlowReturnArrow +syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowExactObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard if version >= 508 || !exists("did_javascript_syn_inits") if version < 508 @@ -59,9 +70,11 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowTypeof PreProc HiLink jsFlowArray PreProc HiLink jsFlowObject PreProc + HiLink jsFlowExactObject PreProc HiLink jsFlowParens PreProc HiLink jsFlowGroup PreProc HiLink jsFlowReturn PreProc + HiLink jsFlowParenAnnotation PreProc HiLink jsFlowReturnObject jsFlowReturn HiLink jsFlowReturnArray jsFlowArray HiLink jsFlowReturnParens jsFlowParens @@ -70,9 +83,10 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowClassGroup PreProc HiLink jsFlowArrowArguments PreProc HiLink jsFlowArrow PreProc + HiLink jsFlowReturnArrow PreProc HiLink jsFlowTypeStatement PreProc HiLink jsFlowTypeKeyword PreProc - HiLink jsFlowTypeOperator PreProc + HiLink jsFlowTypeOperator Operator HiLink jsFlowMaybe PreProc HiLink jsFlowReturnMaybe PreProc HiLink jsFlowClassProperty jsClassProperty @@ -81,7 +95,11 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowInterface PreProc HiLink jsFlowNoise Noise HiLink jsFlowObjectKey jsObjectKey - HiLink jsFlowOrOperator PreProc + HiLink jsFlowOrOperator jsOperator HiLink jsFlowReturnOrOp jsFlowOrOperator + HiLink jsFlowWildcard PreProc + HiLink jsFlowWildcardReturn PreProc + HiLink jsFlowImportType PreProc + HiLink jsFlowTypeValue PreProc delcommand HiLink endif diff --git a/extras/jsdoc.vim b/extras/jsdoc.vim index 645d55a..a19f3a3 100644 --- a/extras/jsdoc.vim +++ b/extras/jsdoc.vim @@ -4,13 +4,13 @@ syntax region jsComment matchgroup=jsComment start="/\*\s*" end="\*/" contai " tags containing a param syntax match jsDocTags contained "@\(alias\|api\|augments\|borrows\|class\|constructs\|default\|defaultvalue\|emits\|exception\|exports\|extends\|fires\|kind\|link\|listens\|member\|member[oO]f\|mixes\|module\|name\|namespace\|requires\|template\|throws\|var\|variation\|version\)\>" skipwhite nextgroup=jsDocParam " tags containing type and param -syntax match jsDocTags contained "@\(arg\|argument\|cfg\|param\|property\|prop\)\>" skipwhite nextgroup=jsDocType +syntax match jsDocTags contained "@\(arg\|argument\|cfg\|param\|property\|prop\|typedef\)\>" skipwhite nextgroup=jsDocType " tags containing type but no param -syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|implements\|this\|type\|typedef\|return\|returns\)\>" skipwhite nextgroup=jsDocTypeNoParam +syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|implements\|this\|type\|return\|returns\)\>" skipwhite nextgroup=jsDocTypeNoParam " tags containing references syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag " other tags (no extra syntax) -syntax match jsDocTags contained "@\(abstract\|access\|accessor\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>" +syntax match jsDocTags contained "@\(abstract\|access\|accessor\|async\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>" syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam diff --git a/ftdetect/javascript.vim b/ftdetect/javascript.vim index d6aa6d0..ff07f4d 100644 --- a/ftdetect/javascript.vim +++ b/ftdetect/javascript.vim @@ -1,6 +1,13 @@ -au BufNewFile,BufRead *.js setf javascript -au BufNewFile,BufRead *.jsm setf javascript -au BufNewFile,BufRead Jakefile setf javascript +au BufNewFile,BufRead *.{js,mjs,jsm,es,es6},Jakefile setf javascript + +fun! s:SourceFlowSyntax() + if !exists('javascript_plugin_flow') && !exists('b:flow_active') && + \ search('\v\C%^\_s*%(//\s*|/\*[ \t\n*]*)\@flow>','nw') + runtime extras/flow.vim + let b:flow_active = 1 + endif +endfun +au FileType javascript au BufRead,BufWritePost call s:SourceFlowSyntax() fun! s:SelectJavascript() if getline(1) =~# '^#!.*/bin/\%(env\s\+\)\?node\>' diff --git a/indent/javascript.vim b/indent/javascript.vim index b72ff92..e7334bf 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: November 6, 2016 +" Last Change: August 12, 2017 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -10,13 +10,27 @@ if exists('b:did_indent') endif let b:did_indent = 1 +" indent correctly if inside