jsgui3-server 0.0.74 → 0.0.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/examples/client-side-popup-menu-button.html +93 -93
  2. package/examples/controls/_html-server-color-palette.js +114 -114
  3. package/examples/controls/html-server-combo-box.js +104 -104
  4. package/examples/controls/html-server-list.js +98 -98
  5. package/examples/controls/html-server-popup-menu-button.js +114 -114
  6. package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
  7. package/examples/controls/scs-arrow-button.js +36 -36
  8. package/examples/controls/scs-date-picker.js +157 -157
  9. package/examples/controls/scs-file-browser.js +82 -82
  10. package/examples/controls/scs-item.js +159 -159
  11. package/examples/controls/scs-month-arrow-selector.js +126 -126
  12. package/examples/controls/scs-month-view.js +95 -95
  13. package/examples/controls/scs-start-stop-toggle-button.js +40 -40
  14. package/examples/controls/scs-tree.js +49 -49
  15. package/examples/controls/scs-year-arrow-selector.js +127 -127
  16. package/examples/demos/date-picker.js +119 -119
  17. package/examples/demos/explain-encapsulation.js +9 -9
  18. package/examples/demos/resizing.js +35 -35
  19. package/examples/demos/server_time.js +6 -6
  20. package/examples/demos/square_box.js +324 -324
  21. package/examples/html-rendering.js +20 -20
  22. package/examples/html-server.js +102 -100
  23. package/fs2.js +1836 -1836
  24. package/module.js +21 -21
  25. package/old/single-control-server.js +418 -418
  26. package/package.json +44 -42
  27. package/publishing/function-publisher.js +202 -202
  28. package/publishing/notes.md +5 -5
  29. package/publishing/observable-publisher.js +118 -118
  30. package/publishing/resource-publisher.js +306 -306
  31. package/resources/data-resource.js +104 -104
  32. package/resources/fs-resource.js +148 -148
  33. package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
  34. package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
  35. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
  36. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
  37. package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
  38. package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
  39. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
  40. package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
  41. package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
  42. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
  43. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
  44. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
  45. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
  46. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
  47. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
  48. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
  49. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
  50. package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
  51. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
  52. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
  53. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
  54. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
  55. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
  56. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
  57. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
  58. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
  59. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
  60. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
  61. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
  62. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
  63. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
  64. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
  65. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
  66. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
  67. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
  68. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
  69. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
  70. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
  71. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
  72. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
  73. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
  74. package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
  75. package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
  76. package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
  77. package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
  78. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
  79. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
  80. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
  81. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
  82. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
  83. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
  84. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
  85. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
  86. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
  87. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
  88. package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
  89. package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
  90. package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
  91. package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
  92. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
  93. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
  94. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
  95. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
  96. package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
  97. package/resources/jsbuilder/JS_AST/query/all.js +0 -0
  98. package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
  99. package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
  100. package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
  101. package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
  102. package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
  103. package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
  104. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
  105. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
  106. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
  107. package/resources/jsbuilder/JS_Builder.js +11 -0
  108. package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
  109. package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
  110. package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
  111. package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
  112. package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
  113. package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
  114. package/resources/jsbuilder/JS_File/JS_File.js +12 -0
  115. package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
  116. package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
  117. package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
  118. package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
  119. package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
  120. package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
  121. package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
  122. package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
  123. package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
  124. package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
  125. package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
  126. package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
  127. package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
  128. package/resources/jsbuilder/Module.js +14 -0
  129. package/resources/jsbuilder/Platform.js +14 -0
  130. package/resources/jsbuilder/Platforms.js +70 -0
  131. package/resources/jsbuilder/Project.js +109 -0
  132. package/resources/jsbuilder/Reference.js +1 -0
  133. package/resources/jsbuilder/Reference_Sequence.js +16 -0
  134. package/resources/jsbuilder/Scope.js +30 -0
  135. package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
  136. package/resources/jsbuilder/_JS_File.js +226 -0
  137. package/resources/jsbuilder/ast_query.js +21 -0
  138. package/resources/jsbuilder/babel/babel_consts.js +150 -0
  139. package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
  140. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
  141. package/resources/jsbuilder/build.js +16 -0
  142. package/resources/jsbuilder/platform_notes.md +66 -0
  143. package/resources/jsbuilder/test/test_ast_node.js +451 -0
  144. package/resources/jsbuilder/test/test_js_file.js +304 -0
  145. package/resources/jsbuilder/test/test_project.js +157 -0
  146. package/resources/local-server-info-resource.js +78 -78
  147. package/resources/process-js.js +537 -537
  148. package/resources/server-resource-pool.js +84 -84
  149. package/resources/website-css-resource.js +411 -411
  150. package/resources/website-javascript-resource.js +761 -731
  151. package/resources/website-resource.js +390 -390
  152. package/resources/website-static-html-resource.js +196 -196
  153. package/server.js +170 -170
  154. package/single-control-server.js +398 -398
  155. package/single-page-app.js +129 -129
@@ -1,537 +1,537 @@
1
- /*
2
- Will move code from the js resource to here.
3
- Some code is a bit more general.
4
-
5
- Could have browserify here too?
6
- Idea being to make the js resource code a lot clearer and more concise.
7
-
8
- */
9
-
10
- const {each} = require('lang-mini');
11
-
12
-
13
- // Strings of js?
14
- // Array of lines?
15
-
16
- // Dealing with array of lines makes sense here.
17
-
18
- const analyse_js_doc_formatting = (str_js) => {
19
-
20
- let line_break;
21
- let s_js, str_indentation;
22
-
23
- // or char code.
24
-
25
- // go through character by character.
26
- // detect \r\n
27
- // can try splitting by that first...
28
-
29
- const split_detect_line_break = () => {
30
- const s_rn = str_js.split('\r\n');
31
-
32
- if (s_rn.length > 1) {
33
- //console.log('s_rn.length', s_rn.length);
34
- s_js = s_rn;
35
- line_break = '\r\n';
36
- } else {
37
- s_js = str_js.split('\n');
38
- line_break = '\n';
39
- }
40
- }
41
-
42
- split_detect_line_break();
43
-
44
- //console.log('s_js.length', s_js.length);
45
- //console.log('line_break', line_break);
46
-
47
- // a map of them?
48
- // finding a common factor with all / almost all of them...
49
- // most likely 2 or 4 with spaces.
50
- // maybe ignore the indentations with comment lines.
51
-
52
-
53
- // keep a map of the number of indentation characters
54
- // then can detect if the factor is either 2 or 4.
55
-
56
- const map_num_spaces = {};
57
-
58
-
59
- // Find the proportion in this map that are a factor of both 2 and 4
60
- // Find the proportion that fit in with each.
61
-
62
- // formatting parse.
63
- const analyse_indentation = () => {
64
-
65
- let line_beginning_spaces, line_beginning_tabs, l, i, stop;
66
- let line_begins_with_space, line_begins_with_tab;
67
- let count_lines_beginning_space = 0, count_lines_beginning_tab = 0;
68
-
69
- let arr_num_indentations = new Array(s_js.length);
70
- let arr_num_tabs = new Array(s_js.length);
71
- let arr_num_spaces = new Array(s_js.length);
72
- let arr_unindented_lines = new Array(s_js.length);
73
-
74
- let arr_indentation_parsed_lines = new Array(s_js.length);
75
-
76
-
77
-
78
- each(s_js, (line, line_num) => {
79
- line_begins_with_space = false;
80
- line_begins_with_tab = false;
81
- line_beginning_spaces = 0;
82
- line_beginning_tabs = 0;
83
- // should not be both tabs and spaces.
84
- // error if there is a mix?
85
- // or just consider it indented by whichever is first.
86
- l = line.length;
87
- i = 0;
88
- stop = false;
89
- while (i < l && stop === false) {
90
- // String#charCodeAt()
91
- const charcode = line.charCodeAt(i);
92
- if (i === 0) {
93
- //console.log('');
94
- //console.log('line', line);
95
- //console.log('[i, charcode]', [i, charcode]);
96
- //console.log('');
97
-
98
- // space is 32
99
- // tab is 9
100
-
101
- if (charcode === 9) {
102
- // tab
103
- line_beginning_tabs++;
104
- count_lines_beginning_tab++;
105
- line_begins_with_tab = true;
106
- } else if (charcode === 32) {
107
- // space
108
- count_lines_beginning_space++;
109
- line_beginning_spaces++;
110
- line_begins_with_space = true;
111
- } else {
112
- stop = true;
113
- }
114
- } else {
115
- if (line_begins_with_tab) {
116
- // Indentation stops with any non-tab character.
117
- if (charcode === 9) {
118
- // tab
119
- line_beginning_tabs++;
120
- //count_lines_beginning_tab++;
121
- //line_begins_with_tab = true;
122
- } else {
123
- stop = true;
124
- }
125
-
126
- } else if (line_begins_with_space) {
127
- // Indentation stops with any non-space character.
128
- if (charcode === 32) {
129
- // tab
130
- line_beginning_spaces++;
131
- //count_lines_beginning_tab++;
132
- //line_begins_with_tab = true;
133
- } else {
134
- stop = true;
135
- }
136
- } else {
137
- throw 'Unexpected.';
138
- }
139
-
140
- // set the arrays of these counts per line.
141
-
142
- if (line_beginning_tabs > 0) {
143
- arr_num_tabs[line_num] = line_beginning_tabs;
144
- }
145
- if (line_begins_with_space > 0) {
146
- arr_num_spaces[line_num] = line_beginning_spaces;
147
- }
148
-
149
- }
150
- i++;
151
- }
152
-
153
- //console.log('');
154
- //console.log('line', line);
155
- //console.log('line.length', line.length);
156
- //console.log('line_begins_with_space', line_begins_with_space);
157
- //console.log('line_begins_with_tab', line_begins_with_tab);
158
- //console.log('line_beginning_spaces', line_beginning_spaces);
159
- //console.log('line_beginning_tabs', line_beginning_tabs);
160
-
161
-
162
- if (line_begins_with_tab) {
163
-
164
- // A map of the number of tabs...?
165
-
166
-
167
- } else if (line_begins_with_space) {
168
-
169
- map_num_spaces[line_beginning_spaces] = map_num_spaces[line_beginning_spaces] || 0;
170
- map_num_spaces[line_beginning_spaces]++;
171
- }
172
- });
173
-
174
- // Determine if the indentation uses spaces or tabs.
175
-
176
- //console.log('count_lines_beginning_space', count_lines_beginning_space);
177
- //console.log('count_lines_beginning_tab', count_lines_beginning_tab);
178
-
179
- let str_indentation;
180
-
181
- // Go through the lines again I think....
182
-
183
-
184
-
185
-
186
- if (count_lines_beginning_space > count_lines_beginning_tab) {
187
- //console.log('indentation uses spaces');
188
- //console.log('map_num_spaces', map_num_spaces);
189
-
190
- // the proportion dividing into 4
191
- // proportion dividing into 2
192
-
193
- let count_factor_2 = 0;
194
- let count_factor_4 = 0;
195
-
196
- //let count_lines_beginning_space = 0;
197
-
198
- each(map_num_spaces, (num_occurrances, str_num_spaces) => {
199
- const num_spaces = parseInt(str_num_spaces, 10);
200
- if (num_spaces % 2 === 0) count_factor_2 += num_occurrances;
201
- if (num_spaces % 4 === 0) count_factor_4 += num_occurrances;
202
- //count_lines_beginning_space += num_occurrances;
203
- })
204
-
205
- //console.log('count_factor_2', count_factor_2);
206
- //console.log('count_factor_4', count_factor_4);
207
- //console.log('count_lines_beginning_space', count_lines_beginning_space);
208
-
209
- let r2 = count_factor_2 / count_lines_beginning_space;
210
- let r4 = count_factor_4 / count_lines_beginning_space;
211
-
212
- //console.log('r2', r2);
213
- //console.log('r4', r4);
214
-
215
- // >= 90%.
216
-
217
- let indentation_length;
218
-
219
- if (r4 >= 0.9) {
220
- str_indentation = ' ';
221
- indentation_length = 4;
222
- } else if (r2 >= 0.9) {
223
- str_indentation = ' ';
224
- indentation_length = 2;
225
- } else {
226
- //throw
227
- throw 'NYI';
228
- }
229
-
230
- //console.log('arr_num_spaces', arr_num_spaces);
231
-
232
- // Then calculate how many indentations per line...
233
-
234
- // // arr_unindented_lines, arr_indentation_parsed_lines, arr_num_indentations
235
-
236
- each(arr_num_spaces, (num_spaces, line_num) => {
237
- const num_indentations = Math.floor((num_spaces || 0) / indentation_length);
238
- //console.log('num_indentations', num_indentations);
239
- arr_num_indentations[line_num] = num_indentations;
240
- const unindented_line = s_js[line_num].substr(num_indentations * indentation_length);
241
- //console.log('unindented_line', unindented_line);
242
- arr_unindented_lines[line_num] = unindented_line;
243
- })
244
-
245
-
246
-
247
- } else {
248
- console.log('indentation uses tabs');
249
- str_indentation = '\t';
250
- console.log('arr_num_tabs', arr_num_tabs);
251
-
252
- throw 'NYI';
253
- }
254
-
255
- //console.log('str_indentation', str_indentation);
256
- //console.log('str_indentation.length', str_indentation.length);
257
- // also the unindented string lines, alongside their indentation levels.
258
- // recreate the lines....
259
- //
260
-
261
-
262
- // return unindented lines as well....
263
-
264
- const arr_res = new Array(s_js.length);
265
- for (let c = 0; c < s_js.length; c++) {
266
- arr_res[c] = [arr_num_indentations[c] || 0, arr_unindented_lines[c]];
267
- }
268
-
269
- const obj_res = {
270
- //js_lines: s_js,
271
- parsed_lines: arr_res,
272
- str_indentation: str_indentation
273
- }
274
- return obj_res;
275
- // If factor 4 is high enough...
276
- // Want the total line count
277
- // Total line count with any spaces...
278
-
279
- }
280
-
281
- const indentation_analysis = analyse_indentation();
282
-
283
- // Now go through the lines and look at indentation.
284
-
285
- const res = {
286
- arr_lines: s_js,
287
- line_break: line_break,
288
- indentation_analysis: indentation_analysis
289
- }
290
-
291
- return res;
292
-
293
- }
294
-
295
- // function to split out the client js from a root js file.
296
-
297
- const extract_client_js = (js_formatting_info) => {
298
- const {line_break, indentation_analysis} = js_formatting_info;
299
- const {parsed_lines, str_indentation} = indentation_analysis;
300
-
301
-
302
-
303
- // parsed line: [indentation level, str line]
304
- // takes the split lines...
305
- let block_type;
306
- // line types:
307
- // require
308
- //
309
- // only identify some specific types of lines.
310
-
311
- // Will need to change a / the jsgui3-html reference to jsgui3-client.
312
- let line_type;
313
-
314
- // And specific parsing for some line types.
315
-
316
- // Need to change a require line here.
317
- //const map_
318
-
319
- // Looking forward to making simple js demo and example files.
320
- // running full apps from them.
321
- // some easy copy and paste getting started examples.
322
-
323
- // Detect and parse?
324
- // Makes sense to do parsing once it's detected.
325
- // Maybe only need to parse require statements.
326
-
327
-
328
- // Removing comment blocks...?
329
-
330
- const map_line_type_detect_parse = {
331
-
332
- // beginning of server side block
333
- // end of code block
334
-
335
- begin_server_block: (line) => {
336
- // line beings: if (require.main === module) {
337
- //console.log('line', line);
338
- //console.log('typeof line', typeof line);
339
- if (line.startsWith('if (require.main === module) {')) return true;
340
-
341
-
342
- return false;
343
- },
344
- end_block: line => {
345
-
346
-
347
- // only having } in the line?
348
-
349
- //console.log('line.length', line.length);
350
-
351
- if (line.length <3) {
352
- if (line.startsWith('}')) return true;
353
- }
354
-
355
-
356
-
357
- return false;
358
-
359
- },
360
-
361
- require: (line) => {
362
- let s1 = 'require(';
363
- let pos1 = line.indexOf(s1);
364
- let res = false;
365
-
366
- if (pos1 > -1) {
367
- let pos2 = pos1 + s1.length;
368
- let pos3 = line.indexOf(')');
369
- let rpath = JSON.parse(line.substring(pos2, pos3).split('\'').join('"'));
370
- //console.log('rpath', rpath);
371
-
372
- //let res = ['require']
373
-
374
- res = {
375
- name: 'require',
376
- path: rpath
377
- }
378
- }
379
- return res;
380
- }
381
- }
382
-
383
- /*
384
- const map_line_type_parsing = {
385
- require: (line) => {
386
-
387
- }
388
- }
389
- */
390
-
391
- // Does seem like a bit more work to make this client js compilation from single file.
392
- // Will greatly improve coder experience.
393
-
394
- // Marking the blocks first could make sense?
395
-
396
- // Determine the block types as we go through.
397
- // At this stage, remove all server-side blocks.
398
- // main module thing.
399
-
400
- // Result array...
401
- // Transformed lines...
402
-
403
- const arr_client_js_lines = [];
404
- each(parsed_lines, (arr_line_info, line_num) => {
405
- //console.log();
406
- const [indentation_level, unindented_line] = arr_line_info;
407
- let res_unindented_line = unindented_line;
408
-
409
- line_type = undefined;
410
- let do_js_copy_to_client = true;
411
-
412
- if (indentation_level === 0) {
413
- //console.log('unindented_line', unindented_line);
414
-
415
-
416
-
417
- each(map_line_type_detect_parse, (fn, name, stop) => {
418
- const detection = fn(unindented_line);
419
- //console.log('detection', detection);
420
-
421
- if (detection) {
422
- stop();
423
- //const {name} = detection;
424
- //console.log('name', name);
425
-
426
- // detection of the beginning / end of server side (main module) code.
427
-
428
- if (name === 'require') {
429
- const {path} = detection;
430
- //console.log('path', path);
431
-
432
- // Can create a new / different line.
433
- // Depending on what gets required.
434
-
435
- if (path === 'jsgui3-html') {
436
- res_unindented_line = unindented_line.split('jsgui3-html').join('jsgui3-client');
437
- //console.log('res_unindented_line', res_unindented_line);
438
- }
439
- //
440
- }
441
-
442
- if (name === 'begin_server_block') {
443
- block_type = 'server_block';
444
- }
445
- if (name === 'end_block') {
446
- if (block_type === 'server_block') {
447
- do_js_copy_to_client = false;
448
- }
449
- block_type = undefined;
450
-
451
- }
452
-
453
- // if we are not in a server block, copy it over to the compiled client js result.
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
- // Check for block ends...
466
-
467
- }
468
-
469
- // or end of block.?
470
- // suppress line write
471
-
472
-
473
- })
474
-
475
-
476
-
477
- // Look at that line for some specific things.
478
-
479
- // line_type as well.
480
- // Already in a block_type?
481
-
482
- // Different possible statements.
483
- // Some line types / code defs will be quite specific.
484
-
485
- // line begins 'const x = require(
486
-
487
- // Could textually break down the lines to make conclusions...
488
- // Semicolon within strings may be a bit tricky.
489
- // Avoid handling that right now.
490
-
491
- // different detection functions for specific things.
492
- // go through them.
493
- // specific detection functions for each line may work best and simplest. Not so good perf when it gets more complex.
494
- // but this will be relatively simple.
495
-
496
- }
497
-
498
- if (block_type === 'server_block') {
499
- do_js_copy_to_client = false;
500
- }
501
-
502
- //console.log('res_unindented_line', res_unindented_line);
503
-
504
- //console.log('do_js_copy_to_client', do_js_copy_to_client);
505
- if (do_js_copy_to_client) {
506
- // blank out the line?
507
- // and put the indentation amount back.
508
- let indent = str_indentation.repeat(indentation_level);
509
- arr_client_js_lines.push(indent + res_unindented_line);
510
- }
511
- })
512
-
513
- //console.log('arr_client_js_lines', arr_client_js_lines);
514
- //console.log('arr_client_js_lines.length', arr_client_js_lines.length);
515
-
516
- let client_js = arr_client_js_lines.join(line_break);
517
-
518
-
519
- return client_js;
520
-
521
-
522
- }
523
-
524
-
525
- //const split_client_server_js = ()
526
-
527
-
528
- const process_js = {
529
- analyse_js_doc_formatting: analyse_js_doc_formatting, // parse_js_lines?
530
- extract_client_js: extract_client_js
531
-
532
- }
533
-
534
- // analyse_js_doc_formatting extract_client_js
535
-
536
- module.exports = process_js;
537
-
1
+ /*
2
+ Will move code from the js resource to here.
3
+ Some code is a bit more general.
4
+
5
+ Could have browserify here too?
6
+ Idea being to make the js resource code a lot clearer and more concise.
7
+
8
+ */
9
+
10
+ const {each} = require('lang-mini');
11
+
12
+
13
+ // Strings of js?
14
+ // Array of lines?
15
+
16
+ // Dealing with array of lines makes sense here.
17
+
18
+ const analyse_js_doc_formatting = (str_js) => {
19
+
20
+ let line_break;
21
+ let s_js, str_indentation;
22
+
23
+ // or char code.
24
+
25
+ // go through character by character.
26
+ // detect \r\n
27
+ // can try splitting by that first...
28
+
29
+ const split_detect_line_break = () => {
30
+ const s_rn = str_js.split('\r\n');
31
+
32
+ if (s_rn.length > 1) {
33
+ //console.log('s_rn.length', s_rn.length);
34
+ s_js = s_rn;
35
+ line_break = '\r\n';
36
+ } else {
37
+ s_js = str_js.split('\n');
38
+ line_break = '\n';
39
+ }
40
+ }
41
+
42
+ split_detect_line_break();
43
+
44
+ //console.log('s_js.length', s_js.length);
45
+ //console.log('line_break', line_break);
46
+
47
+ // a map of them?
48
+ // finding a common factor with all / almost all of them...
49
+ // most likely 2 or 4 with spaces.
50
+ // maybe ignore the indentations with comment lines.
51
+
52
+
53
+ // keep a map of the number of indentation characters
54
+ // then can detect if the factor is either 2 or 4.
55
+
56
+ const map_num_spaces = {};
57
+
58
+
59
+ // Find the proportion in this map that are a factor of both 2 and 4
60
+ // Find the proportion that fit in with each.
61
+
62
+ // formatting parse.
63
+ const analyse_indentation = () => {
64
+
65
+ let line_beginning_spaces, line_beginning_tabs, l, i, stop;
66
+ let line_begins_with_space, line_begins_with_tab;
67
+ let count_lines_beginning_space = 0, count_lines_beginning_tab = 0;
68
+
69
+ let arr_num_indentations = new Array(s_js.length);
70
+ let arr_num_tabs = new Array(s_js.length);
71
+ let arr_num_spaces = new Array(s_js.length);
72
+ let arr_unindented_lines = new Array(s_js.length);
73
+
74
+ let arr_indentation_parsed_lines = new Array(s_js.length);
75
+
76
+
77
+
78
+ each(s_js, (line, line_num) => {
79
+ line_begins_with_space = false;
80
+ line_begins_with_tab = false;
81
+ line_beginning_spaces = 0;
82
+ line_beginning_tabs = 0;
83
+ // should not be both tabs and spaces.
84
+ // error if there is a mix?
85
+ // or just consider it indented by whichever is first.
86
+ l = line.length;
87
+ i = 0;
88
+ stop = false;
89
+ while (i < l && stop === false) {
90
+ // String#charCodeAt()
91
+ const charcode = line.charCodeAt(i);
92
+ if (i === 0) {
93
+ //console.log('');
94
+ //console.log('line', line);
95
+ //console.log('[i, charcode]', [i, charcode]);
96
+ //console.log('');
97
+
98
+ // space is 32
99
+ // tab is 9
100
+
101
+ if (charcode === 9) {
102
+ // tab
103
+ line_beginning_tabs++;
104
+ count_lines_beginning_tab++;
105
+ line_begins_with_tab = true;
106
+ } else if (charcode === 32) {
107
+ // space
108
+ count_lines_beginning_space++;
109
+ line_beginning_spaces++;
110
+ line_begins_with_space = true;
111
+ } else {
112
+ stop = true;
113
+ }
114
+ } else {
115
+ if (line_begins_with_tab) {
116
+ // Indentation stops with any non-tab character.
117
+ if (charcode === 9) {
118
+ // tab
119
+ line_beginning_tabs++;
120
+ //count_lines_beginning_tab++;
121
+ //line_begins_with_tab = true;
122
+ } else {
123
+ stop = true;
124
+ }
125
+
126
+ } else if (line_begins_with_space) {
127
+ // Indentation stops with any non-space character.
128
+ if (charcode === 32) {
129
+ // tab
130
+ line_beginning_spaces++;
131
+ //count_lines_beginning_tab++;
132
+ //line_begins_with_tab = true;
133
+ } else {
134
+ stop = true;
135
+ }
136
+ } else {
137
+ throw 'Unexpected.';
138
+ }
139
+
140
+ // set the arrays of these counts per line.
141
+
142
+ if (line_beginning_tabs > 0) {
143
+ arr_num_tabs[line_num] = line_beginning_tabs;
144
+ }
145
+ if (line_begins_with_space > 0) {
146
+ arr_num_spaces[line_num] = line_beginning_spaces;
147
+ }
148
+
149
+ }
150
+ i++;
151
+ }
152
+
153
+ //console.log('');
154
+ //console.log('line', line);
155
+ //console.log('line.length', line.length);
156
+ //console.log('line_begins_with_space', line_begins_with_space);
157
+ //console.log('line_begins_with_tab', line_begins_with_tab);
158
+ //console.log('line_beginning_spaces', line_beginning_spaces);
159
+ //console.log('line_beginning_tabs', line_beginning_tabs);
160
+
161
+
162
+ if (line_begins_with_tab) {
163
+
164
+ // A map of the number of tabs...?
165
+
166
+
167
+ } else if (line_begins_with_space) {
168
+
169
+ map_num_spaces[line_beginning_spaces] = map_num_spaces[line_beginning_spaces] || 0;
170
+ map_num_spaces[line_beginning_spaces]++;
171
+ }
172
+ });
173
+
174
+ // Determine if the indentation uses spaces or tabs.
175
+
176
+ //console.log('count_lines_beginning_space', count_lines_beginning_space);
177
+ //console.log('count_lines_beginning_tab', count_lines_beginning_tab);
178
+
179
+ let str_indentation;
180
+
181
+ // Go through the lines again I think....
182
+
183
+
184
+
185
+
186
+ if (count_lines_beginning_space > count_lines_beginning_tab) {
187
+ //console.log('indentation uses spaces');
188
+ //console.log('map_num_spaces', map_num_spaces);
189
+
190
+ // the proportion dividing into 4
191
+ // proportion dividing into 2
192
+
193
+ let count_factor_2 = 0;
194
+ let count_factor_4 = 0;
195
+
196
+ //let count_lines_beginning_space = 0;
197
+
198
+ each(map_num_spaces, (num_occurrances, str_num_spaces) => {
199
+ const num_spaces = parseInt(str_num_spaces, 10);
200
+ if (num_spaces % 2 === 0) count_factor_2 += num_occurrances;
201
+ if (num_spaces % 4 === 0) count_factor_4 += num_occurrances;
202
+ //count_lines_beginning_space += num_occurrances;
203
+ })
204
+
205
+ //console.log('count_factor_2', count_factor_2);
206
+ //console.log('count_factor_4', count_factor_4);
207
+ //console.log('count_lines_beginning_space', count_lines_beginning_space);
208
+
209
+ let r2 = count_factor_2 / count_lines_beginning_space;
210
+ let r4 = count_factor_4 / count_lines_beginning_space;
211
+
212
+ //console.log('r2', r2);
213
+ //console.log('r4', r4);
214
+
215
+ // >= 90%.
216
+
217
+ let indentation_length;
218
+
219
+ if (r4 >= 0.9) {
220
+ str_indentation = ' ';
221
+ indentation_length = 4;
222
+ } else if (r2 >= 0.9) {
223
+ str_indentation = ' ';
224
+ indentation_length = 2;
225
+ } else {
226
+ //throw
227
+ throw 'NYI';
228
+ }
229
+
230
+ //console.log('arr_num_spaces', arr_num_spaces);
231
+
232
+ // Then calculate how many indentations per line...
233
+
234
+ // // arr_unindented_lines, arr_indentation_parsed_lines, arr_num_indentations
235
+
236
+ each(arr_num_spaces, (num_spaces, line_num) => {
237
+ const num_indentations = Math.floor((num_spaces || 0) / indentation_length);
238
+ //console.log('num_indentations', num_indentations);
239
+ arr_num_indentations[line_num] = num_indentations;
240
+ const unindented_line = s_js[line_num].substr(num_indentations * indentation_length);
241
+ //console.log('unindented_line', unindented_line);
242
+ arr_unindented_lines[line_num] = unindented_line;
243
+ })
244
+
245
+
246
+
247
+ } else {
248
+ console.log('indentation uses tabs');
249
+ str_indentation = '\t';
250
+ console.log('arr_num_tabs', arr_num_tabs);
251
+
252
+ throw 'NYI';
253
+ }
254
+
255
+ //console.log('str_indentation', str_indentation);
256
+ //console.log('str_indentation.length', str_indentation.length);
257
+ // also the unindented string lines, alongside their indentation levels.
258
+ // recreate the lines....
259
+ //
260
+
261
+
262
+ // return unindented lines as well....
263
+
264
+ const arr_res = new Array(s_js.length);
265
+ for (let c = 0; c < s_js.length; c++) {
266
+ arr_res[c] = [arr_num_indentations[c] || 0, arr_unindented_lines[c]];
267
+ }
268
+
269
+ const obj_res = {
270
+ //js_lines: s_js,
271
+ parsed_lines: arr_res,
272
+ str_indentation: str_indentation
273
+ }
274
+ return obj_res;
275
+ // If factor 4 is high enough...
276
+ // Want the total line count
277
+ // Total line count with any spaces...
278
+
279
+ }
280
+
281
+ const indentation_analysis = analyse_indentation();
282
+
283
+ // Now go through the lines and look at indentation.
284
+
285
+ const res = {
286
+ arr_lines: s_js,
287
+ line_break: line_break,
288
+ indentation_analysis: indentation_analysis
289
+ }
290
+
291
+ return res;
292
+
293
+ }
294
+
295
+ // function to split out the client js from a root js file.
296
+
297
+ const extract_client_js = (js_formatting_info) => {
298
+ const {line_break, indentation_analysis} = js_formatting_info;
299
+ const {parsed_lines, str_indentation} = indentation_analysis;
300
+
301
+
302
+
303
+ // parsed line: [indentation level, str line]
304
+ // takes the split lines...
305
+ let block_type;
306
+ // line types:
307
+ // require
308
+ //
309
+ // only identify some specific types of lines.
310
+
311
+ // Will need to change a / the jsgui3-html reference to jsgui3-client.
312
+ let line_type;
313
+
314
+ // And specific parsing for some line types.
315
+
316
+ // Need to change a require line here.
317
+ //const map_
318
+
319
+ // Looking forward to making simple js demo and example files.
320
+ // running full apps from them.
321
+ // some easy copy and paste getting started examples.
322
+
323
+ // Detect and parse?
324
+ // Makes sense to do parsing once it's detected.
325
+ // Maybe only need to parse require statements.
326
+
327
+
328
+ // Removing comment blocks...?
329
+
330
+ const map_line_type_detect_parse = {
331
+
332
+ // beginning of server side block
333
+ // end of code block
334
+
335
+ begin_server_block: (line) => {
336
+ // line beings: if (require.main === module) {
337
+ //console.log('line', line);
338
+ //console.log('typeof line', typeof line);
339
+ if (line.startsWith('if (require.main === module) {')) return true;
340
+
341
+
342
+ return false;
343
+ },
344
+ end_block: line => {
345
+
346
+
347
+ // only having } in the line?
348
+
349
+ //console.log('line.length', line.length);
350
+
351
+ if (line.length <3) {
352
+ if (line.startsWith('}')) return true;
353
+ }
354
+
355
+
356
+
357
+ return false;
358
+
359
+ },
360
+
361
+ require: (line) => {
362
+ let s1 = 'require(';
363
+ let pos1 = line.indexOf(s1);
364
+ let res = false;
365
+
366
+ if (pos1 > -1) {
367
+ let pos2 = pos1 + s1.length;
368
+ let pos3 = line.indexOf(')');
369
+ let rpath = JSON.parse(line.substring(pos2, pos3).split('\'').join('"'));
370
+ //console.log('rpath', rpath);
371
+
372
+ //let res = ['require']
373
+
374
+ res = {
375
+ name: 'require',
376
+ path: rpath
377
+ }
378
+ }
379
+ return res;
380
+ }
381
+ }
382
+
383
+ /*
384
+ const map_line_type_parsing = {
385
+ require: (line) => {
386
+
387
+ }
388
+ }
389
+ */
390
+
391
+ // Does seem like a bit more work to make this client js compilation from single file.
392
+ // Will greatly improve coder experience.
393
+
394
+ // Marking the blocks first could make sense?
395
+
396
+ // Determine the block types as we go through.
397
+ // At this stage, remove all server-side blocks.
398
+ // main module thing.
399
+
400
+ // Result array...
401
+ // Transformed lines...
402
+
403
+ const arr_client_js_lines = [];
404
+ each(parsed_lines, (arr_line_info, line_num) => {
405
+ //console.log();
406
+ const [indentation_level, unindented_line] = arr_line_info;
407
+ let res_unindented_line = unindented_line;
408
+
409
+ line_type = undefined;
410
+ let do_js_copy_to_client = true;
411
+
412
+ if (indentation_level === 0) {
413
+ //console.log('unindented_line', unindented_line);
414
+
415
+
416
+
417
+ each(map_line_type_detect_parse, (fn, name, stop) => {
418
+ const detection = fn(unindented_line);
419
+ //console.log('detection', detection);
420
+
421
+ if (detection) {
422
+ stop();
423
+ //const {name} = detection;
424
+ //console.log('name', name);
425
+
426
+ // detection of the beginning / end of server side (main module) code.
427
+
428
+ if (name === 'require') {
429
+ const {path} = detection;
430
+ //console.log('path', path);
431
+
432
+ // Can create a new / different line.
433
+ // Depending on what gets required.
434
+
435
+ if (path === 'jsgui3-html') {
436
+ res_unindented_line = unindented_line.split('jsgui3-html').join('jsgui3-client');
437
+ //console.log('res_unindented_line', res_unindented_line);
438
+ }
439
+ //
440
+ }
441
+
442
+ if (name === 'begin_server_block') {
443
+ block_type = 'server_block';
444
+ }
445
+ if (name === 'end_block') {
446
+ if (block_type === 'server_block') {
447
+ do_js_copy_to_client = false;
448
+ }
449
+ block_type = undefined;
450
+
451
+ }
452
+
453
+ // if we are not in a server block, copy it over to the compiled client js result.
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+ // Check for block ends...
466
+
467
+ }
468
+
469
+ // or end of block.?
470
+ // suppress line write
471
+
472
+
473
+ })
474
+
475
+
476
+
477
+ // Look at that line for some specific things.
478
+
479
+ // line_type as well.
480
+ // Already in a block_type?
481
+
482
+ // Different possible statements.
483
+ // Some line types / code defs will be quite specific.
484
+
485
+ // line begins 'const x = require(
486
+
487
+ // Could textually break down the lines to make conclusions...
488
+ // Semicolon within strings may be a bit tricky.
489
+ // Avoid handling that right now.
490
+
491
+ // different detection functions for specific things.
492
+ // go through them.
493
+ // specific detection functions for each line may work best and simplest. Not so good perf when it gets more complex.
494
+ // but this will be relatively simple.
495
+
496
+ }
497
+
498
+ if (block_type === 'server_block') {
499
+ do_js_copy_to_client = false;
500
+ }
501
+
502
+ //console.log('res_unindented_line', res_unindented_line);
503
+
504
+ //console.log('do_js_copy_to_client', do_js_copy_to_client);
505
+ if (do_js_copy_to_client) {
506
+ // blank out the line?
507
+ // and put the indentation amount back.
508
+ let indent = str_indentation.repeat(indentation_level);
509
+ arr_client_js_lines.push(indent + res_unindented_line);
510
+ }
511
+ })
512
+
513
+ //console.log('arr_client_js_lines', arr_client_js_lines);
514
+ //console.log('arr_client_js_lines.length', arr_client_js_lines.length);
515
+
516
+ let client_js = arr_client_js_lines.join(line_break);
517
+
518
+
519
+ return client_js;
520
+
521
+
522
+ }
523
+
524
+
525
+ //const split_client_server_js = ()
526
+
527
+
528
+ const process_js = {
529
+ analyse_js_doc_formatting: analyse_js_doc_formatting, // parse_js_lines?
530
+ extract_client_js: extract_client_js
531
+
532
+ }
533
+
534
+ // analyse_js_doc_formatting extract_client_js
535
+
536
+ module.exports = process_js;
537
+