@swagger-api/apidom-parser-adapter-json 0.70.3 → 0.71.0
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/CHANGELOG.md +19 -0
- package/cjs/syntactic-analysis/TreeCursorIterator.cjs +62 -0
- package/cjs/syntactic-analysis/TreeCursorSyntaxNode.cjs +51 -0
- package/cjs/syntactic-analysis/direct/index.cjs +17 -183
- package/cjs/syntactic-analysis/direct/visitors/CstVisitor.cjs +175 -0
- package/cjs/syntactic-analysis/indirect/index.cjs +14 -2
- package/cjs/syntactic-analysis/indirect/visitors/CstVisitor.cjs +23 -31
- package/dist/apidom-parser-adapter-json.browser.js +463 -337
- package/dist/apidom-parser-adapter-json.browser.min.js +1 -1
- package/es/syntactic-analysis/TreeCursorIterator.js +60 -0
- package/es/syntactic-analysis/TreeCursorSyntaxNode.js +56 -0
- package/es/syntactic-analysis/direct/index.js +18 -185
- package/es/syntactic-analysis/direct/visitors/CstVisitor.js +169 -0
- package/es/syntactic-analysis/indirect/index.js +13 -2
- package/es/syntactic-analysis/indirect/visitors/CstVisitor.js +23 -31
- package/package.json +5 -5
- package/types/dist.d.ts +19 -4
- package/cjs/syntactic-analysis/PreOrderCursorChildrenIterator.cjs +0 -33
- package/cjs/syntactic-analysis/PreOrderCusrorIterator.cjs +0 -31
- package/cjs/syntactic-analysis/direct/CursorIterator.cjs +0 -110
- package/es/syntactic-analysis/PreOrderCursorChildrenIterator.js +0 -32
- package/es/syntactic-analysis/PreOrderCusrorIterator.js +0 -30
- package/es/syntactic-analysis/direct/CursorIterator.js +0 -104
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import stampit from 'stampit';
|
|
2
2
|
import { JsonArray, JsonDocument, JsonFalse, JsonNull, JsonNumber, JsonObject, JsonKey, JsonProperty, JsonString, JsonStringContent, JsonTrue, ParseResult, Position, Point, Literal, Error } from '@swagger-api/apidom-ast';
|
|
3
|
+
import TreeCursorSyntaxNode from "../../TreeCursorSyntaxNode.js";
|
|
3
4
|
export const keyMap = {
|
|
4
5
|
document: ['children'],
|
|
5
6
|
object: ['children'],
|
|
@@ -16,9 +17,6 @@ const CstVisitor = stampit({
|
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
const toPosition = node => {
|
|
19
|
-
if (node === null) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
20
|
const start = Point({
|
|
23
21
|
row: node.startPosition.row,
|
|
24
22
|
column: node.startPosition.column,
|
|
@@ -34,27 +32,19 @@ const CstVisitor = stampit({
|
|
|
34
32
|
end
|
|
35
33
|
});
|
|
36
34
|
};
|
|
37
|
-
const getFieldFromNode = (fieldName, node) => {
|
|
38
|
-
var _node$childForFieldNa;
|
|
39
|
-
return `${fieldName}Node` in node ?
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
node[`${fieldName}Node`] : 'childForFieldName' in node ? (_node$childForFieldNa = node.childForFieldName) === null || _node$childForFieldNa === void 0 ? void 0 : _node$childForFieldNa.call(node, fieldName) : null;
|
|
42
|
-
};
|
|
43
35
|
|
|
44
36
|
/**
|
|
45
37
|
* Public API.
|
|
46
38
|
*/
|
|
47
39
|
|
|
48
40
|
this.enter = function enter(node) {
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
// in `SyntaxNode.isNamed` property. web-tree-sitter has it defined as method
|
|
52
|
-
// whether tree-sitter node binding has it defined as a boolean property.
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
if (typeof node.isNamed === 'function' && !node.isNamed() || node.isNamed === false) {
|
|
41
|
+
// anonymous literals from CST transformed into AST literal nodes
|
|
42
|
+
if (node instanceof TreeCursorSyntaxNode && !node.isNamed) {
|
|
55
43
|
const position = toPosition(node);
|
|
56
44
|
const value = node.type || node.text;
|
|
57
|
-
const
|
|
45
|
+
const {
|
|
46
|
+
isMissing
|
|
47
|
+
} = node;
|
|
58
48
|
return Literal({
|
|
59
49
|
value,
|
|
60
50
|
position,
|
|
@@ -69,7 +59,7 @@ const CstVisitor = stampit({
|
|
|
69
59
|
return JsonDocument({
|
|
70
60
|
children: node.children,
|
|
71
61
|
position,
|
|
72
|
-
isMissing: node.isMissing
|
|
62
|
+
isMissing: node.isMissing
|
|
73
63
|
});
|
|
74
64
|
},
|
|
75
65
|
leave(document) {
|
|
@@ -83,22 +73,24 @@ const CstVisitor = stampit({
|
|
|
83
73
|
return JsonObject({
|
|
84
74
|
children: node.children,
|
|
85
75
|
position,
|
|
86
|
-
isMissing: node.isMissing
|
|
76
|
+
isMissing: node.isMissing
|
|
87
77
|
});
|
|
88
78
|
};
|
|
89
79
|
this.pair = function pair(node) {
|
|
90
80
|
const position = toPosition(node);
|
|
91
81
|
const children = node.children.slice(1);
|
|
92
|
-
const
|
|
82
|
+
const {
|
|
83
|
+
keyNode
|
|
84
|
+
} = node;
|
|
93
85
|
const key = JsonKey({
|
|
94
86
|
children: (keyNode === null || keyNode === void 0 ? void 0 : keyNode.children) || [],
|
|
95
|
-
position: toPosition(keyNode),
|
|
96
|
-
isMissing:
|
|
87
|
+
position: keyNode != null ? toPosition(keyNode) : null,
|
|
88
|
+
isMissing: keyNode != null ? keyNode.isMissing : false
|
|
97
89
|
});
|
|
98
90
|
return JsonProperty({
|
|
99
91
|
children: [key, ...children],
|
|
100
92
|
position,
|
|
101
|
-
isMissing: node.isMissing
|
|
93
|
+
isMissing: node.isMissing
|
|
102
94
|
});
|
|
103
95
|
};
|
|
104
96
|
this.array = function array(node) {
|
|
@@ -106,18 +98,18 @@ const CstVisitor = stampit({
|
|
|
106
98
|
return JsonArray({
|
|
107
99
|
children: node.children,
|
|
108
100
|
position,
|
|
109
|
-
isMissing: node.isMissing
|
|
101
|
+
isMissing: node.isMissing
|
|
110
102
|
});
|
|
111
103
|
};
|
|
112
104
|
this.string = function string(node) {
|
|
113
105
|
const position = toPosition(node);
|
|
114
106
|
const content = JsonStringContent({
|
|
115
|
-
value: node.text
|
|
107
|
+
value: JSON.parse(node.text)
|
|
116
108
|
});
|
|
117
109
|
return JsonString({
|
|
118
110
|
children: [content],
|
|
119
111
|
position,
|
|
120
|
-
isMissing: node.isMissing
|
|
112
|
+
isMissing: node.isMissing
|
|
121
113
|
});
|
|
122
114
|
};
|
|
123
115
|
this.number = function number(node) {
|
|
@@ -126,7 +118,7 @@ const CstVisitor = stampit({
|
|
|
126
118
|
return JsonNumber({
|
|
127
119
|
value,
|
|
128
120
|
position,
|
|
129
|
-
isMissing: node.isMissing
|
|
121
|
+
isMissing: node.isMissing
|
|
130
122
|
});
|
|
131
123
|
};
|
|
132
124
|
|
|
@@ -137,7 +129,7 @@ const CstVisitor = stampit({
|
|
|
137
129
|
return JsonNull({
|
|
138
130
|
value,
|
|
139
131
|
position,
|
|
140
|
-
isMissing: node.isMissing
|
|
132
|
+
isMissing: node.isMissing
|
|
141
133
|
});
|
|
142
134
|
};
|
|
143
135
|
|
|
@@ -148,7 +140,7 @@ const CstVisitor = stampit({
|
|
|
148
140
|
return JsonTrue({
|
|
149
141
|
value,
|
|
150
142
|
position,
|
|
151
|
-
isMissing: node.isMissing
|
|
143
|
+
isMissing: node.isMissing
|
|
152
144
|
});
|
|
153
145
|
};
|
|
154
146
|
|
|
@@ -159,7 +151,7 @@ const CstVisitor = stampit({
|
|
|
159
151
|
return JsonFalse({
|
|
160
152
|
value,
|
|
161
153
|
position,
|
|
162
|
-
isMissing: node.isMissing
|
|
154
|
+
isMissing: node.isMissing
|
|
163
155
|
});
|
|
164
156
|
};
|
|
165
157
|
this.ERROR = function ERROR(node, key, parent, path) {
|
|
@@ -167,8 +159,8 @@ const CstVisitor = stampit({
|
|
|
167
159
|
const errorNode = Error({
|
|
168
160
|
children: node.children,
|
|
169
161
|
position,
|
|
170
|
-
isUnexpected: !node.hasError
|
|
171
|
-
isMissing: node.isMissing
|
|
162
|
+
isUnexpected: !node.hasError,
|
|
163
|
+
isMissing: node.isMissing,
|
|
172
164
|
value: node.text
|
|
173
165
|
});
|
|
174
166
|
if (path.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swagger-api/apidom-parser-adapter-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "Parser adapter for parsing JSON documents into base namespace.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"license": "Apache-2.0",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/runtime-corejs3": "^7.20.7",
|
|
56
|
-
"@swagger-api/apidom-ast": "^0.
|
|
57
|
-
"@swagger-api/apidom-core": "^0.
|
|
58
|
-
"@types/ramda": "~0.29.
|
|
56
|
+
"@swagger-api/apidom-ast": "^0.71.0",
|
|
57
|
+
"@swagger-api/apidom-core": "^0.71.0",
|
|
58
|
+
"@types/ramda": "~0.29.3",
|
|
59
59
|
"ramda": "~0.29.0",
|
|
60
60
|
"ramda-adjunct": "^4.0.0",
|
|
61
61
|
"stampit": "^4.3.2",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"README.md",
|
|
78
78
|
"CHANGELOG.md"
|
|
79
79
|
],
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "397e4cd2fd84bb57038183b177c0da4d80f15004"
|
|
81
81
|
}
|
package/types/dist.d.ts
CHANGED
|
@@ -13,12 +13,19 @@ import { Tree as Tree$2 } from 'tree-sitter';
|
|
|
13
13
|
declare const analyze$2: (source: string) => Promise<Tree$1>;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* This version of syntactic analysis translates TreeSitter CTS
|
|
16
|
+
* This version of syntactic analysis translates TreeSitter CTS
|
|
17
|
+
* directly into ApiDOM.
|
|
18
|
+
*
|
|
19
|
+
* Transient transformation of TreeSitter CST is performed
|
|
20
|
+
* using TreeSitter cursor. TreeSitter cursor is a stateful object
|
|
21
|
+
* that allows us to walk syntax tree containing large number of nodes
|
|
22
|
+
* with maximum efficiency. Using this transient CST transformation
|
|
23
|
+
* gives us double the performance when syntactically analyzing
|
|
24
|
+
* CST into ApiDOM.
|
|
25
|
+
*
|
|
17
26
|
* Single traversal pass is needed to get from CST to ApiDOM.
|
|
18
27
|
*/
|
|
19
|
-
declare const analyze$1: (cst: {
|
|
20
|
-
rootNode: unknown;
|
|
21
|
-
}, { sourceMap }?: {
|
|
28
|
+
declare const analyze$1: (cst: Tree$2 | Tree$1, { sourceMap }?: {
|
|
22
29
|
sourceMap?: boolean | undefined;
|
|
23
30
|
}) => ParseResultElement;
|
|
24
31
|
|
|
@@ -26,6 +33,14 @@ type Tree = Tree$1 | Tree$2;
|
|
|
26
33
|
/**
|
|
27
34
|
* This version of syntactic analysis does following transformations:
|
|
28
35
|
* TreeSitter CST -> JSON AST -> ApiDOM
|
|
36
|
+
*
|
|
37
|
+
* Transient transformation of TreeSitter CST is performed
|
|
38
|
+
* using TreeSitter cursor. TreeSitter cursor is a stateful object
|
|
39
|
+
* that allows us to walk syntax tree containing large number of nodes
|
|
40
|
+
* with maximum efficiency. Using this transient CST transformation
|
|
41
|
+
* gives us double the performance when syntactically analyzing
|
|
42
|
+
* CST into JSON AST.
|
|
43
|
+
*
|
|
29
44
|
* Two traversals passes are needed to get from CST to ApiDOM.
|
|
30
45
|
* This analysis is much slower than the direct one, but allows
|
|
31
46
|
* to do additional analysis magic on JSON AST.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
class PreOrderCursorChildrenIterator {
|
|
6
|
-
constructor(cursor) {
|
|
7
|
-
this.cursor = cursor;
|
|
8
|
-
}
|
|
9
|
-
createNode() {
|
|
10
|
-
return {
|
|
11
|
-
type: this.cursor.nodeType,
|
|
12
|
-
startPosition: this.cursor.startPosition,
|
|
13
|
-
endPosition: this.cursor.endPosition,
|
|
14
|
-
children: []
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
*[Symbol.iterator]() {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const method = this[this.cursor.nodeType];
|
|
20
|
-
const currentNode = (method || this.createNode).call(this);
|
|
21
|
-
const constructor = this.constructor;
|
|
22
|
-
if (this.cursor.gotoFirstChild()) {
|
|
23
|
-
currentNode.children.push(...[...new constructor(this.cursor)]);
|
|
24
|
-
while (this.cursor.gotoNextSibling()) {
|
|
25
|
-
currentNode.children.push(...[...new constructor(this.cursor)]);
|
|
26
|
-
}
|
|
27
|
-
this.cursor.gotoParent();
|
|
28
|
-
}
|
|
29
|
-
yield currentNode;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
var _default = PreOrderCursorChildrenIterator;
|
|
33
|
-
exports.default = _default;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
class PreOrderCursorIterator {
|
|
6
|
-
constructor(cursor) {
|
|
7
|
-
this.cursor = cursor;
|
|
8
|
-
}
|
|
9
|
-
createNode() {
|
|
10
|
-
return {
|
|
11
|
-
type: this.cursor.nodeType,
|
|
12
|
-
startPosition: this.cursor.startPosition,
|
|
13
|
-
endPosition: this.cursor.endPosition
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
*[Symbol.iterator]() {
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
const method = this[this.cursor.nodeType];
|
|
19
|
-
const constructor = this.constructor;
|
|
20
|
-
yield (method || this.createNode).call(this);
|
|
21
|
-
if (this.cursor.gotoFirstChild()) {
|
|
22
|
-
yield* new constructor(this.cursor);
|
|
23
|
-
while (this.cursor.gotoNextSibling()) {
|
|
24
|
-
yield* new constructor(this.cursor);
|
|
25
|
-
}
|
|
26
|
-
this.cursor.gotoParent();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
var _default = PreOrderCursorIterator;
|
|
31
|
-
exports.default = _default;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
exports.__esModule = true;
|
|
5
|
-
exports.default = void 0;
|
|
6
|
-
var _PreOrderCursorChildrenIterator = _interopRequireDefault(require("../PreOrderCursorChildrenIterator.cjs"));
|
|
7
|
-
class CursorIterator extends _PreOrderCursorChildrenIterator.default {
|
|
8
|
-
document() {
|
|
9
|
-
return {
|
|
10
|
-
type: this.cursor.nodeType,
|
|
11
|
-
startPosition: this.cursor.startPosition,
|
|
12
|
-
endPosition: this.cursor.endPosition,
|
|
13
|
-
children: []
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
object() {
|
|
17
|
-
return {
|
|
18
|
-
type: this.cursor.nodeType,
|
|
19
|
-
startPosition: this.cursor.startPosition,
|
|
20
|
-
endPosition: this.cursor.endPosition,
|
|
21
|
-
fieldName: this.cursor.currentFieldName,
|
|
22
|
-
children: []
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
array() {
|
|
26
|
-
return {
|
|
27
|
-
type: this.cursor.nodeType,
|
|
28
|
-
startPosition: this.cursor.startPosition,
|
|
29
|
-
endPosition: this.cursor.endPosition,
|
|
30
|
-
fieldName: this.cursor.currentFieldName,
|
|
31
|
-
children: []
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
pair() {
|
|
35
|
-
return {
|
|
36
|
-
type: this.cursor.nodeType,
|
|
37
|
-
startPosition: this.cursor.startPosition,
|
|
38
|
-
endPosition: this.cursor.endPosition,
|
|
39
|
-
get keyNode() {
|
|
40
|
-
return this.children.find(node => node.fieldName === 'key');
|
|
41
|
-
},
|
|
42
|
-
get valueNode() {
|
|
43
|
-
return this.children.find(node => node.fieldName === 'value');
|
|
44
|
-
},
|
|
45
|
-
children: []
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
string() {
|
|
49
|
-
return {
|
|
50
|
-
type: this.cursor.nodeType,
|
|
51
|
-
startPosition: this.cursor.startPosition,
|
|
52
|
-
endPosition: this.cursor.endPosition,
|
|
53
|
-
text: this.cursor.nodeText,
|
|
54
|
-
fieldName: this.cursor.currentFieldName,
|
|
55
|
-
children: []
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
number() {
|
|
59
|
-
return {
|
|
60
|
-
type: this.cursor.nodeType,
|
|
61
|
-
startPosition: this.cursor.startPosition,
|
|
62
|
-
endPosition: this.cursor.endPosition,
|
|
63
|
-
text: this.cursor.nodeText,
|
|
64
|
-
fieldName: this.cursor.currentFieldName,
|
|
65
|
-
children: []
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
null() {
|
|
69
|
-
return {
|
|
70
|
-
type: this.cursor.nodeType,
|
|
71
|
-
startPosition: this.cursor.startPosition,
|
|
72
|
-
endPosition: this.cursor.endPosition,
|
|
73
|
-
fieldName: this.cursor.currentFieldName,
|
|
74
|
-
children: []
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
true() {
|
|
78
|
-
return {
|
|
79
|
-
type: this.cursor.nodeType,
|
|
80
|
-
startPosition: this.cursor.startPosition,
|
|
81
|
-
endPosition: this.cursor.endPosition,
|
|
82
|
-
fieldName: this.cursor.currentFieldName,
|
|
83
|
-
children: []
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
false() {
|
|
87
|
-
return {
|
|
88
|
-
type: this.cursor.nodeType,
|
|
89
|
-
startPosition: this.cursor.startPosition,
|
|
90
|
-
endPosition: this.cursor.endPosition,
|
|
91
|
-
fieldName: this.cursor.currentFieldName,
|
|
92
|
-
children: []
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
ERROR() {
|
|
96
|
-
const {
|
|
97
|
-
currentNode
|
|
98
|
-
} = this.cursor;
|
|
99
|
-
return {
|
|
100
|
-
type: this.cursor.nodeType,
|
|
101
|
-
startPosition: this.cursor.startPosition,
|
|
102
|
-
endPosition: this.cursor.endPosition,
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
hasError: () => currentNode.hasError(),
|
|
105
|
-
children: []
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
var _default = CursorIterator;
|
|
110
|
-
exports.default = _default;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
-
let _Symbol$iterator;
|
|
3
|
-
_Symbol$iterator = Symbol.iterator;
|
|
4
|
-
class PreOrderCursorChildrenIterator {
|
|
5
|
-
constructor(cursor) {
|
|
6
|
-
_defineProperty(this, "cursor", void 0);
|
|
7
|
-
this.cursor = cursor;
|
|
8
|
-
}
|
|
9
|
-
createNode() {
|
|
10
|
-
return {
|
|
11
|
-
type: this.cursor.nodeType,
|
|
12
|
-
startPosition: this.cursor.startPosition,
|
|
13
|
-
endPosition: this.cursor.endPosition,
|
|
14
|
-
children: []
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
*[_Symbol$iterator]() {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const method = this[this.cursor.nodeType];
|
|
20
|
-
const currentNode = (method || this.createNode).call(this);
|
|
21
|
-
const constructor = this.constructor;
|
|
22
|
-
if (this.cursor.gotoFirstChild()) {
|
|
23
|
-
currentNode.children.push(...[...new constructor(this.cursor)]);
|
|
24
|
-
while (this.cursor.gotoNextSibling()) {
|
|
25
|
-
currentNode.children.push(...[...new constructor(this.cursor)]);
|
|
26
|
-
}
|
|
27
|
-
this.cursor.gotoParent();
|
|
28
|
-
}
|
|
29
|
-
yield currentNode;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export default PreOrderCursorChildrenIterator;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
-
let _Symbol$iterator;
|
|
3
|
-
_Symbol$iterator = Symbol.iterator;
|
|
4
|
-
class PreOrderCursorIterator {
|
|
5
|
-
constructor(cursor) {
|
|
6
|
-
_defineProperty(this, "cursor", void 0);
|
|
7
|
-
this.cursor = cursor;
|
|
8
|
-
}
|
|
9
|
-
createNode() {
|
|
10
|
-
return {
|
|
11
|
-
type: this.cursor.nodeType,
|
|
12
|
-
startPosition: this.cursor.startPosition,
|
|
13
|
-
endPosition: this.cursor.endPosition
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
*[_Symbol$iterator]() {
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
const method = this[this.cursor.nodeType];
|
|
19
|
-
const constructor = this.constructor;
|
|
20
|
-
yield (method || this.createNode).call(this);
|
|
21
|
-
if (this.cursor.gotoFirstChild()) {
|
|
22
|
-
yield* new constructor(this.cursor);
|
|
23
|
-
while (this.cursor.gotoNextSibling()) {
|
|
24
|
-
yield* new constructor(this.cursor);
|
|
25
|
-
}
|
|
26
|
-
this.cursor.gotoParent();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export default PreOrderCursorIterator;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import PreOrderCursorChildrenIterator from "../PreOrderCursorChildrenIterator.js";
|
|
2
|
-
class CursorIterator extends PreOrderCursorChildrenIterator {
|
|
3
|
-
document() {
|
|
4
|
-
return {
|
|
5
|
-
type: this.cursor.nodeType,
|
|
6
|
-
startPosition: this.cursor.startPosition,
|
|
7
|
-
endPosition: this.cursor.endPosition,
|
|
8
|
-
children: []
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
object() {
|
|
12
|
-
return {
|
|
13
|
-
type: this.cursor.nodeType,
|
|
14
|
-
startPosition: this.cursor.startPosition,
|
|
15
|
-
endPosition: this.cursor.endPosition,
|
|
16
|
-
fieldName: this.cursor.currentFieldName,
|
|
17
|
-
children: []
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
array() {
|
|
21
|
-
return {
|
|
22
|
-
type: this.cursor.nodeType,
|
|
23
|
-
startPosition: this.cursor.startPosition,
|
|
24
|
-
endPosition: this.cursor.endPosition,
|
|
25
|
-
fieldName: this.cursor.currentFieldName,
|
|
26
|
-
children: []
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
pair() {
|
|
30
|
-
return {
|
|
31
|
-
type: this.cursor.nodeType,
|
|
32
|
-
startPosition: this.cursor.startPosition,
|
|
33
|
-
endPosition: this.cursor.endPosition,
|
|
34
|
-
get keyNode() {
|
|
35
|
-
return this.children.find(node => node.fieldName === 'key');
|
|
36
|
-
},
|
|
37
|
-
get valueNode() {
|
|
38
|
-
return this.children.find(node => node.fieldName === 'value');
|
|
39
|
-
},
|
|
40
|
-
children: []
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
string() {
|
|
44
|
-
return {
|
|
45
|
-
type: this.cursor.nodeType,
|
|
46
|
-
startPosition: this.cursor.startPosition,
|
|
47
|
-
endPosition: this.cursor.endPosition,
|
|
48
|
-
text: this.cursor.nodeText,
|
|
49
|
-
fieldName: this.cursor.currentFieldName,
|
|
50
|
-
children: []
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
number() {
|
|
54
|
-
return {
|
|
55
|
-
type: this.cursor.nodeType,
|
|
56
|
-
startPosition: this.cursor.startPosition,
|
|
57
|
-
endPosition: this.cursor.endPosition,
|
|
58
|
-
text: this.cursor.nodeText,
|
|
59
|
-
fieldName: this.cursor.currentFieldName,
|
|
60
|
-
children: []
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
null() {
|
|
64
|
-
return {
|
|
65
|
-
type: this.cursor.nodeType,
|
|
66
|
-
startPosition: this.cursor.startPosition,
|
|
67
|
-
endPosition: this.cursor.endPosition,
|
|
68
|
-
fieldName: this.cursor.currentFieldName,
|
|
69
|
-
children: []
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
true() {
|
|
73
|
-
return {
|
|
74
|
-
type: this.cursor.nodeType,
|
|
75
|
-
startPosition: this.cursor.startPosition,
|
|
76
|
-
endPosition: this.cursor.endPosition,
|
|
77
|
-
fieldName: this.cursor.currentFieldName,
|
|
78
|
-
children: []
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
false() {
|
|
82
|
-
return {
|
|
83
|
-
type: this.cursor.nodeType,
|
|
84
|
-
startPosition: this.cursor.startPosition,
|
|
85
|
-
endPosition: this.cursor.endPosition,
|
|
86
|
-
fieldName: this.cursor.currentFieldName,
|
|
87
|
-
children: []
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
ERROR() {
|
|
91
|
-
const {
|
|
92
|
-
currentNode
|
|
93
|
-
} = this.cursor;
|
|
94
|
-
return {
|
|
95
|
-
type: this.cursor.nodeType,
|
|
96
|
-
startPosition: this.cursor.startPosition,
|
|
97
|
-
endPosition: this.cursor.endPosition,
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
hasError: () => currentNode.hasError(),
|
|
100
|
-
children: []
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export default CursorIterator;
|