├── ChangeLog ├── README.mdown ├── indent └── javascript.vim └── test.js /ChangeLog: -------------------------------------------------------------------------------- 1 | 2011-10-19 Version 1.4.6 2 | 3 | New: return indent supported 4 | 5 | return a + 6 | b + 7 | c; 8 | 9 | Fix: failed indent for 10 | 11 | var a, 12 | // ca 13 | b, 14 | /* cb */ 15 | c; 16 | 17 | 2011-10-14 Version 1.4.5 18 | Fix: float indent level is invalid in vim 7.3 19 | 20 | Fix: failed indent for 21 | var a = /reg/, 22 | c = 'bar' 23 | 24 | Optimize code 25 | 26 | 2011-10-13 Version 1.4.4 27 | Fix: failed indent for 28 | (a / b); // c ( 29 | 30 | Fix: failed indent for 31 | '' + "'" + // ' ( 32 | 33 | Fix: failed indent in Brief Mode for 34 | foo (a(b, 35 | c)) { 36 | aoeu 37 | } 38 | 39 | 2011-07-24 Version 1.4.3 40 | Fix: failed indent in brief mode, and optimize in normal mode for code 41 | { 42 | console.info((function() { 43 | }).something); 44 | next(); 45 | } 46 | 47 | 2011-04-25 Version 1.4.2 48 | Update: Add option g:SimpleJsIndenter_CaseIndentLevel 49 | 50 | 2011-04-23 Version 1.4.1 51 | Update: Indent current line when input } ) ] 52 | See https://github.com/jiangmiao/simple-javascript-indenter/issues/4 53 | 54 | Update: Change comment indentation style 55 | See https://github.com/jiangmiao/simple-javascript-indenter/issues/5 56 | 57 | 2011-03-26 Version 1.4.0 58 | New: Support switch case indenting. 59 | 60 | 2011-03-22 Version 1.3.4 61 | Fix: failed indent for 62 | function escapeattr(b) { 63 | return b ? b.replace(/([\.#\[\]])/ig, "\\$1") : "" 64 | } 65 | 66 | https://github.com/jiangmiao/simple-javascript-indenter/issues#issue/1 (Thanks to whentp) 67 | 68 | 2011-01-08 Version 1.3.3 69 | FIX: failed indent for 70 | test(/*a'*/b,'c') { 71 | foo(); 72 | } 73 | 74 | 2011-01-07 Version 1.3.2 75 | FIX: failed indent for 76 | function a() { 77 | $('"', {'b'}, function() { 78 | }); 79 | } 80 | 81 | 2010-11-22 Version 1.3.1 82 | FIX: failed indent for 83 | query = query.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); 84 | // Only use querySelectorAll on non-XML documents 85 | { 86 | for ( var type in Expr.match ) { 87 | Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); 88 | Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)\/*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); 89 | } 90 | } 91 | 92 | FIX: failed indent for 93 | function a() { 94 | test(["hello", 95 | "world", 96 | "a", 97 | "b" 98 | ]) 99 | } 100 | 101 | FIX: failed indent for 102 | function( a ) { 103 | b( this, 104 | c(), 105 | d() ); 106 | }, 107 | 108 | 2010-09-23 Version 1.3.0 109 | New Feature: Brief Mode 110 | 111 | 2010-09-08 Version 1.2.1 112 | Some optimize 113 | 114 | 2010-09-08 Version 1.2.0 115 | Support: indent for if, else, else if, while, try, catch, finally 116 | without brackets 117 | 118 | 2010-09-07 Version 1.1.2 119 | FIX: indent error for regexp 120 | 121 | 2010-09-07 Version 1.1.1 122 | FIX: indent error for code 123 | if( A || 124 | B && 125 | C) 126 | { 127 | } 128 | 129 | 2010-09-06 Version 1.1.0 130 | NEW: Support indent for assign variables. 131 | 132 | 2010-09-05 Version 1.0.1 133 | Fix comment issue isn't solved after whole reindent if the first line is blank 134 | -------------------------------------------------------------------------------- /README.mdown: -------------------------------------------------------------------------------- 1 | Simply Javascript Indenter 2 | ========================== 3 | A simple vim indent plugin for javascript, support OOP, jquery 4 | 5 | Install details 6 | --------------- 7 | 8 | copy indent/javascript.vim to ~/.vim/indent 9 | 10 | Options 11 | ------- 12 | * g:SimpleJsIndenter_BriefMode (default 0) 13 | > set 1 to turn brief mode on. 14 | 15 | About Brief Mode 16 | ---------------- 17 | Add 'let g:SimpleJsIndenter_BriefMode = 1' to ~/.vimrc to use brief mode. 18 | 19 | In Brief Mode script will not indent more than one shiftwidth each line. 20 | eg: 21 | For a lot of people prefer set shiftwidth to 4, so in normal mode, it will indent looks like 22 | each(function { 23 | ........something(); // indent 2 shiftwidth 24 | }); 25 | ((( 26 | ............something(); // indent 3 shiftwidth 27 | ))); 28 | 29 | In brief mode it will indent as 30 | each(function { 31 | ....something(); // indent 1 shiftwidth 32 | }); 33 | ((( 34 | ....something(); 35 | ))) 36 | 37 | ATTENTION: 38 | Be sure to always close the brackets with the same level as open, or the after code will not indent correctly. 39 | eg: 40 | function() { 41 | ....each(function() { 42 | ....} // should use }); instead of } 43 | ); // already indented.. 44 | something(); 45 | } 46 | 47 | About Indenting in switch {} 48 | ---------------------------- 49 | It's not a perfect indenting. 50 | see https://github.com/jiangmiao/simple-javascript-indenter/issues#issue/2 51 | 52 | 53 | Indent Effects 54 | -------------- 55 | /* 56 | * Comment Test 57 | * function() { 58 | */ 59 | { 60 | /* a [{( */ 61 | // b [{( 62 | comment('/* com', a /* [{( */); /* c */ // d 63 | ok(); 64 | // Assign Test 65 | var a, /* { */ 66 | b, // [ 67 | c = '{' 68 | var a = "Hello" + 69 | "World" 70 | d = function() { 71 | aoeu 72 | } 73 | var k = function() { 74 | var k=3, 75 | m=4 76 | } 77 | 78 | var rurl = /{[('"/, 79 | r20 = /%20/g, 80 | 81 | a = 1, 82 | b = 2 83 | a = 1 + 84 | 2 * 85 | 3 86 | } 87 | 88 | // Function nested 89 | ;(function($) { 90 | $(document).ready(function() { 91 | $('#foo').click(function() { 92 | $.post(url, { 93 | a: 1, 94 | b: 2, 95 | }, function() { 96 | ok(); 97 | } 98 | ); 99 | }); 100 | }); 101 | })(jQuery); 102 | 103 | // Array Object Test 104 | string_test("('",'("',"[",'{',"\"{","\\'{"); 105 | { 106 | array_object_test: [ 107 | 1, 108 | 2, 109 | { 110 | a: [3,4], 111 | b: [ 112 | 3, 113 | 4 114 | ], 115 | c: string_test("('",'("',"[",'{',"\"{","\\'{"), 116 | function_test: function() { 117 | return 0; 118 | }, 119 | one_line_function_test: function() { return [1] } 120 | } 121 | ] 122 | } 123 | 124 | // One Line Test 125 | { 126 | if( a == b && 127 | c == d || 128 | e == f) 129 | { 130 | ok(); 131 | } 132 | if(a) { 133 | b; 134 | } else { 135 | e; 136 | } 137 | if(a) 138 | b; 139 | else if(k) { 140 | aeou 141 | } else 142 | c; 143 | while(true) 144 | foo += 1; 145 | try 146 | a; 147 | catch 148 | b; 149 | finally 150 | c; 151 | ok(); 152 | } 153 | 154 | -------------------------------------------------------------------------------- /indent/javascript.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: JavaScript 3 | " Maintainer: JiangMiao 4 | " Last Change: 2011-10-19 5 | " Version: 1.4.6 6 | " Homepage: http://www.vim.org/scripts/script.php?script_id=3227 7 | " Repository: https://github.com/jiangmiao/simple-javascript-indenter 8 | 9 | if exists('b:did_indent') 10 | finish 11 | endif 12 | 13 | " Disable Assginment let script will not indent assignment. 14 | if(!exists('g:SimpleJsIndenter_DisableAssignment')) 15 | let g:SimpleJsIndenter_DisableAssignment = 0 16 | endif 17 | 18 | " Brief Mode will indent no more than one level. 19 | if(!exists('g:SimpleJsIndenter_BriefMode')) 20 | let g:SimpleJsIndenter_BriefMode = 0 21 | endif 22 | 23 | " The value should be float, -1/2 should be written in -0.5 24 | if(!exists('g:SimpleJsIndenter_CaseIndentLevel')) 25 | let g:SimpleJsIndenter_CaseIndentLevel = 0 26 | endif 27 | 28 | if(!exists('g:SimpleJsIndenter_GreedyIndent')) 29 | let g:SimpleJsIndenter_GreedyIndent = 1 30 | endif 31 | 32 | let b:did_indent = 1 33 | let b:indented = 0 34 | let b:in_comment = 0 35 | 36 | setlocal indentexpr=GetJsIndent() 37 | setlocal indentkeys+==},=),=],0=*/,0=/*,0=\,,0=;,* 38 | if exists("*GetJsIndent") 39 | finish 40 | endif 41 | 42 | let s:expr_left = '[[{(]' 43 | let s:expr_right = '[)}\]]' 44 | let s:expr_all = '[[{()}\]]' 45 | 46 | let s:expr_case = '\s\+\(case\s\+[^\:]*\|default\)\s*:\s*' 47 | let s:expr_comment_start = '/\*c' 48 | let s:expr_comment_end = 'c\*/' 49 | 50 | let s:expr_comma_start = '^\s*,' 51 | let s:expr_var = '^\s*var\s' 52 | let s:expr_var_stop = ';' 53 | " add $ to Fix 54 | " ;(function() { 55 | " something; 56 | " }) 57 | let s:expr_semic_start = '^\s*;\s*$' 58 | 59 | " Check prev line 60 | function! DoIndentPrev(ind,str) 61 | let ind = a:ind 62 | let pline = a:str 63 | let first = 1 64 | let last = 0 65 | 66 | if g:SimpleJsIndenter_GreedyIndent || pline !~ s:expr_left || s:IsOneLineIndentLoose(pline) 67 | let mstr = matchstr(pline, '^'.s:expr_right.'*') 68 | let last = strlen(mstr) 69 | let start_with_expr_right = last 70 | else 71 | let start_with_expr_right = 0 72 | endif 73 | 74 | let ind_add = 0 75 | let ind_dec = 0 76 | 77 | while 1 78 | let last=match(pline, s:expr_all, last) 79 | if last == -1 80 | break 81 | endif 82 | let str = pline[last] 83 | let last = last + 1 84 | 85 | if match(str, s:expr_left) != -1 86 | let ind_add += 1 87 | else 88 | if start_with_expr_right == 0 89 | let ind_dec += 1 90 | endif 91 | endif 92 | 93 | endwhile 94 | 95 | 96 | "BriefMode 97 | if(g:SimpleJsIndenter_BriefMode) 98 | if ind_add > 1 99 | let ind_add = 1 100 | endif 101 | 102 | if ind_dec > 1 103 | let ind_dec = 1 104 | endif 105 | endif 106 | let ind = a:ind + (ind_add - ind_dec) * &sw 107 | 108 | if (match(' '.pline, s:expr_case)!=-1) 109 | let ind = float2nr(ind - &sw * g:SimpleJsIndenter_CaseIndentLevel) 110 | endif 111 | 112 | if match(pline, s:expr_comment_start) != -1 113 | let ind = ind + 1 114 | endif 115 | 116 | if match(pline, s:expr_comment_end) != -1 117 | let ind = ind - 1 118 | endif 119 | 120 | if match(pline, s:expr_comma_start) != -1 121 | let ind = ind + 2 122 | if match(pline, s:expr_var_stop) != -1 123 | let ind = ind - 4 124 | endif 125 | endif 126 | 127 | " buggy 128 | if match(pline, s:expr_semic_start) != -1 129 | let ind = ind - 2 130 | endif 131 | 132 | return ind 133 | endfunction 134 | 135 | 136 | " Check current line 137 | function! DoIndent(ind, str, pline) 138 | let ind = a:ind 139 | let line = a:str 140 | let pline = a:pline 141 | let last = 0 142 | let first = 1 143 | 144 | if g:SimpleJsIndenter_GreedyIndent || line !~ s:expr_left || s:IsOneLineIndentLoose(line) 145 | let mstr = matchstr(line, '^'.s:expr_right.'*') 146 | let num = strlen(mstr) 147 | let start_with_expr_right = num 148 | " If start with expr right, then indent as more as possible. 149 | if start_with_expr_right 150 | let num = len(split(line, s:expr_right, 1)) - 1 151 | endif 152 | let ind = ind - &sw * num 153 | endif 154 | 155 | 156 | "BriefMode 157 | if(g:SimpleJsIndenter_BriefMode) 158 | if(inda:ind) 162 | let ind = a:ind + &sw 163 | endif 164 | endif 165 | 166 | 167 | if (match(' '.line, s:expr_case)!=-1) 168 | let ind = float2nr(ind + &sw * g:SimpleJsIndenter_CaseIndentLevel) 169 | endif 170 | 171 | if (match(line, s:expr_comma_start) != -1) 172 | let ind = ind - 2 173 | if (match(pline, s:expr_var) != -1) 174 | let ind = ind + 4 175 | endif 176 | endif 177 | 178 | if (match(line, s:expr_semic_start) != -1 && match(pline, s:expr_comma_start) != -1) 179 | let ind = ind - 2 180 | endif 181 | 182 | if ind<0 183 | let ind=0 184 | endif 185 | 186 | return ind 187 | endfunction 188 | 189 | " Remove strings and comments 190 | function! TrimLine(pline) 191 | let line = substitute(a:pline, '\\\\', '_','g') 192 | let line = substitute(line, '\\.', '_','g') 193 | " One line comment 194 | let line = substitute(line, '^\s*/\*.*\*/\s*$', '//c', 'g') 195 | let line = substitute(line, '^\s*//.*$', '//c', 'g') 196 | " remove all non ascii character 197 | let line = substitute(line, '[^\x00-\x7f]', '', 'g') 198 | 199 | " Strings 200 | let new_line = '' 201 | let sub_line = '' 202 | let min_pos = 0 203 | while 1 204 | let c = '' 205 | let base_pos = min_pos 206 | let min_pos = match(line, '[''"/]', base_pos) 207 | if min_pos == -1 208 | let new_line .= strpart(line, base_pos) 209 | break 210 | endif 211 | let c = line[min_pos] 212 | 213 | let new_line .= strpart(line, base_pos, min_pos - base_pos) 214 | let sub_line = '' 215 | 216 | if c == '''' 217 | let sub_line = matchstr(line, "^'.\\{-}'", min_pos) 218 | if sub_line != '' 219 | let new_line .= '_' 220 | endif 221 | elseif c == '"' 222 | let sub_line = matchstr(line, '^".\{-}"', min_pos) 223 | if sub_line != '' 224 | let new_line .= '_' 225 | endif 226 | elseif c == '/' 227 | " Skip all if match a comment 228 | if line[min_pos+1] == '/' 229 | let sub_line = matchstr(line, '^/.*', min_pos) 230 | if min_pos == 0 && sub_line != '' 231 | let new_line = '//c' 232 | break 233 | endif 234 | elseif line[min_pos+1] == '*' 235 | let sub_line = matchstr(line, '^/\*.\{-}\*/', min_pos) 236 | else 237 | " /.../ sometimes is not a regexp, (a / b); // c 238 | let m = matchlist(line, '^\(/[^/]\+/\)\([^/]\|$\)', min_pos) 239 | if len(m) 240 | let new_line .= '_' 241 | let sub_line = m[1] 242 | endif 243 | endif 244 | endif 245 | if sub_line != '' 246 | let min_pos = min_pos + strlen(sub_line) 247 | else 248 | let new_line .= c 249 | let min_pos = min_pos + 1 250 | endif 251 | endwhile 252 | let line = new_line 253 | 254 | " Comment 255 | let line = substitute(line, '/\*.*$','/*c','') 256 | let line = substitute(line, '^.\{-}\*/','c*/','') 257 | let line = substitute(line, '^\s*\*.*','','') 258 | 259 | " Brackets 260 | let new_line = '' 261 | while new_line != line 262 | let new_line = line 263 | let line = substitute(line,'\(([^)(]*)\|\[[^\][]*\]\|{[^}{]*}\)','_','g') 264 | endwhile 265 | 266 | " Trim Blank 267 | let line = matchlist(line, '\s*\(.\{-}\)\s*$')[1] 268 | 269 | return line 270 | endfunction 271 | 272 | function! s:GetLine(num) 273 | return TrimLine(getline(a:num)) 274 | endfunction 275 | 276 | let s:expr_partial = '[+\-*/|&,]$' 277 | let s:expr_partial2 = '[+\-*/|&]$' 278 | function! s:IsPartial(line) 279 | " Add IndentLoose for 280 | " function a() { 281 | " test(["hello", 282 | " "world", 283 | " "a", 284 | " "b" 285 | " ]) // Failed 286 | " } 287 | return match(a:line, '\*/$') == -1 && match(a:line, s:expr_partial)!=-1 && ( match(a:line, s:expr_all)==-1 || s:IsOneLineIndentLoose(a:line) ) 288 | endfunction 289 | 290 | function! s:IsComment(line) 291 | return a:line =~ '^\s*//' || a:line =~ '^\s*/\*.*\*/\s*$' 292 | endfunction 293 | function! s:SearchBack(num) 294 | let num = a:num 295 | let new_num = num 296 | let partial = 0 297 | while 1 298 | if new_num == 0 299 | break 300 | endif 301 | let line = getline(new_num) 302 | if !s:IsComment(line) 303 | let line = TrimLine(line) 304 | if !s:IsPartial(line) 305 | if partial > 0 306 | " Store line number to last partial 307 | let num = partial 308 | endif 309 | break 310 | endif 311 | " Save the partial postion 312 | let partial = new_num 313 | if match(line, s:expr_all)!=-1 314 | let num = new_num 315 | break 316 | endif 317 | endif 318 | let num = new_num 319 | let new_num = num - 1 320 | endwhile 321 | return num 322 | endfunction 323 | 324 | function! s:AssignIndent(line) 325 | let ind = 0 326 | let line = a:line 327 | let line = matchlist(line, '^\s*\(.\{-}\)\s*$')[1] 328 | 329 | if(match(line,'.*=.*'.s:expr_partial2) != -1) 330 | return ind + strlen(matchstr(line, '.*=\s*')) 331 | elseif(match(line,'\(var\|return\)\s\+.*=\s*') != -1) 332 | return ind + strlen(matchstr(line, '\(var\|return\)\s\+')) 333 | elseif(match(line,'\(var\|return\)\s\+') != -1) 334 | return ind + strlen(matchstr(line, '\(var\|return\)\s\+')) 335 | elseif(match(line,'^\w\s\+=\s*.*[^,]$') != -1) 336 | return ind + strlen(matchstr(line, '^\w\s\+=\s*')) 337 | endif 338 | return ind 339 | endfunction 340 | 341 | function! s:IsAssign(line) 342 | return match(a:line, s:expr_all) == -1 && s:AssignIndent(a:line)>0 343 | endfunction 344 | 345 | function DoIndentAssign(ind, line) 346 | return a:ind + s:AssignIndent(a:line) 347 | endfunction 348 | 349 | function! s:IsOneLineIndent(line) 350 | return match(a:line, '^[})\]]*\s*\(if\|else\|while\|try\|catch\|finally\|for\|else\s\+if\)\s*_\=$') != -1 351 | endfunction 352 | 353 | function! s:IsOneLineIndentLoose(line) 354 | " _\= equal _? in PCRE 355 | return match(a:line, '^[})\]]*\s*\(if\|else\|while\|try\|catch\|finally\|for\|else\s\+if\)') != -1 356 | endfunction 357 | 358 | 359 | function! GetJsIndent() 360 | if v:lnum == 1 361 | return 0 362 | endif 363 | let pnum = prevnonblank(v:lnum-1) 364 | let pline = s:GetLine(pnum) 365 | 366 | let ppnum = prevnonblank(pnum - 1) 367 | let ppline = s:GetLine(ppnum) 368 | 369 | if ((s:IsPartial(pline)||s:IsComment(pline)) && pnum == v:lnum-1)||match(pline, s:expr_left)!=-1 370 | let pnum = s:SearchBack(pnum) 371 | let ind = indent(pnum) 372 | let pline = s:GetLine(pnum) 373 | let ind = DoIndentPrev(ind, pline) 374 | if(!g:SimpleJsIndenter_DisableAssignment) 375 | if s:IsAssign(pline) && match(s:GetLine(v:lnum), s:expr_all)==-1 376 | let ind = DoIndentAssign(ind, pline) 377 | endif 378 | endif 379 | else 380 | let fix = 1 381 | " Ignore the comments 382 | while s:IsComment(ppline) 383 | let ppnum = prevnonblank(ppnum-1) 384 | let ppline = s:GetLine(ppnum) 385 | let fix += 1 386 | endwhile 387 | 388 | if s:IsPartial(ppline) && ppnum == pnum- fix 389 | let pnum = s:SearchBack(ppnum) 390 | endif 391 | 392 | let ind = indent(pnum) 393 | let pline = s:GetLine(pnum) 394 | let ind = DoIndentPrev(ind, pline) 395 | 396 | let ppnum = prevnonblank(pnum-1) 397 | let ppline = s:GetLine(ppnum) 398 | if s:IsOneLineIndent(pline) && match(s:GetLine(v:lnum), s:expr_all)==-1 399 | let ind = ind + &sw 400 | endif 401 | if s:IsOneLineIndent(ppline) 402 | let ind = ind - &sw 403 | endif 404 | endif 405 | 406 | " If pline is indented, and ppline is partial then indent 407 | " Fix for 408 | " function() { 409 | " b( this, 410 | " a(), 411 | " d() ); 412 | " }, 413 | let real_pnum = prevnonblank(v:lnum-1) 414 | if(real_pnum!=pnum) 415 | let pline = s:GetLine(real_pnum) 416 | let ind = DoIndentPrev(ind, pline) 417 | endif 418 | 419 | let line = s:GetLine(v:lnum) 420 | let ind = DoIndent(ind, line, pline) 421 | 422 | return ind 423 | endfunction 424 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Comment Test 3 | * function() { 4 | * 5 | */ 6 | (a / b); // c 7 | '' + "'" + // ' ( 8 | { 9 | { 10 | console.info((function() { 11 | }).something); 12 | next(); 13 | } 14 | 15 | foo (a(b, 16 | c)) { 17 | aoeu 18 | } 19 | 20 | a = "hello \ 21 | world" 22 | 23 | /hello(world/ 24 | a + /aoe(uaoeu/ 25 | (a / b); // c ( / 26 | (a / b); // ( 27 | /a\/b/ // c ( 28 | world 29 | 30 | var rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, 31 | // #7653, #8125, #8152: local protocol detection 32 | rlocalProtocol = /(?:^file|^widget|\-extension):$/, 33 | /* comment 2 */ 34 | assigment2; 35 | 36 | /* a [{( */ 37 | // b [{( 38 | comment('/* com', a /* [{( */); /* c */ // d 39 | ok(); 40 | // Assign Test 41 | var a, /* { */ 42 | b, // [ 43 | /reg/, 44 | c = '{' 45 | var a = "Hello" 46 | (3+4) + 47 | "World" 48 | return a, 49 | b, 50 | c; 51 | d = function() { 52 | aoeu 53 | } 54 | 55 | function a() { 56 | test(["hello", 57 | "world" 58 | ]) 59 | } 60 | var k = function() { 61 | var k=3, 62 | m=4 63 | } 64 | 65 | var m = new SWFUpload({ 66 | debug: false 67 | }); 68 | 69 | var rurl = /{[('"/, 70 | r20 = /%20/g, 71 | 72 | a = 1, 73 | b = 2 74 | a = 1 + 75 | 2 * 76 | 3 77 | 78 | // Function nested 79 | ;(function($) { 80 | $(document).ready(function() { 81 | $('#foo').click(function() { 82 | $.post(url, { 83 | a: 1, 84 | b: 2, 85 | }, function() { 86 | ok(); 87 | }); 88 | }); 89 | }); 90 | })(jQuery); 91 | 92 | // Array Object Test 93 | string_test("('",'("',"[",'{',"\"{","\\'{"); 94 | { 95 | array_object_test: [ 96 | 1, 97 | 2, 98 | { 99 | a: [3,4], 100 | b: [ 101 | 3, 102 | 4 103 | ], 104 | c: string_test("('",'("',"[",'{',"\"{","\\'{"), 105 | function_test: function() { 106 | return 0; 107 | }, 108 | one_line_function_test: function() { return [1] } 109 | } 110 | ] 111 | } 112 | 113 | // One Line Test 114 | { 115 | if( a == b && // comment 116 | c == d || 117 | e == f) 118 | { 119 | ok(); 120 | } 121 | if(a) { 122 | b; 123 | } else { 124 | e; 125 | } 126 | if (a) 127 | b; 128 | if(a) 129 | b; 130 | else if(k) { 131 | aeou 132 | } else 133 | c; 134 | while(true) 135 | foo += 1; 136 | try 137 | a; 138 | catch 139 | b; 140 | finally 141 | c; 142 | ok(); 143 | } 144 | 145 | query = query.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); 146 | // Only use querySelectorAll on non-XML documents 147 | { 148 | for ( var type in Expr.match ) { 149 | Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); 150 | Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)\/*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); 151 | } 152 | } 153 | { 154 | add: function( handleObj ) { 155 | jQuery.event.add( this, 156 | liveConvert( handleObj.origType, handleObj.selector ), 157 | jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) ); 158 | }, 159 | hello() 160 | } 161 | 162 | { 163 | if ( jQuery.isWindow( elem ) ) { 164 | } else if ( elem.nodeType === 9 ) { 165 | // Either scroll[Width/Height] or offset[Width/Height], whichever is greater 166 | return Math.max( 167 | elem.documentElement["client" + name], 168 | elem.body["scroll" + name], elem.documentElement["scroll" + name], 169 | elem.body["offset" + name], elem.documentElement["offset" + name] 170 | ); 171 | 172 | // Get or set width or height on the element 173 | } 174 | 175 | function a() { 176 | $('"', {'b'}, function() { 177 | }); 178 | } 179 | 180 | test(//aoeuaou{ 181 | hello(); 182 | ); 183 | test(/*a'*/,'ee') { 184 | foo(); 185 | } 186 | function escapeattr(b) { 187 | return (/./i, "") : "" 188 | } 189 | 190 | switch (foo) { 191 | case a: break; 192 | 193 | case b: 194 | break; 195 | 196 | case c: { 197 | break; 198 | } 199 | 200 | case d: { 201 | switch (bar) { 202 | case e: 203 | break; 204 | 205 | default: 206 | break; 207 | } 208 | } 209 | 210 | default: 211 | break; 212 | } 213 | } 214 | } 215 | 216 | var a = a 217 | , b = b 218 | , c = c; 219 | 220 | var a = a 221 | , b = b 222 | ; 223 | 224 | foo({ 225 | a : a 226 | , b : b 227 | , c : c 228 | , d : { 229 | e : e 230 | f : f 231 | } 232 | , g : {[ 233 | h : h 234 | , i : i 235 | ]} 236 | }); 237 | --------------------------------------------------------------------------------