jsgui3-server 0.0.75 → 0.0.77
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/examples/client-side-popup-menu-button.html +93 -93
- package/examples/controls/_html-server-color-palette.js +114 -114
- package/examples/controls/html-server-combo-box.js +104 -104
- package/examples/controls/html-server-list.js +98 -98
- package/examples/controls/html-server-popup-menu-button.js +114 -114
- package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
- package/examples/controls/scs-arrow-button.js +36 -36
- package/examples/controls/scs-date-picker.js +157 -157
- package/examples/controls/scs-file-browser.js +82 -82
- package/examples/controls/scs-item.js +159 -159
- package/examples/controls/scs-month-arrow-selector.js +126 -126
- package/examples/controls/scs-month-view.js +95 -95
- package/examples/controls/scs-start-stop-toggle-button.js +40 -40
- package/examples/controls/scs-tree.js +49 -49
- package/examples/controls/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/demos/square_box.js +324 -324
- package/examples/html-rendering.js +20 -20
- package/examples/html-server.js +100 -100
- package/fs2.js +1836 -1836
- package/module.js +21 -21
- package/old/single-control-server.js +418 -418
- package/package.json +44 -42
- package/publishing/function-publisher.js +202 -202
- package/publishing/notes.md +5 -5
- package/publishing/observable-publisher.js +118 -118
- package/publishing/resource-publisher.js +306 -306
- package/resources/data-resource.js +104 -104
- package/resources/fs-resource.js +148 -148
- package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
- package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
- package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
- package/resources/jsbuilder/JS_AST/query/all.js +0 -0
- package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
- package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
- package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
- package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
- package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
- package/resources/jsbuilder/JS_Builder.js +10 -36
- package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
- package/resources/jsbuilder/JS_File/JS_File.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
- package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
- package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
- package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
- package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
- package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
- package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
- package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
- package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
- package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
- package/resources/jsbuilder/Module.js +14 -0
- package/resources/jsbuilder/Platform.js +13 -53
- package/resources/jsbuilder/Platforms.js +69 -15
- package/resources/jsbuilder/Project.js +109 -0
- package/resources/jsbuilder/Reference.js +1 -1
- package/resources/jsbuilder/Reference_Sequence.js +16 -7
- package/resources/jsbuilder/Scope.js +30 -0
- package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
- package/resources/jsbuilder/_JS_File.js +226 -0
- package/resources/jsbuilder/ast_query.js +21 -0
- package/resources/jsbuilder/babel/babel_consts.js +150 -0
- package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
- package/resources/jsbuilder/build.js +16 -0
- package/resources/jsbuilder/platform_notes.md +66 -0
- package/resources/jsbuilder/test/test_ast_node.js +451 -0
- package/resources/jsbuilder/test/test_js_file.js +303 -11
- package/resources/jsbuilder/test/test_project.js +157 -0
- package/resources/local-server-info-resource.js +78 -78
- package/resources/process-js.js +537 -537
- package/resources/server-resource-pool.js +84 -84
- package/resources/website-css-resource.js +411 -411
- package/resources/website-javascript-resource.js +761 -751
- package/resources/website-resource.js +390 -390
- package/resources/website-static-html-resource.js +196 -196
- package/server.js +170 -170
- package/single-control-server.js +398 -398
- package/single-page-app.js +129 -129
- package/resources/jsbuilder/Declaration.js +0 -15
- package/resources/jsbuilder/Declaration_Sequence.js +0 -15
- package/resources/jsbuilder/JS_File.js +0 -77
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Such as for referencing the inner nodes without / before having to have the actual members.
|
|
4
|
+
|
|
5
|
+
// Maybe generators would be effective here too?
|
|
6
|
+
|
|
7
|
+
// origin_node
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// relationship to origin node
|
|
12
|
+
//
|
|
13
|
+
|
|
14
|
+
class JS_AST_Abstract_Node {
|
|
15
|
+
constructor(spec = {}) {
|
|
16
|
+
|
|
17
|
+
// origin node
|
|
18
|
+
// function that will be called to obtain the nodes.
|
|
19
|
+
|
|
20
|
+
let origin, obtainer;
|
|
21
|
+
|
|
22
|
+
let relationship_to, index;
|
|
23
|
+
|
|
24
|
+
if (spec.origin) {
|
|
25
|
+
origin = spec.origin;
|
|
26
|
+
}
|
|
27
|
+
if (spec.obtainer) {
|
|
28
|
+
obtainer = spec.obtainer;
|
|
29
|
+
}
|
|
30
|
+
if (spec.relationship_to) {
|
|
31
|
+
relationship_to = spec.relationship_to;
|
|
32
|
+
}
|
|
33
|
+
if (spec.index !== undefined) {
|
|
34
|
+
index = spec.index;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let arr_cached;
|
|
38
|
+
// so when they do get loaded / we have a ref - does not need to operate only in the abstract.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(this, 'origin', {
|
|
42
|
+
get() {
|
|
43
|
+
return origin;
|
|
44
|
+
},
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: false
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
Object.defineProperty(this, 'index', {
|
|
50
|
+
get() {
|
|
51
|
+
return index;
|
|
52
|
+
},
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: false
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
module.exports = JS_AST_Abstract_Node;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Such as for referencing the inner nodes without / before having to have the actual members.
|
|
4
|
+
|
|
5
|
+
// Maybe generators would be effective here too?
|
|
6
|
+
|
|
7
|
+
// origin_node
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// relationship to origin node
|
|
12
|
+
//
|
|
13
|
+
|
|
14
|
+
class JS_AST_Abstract_Node_Group {
|
|
15
|
+
constructor(spec = {}) {
|
|
16
|
+
|
|
17
|
+
// origin node
|
|
18
|
+
// function that will be called to obtain the nodes.
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
let origin, obtainer;
|
|
22
|
+
|
|
23
|
+
let relationship_to;
|
|
24
|
+
|
|
25
|
+
if (spec.origin) {
|
|
26
|
+
origin = spec.origin;
|
|
27
|
+
}
|
|
28
|
+
if (spec.obtainer) {
|
|
29
|
+
obtainer = spec.obtainer;
|
|
30
|
+
}
|
|
31
|
+
if (spec.relationship_to) {
|
|
32
|
+
relationship_to = spec.relationship_to;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let arr_cached;
|
|
36
|
+
// so when they do get loaded / we have a ref - does not need to operate only in the abstract.
|
|
37
|
+
*/
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
module.exports = JS_AST_Abstract_Node_Group;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
class JS_AST_Group_Shared {
|
|
2
|
+
constructor(spec = {}) {
|
|
3
|
+
|
|
4
|
+
let group_iterator;
|
|
5
|
+
|
|
6
|
+
if (spec.group_iterator) group_iterator = spec.group_iterator;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let shared_type;
|
|
10
|
+
Object.defineProperty(this, 'type', {
|
|
11
|
+
get() {
|
|
12
|
+
if (shared_type === undefined) {
|
|
13
|
+
group_iterator((cn, idx, stop) => {
|
|
14
|
+
if (shared_type === undefined) {
|
|
15
|
+
shared_type = cn.type;
|
|
16
|
+
} else {
|
|
17
|
+
if (cn.type === shared_type) {
|
|
18
|
+
// all good
|
|
19
|
+
} else {
|
|
20
|
+
shared_type = false;
|
|
21
|
+
stop();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
return shared_type;
|
|
28
|
+
//return child_nodes.length;
|
|
29
|
+
},
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: false
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let shared_category;
|
|
35
|
+
Object.defineProperty(this, 'category', {
|
|
36
|
+
get() {
|
|
37
|
+
if (shared_category === undefined) {
|
|
38
|
+
group_iterator((cn, idx, stop) => {
|
|
39
|
+
if (shared_category === undefined) {
|
|
40
|
+
shared_category = cn.category;
|
|
41
|
+
} else {
|
|
42
|
+
if (cn.category === shared_category) {
|
|
43
|
+
// all good
|
|
44
|
+
} else {
|
|
45
|
+
shared_category = false;
|
|
46
|
+
stop();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
return shared_category;
|
|
53
|
+
//return child_nodes.length;
|
|
54
|
+
},
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: false
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = JS_AST_Group_Shared;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Do more to get the mirrored node structure set up earlier.
|
|
2
|
+
|
|
3
|
+
const {each} = require('lang-mini');
|
|
4
|
+
const JS_AST_Node_Changing = require('./JS_AST_Node_10-Changing');
|
|
5
|
+
|
|
6
|
+
const babel_node_tools = require('../babel/babel_node_tools');
|
|
7
|
+
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
8
|
+
|
|
9
|
+
// Possibly able to manage a source babel node and different resultant transformations.
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
deep_iterate_babel_node,
|
|
13
|
+
get_identifier_names,
|
|
14
|
+
get_babel_child_nodes,
|
|
15
|
+
get_require_call
|
|
16
|
+
} = babel_node_tools;
|
|
17
|
+
|
|
18
|
+
// For the moment, do more concerning getting the basic info.
|
|
19
|
+
// Don't do the signature system yet - it's too complex when done fully.
|
|
20
|
+
// Work on getting the info about what is required.
|
|
21
|
+
// In more of a concice fp way.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// A separate Babel mirror structure could make sense.
|
|
25
|
+
//
|
|
26
|
+
|
|
27
|
+
// A queries layer as well?
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// Iterator and generator would be better?
|
|
31
|
+
// Maybe have it attached to a child_nodes object.
|
|
32
|
+
|
|
33
|
+
class JS_AST_Node extends JS_AST_Node_Changing {
|
|
34
|
+
|
|
35
|
+
// Currently they don't maintain themselves in an equivalent tree, and are very disposable.
|
|
36
|
+
// Try it that way for the moment.
|
|
37
|
+
|
|
38
|
+
constructor(spec = {}) {
|
|
39
|
+
super(spec);
|
|
40
|
+
|
|
41
|
+
// Usage query would be an interesting one.
|
|
42
|
+
// Part of a variable declaration - if so, what?
|
|
43
|
+
// Used as a reference?
|
|
44
|
+
|
|
45
|
+
// .used_as_reference
|
|
46
|
+
// .used_in_declaration
|
|
47
|
+
// then what it's value gets set to
|
|
48
|
+
|
|
49
|
+
// Analysis of the identifiers used in the code will provide a major way to track what comes from where.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
let usage;
|
|
53
|
+
|
|
54
|
+
const determine_usage = () => {
|
|
55
|
+
if (this.type === 'Identifier') {
|
|
56
|
+
|
|
57
|
+
} else {
|
|
58
|
+
throw 'NYI';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Object.defineProperty(this, 'usage', {
|
|
64
|
+
get() {
|
|
65
|
+
if (!usage) usage = determine_usage();
|
|
66
|
+
//if (deep_type_signature) return deep_type_signature;
|
|
67
|
+
return usage;
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
//set(newValue) { bValue = newValue; },
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: false
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
[inspect]() {
|
|
79
|
+
// Need the inner part...
|
|
80
|
+
//console.log('this.dimensions', this.dimensions);
|
|
81
|
+
//return 'JS_AST_Node(' + this.type_signature + ')';
|
|
82
|
+
return this.type_signature;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
JS_AST_Node.from_babel_node = (spec) => {
|
|
88
|
+
return new JS_AST_Node(spec);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
JS_AST_Node.from_spec = spec => {
|
|
92
|
+
return new JS_AST_Node(spec);
|
|
93
|
+
}
|
|
94
|
+
module.exports = JS_AST_Node;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const {each} = require('lang-mini');
|
|
2
|
+
|
|
3
|
+
class JS_AST_Node_Core {
|
|
4
|
+
constructor(spec = {}) {
|
|
5
|
+
|
|
6
|
+
// When constructered, and given source, is root, and does not already have a babel node in the spec, will parse the source with the babel parser.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
// Depth
|
|
10
|
+
// Path
|
|
11
|
+
|
|
12
|
+
// Source
|
|
13
|
+
let root_node, parent_node, sibling_index;
|
|
14
|
+
const child_nodes = [];
|
|
15
|
+
|
|
16
|
+
let depth, path;
|
|
17
|
+
let full_source; // only for the root.
|
|
18
|
+
|
|
19
|
+
//console.log('JS_AST_Node_Core Object.keys(spec)', Object.keys(spec));
|
|
20
|
+
|
|
21
|
+
if (spec.root_node) {
|
|
22
|
+
if (spec.root_node === true) {
|
|
23
|
+
root_node = this;
|
|
24
|
+
} else {
|
|
25
|
+
root_node = spec.root_node;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (spec.parent_node) {
|
|
29
|
+
parent_node = spec.parent_node;
|
|
30
|
+
}
|
|
31
|
+
if (typeof spec.sibling_index === 'number') {
|
|
32
|
+
sibling_index = spec.sibling_index;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!parent_node) {
|
|
36
|
+
root_node = this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (root_node === this) {
|
|
40
|
+
if (spec.source) {
|
|
41
|
+
full_source = spec.source;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const idx_named_nodes = {};
|
|
47
|
+
|
|
48
|
+
const get_arr_named_node = (name) => {
|
|
49
|
+
idx_named_nodes[name] = idx_named_nodes[name] || [];
|
|
50
|
+
return idx_named_nodes[name];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const index_named_node = (name, node) => get_arr_named_node(name).push(node);
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
let next_sibling_node, previous_sibling_node;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Object.defineProperty(this, 'source', {
|
|
62
|
+
get() {
|
|
63
|
+
//console.log('full_source', full_source);
|
|
64
|
+
if (full_source) {
|
|
65
|
+
return full_source;
|
|
66
|
+
} else {
|
|
67
|
+
if (this.root_node && this.root_node !== this) {
|
|
68
|
+
const rn = this.root_node;
|
|
69
|
+
|
|
70
|
+
const {babel} = this;
|
|
71
|
+
if (babel) {
|
|
72
|
+
const {start, end} = babel;
|
|
73
|
+
const full_source = this.root_node.source;
|
|
74
|
+
//console.log('full_source', full_source);
|
|
75
|
+
return full_source.substring(start, end);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//return source;
|
|
81
|
+
},
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: false
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (typeof spec.depth === 'number') {
|
|
87
|
+
depth = spec.depth;
|
|
88
|
+
|
|
89
|
+
} else {
|
|
90
|
+
depth = 0;
|
|
91
|
+
}
|
|
92
|
+
if (typeof spec.path === 'string') {
|
|
93
|
+
path = spec.path;
|
|
94
|
+
} else {
|
|
95
|
+
path = '/';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.append_child = (js_ast_node) => {
|
|
99
|
+
child_nodes.push(js_ast_node);
|
|
100
|
+
}
|
|
101
|
+
this.create_append_child = (spec) => {
|
|
102
|
+
const spec2 = {
|
|
103
|
+
babel_node: spec.babel_node,
|
|
104
|
+
parent_node: this,
|
|
105
|
+
root_node: this.root_node,
|
|
106
|
+
path: spec.path
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//const res = new this.constructor(spec2);
|
|
110
|
+
// a from_spec function could load up specific subtypes.
|
|
111
|
+
|
|
112
|
+
const res = this.constructor.from_spec(spec2);
|
|
113
|
+
//console.log('');
|
|
114
|
+
//console.log('create_append_child res.path', res.path);
|
|
115
|
+
//console.log('create_append_child res.type', res.type);
|
|
116
|
+
this.append_child(res);
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Object.defineProperty(this, 'parent_node', {
|
|
121
|
+
get() {
|
|
122
|
+
return parent_node;
|
|
123
|
+
},
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: false
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
Object.defineProperty(this, 'root_node', {
|
|
129
|
+
get() {
|
|
130
|
+
return root_node;
|
|
131
|
+
},
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: false
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(this, 'is_root', {
|
|
136
|
+
get() {
|
|
137
|
+
return root_node === this;
|
|
138
|
+
},
|
|
139
|
+
enumerable: true,
|
|
140
|
+
configurable: false
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
Object.defineProperty(this, 'child_nodes', {
|
|
144
|
+
get() {
|
|
145
|
+
return child_nodes;
|
|
146
|
+
},
|
|
147
|
+
enumerable: true,
|
|
148
|
+
configurable: false
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(this, 'depth', {
|
|
151
|
+
get() {
|
|
152
|
+
return depth;
|
|
153
|
+
},
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: false
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(this, 'path', {
|
|
158
|
+
get() {
|
|
159
|
+
return path;
|
|
160
|
+
},
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: false
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const deep_iterate_INNER = (depth, path, common, callback) => {
|
|
166
|
+
const {max_depth, stop} = common;
|
|
167
|
+
let sibling_number = 0;
|
|
168
|
+
|
|
169
|
+
callback(this, path, depth, stop);
|
|
170
|
+
//console.log('max_depth', max_depth);
|
|
171
|
+
|
|
172
|
+
//console.log('child_nodes', child_nodes);
|
|
173
|
+
//console.log('child_nodes.length', child_nodes.length);
|
|
174
|
+
|
|
175
|
+
if (child_nodes.length > 0 && max_depth === undefined || max_depth === false || depth <= max_depth) {
|
|
176
|
+
each(child_nodes, child_node => {
|
|
177
|
+
//console.log('child_node', child_node);
|
|
178
|
+
child_node.deep_iterate_INNER(depth + 1, path + sibling_number++ + '/', common, callback);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const deep_iterate = (max_depth, callback) => {
|
|
184
|
+
if (!callback && typeof max_depth === 'function') {
|
|
185
|
+
callback = max_depth;
|
|
186
|
+
max_depth = undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const common = {
|
|
190
|
+
max_depth: max_depth,
|
|
191
|
+
stopped: false,
|
|
192
|
+
stop: () => {
|
|
193
|
+
common.stopped = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
deep_iterate_INNER(depth, path, common, callback);
|
|
200
|
+
}
|
|
201
|
+
this.deep_iterate_INNER = deep_iterate_INNER;
|
|
202
|
+
this.deep_iterate = deep_iterate;
|
|
203
|
+
|
|
204
|
+
// Moved down from Query - these are the basics, makes sense in core???
|
|
205
|
+
|
|
206
|
+
const each_child_node = callback => each(this.child_nodes, callback);
|
|
207
|
+
|
|
208
|
+
const filter_each_child_node = (filter, callback) => each_child_node(js_ast_node => {
|
|
209
|
+
if (filter(js_ast_node)) {
|
|
210
|
+
callback(js_ast_node);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
this.each_child_node = each_child_node;
|
|
215
|
+
this.filter_each_child_node = filter_each_child_node;
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
JS_AST_Node_Core.from_spec = spec => {
|
|
223
|
+
return new JS_AST_Node_Core(spec);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// from_string?
|
|
227
|
+
|
|
228
|
+
module.exports = JS_AST_Node_Core;
|