jsgui3-server 0.0.121 → 0.0.123
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.
- package/.vscode/settings.json +6 -0
- package/README.md +10 -10
- package/controls/Active_HTML_Document.js +116 -116
- package/controls/README.md +7 -7
- package/controls/page/admin.js +74 -74
- package/controls/panel/admin.js +11 -11
- package/examples/_css/basic.css +913 -913
- package/examples/_css/database-control.css +51 -51
- package/examples/_css/jsgui.css +66 -66
- package/examples/_css/multi-layout.css +23 -23
- package/examples/_css/style.css +1669 -1669
- package/examples/_css/top-and-bottom-bars.css +54 -54
- package/examples/box/1) square box/client.js +188 -188
- package/examples/box/1) square box/server.js +112 -112
- package/examples/box/2) twenty square boxes/css flex wrap/client.js +112 -248
- package/examples/box/2) twenty square boxes/css flex wrap/server.js +39 -112
- package/examples/box/3) twenty selectable square boxes/css flex wrap/client.js +129 -0
- package/examples/{controls/15) window, text field → box/3) twenty selectable square boxes/css flex wrap}/server.js +38 -38
- package/examples/boxes/square_boxes.js +45 -48
- package/examples/boxes/square_boxes_client.js +132 -136
- package/examples/client-side-popup-menu-button.html +93 -93
- package/examples/color_palette.js +51 -51
- package/examples/color_palette_client.js +95 -95
- package/examples/controls/1) window/client.js +186 -186
- package/examples/controls/1) window/server.js +117 -117
- package/examples/controls/10) window, mirrored text inputs/client.js +118 -320
- package/examples/controls/10) window, mirrored text inputs/server.js +37 -117
- package/examples/controls/11) window, mirrored text fields/client.js +493 -251
- package/examples/controls/11) window, mirrored text fields/server.js +117 -117
- package/examples/controls/11b) window, shared Data_Object model mirrored text fields/client.js +613 -331
- package/examples/controls/11b) window, shared Data_Object model mirrored text fields/server.js +117 -117
- package/examples/controls/11c) window, shared Data_Value model mirrored text fields/client.js +617 -617
- package/examples/controls/11c) window, shared Data_Value model mirrored text fields/server.js +117 -117
- package/examples/controls/11d) window, shared model mirrored integer text fields/client.js +611 -280
- package/examples/controls/11d) window, shared model mirrored integer text fields/server.js +134 -22
- package/examples/controls/12) window, Select_Options control/client.js +66 -452
- package/examples/controls/12) window, Select_Options control/server.js +19 -117
- package/examples/controls/13) window, Dropdown_Menu control/client.js +66 -0
- package/examples/controls/13) window, Dropdown_Menu control/server.js +20 -0
- package/examples/controls/2) two windows/client.js +193 -193
- package/examples/controls/2) two windows/server.js +113 -113
- package/examples/controls/3) five windows/client.js +217 -217
- package/examples/controls/3) five windows/server.js +116 -115
- package/examples/controls/4) window, tabbed panel/client.js +54 -225
- package/examples/controls/4) window, tabbed panel/server.js +17 -117
- package/examples/controls/5) window, grid/client.js +204 -484
- package/examples/controls/5) window, grid/server.js +117 -119
- package/examples/controls/6) window, color_palette/client.js +68 -204
- package/examples/controls/6) window, color_palette/server.js +117 -117
- package/examples/controls/7) window, month_view/client.js +40 -231
- package/examples/controls/7) window, month_view/server.js +117 -117
- package/examples/controls/8) window, checkbox/client.js +33 -209
- package/examples/controls/8) window, checkbox/server.js +117 -117
- package/examples/controls/9) window, date picker/client.js +76 -303
- package/examples/controls/9) window, date picker/server.js +117 -117
- package/examples/controls/9b) window, shared data.model mirrored date pickers/README.md +51 -0
- package/examples/controls/9b) window, shared data.model mirrored date pickers/client.js +83 -398
- package/examples/controls/9b) window, shared data.model mirrored date pickers/server.js +117 -117
- package/examples/controls/__old/_html-server-color-palette.js +114 -114
- package/examples/controls/__old/html-server-combo-box.js +104 -104
- package/examples/controls/__old/html-server-list.js +98 -98
- package/examples/controls/__old/html-server-popup-menu-button.js +114 -114
- package/examples/controls/__old/html-server-start-stop-toggle-button.js +146 -146
- package/examples/controls/__old/scs-arrow-button.js +36 -36
- package/examples/controls/__old/scs-date-picker.js +157 -157
- package/examples/controls/__old/scs-file-browser.js +82 -82
- package/examples/controls/__old/scs-item.js +159 -159
- package/examples/controls/__old/scs-month-arrow-selector.js +126 -126
- package/examples/controls/__old/scs-month-view.js +94 -94
- package/examples/controls/__old/scs-start-stop-toggle-button.js +40 -40
- package/examples/controls/__old/scs-tree.js +49 -49
- package/examples/controls/__old/scs-year-arrow-selector.js +127 -127
- package/examples/demos/date-picker.js +119 -119
- package/examples/demos/explain-encapsulation.js +9 -9
- package/examples/demos/resizing.js +35 -35
- package/examples/demos/server_time.js +6 -6
- package/examples/grids/grid_1.js +45 -45
- package/examples/grids/grid_1_client.js +329 -329
- package/examples/html-rendering.js +20 -20
- package/examples/html-server.js +105 -105
- package/examples/introducing jsgui3/server.js +110 -110
- package/examples/mx_display/mx_display_1.js +45 -45
- package/examples/mx_display/mx_display_1_client.js +444 -444
- package/fs2.js +1836 -1836
- package/http/responders/HTTP_Responder.js +15 -15
- package/http/responders/static/Static_Route_HTTP_Responder.js +105 -105
- package/module.js +34 -34
- package/old/_single-control-server.js +418 -418
- package/old/single-control-server.js +368 -368
- package/old/single-page-app.js +131 -131
- package/package.json +42 -42
- package/page-context.js +92 -92
- package/publishers/helpers/assigners/Assigner.js +10 -10
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -150
- package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +109 -109
- package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +91 -91
- package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -104
- package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +18 -18
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +44 -44
- package/publishers/http-function-publisher.js +212 -212
- package/publishers/http-html-page-publisher.js +5 -5
- package/publishers/http-html-publisher.js +24 -24
- package/publishers/http-js-publisher.js +135 -135
- package/publishers/http-observable-publisher.js +124 -124
- package/publishers/http-publisher.js +53 -53
- package/publishers/http-resource-publisher.js +325 -325
- package/publishers/http-webpage-publisher.js +659 -658
- package/publishers/http-webpageorsite-publisher.js +343 -343
- package/publishers/http-website-publisher.js +640 -640
- package/publishers/notes.md +9 -9
- package/resources/README.md +16 -16
- package/resources/_old_website-javascript-resource.js +994 -994
- package/resources/_old_website-resource.js +507 -507
- package/resources/compile/server-resource-compilation.js +43 -43
- package/resources/data-resource.js +118 -118
- package/resources/fs-resource.js +146 -146
- package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -105
- package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +42 -42
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +41 -41
- package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Node.js +93 -93
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +253 -253
- package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +337 -337
- package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +96 -96
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +37 -37
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +72 -72
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +92 -92
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -29
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -116
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +159 -159
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +178 -178
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +87 -87
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +91 -91
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +136 -136
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +73 -73
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +85 -85
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +42 -42
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +40 -40
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +54 -54
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +45 -45
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +343 -343
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +38 -38
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +30 -30
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +28 -28
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +26 -26
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +8 -8
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +21 -21
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +89 -89
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +8 -8
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +27 -27
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +28 -28
- package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +736 -736
- package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +64 -64
- package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +31 -31
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -15
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +305 -305
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +77 -77
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +248 -248
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +138 -138
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -10
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +100 -100
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +60 -60
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +179 -179
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -12
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -35
- package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -11
- package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +31 -31
- package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +37 -37
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -25
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +200 -200
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +43 -43
- package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +76 -76
- package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +227 -227
- package/resources/jsbuilder/JS_AST/query/find_object_keys.js +404 -404
- package/resources/jsbuilder/JS_AST/query/node_queries.js +8 -8
- package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +11 -11
- package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +85 -85
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +123 -123
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +87 -87
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +10 -10
- package/resources/jsbuilder/JS_Builder.js +10 -10
- package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +31 -31
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +25 -25
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +78 -78
- package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +17 -17
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +25 -25
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +8 -8
- package/resources/jsbuilder/JS_File/JS_File.js +12 -12
- package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -202
- package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -175
- package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -81
- package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -86
- package/resources/jsbuilder/JS_File/JS_File_4-Query.js +413 -413
- package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +414 -414
- package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -59
- package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -24
- package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -12
- package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +23 -23
- package/resources/jsbuilder/JS_File/JS_File_Import_References.js +31 -31
- package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -16
- package/resources/jsbuilder/JS_File/JS_Files.js +15 -15
- package/resources/jsbuilder/Module.js +14 -14
- package/resources/jsbuilder/Platform.js +13 -13
- package/resources/jsbuilder/Platforms.js +69 -69
- package/resources/jsbuilder/Project.js +109 -109
- package/resources/jsbuilder/Reference.js +1 -1
- package/resources/jsbuilder/Reference_Sequence.js +16 -16
- package/resources/jsbuilder/Scope.js +29 -29
- package/resources/jsbuilder/Variable_Name_Provider.js +42 -42
- package/resources/jsbuilder/_JS_File.js +225 -225
- package/resources/jsbuilder/ast_query.js +20 -20
- package/resources/jsbuilder/babel/babel_consts.js +162 -162
- package/resources/jsbuilder/babel/babel_node_tools.js +541 -541
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +923 -904
- package/resources/jsbuilder/build.js +16 -16
- package/resources/jsbuilder/platform_notes.md +66 -66
- package/resources/jsbuilder/test/test_ast_node.js +381 -381
- package/resources/jsbuilder/test/test_js_file.js +303 -303
- package/resources/jsbuilder/test/test_project.js +157 -157
- package/resources/local-server-info-resource.js +96 -96
- package/resources/notes.txt +10 -10
- package/resources/old/website-image-resource.js +1185 -1185
- package/resources/process-js.js +498 -498
- package/resources/processors/bundlers/bundle.js +29 -29
- package/resources/processors/bundlers/bundler.js +23 -23
- package/resources/processors/bundlers/css-bundler.js +234 -234
- package/resources/processors/bundlers/js/JS_Bundler.js +51 -51
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +388 -391
- package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +8 -8
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +188 -188
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -192
- package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +239 -239
- package/resources/processors/bundlers/js-bundler.js +263 -263
- package/resources/processors/bundlers/test_ast.js +73 -73
- package/resources/processors/bundlers/webpage-bundler.js +404 -404
- package/resources/processors/bundlers/website-bundler.js +22 -22
- package/resources/processors/extractors/Extractor.js +9 -11
- package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -254
- package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +3 -3
- package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +93 -93
- package/resources/server-installed-tools.js +28 -28
- package/resources/server-resource-pool.js +41 -41
- package/resources/website-audio-resource.js +735 -735
- package/resources/website-css-resource.js +411 -411
- package/resources/website-image-resource.js +412 -412
- package/resources/website-javascript-resource-processor.js +908 -908
- package/resources/website-javascript-resource.js +874 -874
- package/resources/website-resource-processor.js +10 -10
- package/resources/website-resource.js +164 -164
- package/resources/website-static-html-resource.js +199 -199
- package/resources/website-template-html-resource.js +231 -231
- package/roadmap.md +75 -75
- package/server.js +609 -573
- package/static-page-context.js +13 -13
- package/website/webpage.js +81 -81
- package/website/website-group.js +15 -15
- package/website/website.js +260 -260
- package/examples/controls/11d) window, shared model mirrored integer text fields/both.js +0 -17
- package/examples/controls/13) window, shared model mirrored lat_long/client.js +0 -933
- package/examples/controls/13) window, shared model mirrored lat_long/server.js +0 -50
- package/examples/controls/14) window, control compositional model/client.js +0 -328
- package/examples/controls/14) window, control compositional model/server.js +0 -118
- package/examples/controls/14a) window, control spec has compositional model/client.js +0 -440
- package/examples/controls/14a) window, control spec has compositional model/server.js +0 -118
- package/examples/controls/15) window, text field/client.js +0 -256
- package/examples/controls/16) Window([Text_Input])/client.js +0 -266
- package/examples/controls/16) Window([Text_Input])/server.js +0 -109
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/client.js +0 -494
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/isomorphic.js +0 -24
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/server.js +0 -73
- package/examples/controls/2b) two window, context menus/client.js +0 -193
- package/examples/controls/2b) two window, context menus/server.js +0 -114
- package/examples/controls/4a) window, tabbed panel with various controls inside/client.js +0 -233
- package/examples/controls/4a) window, tabbed panel with various controls inside/server.js +0 -118
|
@@ -1,737 +1,737 @@
|
|
|
1
|
-
//const babel_node_tools = require('../babel/babel_node_tools');
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
const JS_AST_Node_Type_Variable_Declarator = require('./JS_AST_Node_6.3-Type_Variable_Declarator');
|
|
5
|
-
|
|
6
|
-
const enable_array_as_queryable = require('./query/enable_array_as_queryable');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const create_query_execution_fn = (node, words) => {
|
|
10
|
-
//console.log('words', words);
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
deep_iterate,
|
|
14
|
-
each_child_node, filter_each_child_node,
|
|
15
|
-
find_node, filter_deep_iterate, filter_inner_deep_iterate, filter_child_nodes_by_type,
|
|
16
|
-
select_all, select_child, select_inner,
|
|
17
|
-
callmap_deep_iterate, signature_callmap_deep_iterate, callmap_child_nodes, signature_callmap_child_nodes
|
|
18
|
-
} = node;
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
this.select_all = select_all;
|
|
22
|
-
this.select_child = select_child;
|
|
23
|
-
this.select_inner = select_inner;
|
|
24
|
-
|
|
25
|
-
this.filter = filter;
|
|
26
|
-
this.filter_deep_iterate = filter_deep_iterate;
|
|
27
|
-
this.filter_inner_deep_iterate = filter_inner_deep_iterate;
|
|
28
|
-
this.filter_each_child_node = filter_each_child_node;
|
|
29
|
-
this.filter_child_nodes_by_type = filter_child_nodes_by_type;
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
// find_child_identifier
|
|
33
|
-
// Looks like more work is needed on the 'find' part of the .query system.
|
|
34
|
-
|
|
35
|
-
// Does seem best to use some kind of OO parsing into a query object.
|
|
36
|
-
// That would then have the structure to support longer queries.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// filter child node by type
|
|
40
|
-
// then the execution function has a single type parameter.
|
|
41
|
-
|
|
42
|
-
// can have a variety of English sentences and match them up with the calls to do it.
|
|
43
|
-
// see that the Basic part makes the right functions to do many of these things.
|
|
44
|
-
|
|
45
|
-
const sentence = words.join(' ');
|
|
46
|
-
//console.log('sentence', sentence);
|
|
47
|
-
|
|
48
|
-
// each.child.declaration.with.name
|
|
49
|
-
// each.child.declaration.filter.by.name
|
|
50
|
-
|
|
51
|
-
// each_child_declarator
|
|
52
|
-
|
|
53
|
-
const each_child_declarator = (callback) => filter_each_child_node(node => node.category === 'Declarator', callback);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const each_child_variabledeclaration = callback => filter_each_child_node(node => node.type === 'VariableDeclaration', callback);
|
|
57
|
-
|
|
58
|
-
const each_child_declaration = (callback) => filter_each_child_node(node => node.is_declaration, callback);
|
|
59
|
-
const each_child_identifier = (callback) => filter_each_child_node(node => node.is_identifier, callback);
|
|
60
|
-
|
|
61
|
-
// each_child_identifier
|
|
62
|
-
|
|
63
|
-
const filter_each_child_node_by_signature = (signature, callback) => filter_each_child_node(node => node.signature === signature, callback);
|
|
64
|
-
const filter_each_child_node_by_type = (type, callback) => filter_each_child_node(node => node.type === type, callback);
|
|
65
|
-
|
|
66
|
-
// filter_each_child_variabledeclaration_node
|
|
67
|
-
|
|
68
|
-
const filter_each_child_variabledeclaration_node = (filterer, callback) => each_child_variabledeclaration(node => {
|
|
69
|
-
if (filterer(node)) callback(node);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const filter_each_child_node_by_category = (category, callback) => filter_each_child_node(node => node.category === category, callback);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const select_child_node_by_signature = (signature) => {
|
|
76
|
-
const res = [];
|
|
77
|
-
filter_each_child_node_by_signature(signature, node => res.push(node));
|
|
78
|
-
return res;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const select_child_node_by_type = (type) => {
|
|
82
|
-
const res = [];
|
|
83
|
-
filter_each_child_node_by_type(type, node => res.push(node));
|
|
84
|
-
enable_array_as_queryable(res);
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const select_child_node_by_category = (cateogry) => {
|
|
89
|
-
const res = [];
|
|
90
|
-
filter_each_child_node_by_category(cateogry, node => res.push(node));
|
|
91
|
-
enable_array_as_queryable(res);
|
|
92
|
-
return res;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// select_child_node_by_category
|
|
96
|
-
|
|
97
|
-
const find_child_node = finder => {
|
|
98
|
-
let res;
|
|
99
|
-
each_child_node((cn, path, depth, stop) => {
|
|
100
|
-
if (!res) if (finder(cn)) {
|
|
101
|
-
res = cn;
|
|
102
|
-
//stop();
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
return res;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const find_child_node_by_type = type => find_child_node(node => node.type === type);
|
|
109
|
-
const find_child_identifier = () => find_child_node_by_type('Identifier');
|
|
110
|
-
|
|
111
|
-
// collect child name
|
|
112
|
-
|
|
113
|
-
const collect_child_name = () => {
|
|
114
|
-
const res = [];
|
|
115
|
-
each_child_node(node => {
|
|
116
|
-
if (node.name !== undefined) res.push(node.name);
|
|
117
|
-
})
|
|
118
|
-
return res;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const find_node_by_type = type => find_node(node => node.type === type);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const select_by_type = type => select_all(node => node.type === type);
|
|
125
|
-
const select_by_type_abbreviation = t => select_all(node => node.t === t);
|
|
126
|
-
const select_by_category = category => select_all(node => node.category === category);
|
|
127
|
-
|
|
128
|
-
const select_by_first_child_first_child_name = name => {
|
|
129
|
-
return select_all(node => {
|
|
130
|
-
|
|
131
|
-
const cn1 = node.child_nodes[0];
|
|
132
|
-
let res = false;
|
|
133
|
-
|
|
134
|
-
if (cn1) {
|
|
135
|
-
const gcn1 = cn1.child_nodes[0];
|
|
136
|
-
if (gcn1) {
|
|
137
|
-
const nn = gcn1.name;
|
|
138
|
-
if (nn !== undefined) {
|
|
139
|
-
if (nn === name) res = true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return res;
|
|
144
|
-
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const collect_objectproperty_nodes = () => select_by_type('ObjectProperty');
|
|
150
|
-
const collect_identifier_nodes = () => select_by_type('Identifier');
|
|
151
|
-
const collect_pattern_nodes = () => select_by_category('Pattern');
|
|
152
|
-
const collect_expression_nodes = () => select_by_category('Expression');
|
|
153
|
-
const collect_property_nodes = () => select_by_category('Property');
|
|
154
|
-
// collect_property_nodes
|
|
155
|
-
|
|
156
|
-
const collect_child_identifier_nodes = () => select_child(node => node.is_identifier);
|
|
157
|
-
|
|
158
|
-
const collect_id_name = () => {
|
|
159
|
-
const res = [];
|
|
160
|
-
if (node.id) {
|
|
161
|
-
if (node.id.name !== undefined) res.push(node.id.name);
|
|
162
|
-
}
|
|
163
|
-
return res;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const collect_child_identifier_name = () => {
|
|
167
|
-
const res = [];
|
|
168
|
-
|
|
169
|
-
filter_each_child_node_by_type('Identifier', node => {
|
|
170
|
-
res.push(node.name);
|
|
171
|
-
})
|
|
172
|
-
return res;
|
|
173
|
-
}
|
|
174
|
-
const collect_child_node_signature = () => {
|
|
175
|
-
const res = [];
|
|
176
|
-
each_child_node(node => {
|
|
177
|
-
res.push(node.signature);
|
|
178
|
-
})
|
|
179
|
-
return res;
|
|
180
|
-
}
|
|
181
|
-
const count_identifier_nodes = () => {
|
|
182
|
-
let res = 0;
|
|
183
|
-
deep_iterate(node => {
|
|
184
|
-
if (node.is_identifier) res++;
|
|
185
|
-
})
|
|
186
|
-
return res;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const collect_declared_keys = () => {
|
|
190
|
-
const res = [];
|
|
191
|
-
if (node.is_declaration) {
|
|
192
|
-
each(node.declaration.declared.keys, k => res.push(k));
|
|
193
|
-
}
|
|
194
|
-
enable_array_as_queryable(res);
|
|
195
|
-
return res;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const collect_declaration_assigned_values = () => {
|
|
199
|
-
const res = [];
|
|
200
|
-
if (node.is_declaration) {
|
|
201
|
-
const vals = declaration.assigned.values;
|
|
202
|
-
each(vals, v => res.push(v));
|
|
203
|
-
}
|
|
204
|
-
return res;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const count_all_nodes = () => {
|
|
208
|
-
let res = 0;
|
|
209
|
-
deep_iterate(n => res++);
|
|
210
|
-
return res;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// signature_callmap_deep_iterate
|
|
214
|
-
|
|
215
|
-
if (sentence === 'callmap by signature' || sentence === 'callmap deep iterate by signature') {
|
|
216
|
-
// not so sure about the query results for callmap....
|
|
217
|
-
return (map_handlers, fn_default_handler) => {
|
|
218
|
-
signature_callmap_deep_iterate(map_handlers, fn_default_handler);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (sentence === 'callmap' || sentence === 'callmap deep iterate') {
|
|
223
|
-
// not so sure about the query results for callmap....
|
|
224
|
-
|
|
225
|
-
return (fntostring, map_handlers, fn_default_handler) => {
|
|
226
|
-
callmap_deep_iterate(fntostring, map_handlers, fn_default_handler);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (sentence === 'callmap child' || sentence === 'callmap child nodes') {
|
|
232
|
-
// not so sure about the query results for callmap....
|
|
233
|
-
|
|
234
|
-
return (fntostring, map_handlers, fn_default_handler) => {
|
|
235
|
-
callmap_child_nodes(fntostring, map_handlers, fn_default_handler);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (sentence === 'collect child node' || sentence === 'collect child') {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return () => {
|
|
245
|
-
const res = [];
|
|
246
|
-
each(node.child_nodes, cn => res.push(cn));
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
enable_array_as_queryable(res);
|
|
250
|
-
return res;
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
//throw 'NYI';
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (sentence === 'collect child type' || sentence === 'collect child node type') {
|
|
257
|
-
return () => {
|
|
258
|
-
const res = [];
|
|
259
|
-
each(node.child_nodes, cn => res.push(cn.type));
|
|
260
|
-
return res;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (sentence === 'collect child t' || sentence === 'collect child node t' ||
|
|
265
|
-
sentence === 'collect child abbreviated type' || sentence === 'collect child type abbreviation' ||
|
|
266
|
-
sentence === 'collect child node abbreviated type' || sentence === 'collect child node type abbreviation') {
|
|
267
|
-
return () => {
|
|
268
|
-
const res = [];
|
|
269
|
-
each(node.child_nodes, cn => res.push(cn.t));
|
|
270
|
-
return res;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (sentence === 'collect child category' || sentence === 'collect child node category') {
|
|
275
|
-
return () => {
|
|
276
|
-
const res = [];
|
|
277
|
-
each(node.child_nodes, cn => res.push(cn.category));
|
|
278
|
-
return res;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (sentence === 'collect child count' || sentence === 'collect child node count') {
|
|
282
|
-
return () => [node.child_nodes.length];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (sentence === 'collect first child node' || sentence === 'collect first child') {
|
|
286
|
-
return () => {
|
|
287
|
-
const res = [];
|
|
288
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
289
|
-
if (node.child_nodes[0]) res.push(node.child_nodes[0]);
|
|
290
|
-
enable_array_as_queryable(res);
|
|
291
|
-
return res;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (sentence === 'collect first child name' || sentence === 'collect first child node name') {
|
|
296
|
-
return () => {
|
|
297
|
-
const res = [];
|
|
298
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
299
|
-
if (node.child_nodes[0]) {
|
|
300
|
-
if (node.child_nodes[0].name) {
|
|
301
|
-
res.push(node.child_nodes[0].name);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
//enable_array_as_queryable(res);
|
|
305
|
-
return res;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// collect.child.value
|
|
310
|
-
|
|
311
|
-
if (sentence === 'collect child value' || sentence === 'collect child node value') {
|
|
312
|
-
return () => {
|
|
313
|
-
const res = [];
|
|
314
|
-
each(node.child_nodes, cn => {
|
|
315
|
-
const v = cn.value;
|
|
316
|
-
if (v !== undefined) {
|
|
317
|
-
res.push(v);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
//if (node.child_nodes[0]) res.push(node.child_nodes[0].value);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
//enable_array_as_queryable(res);
|
|
324
|
-
return res;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (sentence === 'collect first child first child' || sentence === 'collect first child node first child node') {
|
|
329
|
-
return () => {
|
|
330
|
-
const res = [];
|
|
331
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
332
|
-
if (node.child_nodes[0] && node.child_nodes[0].child_nodes[0]) {
|
|
333
|
-
res.push(node.child_nodes[0].child_nodes[0]);
|
|
334
|
-
}
|
|
335
|
-
//enable_array_as_queryable(res);
|
|
336
|
-
return res;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (sentence === 'collect first child first child name' || sentence === 'collect first child node first child name' || sentence === 'collect first child node first child node name') {
|
|
341
|
-
return () => {
|
|
342
|
-
const res = [];
|
|
343
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
344
|
-
if (node.child_nodes[0] && node.child_nodes[0].child_nodes[0]) {
|
|
345
|
-
const n = node.child_nodes[0].child_nodes[0].name;
|
|
346
|
-
if (n !== undefined) {
|
|
347
|
-
res.push(n);
|
|
348
|
-
}
|
|
349
|
-
//res.push(node.child_nodes[0].child_nodes[0]);
|
|
350
|
-
}
|
|
351
|
-
//enable_array_as_queryable(res);
|
|
352
|
-
return res;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (sentence === 'collect first child value' || sentence === 'collect first child node value') {
|
|
359
|
-
return () => {
|
|
360
|
-
const res = [];
|
|
361
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
362
|
-
if (node.child_nodes[0]) res.push(node.child_nodes[0].value);
|
|
363
|
-
//enable_array_as_queryable(res);
|
|
364
|
-
return res;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
if (sentence === 'collect second child node' || sentence === 'collect second child') {
|
|
368
|
-
return () => {
|
|
369
|
-
const res = [];
|
|
370
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
371
|
-
if (node.child_nodes[1]) res.push(node.child_nodes[1]);
|
|
372
|
-
enable_array_as_queryable(res);
|
|
373
|
-
return res;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (sentence === 'collect third child node' || sentence === 'collect third child') {
|
|
377
|
-
return () => {
|
|
378
|
-
const res = [];
|
|
379
|
-
//each(node.child_nodes, cn => res.push(cn));
|
|
380
|
-
if (node.child_nodes[2]) res.push(node.child_nodes[2]);
|
|
381
|
-
enable_array_as_queryable(res);
|
|
382
|
-
return res;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (sentence === 'collect child node name' || sentence === 'collect child name') {
|
|
387
|
-
return collect_child_name;
|
|
388
|
-
} else {
|
|
389
|
-
//throw 'NYI';
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// collect_child_identifier_nodes
|
|
393
|
-
|
|
394
|
-
if (sentence === 'collect identifier' || sentence === 'collect identifier node') {
|
|
395
|
-
return collect_identifier_nodes;
|
|
396
|
-
}
|
|
397
|
-
if (sentence === 'collect expression' || sentence === 'collect expression node') {
|
|
398
|
-
return collect_expression_nodes;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (sentence === 'collect objectproperty' || sentence === 'collect objectproperty node') {
|
|
402
|
-
return collect_objectproperty_nodes;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// collect_expression_nodes
|
|
406
|
-
|
|
407
|
-
// collect child signature.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (sentence === 'collect child signature' || sentence === 'collect child node signature' ||
|
|
412
|
-
sentence === 'collect each child signature' || sentence === 'collect each child node signature') {
|
|
413
|
-
return collect_child_node_signature;
|
|
414
|
-
} else {
|
|
415
|
-
//throw 'NYI';
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (sentence === 'collect child identifier' || sentence === 'collect child node identifier node') {
|
|
420
|
-
return collect_child_identifier_nodes;
|
|
421
|
-
} else {
|
|
422
|
-
//throw 'NYI';
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (sentence === 'collect child identifier name' || sentence === 'collect child node identifier name') {
|
|
426
|
-
return collect_child_identifier_name;
|
|
427
|
-
} else {
|
|
428
|
-
//throw 'NYI';
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (sentence === 'collect id name') {
|
|
432
|
-
return collect_id_name;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const collect_child_variable_declarators = () => {
|
|
436
|
-
return select_child_node_by_type('VariableDeclarator');
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const collect_child_variable_declarations = () => select_child_node_by_type('VariableDeclaration');
|
|
440
|
-
|
|
441
|
-
// collect_child_variable_declarations
|
|
442
|
-
const collect_child_literal = () => {
|
|
443
|
-
return select_child_node_by_category('Literal');
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// collect.child.variabledeclaration
|
|
447
|
-
|
|
448
|
-
if (sentence === 'collect child variabledeclaration') {
|
|
449
|
-
return collect_child_variable_declarations;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (sentence === 'collect child variabledeclarator') {
|
|
453
|
-
return collect_child_variable_declarators;
|
|
454
|
-
}
|
|
455
|
-
if (sentence === 'collect child literal') {
|
|
456
|
-
return collect_child_literal;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// or just key with all nouns being singular despite operating on plurals?
|
|
460
|
-
if (sentence === 'collect own declared key' || sentence === 'collect own declaration declared key' ||
|
|
461
|
-
sentence === 'collect own declared keys' || sentence === 'collect own declaration declared keys') {
|
|
462
|
-
return collect_declared_keys;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (sentence === 'collect own declaration assigned values' || sentence === 'collect own declaration assigned values') {
|
|
466
|
-
return collect_declaration_assigned_values;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// .query.collect.own.declaration.assigned.value
|
|
470
|
-
|
|
471
|
-
// collect.child.variabledeclarator
|
|
472
|
-
|
|
473
|
-
if (sentence === 'collect name') {
|
|
474
|
-
return () => [node.name];
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (sentence === 'collect pattern' || sentence === 'collect pattern node' || sentence === 'collect node with category pattern') {
|
|
479
|
-
return collect_pattern_nodes;
|
|
480
|
-
}
|
|
481
|
-
if (sentence === 'collect property' || sentence === 'collect property node' || sentence === 'collect node with category property') {
|
|
482
|
-
return collect_property_nodes;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
if (sentence === 'count child node' || sentence === 'count child' || sentence === 'child count' || sentence === 'child node count') {
|
|
486
|
-
return () => node.child_nodes.length;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
if (sentence === 'count all' || sentence === 'count all node') {
|
|
490
|
-
return count_all_nodes;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (sentence === 'count identifier node' || sentence === 'count identifier' || sentence === 'identifier count' || sentence === 'identifier node count') {
|
|
495
|
-
return count_identifier_nodes;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
// counts...
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (sentence === 'filter child node' || sentence === 'filter each child' || sentence === 'filter each child node') {
|
|
502
|
-
return filter_each_child_node;
|
|
503
|
-
} else {
|
|
504
|
-
//throw 'NYI';
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (sentence === 'filter child variabledeclaration' || sentence === 'filter each child variabledeclaration' || sentence === 'filter each child variabledeclaration node') {
|
|
508
|
-
return filter_each_child_variabledeclaration_node;
|
|
509
|
-
} else {
|
|
510
|
-
//throw 'NYI';
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (sentence === 'filter child node by signature' || sentence === 'filter each child by signature' || sentence === 'filter each child node by signature') {
|
|
514
|
-
return filter_each_child_node_by_signature;
|
|
515
|
-
} else {
|
|
516
|
-
//throw 'NYI';
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
if (sentence === 'filter child node by type' || sentence === 'filter each child by type' || sentence === 'filter each child node by type') {
|
|
520
|
-
return filter_each_child_node_by_type;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// filter child node by child count || filter child nodes by their child counts
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
// filter.child.by.type
|
|
528
|
-
|
|
529
|
-
if (sentence === 'each child node' || sentence === 'each child') {
|
|
530
|
-
return each_child_node;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// each.child.declarator
|
|
534
|
-
|
|
535
|
-
// Declarator
|
|
536
|
-
|
|
537
|
-
// each.child.variabledeclaration
|
|
538
|
-
|
|
539
|
-
if (sentence === 'each child declarator node' || sentence === 'each child declarator') {
|
|
540
|
-
return each_child_declarator;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (sentence === 'each child variabledeclaration node' || sentence === 'each child variabledeclaration') {
|
|
544
|
-
return each_child_variabledeclaration;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (sentence === 'each child declaration node' || sentence === 'each child declaration') {
|
|
548
|
-
return each_child_declaration;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
if (sentence === 'each child identifier node' || sentence === 'each child identifier') {
|
|
552
|
-
return each_child_identifier;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// parse it to the nth child general case....
|
|
556
|
-
if (sentence === 'first child node' || sentence === 'first child') {
|
|
557
|
-
return () => node.child_nodes[0];
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
if (sentence === 'find node' || sentence === 'find') {
|
|
561
|
-
return find_node;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
if (sentence === 'find child identifier' || sentence === 'find a childnode which is an identifier too') {
|
|
566
|
-
return find_child_identifier;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// find.by.type
|
|
570
|
-
|
|
571
|
-
// find_node_by_type
|
|
572
|
-
|
|
573
|
-
if (sentence === 'find node by type' || sentence === 'find by type') {
|
|
574
|
-
return find_node_by_type;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
// filter_deep_iterate
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (sentence === 'filter node' || sentence === 'filter' || sentence === 'filter all node' || sentence === 'deep filter') {
|
|
584
|
-
return filter_deep_iterate;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// filter.child.by.type
|
|
588
|
-
|
|
589
|
-
// filter_inner_deep_iterate
|
|
590
|
-
|
|
591
|
-
if (sentence === 'filter inner node' || sentence === 'filter inner' || sentence === 'inner filter' || sentence === 'filter inner node' || sentence === 'deep inner filter') {
|
|
592
|
-
return filter_inner_deep_iterate;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (sentence === 'second child node' || sentence === 'second child') {
|
|
597
|
-
return () => node.child_nodes[1];
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
if (sentence === 'name' || sentence === 'node name') {
|
|
601
|
-
return () => node.name;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// select_child
|
|
605
|
-
|
|
606
|
-
if (sentence === 'select by type') {
|
|
607
|
-
return select_by_type;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (sentence === 'select by t' || sentence === 'select by type abbreviation' || sentence === 'select by abbreviated type') {
|
|
611
|
-
return select_by_type_abbreviation;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// select_by_type_abbreviation
|
|
615
|
-
|
|
616
|
-
if (sentence === 'select child node' || sentence === 'select child') {
|
|
617
|
-
return select_child;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
if (sentence === 'select child node by signature' || sentence === 'select child by signature') {
|
|
621
|
-
return select_child_node_by_signature;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (sentence === 'select by category' || sentence === 'select node by category') {
|
|
625
|
-
return select_by_category;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// select node by first child first child name
|
|
629
|
-
|
|
630
|
-
if (sentence === 'select by first child first child name' || sentence === 'select node by first child first child name') {
|
|
631
|
-
return select_by_first_child_first_child_name;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
// select_each_child_node_by_signature
|
|
637
|
-
|
|
638
|
-
// .select.child.by.signature
|
|
639
|
-
|
|
640
|
-
// first child identifier
|
|
641
|
-
|
|
642
|
-
// each child identifier
|
|
643
|
-
// each child declaration
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
//
|
|
653
|
-
|
|
654
|
-
const create_query = (node, words = []) => {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const res = {
|
|
659
|
-
//message1: "hello",
|
|
660
|
-
//message2: "everyone"
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
const handler2 = {
|
|
664
|
-
get: function(target, prop, receiver) {
|
|
665
|
-
|
|
666
|
-
//console.log('target', target);
|
|
667
|
-
//console.log('prop', prop);
|
|
668
|
-
//console.log('receiver', receiver);
|
|
669
|
-
|
|
670
|
-
//console.log('target === res', target === res);
|
|
671
|
-
|
|
672
|
-
if (target === res) {
|
|
673
|
-
|
|
674
|
-
if (prop === 'exe') {
|
|
675
|
-
|
|
676
|
-
//throw 'stop';
|
|
677
|
-
|
|
678
|
-
return create_query_execution_fn(node, words);
|
|
679
|
-
|
|
680
|
-
//throw 'NYI'
|
|
681
|
-
|
|
682
|
-
// return the execution function.
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
} else if (prop === 'qstring') {
|
|
687
|
-
return words.join('.');
|
|
688
|
-
} else {
|
|
689
|
-
words.push(prop);
|
|
690
|
-
return create_query(node, words);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
} else {
|
|
694
|
-
throw 'stop';
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
//throw 'NYI';
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
const proxy2 = new Proxy(res, handler2);
|
|
704
|
-
|
|
705
|
-
return proxy2;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
class JS_AST_Node_Query extends JS_AST_Node_Type_Variable_Declarator {
|
|
710
|
-
constructor(spec = {}) {
|
|
711
|
-
super(spec);
|
|
712
|
-
|
|
713
|
-
// query property.
|
|
714
|
-
|
|
715
|
-
// but each time provide a new query object.
|
|
716
|
-
|
|
717
|
-
//let query;
|
|
718
|
-
Object.defineProperty(this, 'query', {
|
|
719
|
-
get() {
|
|
720
|
-
return create_query(this);
|
|
721
|
-
},
|
|
722
|
-
enumerable: true,
|
|
723
|
-
configurable: false
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
this.query_with_words = arr_words => {
|
|
728
|
-
const q = create_query(this, arr_words);
|
|
729
|
-
return q;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
1
|
+
//const babel_node_tools = require('../babel/babel_node_tools');
|
|
2
|
+
|
|
3
|
+
//
|
|
4
|
+
const JS_AST_Node_Type_Variable_Declarator = require('./JS_AST_Node_6.3-Type_Variable_Declarator');
|
|
5
|
+
|
|
6
|
+
const enable_array_as_queryable = require('./query/enable_array_as_queryable');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const create_query_execution_fn = (node, words) => {
|
|
10
|
+
//console.log('words', words);
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
deep_iterate,
|
|
14
|
+
each_child_node, filter_each_child_node,
|
|
15
|
+
find_node, filter_deep_iterate, filter_inner_deep_iterate, filter_child_nodes_by_type,
|
|
16
|
+
select_all, select_child, select_inner,
|
|
17
|
+
callmap_deep_iterate, signature_callmap_deep_iterate, callmap_child_nodes, signature_callmap_child_nodes
|
|
18
|
+
} = node;
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
this.select_all = select_all;
|
|
22
|
+
this.select_child = select_child;
|
|
23
|
+
this.select_inner = select_inner;
|
|
24
|
+
|
|
25
|
+
this.filter = filter;
|
|
26
|
+
this.filter_deep_iterate = filter_deep_iterate;
|
|
27
|
+
this.filter_inner_deep_iterate = filter_inner_deep_iterate;
|
|
28
|
+
this.filter_each_child_node = filter_each_child_node;
|
|
29
|
+
this.filter_child_nodes_by_type = filter_child_nodes_by_type;
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// find_child_identifier
|
|
33
|
+
// Looks like more work is needed on the 'find' part of the .query system.
|
|
34
|
+
|
|
35
|
+
// Does seem best to use some kind of OO parsing into a query object.
|
|
36
|
+
// That would then have the structure to support longer queries.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// filter child node by type
|
|
40
|
+
// then the execution function has a single type parameter.
|
|
41
|
+
|
|
42
|
+
// can have a variety of English sentences and match them up with the calls to do it.
|
|
43
|
+
// see that the Basic part makes the right functions to do many of these things.
|
|
44
|
+
|
|
45
|
+
const sentence = words.join(' ');
|
|
46
|
+
//console.log('sentence', sentence);
|
|
47
|
+
|
|
48
|
+
// each.child.declaration.with.name
|
|
49
|
+
// each.child.declaration.filter.by.name
|
|
50
|
+
|
|
51
|
+
// each_child_declarator
|
|
52
|
+
|
|
53
|
+
const each_child_declarator = (callback) => filter_each_child_node(node => node.category === 'Declarator', callback);
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const each_child_variabledeclaration = callback => filter_each_child_node(node => node.type === 'VariableDeclaration', callback);
|
|
57
|
+
|
|
58
|
+
const each_child_declaration = (callback) => filter_each_child_node(node => node.is_declaration, callback);
|
|
59
|
+
const each_child_identifier = (callback) => filter_each_child_node(node => node.is_identifier, callback);
|
|
60
|
+
|
|
61
|
+
// each_child_identifier
|
|
62
|
+
|
|
63
|
+
const filter_each_child_node_by_signature = (signature, callback) => filter_each_child_node(node => node.signature === signature, callback);
|
|
64
|
+
const filter_each_child_node_by_type = (type, callback) => filter_each_child_node(node => node.type === type, callback);
|
|
65
|
+
|
|
66
|
+
// filter_each_child_variabledeclaration_node
|
|
67
|
+
|
|
68
|
+
const filter_each_child_variabledeclaration_node = (filterer, callback) => each_child_variabledeclaration(node => {
|
|
69
|
+
if (filterer(node)) callback(node);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const filter_each_child_node_by_category = (category, callback) => filter_each_child_node(node => node.category === category, callback);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const select_child_node_by_signature = (signature) => {
|
|
76
|
+
const res = [];
|
|
77
|
+
filter_each_child_node_by_signature(signature, node => res.push(node));
|
|
78
|
+
return res;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const select_child_node_by_type = (type) => {
|
|
82
|
+
const res = [];
|
|
83
|
+
filter_each_child_node_by_type(type, node => res.push(node));
|
|
84
|
+
enable_array_as_queryable(res);
|
|
85
|
+
return res;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const select_child_node_by_category = (cateogry) => {
|
|
89
|
+
const res = [];
|
|
90
|
+
filter_each_child_node_by_category(cateogry, node => res.push(node));
|
|
91
|
+
enable_array_as_queryable(res);
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// select_child_node_by_category
|
|
96
|
+
|
|
97
|
+
const find_child_node = finder => {
|
|
98
|
+
let res;
|
|
99
|
+
each_child_node((cn, path, depth, stop) => {
|
|
100
|
+
if (!res) if (finder(cn)) {
|
|
101
|
+
res = cn;
|
|
102
|
+
//stop();
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
return res;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const find_child_node_by_type = type => find_child_node(node => node.type === type);
|
|
109
|
+
const find_child_identifier = () => find_child_node_by_type('Identifier');
|
|
110
|
+
|
|
111
|
+
// collect child name
|
|
112
|
+
|
|
113
|
+
const collect_child_name = () => {
|
|
114
|
+
const res = [];
|
|
115
|
+
each_child_node(node => {
|
|
116
|
+
if (node.name !== undefined) res.push(node.name);
|
|
117
|
+
})
|
|
118
|
+
return res;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const find_node_by_type = type => find_node(node => node.type === type);
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
const select_by_type = type => select_all(node => node.type === type);
|
|
125
|
+
const select_by_type_abbreviation = t => select_all(node => node.t === t);
|
|
126
|
+
const select_by_category = category => select_all(node => node.category === category);
|
|
127
|
+
|
|
128
|
+
const select_by_first_child_first_child_name = name => {
|
|
129
|
+
return select_all(node => {
|
|
130
|
+
|
|
131
|
+
const cn1 = node.child_nodes[0];
|
|
132
|
+
let res = false;
|
|
133
|
+
|
|
134
|
+
if (cn1) {
|
|
135
|
+
const gcn1 = cn1.child_nodes[0];
|
|
136
|
+
if (gcn1) {
|
|
137
|
+
const nn = gcn1.name;
|
|
138
|
+
if (nn !== undefined) {
|
|
139
|
+
if (nn === name) res = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
const collect_objectproperty_nodes = () => select_by_type('ObjectProperty');
|
|
150
|
+
const collect_identifier_nodes = () => select_by_type('Identifier');
|
|
151
|
+
const collect_pattern_nodes = () => select_by_category('Pattern');
|
|
152
|
+
const collect_expression_nodes = () => select_by_category('Expression');
|
|
153
|
+
const collect_property_nodes = () => select_by_category('Property');
|
|
154
|
+
// collect_property_nodes
|
|
155
|
+
|
|
156
|
+
const collect_child_identifier_nodes = () => select_child(node => node.is_identifier);
|
|
157
|
+
|
|
158
|
+
const collect_id_name = () => {
|
|
159
|
+
const res = [];
|
|
160
|
+
if (node.id) {
|
|
161
|
+
if (node.id.name !== undefined) res.push(node.id.name);
|
|
162
|
+
}
|
|
163
|
+
return res;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const collect_child_identifier_name = () => {
|
|
167
|
+
const res = [];
|
|
168
|
+
|
|
169
|
+
filter_each_child_node_by_type('Identifier', node => {
|
|
170
|
+
res.push(node.name);
|
|
171
|
+
})
|
|
172
|
+
return res;
|
|
173
|
+
}
|
|
174
|
+
const collect_child_node_signature = () => {
|
|
175
|
+
const res = [];
|
|
176
|
+
each_child_node(node => {
|
|
177
|
+
res.push(node.signature);
|
|
178
|
+
})
|
|
179
|
+
return res;
|
|
180
|
+
}
|
|
181
|
+
const count_identifier_nodes = () => {
|
|
182
|
+
let res = 0;
|
|
183
|
+
deep_iterate(node => {
|
|
184
|
+
if (node.is_identifier) res++;
|
|
185
|
+
})
|
|
186
|
+
return res;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const collect_declared_keys = () => {
|
|
190
|
+
const res = [];
|
|
191
|
+
if (node.is_declaration) {
|
|
192
|
+
each(node.declaration.declared.keys, k => res.push(k));
|
|
193
|
+
}
|
|
194
|
+
enable_array_as_queryable(res);
|
|
195
|
+
return res;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const collect_declaration_assigned_values = () => {
|
|
199
|
+
const res = [];
|
|
200
|
+
if (node.is_declaration) {
|
|
201
|
+
const vals = declaration.assigned.values;
|
|
202
|
+
each(vals, v => res.push(v));
|
|
203
|
+
}
|
|
204
|
+
return res;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const count_all_nodes = () => {
|
|
208
|
+
let res = 0;
|
|
209
|
+
deep_iterate(n => res++);
|
|
210
|
+
return res;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// signature_callmap_deep_iterate
|
|
214
|
+
|
|
215
|
+
if (sentence === 'callmap by signature' || sentence === 'callmap deep iterate by signature') {
|
|
216
|
+
// not so sure about the query results for callmap....
|
|
217
|
+
return (map_handlers, fn_default_handler) => {
|
|
218
|
+
signature_callmap_deep_iterate(map_handlers, fn_default_handler);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (sentence === 'callmap' || sentence === 'callmap deep iterate') {
|
|
223
|
+
// not so sure about the query results for callmap....
|
|
224
|
+
|
|
225
|
+
return (fntostring, map_handlers, fn_default_handler) => {
|
|
226
|
+
callmap_deep_iterate(fntostring, map_handlers, fn_default_handler);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (sentence === 'callmap child' || sentence === 'callmap child nodes') {
|
|
232
|
+
// not so sure about the query results for callmap....
|
|
233
|
+
|
|
234
|
+
return (fntostring, map_handlers, fn_default_handler) => {
|
|
235
|
+
callmap_child_nodes(fntostring, map_handlers, fn_default_handler);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (sentence === 'collect child node' || sentence === 'collect child') {
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
return () => {
|
|
245
|
+
const res = [];
|
|
246
|
+
each(node.child_nodes, cn => res.push(cn));
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
enable_array_as_queryable(res);
|
|
250
|
+
return res;
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
//throw 'NYI';
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (sentence === 'collect child type' || sentence === 'collect child node type') {
|
|
257
|
+
return () => {
|
|
258
|
+
const res = [];
|
|
259
|
+
each(node.child_nodes, cn => res.push(cn.type));
|
|
260
|
+
return res;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (sentence === 'collect child t' || sentence === 'collect child node t' ||
|
|
265
|
+
sentence === 'collect child abbreviated type' || sentence === 'collect child type abbreviation' ||
|
|
266
|
+
sentence === 'collect child node abbreviated type' || sentence === 'collect child node type abbreviation') {
|
|
267
|
+
return () => {
|
|
268
|
+
const res = [];
|
|
269
|
+
each(node.child_nodes, cn => res.push(cn.t));
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (sentence === 'collect child category' || sentence === 'collect child node category') {
|
|
275
|
+
return () => {
|
|
276
|
+
const res = [];
|
|
277
|
+
each(node.child_nodes, cn => res.push(cn.category));
|
|
278
|
+
return res;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (sentence === 'collect child count' || sentence === 'collect child node count') {
|
|
282
|
+
return () => [node.child_nodes.length];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (sentence === 'collect first child node' || sentence === 'collect first child') {
|
|
286
|
+
return () => {
|
|
287
|
+
const res = [];
|
|
288
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
289
|
+
if (node.child_nodes[0]) res.push(node.child_nodes[0]);
|
|
290
|
+
enable_array_as_queryable(res);
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (sentence === 'collect first child name' || sentence === 'collect first child node name') {
|
|
296
|
+
return () => {
|
|
297
|
+
const res = [];
|
|
298
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
299
|
+
if (node.child_nodes[0]) {
|
|
300
|
+
if (node.child_nodes[0].name) {
|
|
301
|
+
res.push(node.child_nodes[0].name);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
//enable_array_as_queryable(res);
|
|
305
|
+
return res;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// collect.child.value
|
|
310
|
+
|
|
311
|
+
if (sentence === 'collect child value' || sentence === 'collect child node value') {
|
|
312
|
+
return () => {
|
|
313
|
+
const res = [];
|
|
314
|
+
each(node.child_nodes, cn => {
|
|
315
|
+
const v = cn.value;
|
|
316
|
+
if (v !== undefined) {
|
|
317
|
+
res.push(v);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
//if (node.child_nodes[0]) res.push(node.child_nodes[0].value);
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
//enable_array_as_queryable(res);
|
|
324
|
+
return res;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (sentence === 'collect first child first child' || sentence === 'collect first child node first child node') {
|
|
329
|
+
return () => {
|
|
330
|
+
const res = [];
|
|
331
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
332
|
+
if (node.child_nodes[0] && node.child_nodes[0].child_nodes[0]) {
|
|
333
|
+
res.push(node.child_nodes[0].child_nodes[0]);
|
|
334
|
+
}
|
|
335
|
+
//enable_array_as_queryable(res);
|
|
336
|
+
return res;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (sentence === 'collect first child first child name' || sentence === 'collect first child node first child name' || sentence === 'collect first child node first child node name') {
|
|
341
|
+
return () => {
|
|
342
|
+
const res = [];
|
|
343
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
344
|
+
if (node.child_nodes[0] && node.child_nodes[0].child_nodes[0]) {
|
|
345
|
+
const n = node.child_nodes[0].child_nodes[0].name;
|
|
346
|
+
if (n !== undefined) {
|
|
347
|
+
res.push(n);
|
|
348
|
+
}
|
|
349
|
+
//res.push(node.child_nodes[0].child_nodes[0]);
|
|
350
|
+
}
|
|
351
|
+
//enable_array_as_queryable(res);
|
|
352
|
+
return res;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
if (sentence === 'collect first child value' || sentence === 'collect first child node value') {
|
|
359
|
+
return () => {
|
|
360
|
+
const res = [];
|
|
361
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
362
|
+
if (node.child_nodes[0]) res.push(node.child_nodes[0].value);
|
|
363
|
+
//enable_array_as_queryable(res);
|
|
364
|
+
return res;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (sentence === 'collect second child node' || sentence === 'collect second child') {
|
|
368
|
+
return () => {
|
|
369
|
+
const res = [];
|
|
370
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
371
|
+
if (node.child_nodes[1]) res.push(node.child_nodes[1]);
|
|
372
|
+
enable_array_as_queryable(res);
|
|
373
|
+
return res;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (sentence === 'collect third child node' || sentence === 'collect third child') {
|
|
377
|
+
return () => {
|
|
378
|
+
const res = [];
|
|
379
|
+
//each(node.child_nodes, cn => res.push(cn));
|
|
380
|
+
if (node.child_nodes[2]) res.push(node.child_nodes[2]);
|
|
381
|
+
enable_array_as_queryable(res);
|
|
382
|
+
return res;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (sentence === 'collect child node name' || sentence === 'collect child name') {
|
|
387
|
+
return collect_child_name;
|
|
388
|
+
} else {
|
|
389
|
+
//throw 'NYI';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// collect_child_identifier_nodes
|
|
393
|
+
|
|
394
|
+
if (sentence === 'collect identifier' || sentence === 'collect identifier node') {
|
|
395
|
+
return collect_identifier_nodes;
|
|
396
|
+
}
|
|
397
|
+
if (sentence === 'collect expression' || sentence === 'collect expression node') {
|
|
398
|
+
return collect_expression_nodes;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (sentence === 'collect objectproperty' || sentence === 'collect objectproperty node') {
|
|
402
|
+
return collect_objectproperty_nodes;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// collect_expression_nodes
|
|
406
|
+
|
|
407
|
+
// collect child signature.
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
if (sentence === 'collect child signature' || sentence === 'collect child node signature' ||
|
|
412
|
+
sentence === 'collect each child signature' || sentence === 'collect each child node signature') {
|
|
413
|
+
return collect_child_node_signature;
|
|
414
|
+
} else {
|
|
415
|
+
//throw 'NYI';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
if (sentence === 'collect child identifier' || sentence === 'collect child node identifier node') {
|
|
420
|
+
return collect_child_identifier_nodes;
|
|
421
|
+
} else {
|
|
422
|
+
//throw 'NYI';
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (sentence === 'collect child identifier name' || sentence === 'collect child node identifier name') {
|
|
426
|
+
return collect_child_identifier_name;
|
|
427
|
+
} else {
|
|
428
|
+
//throw 'NYI';
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (sentence === 'collect id name') {
|
|
432
|
+
return collect_id_name;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const collect_child_variable_declarators = () => {
|
|
436
|
+
return select_child_node_by_type('VariableDeclarator');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const collect_child_variable_declarations = () => select_child_node_by_type('VariableDeclaration');
|
|
440
|
+
|
|
441
|
+
// collect_child_variable_declarations
|
|
442
|
+
const collect_child_literal = () => {
|
|
443
|
+
return select_child_node_by_category('Literal');
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// collect.child.variabledeclaration
|
|
447
|
+
|
|
448
|
+
if (sentence === 'collect child variabledeclaration') {
|
|
449
|
+
return collect_child_variable_declarations;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (sentence === 'collect child variabledeclarator') {
|
|
453
|
+
return collect_child_variable_declarators;
|
|
454
|
+
}
|
|
455
|
+
if (sentence === 'collect child literal') {
|
|
456
|
+
return collect_child_literal;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// or just key with all nouns being singular despite operating on plurals?
|
|
460
|
+
if (sentence === 'collect own declared key' || sentence === 'collect own declaration declared key' ||
|
|
461
|
+
sentence === 'collect own declared keys' || sentence === 'collect own declaration declared keys') {
|
|
462
|
+
return collect_declared_keys;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (sentence === 'collect own declaration assigned values' || sentence === 'collect own declaration assigned values') {
|
|
466
|
+
return collect_declaration_assigned_values;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// .query.collect.own.declaration.assigned.value
|
|
470
|
+
|
|
471
|
+
// collect.child.variabledeclarator
|
|
472
|
+
|
|
473
|
+
if (sentence === 'collect name') {
|
|
474
|
+
return () => [node.name];
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
if (sentence === 'collect pattern' || sentence === 'collect pattern node' || sentence === 'collect node with category pattern') {
|
|
479
|
+
return collect_pattern_nodes;
|
|
480
|
+
}
|
|
481
|
+
if (sentence === 'collect property' || sentence === 'collect property node' || sentence === 'collect node with category property') {
|
|
482
|
+
return collect_property_nodes;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (sentence === 'count child node' || sentence === 'count child' || sentence === 'child count' || sentence === 'child node count') {
|
|
486
|
+
return () => node.child_nodes.length;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (sentence === 'count all' || sentence === 'count all node') {
|
|
490
|
+
return count_all_nodes;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
if (sentence === 'count identifier node' || sentence === 'count identifier' || sentence === 'identifier count' || sentence === 'identifier node count') {
|
|
495
|
+
return count_identifier_nodes;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// counts...
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
if (sentence === 'filter child node' || sentence === 'filter each child' || sentence === 'filter each child node') {
|
|
502
|
+
return filter_each_child_node;
|
|
503
|
+
} else {
|
|
504
|
+
//throw 'NYI';
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (sentence === 'filter child variabledeclaration' || sentence === 'filter each child variabledeclaration' || sentence === 'filter each child variabledeclaration node') {
|
|
508
|
+
return filter_each_child_variabledeclaration_node;
|
|
509
|
+
} else {
|
|
510
|
+
//throw 'NYI';
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (sentence === 'filter child node by signature' || sentence === 'filter each child by signature' || sentence === 'filter each child node by signature') {
|
|
514
|
+
return filter_each_child_node_by_signature;
|
|
515
|
+
} else {
|
|
516
|
+
//throw 'NYI';
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (sentence === 'filter child node by type' || sentence === 'filter each child by type' || sentence === 'filter each child node by type') {
|
|
520
|
+
return filter_each_child_node_by_type;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// filter child node by child count || filter child nodes by their child counts
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
// filter.child.by.type
|
|
528
|
+
|
|
529
|
+
if (sentence === 'each child node' || sentence === 'each child') {
|
|
530
|
+
return each_child_node;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// each.child.declarator
|
|
534
|
+
|
|
535
|
+
// Declarator
|
|
536
|
+
|
|
537
|
+
// each.child.variabledeclaration
|
|
538
|
+
|
|
539
|
+
if (sentence === 'each child declarator node' || sentence === 'each child declarator') {
|
|
540
|
+
return each_child_declarator;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (sentence === 'each child variabledeclaration node' || sentence === 'each child variabledeclaration') {
|
|
544
|
+
return each_child_variabledeclaration;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (sentence === 'each child declaration node' || sentence === 'each child declaration') {
|
|
548
|
+
return each_child_declaration;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (sentence === 'each child identifier node' || sentence === 'each child identifier') {
|
|
552
|
+
return each_child_identifier;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// parse it to the nth child general case....
|
|
556
|
+
if (sentence === 'first child node' || sentence === 'first child') {
|
|
557
|
+
return () => node.child_nodes[0];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (sentence === 'find node' || sentence === 'find') {
|
|
561
|
+
return find_node;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
if (sentence === 'find child identifier' || sentence === 'find a childnode which is an identifier too') {
|
|
566
|
+
return find_child_identifier;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// find.by.type
|
|
570
|
+
|
|
571
|
+
// find_node_by_type
|
|
572
|
+
|
|
573
|
+
if (sentence === 'find node by type' || sentence === 'find by type') {
|
|
574
|
+
return find_node_by_type;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
// filter_deep_iterate
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
if (sentence === 'filter node' || sentence === 'filter' || sentence === 'filter all node' || sentence === 'deep filter') {
|
|
584
|
+
return filter_deep_iterate;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// filter.child.by.type
|
|
588
|
+
|
|
589
|
+
// filter_inner_deep_iterate
|
|
590
|
+
|
|
591
|
+
if (sentence === 'filter inner node' || sentence === 'filter inner' || sentence === 'inner filter' || sentence === 'filter inner node' || sentence === 'deep inner filter') {
|
|
592
|
+
return filter_inner_deep_iterate;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
if (sentence === 'second child node' || sentence === 'second child') {
|
|
597
|
+
return () => node.child_nodes[1];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (sentence === 'name' || sentence === 'node name') {
|
|
601
|
+
return () => node.name;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// select_child
|
|
605
|
+
|
|
606
|
+
if (sentence === 'select by type') {
|
|
607
|
+
return select_by_type;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (sentence === 'select by t' || sentence === 'select by type abbreviation' || sentence === 'select by abbreviated type') {
|
|
611
|
+
return select_by_type_abbreviation;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// select_by_type_abbreviation
|
|
615
|
+
|
|
616
|
+
if (sentence === 'select child node' || sentence === 'select child') {
|
|
617
|
+
return select_child;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (sentence === 'select child node by signature' || sentence === 'select child by signature') {
|
|
621
|
+
return select_child_node_by_signature;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (sentence === 'select by category' || sentence === 'select node by category') {
|
|
625
|
+
return select_by_category;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// select node by first child first child name
|
|
629
|
+
|
|
630
|
+
if (sentence === 'select by first child first child name' || sentence === 'select node by first child first child name') {
|
|
631
|
+
return select_by_first_child_first_child_name;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
// select_each_child_node_by_signature
|
|
637
|
+
|
|
638
|
+
// .select.child.by.signature
|
|
639
|
+
|
|
640
|
+
// first child identifier
|
|
641
|
+
|
|
642
|
+
// each child identifier
|
|
643
|
+
// each child declaration
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
//
|
|
653
|
+
|
|
654
|
+
const create_query = (node, words = []) => {
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
const res = {
|
|
659
|
+
//message1: "hello",
|
|
660
|
+
//message2: "everyone"
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
const handler2 = {
|
|
664
|
+
get: function(target, prop, receiver) {
|
|
665
|
+
|
|
666
|
+
//console.log('target', target);
|
|
667
|
+
//console.log('prop', prop);
|
|
668
|
+
//console.log('receiver', receiver);
|
|
669
|
+
|
|
670
|
+
//console.log('target === res', target === res);
|
|
671
|
+
|
|
672
|
+
if (target === res) {
|
|
673
|
+
|
|
674
|
+
if (prop === 'exe') {
|
|
675
|
+
|
|
676
|
+
//throw 'stop';
|
|
677
|
+
|
|
678
|
+
return create_query_execution_fn(node, words);
|
|
679
|
+
|
|
680
|
+
//throw 'NYI'
|
|
681
|
+
|
|
682
|
+
// return the execution function.
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
} else if (prop === 'qstring') {
|
|
687
|
+
return words.join('.');
|
|
688
|
+
} else {
|
|
689
|
+
words.push(prop);
|
|
690
|
+
return create_query(node, words);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
} else {
|
|
694
|
+
throw 'stop';
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
//throw 'NYI';
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const proxy2 = new Proxy(res, handler2);
|
|
704
|
+
|
|
705
|
+
return proxy2;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
class JS_AST_Node_Query extends JS_AST_Node_Type_Variable_Declarator {
|
|
710
|
+
constructor(spec = {}) {
|
|
711
|
+
super(spec);
|
|
712
|
+
|
|
713
|
+
// query property.
|
|
714
|
+
|
|
715
|
+
// but each time provide a new query object.
|
|
716
|
+
|
|
717
|
+
//let query;
|
|
718
|
+
Object.defineProperty(this, 'query', {
|
|
719
|
+
get() {
|
|
720
|
+
return create_query(this);
|
|
721
|
+
},
|
|
722
|
+
enumerable: true,
|
|
723
|
+
configurable: false
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
this.query_with_words = arr_words => {
|
|
728
|
+
const q = create_query(this, arr_words);
|
|
729
|
+
return q;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
737
|
module.exports = JS_AST_Node_Query;
|