test.min.js (3949B)
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 (function() { 5 var mode = CodeMirror.getMode({indentUnit: 2}, "jsx") 6 function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)) } 7 8 MT("selfclose", 9 "[keyword var] [def x] [operator =] [bracket&tag <] [tag foo] [bracket&tag />] [operator +] [number 1];") 10 11 MT("openclose", 12 "([bracket&tag <][tag foo][bracket&tag >]hello [atom &][bracket&tag </][tag foo][bracket&tag >][operator ++])") 13 14 MT("attr", 15 "([bracket&tag <][tag foo] [attribute abc]=[string 'value'][bracket&tag >]hello [atom &][bracket&tag </][tag foo][bracket&tag >][operator ++])") 16 17 MT("braced_attr", 18 "([bracket&tag <][tag foo] [attribute abc]={[number 10]}[bracket&tag >]hello [atom &][bracket&tag </][tag foo][bracket&tag >][operator ++])") 19 20 MT("braced_text", 21 "([bracket&tag <][tag foo][bracket&tag >]hello {[number 10]} [atom &][bracket&tag </][tag foo][bracket&tag >][operator ++])") 22 23 MT("nested_tag", 24 "([bracket&tag <][tag foo][bracket&tag ><][tag bar][bracket&tag ></][tag bar][bracket&tag ></][tag foo][bracket&tag >][operator ++])") 25 26 MT("nested_jsx", 27 "[keyword return] (", 28 " [bracket&tag <][tag foo][bracket&tag >]", 29 " say {[number 1] [operator +] [bracket&tag <][tag bar] [attribute attr]={[number 10]}[bracket&tag />]}!", 30 " [bracket&tag </][tag foo][bracket&tag >][operator ++]", 31 ")") 32 33 MT("preserve_js_context", 34 "[variable x] [operator =] [string-2 `quasi${][bracket&tag <][tag foo][bracket&tag />][string-2 }quoted`]") 35 36 MT("string_interpolation", 37 "[variable x] [operator =] [string-2 `quasi<code>${] [number 10] [string-2 }</code>`]") 38 39 MT("line_comment", 40 "([bracket&tag <][tag foo] [comment // hello]", 41 " [bracket&tag ></][tag foo][bracket&tag >][operator ++])") 42 43 MT("line_comment_not_in_tag", 44 "([bracket&tag <][tag foo][bracket&tag >] // hello", 45 " [bracket&tag </][tag foo][bracket&tag >][operator ++])") 46 47 MT("block_comment", 48 "([bracket&tag <][tag foo] [comment /* hello]", 49 "[comment line 2]", 50 "[comment line 3 */] [bracket&tag ></][tag foo][bracket&tag >][operator ++])") 51 52 MT("block_comment_not_in_tag", 53 "([bracket&tag <][tag foo][bracket&tag >]/* hello", 54 " line 2", 55 " line 3 */ [bracket&tag </][tag foo][bracket&tag >][operator ++])") 56 57 MT("missing_attr", 58 "([bracket&tag <][tag foo] [attribute selected][bracket&tag />][operator ++])") 59 60 MT("indent_js", 61 "([bracket&tag <][tag foo][bracket&tag >]", 62 " [bracket&tag <][tag bar] [attribute baz]={[keyword function]() {", 63 " [keyword return] [number 10]", 64 " }}[bracket&tag />]", 65 " [bracket&tag </][tag foo][bracket&tag >])") 66 67 MT("spread", 68 "([bracket&tag <][tag foo] [attribute bar]={[meta ...][variable baz] [operator /][number 2]}[bracket&tag />])") 69 70 MT("tag_attribute", 71 "([bracket&tag <][tag foo] [attribute bar]=[bracket&tag <][tag foo][bracket&tag />/>][operator ++])") 72 73 var ts_mode = CodeMirror.getMode({indentUnit: 2}, "text/typescript-jsx") 74 function TS(name) { test.mode(name, ts_mode, Array.prototype.slice.call(arguments, 1)) } 75 76 TS("tsx_react_integration", 77 "[keyword interface] [def Props] {", 78 " [property foo]: [type string];", 79 "}", 80 "[keyword class] [def MyComponent] [keyword extends] [type React].[type Component] [operator <] [type Props], [type any] [operator >] {", 81 " [property render]() {", 82 " [keyword return] [bracket&tag <][tag span][bracket&tag >]{[keyword this].[property props].[property foo]}[bracket&tag </][tag span][bracket&tag >]", 83 " }", 84 "}", 85 "[bracket&tag <][tag MyComponent] [attribute foo]=[string \"bar\"] [bracket&tag />]; [comment //ok]", 86 "[bracket&tag <][tag MyComponent] [attribute foo]={[number 0]} [bracket&tag />]; [comment //error]") 87 88 })()