@swagger-api/apidom-parser-adapter-json 0.91.0 → 0.92.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 +4 -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 +447 -482
- 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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import stampit from 'stampit';
|
|
2
1
|
import { JsonArray, JsonDocument, JsonObject, JsonProperty, ParseResult, Error, isNode as isCSTNode, getNodeType as getCSTNodeType } from '@swagger-api/apidom-ast';
|
|
3
2
|
import { ParseResultElement, ObjectElement, SourceMapElement, MemberElement, ArrayElement, BooleanElement, NullElement, NumberElement, StringElement, AnnotationElement, isParseResultElement, isPrimitiveElement, isElement, keyMap as keyMapApiDOM, getNodeType as getNodeTypeApiDOM } from '@swagger-api/apidom-core';
|
|
4
3
|
export const keyMap = {
|
|
@@ -29,150 +28,144 @@ export const isNode = element => isElement(element) || isCSTNode(element);
|
|
|
29
28
|
|
|
30
29
|
/* eslint-disable no-underscore-dangle */
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
init() {
|
|
38
|
-
/**
|
|
39
|
-
* Private API.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
this.annotation = [];
|
|
43
|
-
const maybeAddSourceMap = (node, element) => {
|
|
44
|
-
if (!this.sourceMap) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const sourceMap = new SourceMapElement();
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
sourceMap.position = node.position;
|
|
31
|
+
class JsonAstVisitor {
|
|
32
|
+
sourceMap = false;
|
|
33
|
+
ParseResultElement = {
|
|
34
|
+
leave: element => {
|
|
35
|
+
// mark first-non Annotation element as result
|
|
50
36
|
// @ts-ignore
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* Public API.
|
|
57
|
-
*/
|
|
37
|
+
const elements = element.findElements(isPrimitiveElement);
|
|
38
|
+
if (elements.length > 0) {
|
|
39
|
+
const resultElement = elements[0];
|
|
40
|
+
resultElement.classes.push('result');
|
|
41
|
+
}
|
|
58
42
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const elements = element.findElements(isPrimitiveElement);
|
|
70
|
-
if (elements.length > 0) {
|
|
71
|
-
const resultElement = elements[0];
|
|
72
|
-
resultElement.classes.push('result');
|
|
73
|
-
}
|
|
43
|
+
// provide annotations
|
|
44
|
+
this.annotations.forEach(annotationElement => {
|
|
45
|
+
element.push(annotationElement);
|
|
46
|
+
});
|
|
47
|
+
this.annotations = [];
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
constructor() {
|
|
51
|
+
this.annotations = [];
|
|
52
|
+
}
|
|
74
53
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
54
|
+
// eslint-disable-next-line class-methods-use-this
|
|
55
|
+
document(node) {
|
|
56
|
+
const element = new ParseResultElement();
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
element._content = node.children;
|
|
59
|
+
return element;
|
|
60
|
+
}
|
|
61
|
+
object(node) {
|
|
62
|
+
const element = new ObjectElement();
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
element._content = node.children;
|
|
65
|
+
this.maybeAddSourceMap(node, element);
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
property(node) {
|
|
69
|
+
const element = new MemberElement();
|
|
91
70
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
element.content.key = node.key;
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
element.content.value = node.value;
|
|
75
|
+
this.maybeAddSourceMap(node, element);
|
|
97
76
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Process possible errors here that may be present in pair node children as we're using direct field access.
|
|
79
|
+
* There are usually 3 children here found: "key", ":", "value".
|
|
80
|
+
*/
|
|
81
|
+
if (node.children.length > 3) {
|
|
82
|
+
node.children
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
.filter(child => child.type === 'error')
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
.forEach(errorNode => {
|
|
87
|
+
this.error(errorNode, node, [], [node]);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return element;
|
|
91
|
+
}
|
|
92
|
+
key(node) {
|
|
93
|
+
const element = new StringElement(node.value);
|
|
94
|
+
this.maybeAddSourceMap(node, element);
|
|
95
|
+
return element;
|
|
96
|
+
}
|
|
97
|
+
array(node) {
|
|
98
|
+
const element = new ArrayElement();
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
element._content = node.children;
|
|
101
|
+
this.maybeAddSourceMap(node, element);
|
|
102
|
+
return element;
|
|
103
|
+
}
|
|
104
|
+
string(node) {
|
|
105
|
+
const element = new StringElement(node.value);
|
|
106
|
+
this.maybeAddSourceMap(node, element);
|
|
107
|
+
return element;
|
|
108
|
+
}
|
|
109
|
+
number(node) {
|
|
110
|
+
const element = new NumberElement(Number(node.value));
|
|
111
|
+
this.maybeAddSourceMap(node, element);
|
|
112
|
+
return element;
|
|
113
|
+
}
|
|
131
114
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
116
|
+
null(node) {
|
|
117
|
+
const element = new NullElement();
|
|
118
|
+
this.maybeAddSourceMap(node, element);
|
|
119
|
+
return element;
|
|
120
|
+
}
|
|
138
121
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
123
|
+
true(node) {
|
|
124
|
+
const element = new BooleanElement(true);
|
|
125
|
+
this.maybeAddSourceMap(node, element);
|
|
126
|
+
return element;
|
|
127
|
+
}
|
|
145
128
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const element = new AnnotationElement(message);
|
|
156
|
-
element.classes.push('warning');
|
|
157
|
-
maybeAddSourceMap(node, element);
|
|
158
|
-
this.annotations.push(element);
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
};
|
|
162
|
-
this.error = function error(node, key, parent, path) {
|
|
163
|
-
const message = node.isUnexpected ? `(Unexpected ${node.value})` : `(Error ${node.value})`;
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
130
|
+
false(node) {
|
|
131
|
+
const element = new BooleanElement(false);
|
|
132
|
+
this.maybeAddSourceMap(node, element);
|
|
133
|
+
return element;
|
|
134
|
+
}
|
|
135
|
+
literal(node) {
|
|
136
|
+
if (node.isMissing) {
|
|
137
|
+
const message = `(Missing ${node.value})`;
|
|
164
138
|
const element = new AnnotationElement(message);
|
|
165
|
-
element.classes.push('
|
|
166
|
-
maybeAddSourceMap(node, element);
|
|
167
|
-
if (path.length === 0) {
|
|
168
|
-
// no document to visit, only error is present in CST
|
|
169
|
-
const parseResultElement = new ParseResultElement();
|
|
170
|
-
parseResultElement.push(element);
|
|
171
|
-
return parseResultElement;
|
|
172
|
-
}
|
|
139
|
+
element.classes.push('warning');
|
|
140
|
+
this.maybeAddSourceMap(node, element);
|
|
173
141
|
this.annotations.push(element);
|
|
174
|
-
|
|
175
|
-
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
error(node, key, parent, path) {
|
|
146
|
+
const message = node.isUnexpected ? `(Unexpected ${node.value})` : `(Error ${node.value})`;
|
|
147
|
+
const element = new AnnotationElement(message);
|
|
148
|
+
element.classes.push('error');
|
|
149
|
+
this.maybeAddSourceMap(node, element);
|
|
150
|
+
if (path.length === 0) {
|
|
151
|
+
// no document to visit, only error is present in CST
|
|
152
|
+
const parseResultElement = new ParseResultElement();
|
|
153
|
+
parseResultElement.push(element);
|
|
154
|
+
return parseResultElement;
|
|
155
|
+
}
|
|
156
|
+
this.annotations.push(element);
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
maybeAddSourceMap(node, element) {
|
|
160
|
+
if (!this.sourceMap) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const sourceMap = new SourceMapElement();
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
sourceMap.position = node.position;
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
sourceMap.astNode = node;
|
|
168
|
+
element.meta.set('sourceMap', sourceMap);
|
|
176
169
|
}
|
|
177
|
-
}
|
|
170
|
+
}
|
|
178
171
|
export default JsonAstVisitor;
|
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.92.0",
|
|
4
4
|
"description": "Parser adapter for parsing JSON documents into base namespace.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -53,13 +53,12 @@
|
|
|
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
|
-
"@swagger-api/apidom-error": "^0.
|
|
56
|
+
"@swagger-api/apidom-ast": "^0.92.0",
|
|
57
|
+
"@swagger-api/apidom-core": "^0.92.0",
|
|
58
|
+
"@swagger-api/apidom-error": "^0.92.0",
|
|
59
59
|
"@types/ramda": "~0.29.6",
|
|
60
60
|
"ramda": "~0.29.1",
|
|
61
61
|
"ramda-adjunct": "^4.1.1",
|
|
62
|
-
"stampit": "^4.3.2",
|
|
63
62
|
"tree-sitter": "=0.20.4",
|
|
64
63
|
"tree-sitter-json": "=0.20.1",
|
|
65
64
|
"web-tree-sitter": "=0.20.3"
|
|
@@ -78,5 +77,5 @@
|
|
|
78
77
|
"README.md",
|
|
79
78
|
"CHANGELOG.md"
|
|
80
79
|
],
|
|
81
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "c7a45ee8d68ac82ac2ab93ebb639a95ced1d6e86"
|
|
82
81
|
}
|