@swagger-api/apidom-parser-adapter-json 0.91.0 → 0.93.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 +8 -0
- package/README.md +1 -1
- package/cjs/syntactic-analysis/direct/index.cjs +1 -1
- package/cjs/syntactic-analysis/direct/visitors/CstVisitor.cjs +138 -151
- package/cjs/syntactic-analysis/indirect/index.cjs +2 -2
- package/cjs/syntactic-analysis/indirect/visitors/CstVisitor.cjs +138 -147
- package/cjs/syntactic-analysis/indirect/visitors/JsonAstVisitor.cjs +129 -137
- package/dist/apidom-parser-adapter-json.browser.js +641 -805
- package/dist/apidom-parser-adapter-json.browser.min.js +1 -1
- package/es/syntactic-analysis/direct/index.mjs +1 -1
- package/es/syntactic-analysis/direct/visitors/CstVisitor.mjs +138 -151
- package/es/syntactic-analysis/indirect/index.mjs +2 -2
- package/es/syntactic-analysis/indirect/visitors/CstVisitor.mjs +138 -147
- package/es/syntactic-analysis/indirect/visitors/JsonAstVisitor.mjs +129 -136
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.93.0](https://github.com/swagger-api/apidom/compare/v0.92.0...v0.93.0) (2024-01-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-json
|
|
9
|
+
|
|
10
|
+
# [0.92.0](https://github.com/swagger-api/apidom/compare/v0.91.0...v0.92.0) (2024-01-12)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-json
|
|
13
|
+
|
|
6
14
|
# [0.91.0](https://github.com/swagger-api/apidom/compare/v0.90.0...v0.91.0) (2024-01-08)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-json
|
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ You can omit the `mediaType` option here, but please read [Word on detect vs med
|
|
|
117
117
|
import ApiDOMParser from '@swagger-api/apidom-parser';
|
|
118
118
|
import * as jsonParserAdapter from '@swagger-api/apidom-parser-adapter-json';
|
|
119
119
|
|
|
120
|
-
const parser = ApiDOMParser();
|
|
120
|
+
const parser = new ApiDOMParser();
|
|
121
121
|
|
|
122
122
|
parser.use(jsonParserAdapter);
|
|
123
123
|
|
|
@@ -46,7 +46,7 @@ const isNode = element => (0, _apidomCore.isElement)(element) || (0, _apidomAst.
|
|
|
46
46
|
const analyze = (cst, {
|
|
47
47
|
sourceMap = false
|
|
48
48
|
} = {}) => {
|
|
49
|
-
const visitor =
|
|
49
|
+
const visitor = new _CstVisitor.default();
|
|
50
50
|
const cursor = cst.walk();
|
|
51
51
|
const iterator = new _TreeCursorIterator.default(cursor);
|
|
52
52
|
const [rootNode] = Array.from(iterator);
|
|
@@ -3,171 +3,158 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
var _stampit = _interopRequireDefault(require("stampit"));
|
|
7
6
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
7
|
var _TreeCursorSyntaxNode = _interopRequireDefault(require("../../TreeCursorSyntaxNode.cjs"));
|
|
9
8
|
/* eslint-disable no-underscore-dangle */
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
class CstVisitor {
|
|
11
|
+
static toPosition(node) {
|
|
12
|
+
const start = new _apidomCore.ArrayElement([node.startPosition.row, node.startPosition.column, node.startIndex]);
|
|
13
|
+
const end = new _apidomCore.ArrayElement([node.endPosition.row, node.endPosition.column, node.endIndex]);
|
|
14
|
+
start.classes.push('position');
|
|
15
|
+
end.classes.push('position');
|
|
16
|
+
return [start, end];
|
|
17
|
+
}
|
|
18
|
+
sourceMap = false;
|
|
19
|
+
ParseResultElement = {
|
|
20
|
+
leave: element => {
|
|
21
|
+
// mark first-non Annotation element as result
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const elements = element.findElements(_apidomCore.isPrimitiveElement);
|
|
24
|
+
if (elements.length > 0) {
|
|
25
|
+
const resultElement = elements[0];
|
|
26
|
+
resultElement.classes.push('result');
|
|
27
|
+
}
|
|
20
28
|
|
|
29
|
+
// provide annotations
|
|
30
|
+
this.annotations.forEach(annotationElement => {
|
|
31
|
+
element.push(annotationElement);
|
|
32
|
+
});
|
|
33
|
+
this.annotations = [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
constructor() {
|
|
21
37
|
this.annotations = [];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
}
|
|
39
|
+
enter(node) {
|
|
40
|
+
// missing anonymous literals from CST transformed into AnnotationElements.
|
|
41
|
+
if (node instanceof _TreeCursorSyntaxNode.default && !node.isNamed && node.isMissing) {
|
|
42
|
+
// collect annotations from missing literals
|
|
43
|
+
const value = node.type || node.text;
|
|
44
|
+
const message = `(Missing ${value})`;
|
|
45
|
+
const element = new _apidomCore.AnnotationElement(message);
|
|
46
|
+
element.classes.push('warning');
|
|
47
|
+
this.maybeAddSourceMap(node, element);
|
|
48
|
+
this.annotations.push(element);
|
|
49
|
+
}
|
|
50
|
+
return null; // remove everything unrecognized
|
|
51
|
+
}
|
|
52
|
+
document(node) {
|
|
53
|
+
const element = new _apidomCore.ParseResultElement();
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
element._content = node.children;
|
|
56
|
+
this.maybeAddSourceMap(node, element);
|
|
57
|
+
return element;
|
|
58
|
+
}
|
|
59
|
+
object(node) {
|
|
60
|
+
const element = new _apidomCore.ObjectElement();
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
element._content = node.children;
|
|
63
|
+
this.maybeAddSourceMap(node, element);
|
|
64
|
+
return element;
|
|
65
|
+
}
|
|
66
|
+
array(node) {
|
|
67
|
+
const element = new _apidomCore.ArrayElement();
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
element._content = node.children;
|
|
70
|
+
this.maybeAddSourceMap(node, element);
|
|
71
|
+
return element;
|
|
72
|
+
}
|
|
73
|
+
pair(node) {
|
|
74
|
+
const element = new _apidomCore.MemberElement();
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
element.content.key = node.keyNode;
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
element.content.value = node.valueNode;
|
|
79
|
+
this.maybeAddSourceMap(node, element);
|
|
44
80
|
|
|
45
81
|
/**
|
|
46
|
-
*
|
|
82
|
+
* Process possible errors here that may be present in pair node children as we're using direct field access.
|
|
83
|
+
* There are usually 3 children here found: "key", ":", "value".
|
|
47
84
|
*/
|
|
85
|
+
if (node.children.length > 3) {
|
|
86
|
+
node.children.filter(child => child.type === 'ERROR').forEach(errorNode => {
|
|
87
|
+
this.ERROR(errorNode, node, [], [node]);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return element;
|
|
91
|
+
}
|
|
92
|
+
string(node) {
|
|
93
|
+
const element = new _apidomCore.StringElement(JSON.parse(node.text));
|
|
94
|
+
this.maybeAddSourceMap(node, element);
|
|
95
|
+
return element;
|
|
96
|
+
}
|
|
97
|
+
number(node) {
|
|
98
|
+
const element = new _apidomCore.NumberElement(Number(node.text));
|
|
99
|
+
this.maybeAddSourceMap(node, element);
|
|
100
|
+
return element;
|
|
101
|
+
}
|
|
48
102
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const element = new _apidomCore.AnnotationElement(message);
|
|
56
|
-
element.classes.push('warning');
|
|
57
|
-
maybeAddSourceMap(node, element);
|
|
58
|
-
this.annotations.push(element);
|
|
59
|
-
}
|
|
60
|
-
return null; // remove everything unrecognized
|
|
61
|
-
};
|
|
62
|
-
this.document = function document(node) {
|
|
63
|
-
const element = new _apidomCore.ParseResultElement();
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
element._content = node.children;
|
|
66
|
-
maybeAddSourceMap(node, element);
|
|
67
|
-
return element;
|
|
68
|
-
};
|
|
69
|
-
this.ParseResultElement = {
|
|
70
|
-
leave(element) {
|
|
71
|
-
// mark first-non Annotation element as result
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
const elements = element.findElements(_apidomCore.isPrimitiveElement);
|
|
74
|
-
if (elements.length > 0) {
|
|
75
|
-
const resultElement = elements[0];
|
|
76
|
-
resultElement.classes.push('result');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// provide annotations
|
|
80
|
-
this.annotations.forEach(annotationElement => {
|
|
81
|
-
element.push(annotationElement);
|
|
82
|
-
});
|
|
83
|
-
this.annotations = [];
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
this.object = function object(node) {
|
|
87
|
-
const element = new _apidomCore.ObjectElement();
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
element._content = node.children;
|
|
90
|
-
maybeAddSourceMap(node, element);
|
|
91
|
-
return element;
|
|
92
|
-
};
|
|
93
|
-
this.array = function array(node) {
|
|
94
|
-
const element = new _apidomCore.ArrayElement();
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
element._content = node.children;
|
|
97
|
-
maybeAddSourceMap(node, element);
|
|
98
|
-
return element;
|
|
99
|
-
};
|
|
100
|
-
this.pair = function pair(node) {
|
|
101
|
-
const element = new _apidomCore.MemberElement();
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
element.content.key = node.keyNode;
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
element.content.value = node.valueNode;
|
|
106
|
-
maybeAddSourceMap(node, element);
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Process possible errors here that may be present in pair node children as we're using direct field access.
|
|
110
|
-
* There are usually 3 children here found: "key", ":", "value".
|
|
111
|
-
*/
|
|
112
|
-
if (node.children.length > 3) {
|
|
113
|
-
node.children.filter(child => child.type === 'ERROR').forEach(errorNode => {
|
|
114
|
-
this.ERROR(errorNode, node, [], [node]);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return element;
|
|
118
|
-
};
|
|
119
|
-
this.string = function string(node) {
|
|
120
|
-
const element = new _apidomCore.StringElement(JSON.parse(node.text));
|
|
121
|
-
maybeAddSourceMap(node, element);
|
|
122
|
-
return element;
|
|
123
|
-
};
|
|
124
|
-
this.number = function number(node) {
|
|
125
|
-
const element = new _apidomCore.NumberElement(Number(node.text));
|
|
126
|
-
maybeAddSourceMap(node, element);
|
|
127
|
-
return element;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
131
|
-
this.null = function _null(node) {
|
|
132
|
-
const element = new _apidomCore.NullElement();
|
|
133
|
-
maybeAddSourceMap(node, element);
|
|
134
|
-
return element;
|
|
135
|
-
};
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
104
|
+
null(node) {
|
|
105
|
+
const element = new _apidomCore.NullElement();
|
|
106
|
+
this.maybeAddSourceMap(node, element);
|
|
107
|
+
return element;
|
|
108
|
+
}
|
|
136
109
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
111
|
+
true(node) {
|
|
112
|
+
const element = new _apidomCore.BooleanElement(true);
|
|
113
|
+
this.maybeAddSourceMap(node, element);
|
|
114
|
+
return element;
|
|
115
|
+
}
|
|
143
116
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
118
|
+
false(node) {
|
|
119
|
+
const element = new _apidomCore.BooleanElement(false);
|
|
120
|
+
this.maybeAddSourceMap(node, element);
|
|
121
|
+
return element;
|
|
122
|
+
}
|
|
123
|
+
ERROR(node, key, parent, path) {
|
|
124
|
+
// collect errors as annotations
|
|
125
|
+
const isUnexpected = !node.hasError;
|
|
126
|
+
const value = node.text;
|
|
127
|
+
const message = isUnexpected ? `(Unexpected ${value})` : `(Error ${value})`;
|
|
128
|
+
const element = new _apidomCore.AnnotationElement(message);
|
|
129
|
+
element.classes.push('error');
|
|
130
|
+
this.maybeAddSourceMap(node, element);
|
|
131
|
+
if (path.length === 0) {
|
|
132
|
+
// no document to visit, only error is present in CST
|
|
133
|
+
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
134
|
+
parseResultElement.push(element);
|
|
135
|
+
return parseResultElement;
|
|
136
|
+
}
|
|
164
137
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
138
|
+
// we have CST node for document
|
|
139
|
+
this.annotations.push(element);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
maybeAddSourceMap(node, element) {
|
|
143
|
+
if (!this.sourceMap) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const sourceMap = new _apidomCore.SourceMapElement();
|
|
147
|
+
const position = CstVisitor.toPosition(node);
|
|
148
|
+
if (position !== null) {
|
|
149
|
+
const [start, end] = position;
|
|
150
|
+
sourceMap.push(start);
|
|
151
|
+
sourceMap.push(end);
|
|
152
|
+
}
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
sourceMap.astNode = node;
|
|
155
|
+
element.meta.set('sourceMap', sourceMap);
|
|
169
156
|
}
|
|
170
|
-
}
|
|
157
|
+
}
|
|
171
158
|
|
|
172
159
|
/* eslint-enable no-underscore-dangle */
|
|
173
160
|
var _default = exports.default = CstVisitor;
|
|
@@ -29,8 +29,8 @@ const analyze = (cst, {
|
|
|
29
29
|
const cursor = cst.walk();
|
|
30
30
|
const iterator = new _TreeCursorIterator.default(cursor);
|
|
31
31
|
const [rootNode] = Array.from(iterator);
|
|
32
|
-
const cstVisitor =
|
|
33
|
-
const astVisitor =
|
|
32
|
+
const cstVisitor = new _CstVisitor.default();
|
|
33
|
+
const astVisitor = new _JsonAstVisitor.default();
|
|
34
34
|
const jsonAst = (0, _apidomAst.visit)(rootNode, cstVisitor, {
|
|
35
35
|
// @ts-ignore
|
|
36
36
|
keyMap: _CstVisitor.keyMap,
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.keyMap = exports.default = void 0;
|
|
6
|
-
var _stampit = _interopRequireDefault(require("stampit"));
|
|
7
6
|
var _apidomAst = require("@swagger-api/apidom-ast");
|
|
8
7
|
var _TreeCursorSyntaxNode = _interopRequireDefault(require("../../TreeCursorSyntaxNode.cjs"));
|
|
9
8
|
const keyMap = exports.keyMap = {
|
|
@@ -15,166 +14,158 @@ const keyMap = exports.keyMap = {
|
|
|
15
14
|
key: ['children'],
|
|
16
15
|
error: ['children']
|
|
17
16
|
};
|
|
18
|
-
const CstVisitor = (0, _stampit.default)({
|
|
19
|
-
init() {
|
|
20
|
-
/**
|
|
21
|
-
* Private API.
|
|
22
|
-
*/
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
const start = (0, _apidomAst.Point)({
|
|
26
|
-
row: node.startPosition.row,
|
|
27
|
-
column: node.startPosition.column,
|
|
28
|
-
char: node.startIndex
|
|
29
|
-
});
|
|
30
|
-
const end = (0, _apidomAst.Point)({
|
|
31
|
-
row: node.endPosition.row,
|
|
32
|
-
column: node.endPosition.column,
|
|
33
|
-
char: node.endIndex
|
|
34
|
-
});
|
|
35
|
-
return (0, _apidomAst.Position)({
|
|
36
|
-
start,
|
|
37
|
-
end
|
|
38
|
-
});
|
|
39
|
-
};
|
|
18
|
+
/* eslint-disable class-methods-use-this */
|
|
40
19
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
enter(node) {
|
|
63
|
-
const position = toPosition(node);
|
|
64
|
-
return (0, _apidomAst.JsonDocument)({
|
|
65
|
-
children: node.children,
|
|
66
|
-
position,
|
|
67
|
-
isMissing: node.isMissing
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
leave(document) {
|
|
71
|
-
return (0, _apidomAst.ParseResult)({
|
|
72
|
-
children: [document]
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
this.object = function object(node) {
|
|
77
|
-
const position = toPosition(node);
|
|
78
|
-
return (0, _apidomAst.JsonObject)({
|
|
20
|
+
class CstVisitor {
|
|
21
|
+
static toPosition(node) {
|
|
22
|
+
const start = new _apidomAst.Point({
|
|
23
|
+
row: node.startPosition.row,
|
|
24
|
+
column: node.startPosition.column,
|
|
25
|
+
char: node.startIndex
|
|
26
|
+
});
|
|
27
|
+
const end = new _apidomAst.Point({
|
|
28
|
+
row: node.endPosition.row,
|
|
29
|
+
column: node.endPosition.column,
|
|
30
|
+
char: node.endIndex
|
|
31
|
+
});
|
|
32
|
+
return new _apidomAst.Position({
|
|
33
|
+
start,
|
|
34
|
+
end
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
document = {
|
|
38
|
+
enter: node => {
|
|
39
|
+
const position = CstVisitor.toPosition(node);
|
|
40
|
+
return new _apidomAst.JsonDocument({
|
|
79
41
|
children: node.children,
|
|
80
42
|
position,
|
|
81
43
|
isMissing: node.isMissing
|
|
82
44
|
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
45
|
+
},
|
|
46
|
+
leave: document => {
|
|
47
|
+
return new _apidomAst.ParseResult({
|
|
48
|
+
children: [document]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
enter(node) {
|
|
53
|
+
// anonymous literals from CST transformed into AST literal nodes
|
|
54
|
+
if (node instanceof _TreeCursorSyntaxNode.default && !node.isNamed) {
|
|
55
|
+
const position = CstVisitor.toPosition(node);
|
|
56
|
+
const value = node.type || node.text;
|
|
87
57
|
const {
|
|
88
|
-
|
|
58
|
+
isMissing
|
|
89
59
|
} = node;
|
|
90
|
-
|
|
91
|
-
children: (keyNode == null ? void 0 : keyNode.children) || [],
|
|
92
|
-
position: keyNode != null ? toPosition(keyNode) : null,
|
|
93
|
-
isMissing: keyNode != null ? keyNode.isMissing : false
|
|
94
|
-
});
|
|
95
|
-
return (0, _apidomAst.JsonProperty)({
|
|
96
|
-
children: [key, ...children],
|
|
97
|
-
position,
|
|
98
|
-
isMissing: node.isMissing
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
this.array = function array(node) {
|
|
102
|
-
const position = toPosition(node);
|
|
103
|
-
return (0, _apidomAst.JsonArray)({
|
|
104
|
-
children: node.children,
|
|
105
|
-
position,
|
|
106
|
-
isMissing: node.isMissing
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
this.string = function string(node) {
|
|
110
|
-
const position = toPosition(node);
|
|
111
|
-
const content = (0, _apidomAst.JsonStringContent)({
|
|
112
|
-
value: JSON.parse(node.text)
|
|
113
|
-
});
|
|
114
|
-
return (0, _apidomAst.JsonString)({
|
|
115
|
-
children: [content],
|
|
116
|
-
position,
|
|
117
|
-
isMissing: node.isMissing
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
this.number = function number(node) {
|
|
121
|
-
const position = toPosition(node);
|
|
122
|
-
const value = node.text;
|
|
123
|
-
return (0, _apidomAst.JsonNumber)({
|
|
60
|
+
return new _apidomAst.Literal({
|
|
124
61
|
value,
|
|
125
62
|
position,
|
|
126
|
-
isMissing
|
|
63
|
+
isMissing
|
|
127
64
|
});
|
|
128
|
-
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
object(node) {
|
|
69
|
+
const position = CstVisitor.toPosition(node);
|
|
70
|
+
return new _apidomAst.JsonObject({
|
|
71
|
+
children: node.children,
|
|
72
|
+
position,
|
|
73
|
+
isMissing: node.isMissing
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
pair(node) {
|
|
77
|
+
const position = CstVisitor.toPosition(node);
|
|
78
|
+
const children = node.children.slice(1);
|
|
79
|
+
const {
|
|
80
|
+
keyNode
|
|
81
|
+
} = node;
|
|
82
|
+
const key = new _apidomAst.JsonKey({
|
|
83
|
+
children: (keyNode == null ? void 0 : keyNode.children) || [],
|
|
84
|
+
position: keyNode != null ? CstVisitor.toPosition(keyNode) : undefined,
|
|
85
|
+
isMissing: keyNode != null ? keyNode.isMissing : false
|
|
86
|
+
});
|
|
87
|
+
return new _apidomAst.JsonProperty({
|
|
88
|
+
children: [key, ...children],
|
|
89
|
+
position,
|
|
90
|
+
isMissing: node.isMissing
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
array(node) {
|
|
94
|
+
const position = CstVisitor.toPosition(node);
|
|
95
|
+
return new _apidomAst.JsonArray({
|
|
96
|
+
children: node.children,
|
|
97
|
+
position,
|
|
98
|
+
isMissing: node.isMissing
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
string(node) {
|
|
102
|
+
const position = CstVisitor.toPosition(node);
|
|
103
|
+
const content = new _apidomAst.JsonStringContent({
|
|
104
|
+
value: JSON.parse(node.text)
|
|
105
|
+
});
|
|
106
|
+
return new _apidomAst.JsonString({
|
|
107
|
+
children: [content],
|
|
108
|
+
position,
|
|
109
|
+
isMissing: node.isMissing
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
number(node) {
|
|
113
|
+
const position = CstVisitor.toPosition(node);
|
|
114
|
+
const value = node.text;
|
|
115
|
+
return new _apidomAst.JsonNumber({
|
|
116
|
+
value,
|
|
117
|
+
position,
|
|
118
|
+
isMissing: node.isMissing
|
|
119
|
+
});
|
|
120
|
+
}
|
|
129
121
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
123
|
+
null(node) {
|
|
124
|
+
const position = CstVisitor.toPosition(node);
|
|
125
|
+
const value = node.text;
|
|
126
|
+
return new _apidomAst.JsonNull({
|
|
127
|
+
value,
|
|
128
|
+
position,
|
|
129
|
+
isMissing: node.isMissing
|
|
130
|
+
});
|
|
131
|
+
}
|
|
140
132
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
134
|
+
true(node) {
|
|
135
|
+
const position = CstVisitor.toPosition(node);
|
|
136
|
+
const value = node.text;
|
|
137
|
+
return new _apidomAst.JsonTrue({
|
|
138
|
+
value,
|
|
139
|
+
position,
|
|
140
|
+
isMissing: node.isMissing
|
|
141
|
+
});
|
|
142
|
+
}
|
|
151
143
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
145
|
+
false(node) {
|
|
146
|
+
const position = CstVisitor.toPosition(node);
|
|
147
|
+
const value = node.text;
|
|
148
|
+
return new _apidomAst.JsonFalse({
|
|
149
|
+
value,
|
|
150
|
+
position,
|
|
151
|
+
isMissing: node.isMissing
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
ERROR(node, key, parent, path) {
|
|
155
|
+
const position = CstVisitor.toPosition(node);
|
|
156
|
+
const errorNode = new _apidomAst.Error({
|
|
157
|
+
children: node.children,
|
|
158
|
+
position,
|
|
159
|
+
isUnexpected: !node.hasError,
|
|
160
|
+
isMissing: node.isMissing,
|
|
161
|
+
value: node.text
|
|
162
|
+
});
|
|
163
|
+
if (path.length === 0) {
|
|
164
|
+
return new _apidomAst.ParseResult({
|
|
165
|
+
children: [errorNode]
|
|
170
166
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
children: [errorNode]
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
return errorNode;
|
|
177
|
-
};
|
|
167
|
+
}
|
|
168
|
+
return errorNode;
|
|
178
169
|
}
|
|
179
|
-
}
|
|
170
|
+
}
|
|
180
171
|
var _default = exports.default = CstVisitor;
|