From 7145139cf0af5a87b7cbdd405e27f550a7c9f390 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 31 Oct 2017 07:47:19 -0700 Subject: [PATCH 01/82] jsx context fix (#1068) * match vs index(split()) * actually, jsx fix * convention --- indent/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 13727827..2187b3c4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -303,6 +303,7 @@ endfunction function s:IsBlock() let tok = s:PreviousToken() if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx' + let s:in_jsx = 1 return tok != '{' elseif tok =~ '\k' if tok ==# 'type' @@ -389,10 +390,10 @@ function GetJavascriptIndent() let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]] - let [num_ind, is_op, b_l, l:switch_offset] = [s:Nat(indent(num)),0,0,0] + let [num_ind, is_op, b_l, l:switch_offset, s:in_jsx] = [s:Nat(indent(num)),0,0,0,0] if !num || s:LookingAt() == '{' && s:IsBlock() let ilnum = line('.') - if num && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) + if num && !s:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) if ilnum == num let [num, num_ind] = [line('.'), indent('.')] endif From 3b21b5bade24c651e172784dead19e589aa3798e Mon Sep 17 00:00:00 2001 From: Florian Breisch Date: Tue, 31 Oct 2017 17:42:55 +0100 Subject: [PATCH 02/82] Add WeakSet to syntax keywords (#1069) Add [WeakSet](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) to the list of jsGlobalObjects keywords. --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index a4623543..455c83f4 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -110,7 +110,7 @@ syntax keyword jsAsyncKeyword async await syntax match jsSwitchColon contained /::\@!/ skipwhite skipempty nextgroup=jsSwitchBlock " Keywords -syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat fetch +syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set WeakSet RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat fetch syntax keyword jsGlobalNodeObjects module exports global process __dirname __filename syntax match jsGlobalNodeObjects /\/ containedin=jsFuncCall syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError From 0f1f71f2f22fdf62e8eb9e1c226db5939edf4472 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 1 Nov 2017 18:02:04 -0700 Subject: [PATCH 03/82] PToken() optimize (#1070) --- indent/javascript.vim | 46 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 2187b3c4..42744725 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -26,11 +26,6 @@ setlocal indentkeys+=0],0) let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<' " Regex of syntax group names that are or delimit string or are comments. -let b:syng_strcom = get(b:,'syng_strcom','string\|comment\|regex\|special\|doc\|template\%(braces\)\@!') -let b:syng_str = get(b:,'syng_str','string\|template\|special') -" template strings may want to be excluded when editing graphql: -" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' -" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' " Only define the function once. if exists('*GetJavascriptIndent') @@ -40,6 +35,19 @@ endif let s:cpo_save = &cpo set cpo&vim +let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!' +let s:syng_str = 'string\|template\|special' +" template strings may want to be excluded when editing graphql: +" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' +" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' +let s:js_cache = [0,0,0] + +function s:GetVars() + for svar in ['syng_strcom', 'syng_str', 'js_cache'] + let b:{svar} = get(b:,svar,copy(s:{svar})) + endfor +endfunction + " Get shiftwidth value if exists('*shiftwidth') function s:sw() @@ -159,19 +167,29 @@ function s:Token() return s:LookingAt() =~ '\k' ? expand('') : s:LookingAt() endfunction -function s:PreviousToken() - let l:col = col('.') +function s:PreviousToken(...) + let [l:pos, tok] = [getpos('.'), ''] if search('\m\k\{1,}\|\S','ebW') - if search('\m\*\%#\/\|\/\/\%<'.a:firstline.'l','nbW',line('.')) && eval(s:in_comm) - if s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) - return s:Token() + if getline('.')[col('.')-2:col('.')-1] == '*/' + if eval(s:in_comm) && !s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) + call setpos('.',l:pos) + else + let tok = s:Token() endif - call cursor(a:firstline, l:col) else - return s:Token() + let two = a:0 || line('.') != l:pos[1] ? strridx(getline('.')[:col('.')],'//') + 1 : 0 + if two && eval(s:in_comm) + call cursor(0,two) + let tok = s:PreviousToken(1) + if tok is '' + call setpos('.',l:pos) + endif + else + let tok = s:Token() + endif endif endif - return '' + return tok endfunction function s:Pure(f,...) @@ -328,7 +346,7 @@ function s:IsBlock() endfunction function GetJavascriptIndent() - let b:js_cache = get(b:,'js_cache',[0,0,0]) + call s:GetVars() let s:synid_cache = [[],[]] let l:line = getline(v:lnum) " use synstack as it validates syn state and works in an empty line From 77e4bf814c53a4f2c23d4c4d5a4ef718d013a4db Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 1 Nov 2017 20:18:05 -0700 Subject: [PATCH 04/82] one time sourced so b: vars only created for first buffer --- indent/javascript.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 42744725..9a4623a7 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -12,7 +12,8 @@ let b:did_indent = 1 " indent correctly if inside