sun-form-v3 1.0.65 → 1.0.66
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +8 -5
- package/src/App.vue +9 -0
- package/src/assets/font/YouSheBiaoTiHei-2.ttf +0 -0
- package/src/assets/font/demo.css +539 -0
- package/src/assets/font/demo_index.html +1200 -0
- package/src/assets/font/iconfont.css +191 -0
- package/src/assets/font/iconfont.js +1 -0
- package/src/assets/font/iconfont.json +317 -0
- package/src/assets/font/iconfont.ttf +0 -0
- package/src/assets/font/iconfont.woff +0 -0
- package/src/assets/font/iconfont.woff2 +0 -0
- package/src/assets/img/bg_footer.png +0 -0
- package/src/assets/img/bg_title.png +0 -0
- package/src/assets/img/file.png +0 -0
- package/src/assets/img/logo.png +0 -0
- package/src/assets/img/logo2.png +0 -0
- package/src/assets/img/logo22.png +0 -0
- package/src/assets/img/logo23.png +0 -0
- package/src/assets/img/logo3.png +0 -0
- package/src/assets/img//347/237/251/345/275/242@2x.png +0 -0
- package/src/assets/logo.svg +1 -0
- package/src/assets/styles/element/index.scss +15 -0
- package/src/assets/styles/index.css +3 -0
- package/src/components/a.js +14 -0
- package/src/components/aDesigner/config.vue +127 -0
- package/src/components/aDesigner/design.vue +21 -0
- package/src/components/aDesigner/designer.js +342 -0
- package/src/components/aDesigner/http.js +292 -0
- package/src/components/aDesigner/index.vue +144 -0
- package/src/components/aDesigner/panel.vue +144 -0
- package/src/components/aDesigner/show.vue +24 -0
- package/src/components/widgetCommonComps/commonApiConfig/index.vue +194 -0
- package/src/components/widgetCommonComps/commonCard/index.vue +36 -0
- package/src/components/widgetCommonComps/commonCodeEditor/editor.vue +219 -0
- package/src/components/widgetCommonComps/commonCodeEditor/modalEditor.vue +68 -0
- package/src/components/widgetCommonComps/commonCollapseCard/index.vue +10 -0
- package/src/components/widgetCommonComps/commonContainer/index.vue +95 -0
- package/src/components/widgetCommonComps/commonJsonInput/index.vue +59 -0
- package/src/components/widgetCommonComps/commonLabelContainer/index.vue +39 -0
- package/src/components/widgetCommonComps/commonSidetree/index.vue +61 -0
- package/src/components/widgetCommonComps/commonTypeInput/index.vue +75 -0
- package/src/components/widgetCommonComps/commonWidgetLabelContainer/index.vue +55 -0
- package/src/components/widgetCommonComps/index copy.js +17 -0
- package/src/components/widgetCommonComps/index.js +17 -0
- package/src/components/widgetConfigComps/config-input/index.vue +60 -0
- package/src/components/widgetConfigComps/index copy.js +13 -0
- package/src/components/widgetConfigComps/index.js +17 -0
- package/src/components/widgetShowComps/index.js +29 -0
- package/src/components/widgetShowComps/widget-form/index.vue +43 -0
- package/src/components/widgetShowComps/widget-homepage/index.vue +41 -0
- package/src/components/widgetShowComps/widget-input/index.vue +85 -0
- package/src/components/widgetShowComps/widget-select/index.vue +31 -0
- package/src/designer.js +342 -0
- package/src/http.js +292 -0
- package/src/index.js +24 -0
- package/src/index2.js +23 -0
- package/src/main.js +19 -0
- package/src/remark.js +708 -0
- package/src/testBtn.vue +11 -0
- package/src/testInput.vue +12 -0
- package/src/util/jsformat.js +568 -0
- package/src/widgetConfig.js +1112 -0
- package/dist/abap-DfvySaIJ.js +0 -1404
- package/dist/apex-B__0irD3.js +0 -332
- package/dist/assets/css.worker-OK053IOu.js +0 -84
- package/dist/assets/editor.worker-D9iUZyMP.js +0 -11
- package/dist/assets/html.worker-CL40hqKM.js +0 -458
- package/dist/assets/json.worker-6f9bhSHY.js +0 -42
- package/dist/assets/ts.worker-B6g3wjaE.js +0 -37021
- package/dist/azcli-CDMGhRmx.js +0 -74
- package/dist/bat-0Mk8aqzx.js +0 -106
- package/dist/bicep-BBi_I06Z.js +0 -108
- package/dist/cameligo-D0G_Zm6X.js +0 -180
- package/dist/clojure-o2ZKLeMp.js +0 -767
- package/dist/coffee-DOQff5VC.js +0 -238
- package/dist/cpp-CQGJnWhD.js +0 -395
- package/dist/csharp-C1jLsHl8.js +0 -332
- package/dist/csp-C_ttMQaW.js +0 -59
- package/dist/css-BC202kVV.js +0 -193
- package/dist/cssMode-B2c4O0YS.js +0 -1541
- package/dist/cypher-DwtEH7Fi.js +0 -269
- package/dist/dart-D9XknsP2.js +0 -287
- package/dist/dockerfile-DgsNjqqa.js +0 -136
- package/dist/ecl-BAMCHBl6.js +0 -462
- package/dist/elixir-CegIttP8.js +0 -575
- package/dist/favicon.ico +0 -0
- package/dist/flow9-9608t7UV.js +0 -148
- package/dist/freemarker2-C0V-2C6A.js +0 -995
- package/dist/fsharp-CCtt9-1_.js +0 -223
- package/dist/go-CGUIPbct.js +0 -224
- package/dist/graphql-BNRIFFIn.js +0 -157
- package/dist/handlebars-Dq-D2gGP.js +0 -425
- package/dist/hcl-C__KLIXe.js +0 -189
- package/dist/html-CHe4dRTt.js +0 -314
- package/dist/htmlMode-DmZav6BJ.js +0 -1551
- package/dist/index2-CDdAhO0H.js +0 -124690
- package/dist/ini-CeKYn_zA.js +0 -77
- package/dist/java-Dm24deQl.js +0 -238
- package/dist/javascript-e6NjSQC6.js +0 -76
- package/dist/jsonMode-pOauncTt.js +0 -1957
- package/dist/julia-BImNW7VE.js +0 -517
- package/dist/kotlin-BfE79GEb.js +0 -259
- package/dist/less-DglNOcaC.js +0 -168
- package/dist/lexon-BA0dRz9Q.js +0 -163
- package/dist/liquid-DGCC4WOg.js +0 -246
- package/dist/lua-DMkWzJcm.js +0 -168
- package/dist/m3-sA-5shO8.js +0 -216
- package/dist/markdown-OYRB1igA.js +0 -235
- package/dist/mdx-GitjX2xy.js +0 -171
- package/dist/mips-rRzkJ_7G.js +0 -204
- package/dist/msdax-DoVJdUhd.js +0 -381
- package/dist/mysql-Ty44IHXo.js +0 -884
- package/dist/objective-c-VUfyhYrA.js +0 -189
- package/dist/pascal-DkASiYyw.js +0 -257
- package/dist/pascaligo-p-ELPlVO.js +0 -170
- package/dist/perl-Cjl1FxLZ.js +0 -632
- package/dist/pgsql-DjVenF7s.js +0 -857
- package/dist/php-CwvGzZOO.js +0 -506
- package/dist/pla-Br1iaBIV.js +0 -143
- package/dist/postiats-BaeP8zZY.js +0 -913
- package/dist/powerquery-CLCshuo8.js +0 -896
- package/dist/powershell-CZV50w5N.js +0 -245
- package/dist/protobuf-MV3XTewJ.js +0 -426
- package/dist/pug-DkDg4c4l.js +0 -408
- package/dist/python-BxUPejAm.js +0 -282
- package/dist/qsharp-BAtiKA97.js +0 -291
- package/dist/r-8ocrd-h-.js +0 -249
- package/dist/razor-B0zHeS7k.js +0 -556
- package/dist/redis-9sZiddxc.js +0 -308
- package/dist/redshift-DQfTOGC0.js +0 -815
- package/dist/restructuredtext-DXU-vkgr.js +0 -180
- package/dist/ruby-DotfqwMf.js +0 -517
- package/dist/rust-BIauJ5KN.js +0 -349
- package/dist/sb-CmWMvDEV.js +0 -121
- package/dist/scala-C81brEbk.js +0 -376
- package/dist/scheme-D0pcFz2x.js +0 -114
- package/dist/scss-BOdN2fGG.js +0 -268
- package/dist/shell-6E09eAkU.js +0 -227
- package/dist/solidity-CWStzA1K.js +0 -1373
- package/dist/sophia-76Sb6CWe.js +0 -205
- package/dist/sparql-BmZTkOWT.js +0 -207
- package/dist/sql-Cs9TBAW5.js +0 -859
- package/dist/st-B-rqE1Bu.js +0 -422
- package/dist/style.css +0 -1
- package/dist/sun-form-v3.es.js +0 -4
- package/dist/sun-form-v3.umd.js +0 -1908
- package/dist/swift-Btsj6YxQ.js +0 -318
- package/dist/systemverilog-B3RHBRa2.js +0 -582
- package/dist/tcl-Dpj776pn.js +0 -238
- package/dist/tsMode-AhR0apFR.js +0 -886
- package/dist/twig-Bb9JmBsE.js +0 -398
- package/dist/typescript-DW_IjlW5.js +0 -349
- package/dist/typespec-CDWeg3SU.js +0 -123
- package/dist/vb-DEXnYwEI.js +0 -378
- package/dist/wgsl-D602c1lx.js +0 -445
- package/dist/xml-CraN90Vi.js +0 -101
- package/dist/yaml-D6yA8dTm.js +0 -212
package/src/testBtn.vue
ADDED
@@ -0,0 +1,568 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
export function js_beautify(js_source_text, indent_size, indent_character, indent_level)
|
4
|
+
{
|
5
|
+
|
6
|
+
var input, output, token_text, last_type, last_text, last_word, current_mode, modes, indent_string;
|
7
|
+
var whitespace, wordchar, punct, parser_pos, line_starters, in_case;
|
8
|
+
var prefix, token_type, do_block_just_closed, var_line, var_line_tainted;
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
function trim_output()
|
13
|
+
{
|
14
|
+
while (output.length && (output[output.length - 1] === ' ' || output[output.length - 1] === indent_string)) {
|
15
|
+
output.pop();
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
function print_newline(ignore_repeated)
|
20
|
+
{
|
21
|
+
ignore_repeated = typeof ignore_repeated === 'undefined' ? true: ignore_repeated;
|
22
|
+
|
23
|
+
trim_output();
|
24
|
+
|
25
|
+
if (!output.length) {
|
26
|
+
return; // no newline on start of file
|
27
|
+
}
|
28
|
+
|
29
|
+
if (output[output.length - 1] !== "\n" || !ignore_repeated) {
|
30
|
+
output.push("\n");
|
31
|
+
}
|
32
|
+
for (var i = 0; i < indent_level; i++) {
|
33
|
+
output.push(indent_string);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
function print_space()
|
40
|
+
{
|
41
|
+
var last_output = output.length ? output[output.length - 1] : ' ';
|
42
|
+
if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space
|
43
|
+
output.push(' ');
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
function print_token()
|
49
|
+
{
|
50
|
+
output.push(token_text);
|
51
|
+
}
|
52
|
+
|
53
|
+
function indent()
|
54
|
+
{
|
55
|
+
indent_level++;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
function unindent()
|
60
|
+
{
|
61
|
+
if (indent_level) {
|
62
|
+
indent_level--;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
function remove_indent()
|
68
|
+
{
|
69
|
+
if (output.length && output[output.length - 1] === indent_string) {
|
70
|
+
output.pop();
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
function set_mode(mode)
|
76
|
+
{
|
77
|
+
modes.push(current_mode);
|
78
|
+
current_mode = mode;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
function restore_mode()
|
83
|
+
{
|
84
|
+
do_block_just_closed = current_mode === 'DO_BLOCK';
|
85
|
+
current_mode = modes.pop();
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
function in_array(what, arr)
|
90
|
+
{
|
91
|
+
for (var i = 0; i < arr.length; i++)
|
92
|
+
{
|
93
|
+
if (arr[i] === what) {
|
94
|
+
return true;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
return false;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
function get_next_token()
|
103
|
+
{
|
104
|
+
var n_newlines = 0;
|
105
|
+
var c = '';
|
106
|
+
|
107
|
+
do {
|
108
|
+
if (parser_pos >= input.length) {
|
109
|
+
return ['', 'TK_EOF'];
|
110
|
+
}
|
111
|
+
c = input.charAt(parser_pos);
|
112
|
+
|
113
|
+
parser_pos += 1;
|
114
|
+
if (c === "\n") {
|
115
|
+
n_newlines += 1;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
while (in_array(c, whitespace));
|
119
|
+
|
120
|
+
if (n_newlines > 1) {
|
121
|
+
for (var i = 0; i < 2; i++) {
|
122
|
+
print_newline(i === 0);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
var wanted_newline = (n_newlines === 1);
|
126
|
+
|
127
|
+
|
128
|
+
if (in_array(c, wordchar)) {
|
129
|
+
if (parser_pos < input.length) {
|
130
|
+
while (in_array(input.charAt(parser_pos), wordchar)) {
|
131
|
+
c += input.charAt(parser_pos);
|
132
|
+
parser_pos += 1;
|
133
|
+
if (parser_pos === input.length) {
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
// small and surprisingly unugly hack for 1E-10 representation
|
140
|
+
if (parser_pos !== input.length && c.match(/^[0-9]+[Ee]$/) && input.charAt(parser_pos) === '-') {
|
141
|
+
parser_pos += 1;
|
142
|
+
|
143
|
+
var t = get_next_token(parser_pos);
|
144
|
+
c += '-' + t[0];
|
145
|
+
return [c, 'TK_WORD'];
|
146
|
+
}
|
147
|
+
|
148
|
+
if (c === 'in') { // hack for 'in' operator
|
149
|
+
return [c, 'TK_OPERATOR'];
|
150
|
+
}
|
151
|
+
return [c, 'TK_WORD'];
|
152
|
+
}
|
153
|
+
|
154
|
+
if (c === '(' || c === '[') {
|
155
|
+
return [c, 'TK_START_EXPR'];
|
156
|
+
}
|
157
|
+
|
158
|
+
if (c === ')' || c === ']') {
|
159
|
+
return [c, 'TK_END_EXPR'];
|
160
|
+
}
|
161
|
+
|
162
|
+
if (c === '{') {
|
163
|
+
return [c, 'TK_START_BLOCK'];
|
164
|
+
}
|
165
|
+
|
166
|
+
if (c === '}') {
|
167
|
+
return [c, 'TK_END_BLOCK'];
|
168
|
+
}
|
169
|
+
|
170
|
+
if (c === ';') {
|
171
|
+
return [c, 'TK_END_COMMAND'];
|
172
|
+
}
|
173
|
+
|
174
|
+
if (c === '/') {
|
175
|
+
var comment = '';
|
176
|
+
// peek for comment /* ... */
|
177
|
+
if (input.charAt(parser_pos) === '*') {
|
178
|
+
parser_pos += 1;
|
179
|
+
if (parser_pos < input.length) {
|
180
|
+
while (! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input.length) {
|
181
|
+
comment += input.charAt(parser_pos);
|
182
|
+
parser_pos += 1;
|
183
|
+
if (parser_pos >= input.length) {
|
184
|
+
break;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
parser_pos += 2;
|
189
|
+
return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
|
190
|
+
}
|
191
|
+
// peek for comment // ...
|
192
|
+
if (input.charAt(parser_pos) === '/') {
|
193
|
+
comment = c;
|
194
|
+
while (input.charAt(parser_pos) !== "\x0d" && input.charAt(parser_pos) !== "\x0a") {
|
195
|
+
comment += input.charAt(parser_pos);
|
196
|
+
parser_pos += 1;
|
197
|
+
if (parser_pos >= input.length) {
|
198
|
+
break;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
parser_pos += 1;
|
202
|
+
if (wanted_newline) {
|
203
|
+
print_newline();
|
204
|
+
}
|
205
|
+
return [comment, 'TK_COMMENT'];
|
206
|
+
}
|
207
|
+
|
208
|
+
}
|
209
|
+
|
210
|
+
if (c === "'" || // string
|
211
|
+
c === '"' || // string
|
212
|
+
(c === '/' &&
|
213
|
+
((last_type === 'TK_WORD' && last_text === 'return') || (last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EOF' || last_type === 'TK_END_COMMAND')))) { // regexp
|
214
|
+
var sep = c;
|
215
|
+
var esc = false;
|
216
|
+
c = '';
|
217
|
+
|
218
|
+
if (parser_pos < input.length) {
|
219
|
+
|
220
|
+
while (esc || input.charAt(parser_pos) !== sep) {
|
221
|
+
c += input.charAt(parser_pos);
|
222
|
+
if (!esc) {
|
223
|
+
esc = input.charAt(parser_pos) === '\\';
|
224
|
+
} else {
|
225
|
+
esc = false;
|
226
|
+
}
|
227
|
+
parser_pos += 1;
|
228
|
+
if (parser_pos >= input.length) {
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
parser_pos += 1;
|
236
|
+
if (last_type === 'TK_END_COMMAND') {
|
237
|
+
print_newline();
|
238
|
+
}
|
239
|
+
return [sep + c + sep, 'TK_STRING'];
|
240
|
+
}
|
241
|
+
|
242
|
+
if (in_array(c, punct)) {
|
243
|
+
while (parser_pos < input.length && in_array(c + input.charAt(parser_pos), punct)) {
|
244
|
+
c += input.charAt(parser_pos);
|
245
|
+
parser_pos += 1;
|
246
|
+
if (parser_pos >= input.length) {
|
247
|
+
break;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
return [c, 'TK_OPERATOR'];
|
251
|
+
}
|
252
|
+
|
253
|
+
return [c, 'TK_UNKNOWN'];
|
254
|
+
}
|
255
|
+
|
256
|
+
|
257
|
+
//----------------------------------
|
258
|
+
|
259
|
+
indent_character = indent_character || ' ';
|
260
|
+
indent_size = indent_size || 2;
|
261
|
+
|
262
|
+
indent_string = '';
|
263
|
+
while (indent_size--) {
|
264
|
+
indent_string += indent_character;
|
265
|
+
}
|
266
|
+
|
267
|
+
input = js_source_text;
|
268
|
+
|
269
|
+
last_word = ''; // last 'TK_WORD' passed
|
270
|
+
last_type = 'TK_START_EXPR'; // last token type
|
271
|
+
last_text = ''; // last token text
|
272
|
+
output = [];
|
273
|
+
|
274
|
+
do_block_just_closed = false;
|
275
|
+
var_line = false;
|
276
|
+
var_line_tainted = false;
|
277
|
+
|
278
|
+
whitespace = "\n\r\t ".split('');
|
279
|
+
wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
|
280
|
+
punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |='.split(' ');
|
281
|
+
|
282
|
+
// words which should always start on new line.
|
283
|
+
line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
|
284
|
+
|
285
|
+
// states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
|
286
|
+
// some formatting depends on that.
|
287
|
+
current_mode = 'BLOCK';
|
288
|
+
modes = [current_mode];
|
289
|
+
|
290
|
+
indent_level = indent_level || 0;
|
291
|
+
parser_pos = 0; // parser position
|
292
|
+
in_case = false; // flag for parser that case/default has been processed, and next colon needs special attention
|
293
|
+
while (true) {
|
294
|
+
var t = get_next_token(parser_pos);
|
295
|
+
token_text = t[0];
|
296
|
+
token_type = t[1];
|
297
|
+
if (token_type === 'TK_EOF') {
|
298
|
+
break;
|
299
|
+
}
|
300
|
+
|
301
|
+
switch (token_type) {
|
302
|
+
|
303
|
+
case 'TK_START_EXPR':
|
304
|
+
var_line = false;
|
305
|
+
set_mode('EXPRESSION');
|
306
|
+
if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR') {
|
307
|
+
// do nothing on (( and )( and ][ and ]( ..
|
308
|
+
} else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
|
309
|
+
print_space();
|
310
|
+
} else if (in_array(last_word, line_starters) && last_word !== 'function') {
|
311
|
+
print_space();
|
312
|
+
}
|
313
|
+
print_token();
|
314
|
+
break;
|
315
|
+
|
316
|
+
case 'TK_END_EXPR':
|
317
|
+
print_token();
|
318
|
+
restore_mode();
|
319
|
+
break;
|
320
|
+
|
321
|
+
case 'TK_START_BLOCK':
|
322
|
+
|
323
|
+
if (last_word === 'do') {
|
324
|
+
set_mode('DO_BLOCK');
|
325
|
+
} else {
|
326
|
+
set_mode('BLOCK');
|
327
|
+
}
|
328
|
+
if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
|
329
|
+
if (last_type === 'TK_START_BLOCK') {
|
330
|
+
print_newline();
|
331
|
+
} else {
|
332
|
+
print_space();
|
333
|
+
}
|
334
|
+
}
|
335
|
+
print_token();
|
336
|
+
indent();
|
337
|
+
break;
|
338
|
+
|
339
|
+
case 'TK_END_BLOCK':
|
340
|
+
if (last_type === 'TK_START_BLOCK') {
|
341
|
+
// nothing
|
342
|
+
trim_output();
|
343
|
+
unindent();
|
344
|
+
} else {
|
345
|
+
unindent();
|
346
|
+
print_newline();
|
347
|
+
}
|
348
|
+
print_token();
|
349
|
+
restore_mode();
|
350
|
+
break;
|
351
|
+
|
352
|
+
case 'TK_WORD':
|
353
|
+
|
354
|
+
if (do_block_just_closed) {
|
355
|
+
print_space();
|
356
|
+
print_token();
|
357
|
+
print_space();
|
358
|
+
break;
|
359
|
+
}
|
360
|
+
|
361
|
+
if (token_text === 'case' || token_text === 'default') {
|
362
|
+
if (last_text === ':') {
|
363
|
+
// switch cases following one another
|
364
|
+
remove_indent();
|
365
|
+
} else {
|
366
|
+
// case statement starts in the same line where switch
|
367
|
+
unindent();
|
368
|
+
print_newline();
|
369
|
+
indent();
|
370
|
+
}
|
371
|
+
print_token();
|
372
|
+
in_case = true;
|
373
|
+
break;
|
374
|
+
}
|
375
|
+
|
376
|
+
|
377
|
+
prefix = 'NONE';
|
378
|
+
if (last_type === 'TK_END_BLOCK') {
|
379
|
+
if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
|
380
|
+
prefix = 'NEWLINE';
|
381
|
+
} else {
|
382
|
+
prefix = 'SPACE';
|
383
|
+
print_space();
|
384
|
+
}
|
385
|
+
} else if (last_type === 'TK_END_COMMAND' && (current_mode === 'BLOCK' || current_mode === 'DO_BLOCK')) {
|
386
|
+
prefix = 'NEWLINE';
|
387
|
+
} else if (last_type === 'TK_END_COMMAND' && current_mode === 'EXPRESSION') {
|
388
|
+
prefix = 'SPACE';
|
389
|
+
} else if (last_type === 'TK_WORD') {
|
390
|
+
prefix = 'SPACE';
|
391
|
+
} else if (last_type === 'TK_START_BLOCK') {
|
392
|
+
prefix = 'NEWLINE';
|
393
|
+
} else if (last_type === 'TK_END_EXPR') {
|
394
|
+
print_space();
|
395
|
+
prefix = 'NEWLINE';
|
396
|
+
}
|
397
|
+
|
398
|
+
if (last_type !== 'TK_END_BLOCK' && in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
|
399
|
+
print_newline();
|
400
|
+
} else if (in_array(token_text, line_starters) || prefix === 'NEWLINE') {
|
401
|
+
if (last_text === 'else') {
|
402
|
+
// no need to force newline on else break
|
403
|
+
print_space();
|
404
|
+
} else if ((last_type === 'TK_START_EXPR' || last_text === '=') && token_text === 'function') {
|
405
|
+
// no need to force newline on 'function': (function
|
406
|
+
// DONOTHING
|
407
|
+
} else if (last_type === 'TK_WORD' && (last_text === 'return' || last_text === 'throw')) {
|
408
|
+
// no newline between 'return nnn'
|
409
|
+
print_space();
|
410
|
+
} else if (last_type !== 'TK_END_EXPR') {
|
411
|
+
if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') {
|
412
|
+
// no need to force newline on 'var': for (var x = 0...)
|
413
|
+
if (token_text === 'if' && last_type === 'TK_WORD' && last_word === 'else') {
|
414
|
+
// no newline for } else if {
|
415
|
+
print_space();
|
416
|
+
} else {
|
417
|
+
print_newline();
|
418
|
+
}
|
419
|
+
}
|
420
|
+
} else {
|
421
|
+
if (in_array(token_text, line_starters) && last_text !== ')') {
|
422
|
+
print_newline();
|
423
|
+
}
|
424
|
+
}
|
425
|
+
} else if (prefix === 'SPACE') {
|
426
|
+
print_space();
|
427
|
+
}
|
428
|
+
print_token();
|
429
|
+
last_word = token_text;
|
430
|
+
|
431
|
+
if (token_text === 'var') {
|
432
|
+
var_line = true;
|
433
|
+
var_line_tainted = false;
|
434
|
+
}
|
435
|
+
|
436
|
+
break;
|
437
|
+
|
438
|
+
case 'TK_END_COMMAND':
|
439
|
+
|
440
|
+
print_token();
|
441
|
+
var_line = false;
|
442
|
+
break;
|
443
|
+
|
444
|
+
case 'TK_STRING':
|
445
|
+
|
446
|
+
if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK') {
|
447
|
+
print_newline();
|
448
|
+
} else if (last_type === 'TK_WORD') {
|
449
|
+
print_space();
|
450
|
+
}
|
451
|
+
print_token();
|
452
|
+
break;
|
453
|
+
|
454
|
+
case 'TK_OPERATOR':
|
455
|
+
|
456
|
+
var start_delim = true;
|
457
|
+
var end_delim = true;
|
458
|
+
if (var_line && token_text !== ',') {
|
459
|
+
var_line_tainted = true;
|
460
|
+
if (token_text === ':') {
|
461
|
+
var_line = false;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
if (token_text === ':' && in_case) {
|
466
|
+
print_token(); // colon really asks for separate treatment
|
467
|
+
print_newline();
|
468
|
+
break;
|
469
|
+
}
|
470
|
+
|
471
|
+
in_case = false;
|
472
|
+
|
473
|
+
if (token_text === ',') {
|
474
|
+
if (var_line) {
|
475
|
+
if (var_line_tainted) {
|
476
|
+
print_token();
|
477
|
+
print_newline();
|
478
|
+
var_line_tainted = false;
|
479
|
+
} else {
|
480
|
+
print_token();
|
481
|
+
print_space();
|
482
|
+
}
|
483
|
+
} else if (last_type === 'TK_END_BLOCK') {
|
484
|
+
print_token();
|
485
|
+
print_newline();
|
486
|
+
} else {
|
487
|
+
if (current_mode === 'BLOCK') {
|
488
|
+
print_token();
|
489
|
+
print_newline();
|
490
|
+
} else {
|
491
|
+
// EXPR od DO_BLOCK
|
492
|
+
print_token();
|
493
|
+
print_space();
|
494
|
+
}
|
495
|
+
}
|
496
|
+
break;
|
497
|
+
} else if (token_text === '--' || token_text === '++') { // unary operators special case
|
498
|
+
if (last_text === ';') {
|
499
|
+
// space for (;; ++i)
|
500
|
+
start_delim = true;
|
501
|
+
end_delim = false;
|
502
|
+
} else {
|
503
|
+
start_delim = false;
|
504
|
+
end_delim = false;
|
505
|
+
}
|
506
|
+
} else if (token_text === '!' && last_type === 'TK_START_EXPR') {
|
507
|
+
// special case handling: if (!a)
|
508
|
+
start_delim = false;
|
509
|
+
end_delim = false;
|
510
|
+
} else if (last_type === 'TK_OPERATOR') {
|
511
|
+
start_delim = false;
|
512
|
+
end_delim = false;
|
513
|
+
} else if (last_type === 'TK_END_EXPR') {
|
514
|
+
start_delim = true;
|
515
|
+
end_delim = true;
|
516
|
+
} else if (token_text === '.') {
|
517
|
+
// decimal digits or object.property
|
518
|
+
start_delim = false;
|
519
|
+
end_delim = false;
|
520
|
+
|
521
|
+
} else if (token_text === ':') {
|
522
|
+
// zz: xx
|
523
|
+
// can't differentiate ternary op, so for now it's a ? b: c; without space before colon
|
524
|
+
if (last_text.match(/^\d+$/)) {
|
525
|
+
// a little help for ternary a ? 1 : 0;
|
526
|
+
start_delim = true;
|
527
|
+
} else {
|
528
|
+
start_delim = false;
|
529
|
+
}
|
530
|
+
}
|
531
|
+
if (start_delim) {
|
532
|
+
print_space();
|
533
|
+
}
|
534
|
+
|
535
|
+
print_token();
|
536
|
+
|
537
|
+
if (end_delim) {
|
538
|
+
print_space();
|
539
|
+
}
|
540
|
+
break;
|
541
|
+
|
542
|
+
case 'TK_BLOCK_COMMENT':
|
543
|
+
|
544
|
+
print_newline();
|
545
|
+
print_token();
|
546
|
+
print_newline();
|
547
|
+
break;
|
548
|
+
|
549
|
+
case 'TK_COMMENT':
|
550
|
+
|
551
|
+
// print_newline();
|
552
|
+
print_space();
|
553
|
+
print_token();
|
554
|
+
print_newline();
|
555
|
+
break;
|
556
|
+
|
557
|
+
case 'TK_UNKNOWN':
|
558
|
+
print_token();
|
559
|
+
break;
|
560
|
+
}
|
561
|
+
|
562
|
+
last_type = token_type;
|
563
|
+
last_text = token_text;
|
564
|
+
}
|
565
|
+
|
566
|
+
return output.join('');
|
567
|
+
|
568
|
+
}
|