comparison .cms/lib/codemirror/mode/jsx/test.js @ 0:78edf6b517a0 draft

24.10
author Coffee CMS <info@coffee-cms.ru>
date Fri, 11 Oct 2024 22:40:23 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:78edf6b517a0
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: https://codemirror.net/5/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 &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
13
14 MT("openclosefragment",
15 "([bracket&tag <><][tag foo][bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag ></>][operator ++])")
16
17 MT("attr",
18 "([bracket&tag <][tag foo] [attribute abc]=[string 'value'][bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
19
20 MT("braced_attr",
21 "([bracket&tag <][tag foo] [attribute abc]={[number 10]}[bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
22
23 MT("braced_text",
24 "([bracket&tag <][tag foo][bracket&tag >]hello {[number 10]} [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
25
26 MT("nested_tag",
27 "([bracket&tag <][tag foo][bracket&tag ><][tag bar][bracket&tag ></][tag bar][bracket&tag ></][tag foo][bracket&tag >][operator ++])")
28
29 MT("nested_jsx",
30 "[keyword return] (",
31 " [bracket&tag <][tag foo][bracket&tag >]",
32 " say {[number 1] [operator +] [bracket&tag <][tag bar] [attribute attr]={[number 10]}[bracket&tag />]}!",
33 " [bracket&tag </][tag foo][bracket&tag >][operator ++]",
34 ")")
35
36 MT("preserve_js_context",
37 "[variable x] [operator =] [string-2 `quasi${][bracket&tag <][tag foo][bracket&tag />][string-2 }quoted`]")
38
39 MT("string_interpolation",
40 "[variable x] [operator =] [string-2 `quasi<code>${] [number 10] [string-2 }</code>`]")
41
42 MT("line_comment",
43 "([bracket&tag <][tag foo] [comment // hello]",
44 " [bracket&tag ></][tag foo][bracket&tag >][operator ++])")
45
46 MT("line_comment_not_in_tag",
47 "([bracket&tag <][tag foo][bracket&tag >] // hello",
48 " [bracket&tag </][tag foo][bracket&tag >][operator ++])")
49
50 MT("block_comment",
51 "([bracket&tag <][tag foo] [comment /* hello]",
52 "[comment line 2]",
53 "[comment line 3 */] [bracket&tag ></][tag foo][bracket&tag >][operator ++])")
54
55 MT("block_comment_not_in_tag",
56 "([bracket&tag <][tag foo][bracket&tag >]/* hello",
57 " line 2",
58 " line 3 */ [bracket&tag </][tag foo][bracket&tag >][operator ++])")
59
60 MT("missing_attr",
61 "([bracket&tag <][tag foo] [attribute selected][bracket&tag />][operator ++])")
62
63 MT("indent_js",
64 "([bracket&tag <][tag foo][bracket&tag >]",
65 " [bracket&tag <][tag bar] [attribute baz]={[keyword function]() {",
66 " [keyword return] [number 10]",
67 " }}[bracket&tag />]",
68 " [bracket&tag </][tag foo][bracket&tag >])")
69
70 MT("spread",
71 "([bracket&tag <][tag foo] [attribute bar]={[meta ...][variable baz] [operator /][number 2]}[bracket&tag />])")
72
73 MT("tag_attribute",
74 "([bracket&tag <][tag foo] [attribute bar]=[bracket&tag <][tag foo][bracket&tag />/>][operator ++])")
75
76 MT("in_array",
77 "[[",
78 " [bracket&tag <][tag Something][bracket&tag />],",
79 " [string-2 `${][variable x][string-2 }`],",
80 " [variable y]",
81 "]]")
82
83 var ts_mode = CodeMirror.getMode({indentUnit: 2}, "text/typescript-jsx")
84 function TS(name) { test.mode(name, ts_mode, Array.prototype.slice.call(arguments, 1)) }
85
86 TS("tsx_react_integration",
87 "[keyword interface] [def Props] {",
88 " [property foo]: [type string];",
89 "}",
90 "[keyword class] [def MyComponent] [keyword extends] [type React].[type Component] [operator <] [type Props], [type any] [operator >] {",
91 " [property render]() {",
92 " [keyword return] [bracket&tag <][tag span][bracket&tag >]{[keyword this].[property props].[property foo]}[bracket&tag </][tag span][bracket&tag >]",
93 " }",
94 "}",
95 "[bracket&tag <][tag MyComponent] [attribute foo]=[string \"bar\"] [bracket&tag />]; [comment //ok]",
96 "[bracket&tag <][tag MyComponent] [attribute foo]={[number 0]} [bracket&tag />]; [comment //error]")
97
98 TS("tsx_react_generics",
99 "[variable x] [operator =] [operator <] [variable T],[operator >] ([def v]: [type T]) [operator =>] [variable-2 v];")
100 })()