@aeriajs/compiler 0.0.33 → 0.0.35
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/dist/ast.d.ts +1 -0
- package/dist/parser.js +13 -3
- package/dist/parser.mjs +13 -3
- package/dist/semantic.js +18 -5
- package/dist/semantic.mjs +16 -5
- package/package.json +1 -1
package/dist/ast.d.ts
CHANGED
package/dist/parser.js
CHANGED
|
@@ -191,11 +191,15 @@ const parse = (tokens) => {
|
|
|
191
191
|
};
|
|
192
192
|
const parseArrayBlockWithAttributes = (allowedAttributes, cb) => {
|
|
193
193
|
const array = {};
|
|
194
|
+
const symbols = [];
|
|
194
195
|
let hasAttributes = false;
|
|
195
196
|
consume(token_js_1.TokenType.LeftBracket);
|
|
196
197
|
while (!match(token_js_1.TokenType.RightBracket)) {
|
|
197
|
-
const { value: identifier } = consume(token_js_1.TokenType.Identifier);
|
|
198
|
+
const { value: identifier, location } = consume(token_js_1.TokenType.Identifier);
|
|
198
199
|
array[identifier] = true;
|
|
200
|
+
const elemSymbol = Symbol();
|
|
201
|
+
symbols.push(elemSymbol);
|
|
202
|
+
exports.locationMap.set(elemSymbol, location);
|
|
199
203
|
if (match(token_js_1.TokenType.AttributeName)) {
|
|
200
204
|
hasAttributes = true;
|
|
201
205
|
}
|
|
@@ -206,9 +210,13 @@ const parse = (tokens) => {
|
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
consume(token_js_1.TokenType.RightBracket);
|
|
209
|
-
|
|
213
|
+
const value = hasAttributes
|
|
210
214
|
? array
|
|
211
215
|
: Object.keys(array);
|
|
216
|
+
return {
|
|
217
|
+
value,
|
|
218
|
+
symbols,
|
|
219
|
+
};
|
|
212
220
|
};
|
|
213
221
|
const parsePropertyAttributeValue = (attributeName, property, location) => {
|
|
214
222
|
const consumeBoolean = () => {
|
|
@@ -711,7 +719,7 @@ const parse = (tokens) => {
|
|
|
711
719
|
break;
|
|
712
720
|
}
|
|
713
721
|
case 'required': {
|
|
714
|
-
|
|
722
|
+
const { value, symbols } = parseArrayBlockWithAttributes(['if'], (attributeName, array, identifier) => {
|
|
715
723
|
switch (attributeName) {
|
|
716
724
|
case 'if': {
|
|
717
725
|
const ifTerms = [];
|
|
@@ -721,6 +729,8 @@ const parse = (tokens) => {
|
|
|
721
729
|
}
|
|
722
730
|
}
|
|
723
731
|
});
|
|
732
|
+
node.required = value;
|
|
733
|
+
node[AST.LOCATION_SYMBOL].required = symbols;
|
|
724
734
|
break;
|
|
725
735
|
}
|
|
726
736
|
case 'presets': {
|
package/dist/parser.mjs
CHANGED
|
@@ -153,11 +153,15 @@ export const parse = (tokens) => {
|
|
|
153
153
|
};
|
|
154
154
|
const parseArrayBlockWithAttributes = (allowedAttributes, cb) => {
|
|
155
155
|
const array = {};
|
|
156
|
+
const symbols = [];
|
|
156
157
|
let hasAttributes = false;
|
|
157
158
|
consume(TokenType.LeftBracket);
|
|
158
159
|
while (!match(TokenType.RightBracket)) {
|
|
159
|
-
const { value: identifier } = consume(TokenType.Identifier);
|
|
160
|
+
const { value: identifier, location } = consume(TokenType.Identifier);
|
|
160
161
|
array[identifier] = true;
|
|
162
|
+
const elemSymbol = Symbol();
|
|
163
|
+
symbols.push(elemSymbol);
|
|
164
|
+
locationMap.set(elemSymbol, location);
|
|
161
165
|
if (match(TokenType.AttributeName)) {
|
|
162
166
|
hasAttributes = true;
|
|
163
167
|
}
|
|
@@ -168,7 +172,11 @@ export const parse = (tokens) => {
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
consume(TokenType.RightBracket);
|
|
171
|
-
|
|
175
|
+
const value = hasAttributes ? array : Object.keys(array);
|
|
176
|
+
return {
|
|
177
|
+
value,
|
|
178
|
+
symbols
|
|
179
|
+
};
|
|
172
180
|
};
|
|
173
181
|
const parsePropertyAttributeValue = (attributeName, property, location) => {
|
|
174
182
|
const consumeBoolean = () => {
|
|
@@ -657,7 +665,7 @@ export const parse = (tokens) => {
|
|
|
657
665
|
break;
|
|
658
666
|
}
|
|
659
667
|
case "required": {
|
|
660
|
-
|
|
668
|
+
const { value, symbols } = parseArrayBlockWithAttributes(["if"], (attributeName, array, identifier) => {
|
|
661
669
|
switch (attributeName) {
|
|
662
670
|
case "if": {
|
|
663
671
|
const ifTerms = [];
|
|
@@ -667,6 +675,8 @@ export const parse = (tokens) => {
|
|
|
667
675
|
}
|
|
668
676
|
}
|
|
669
677
|
});
|
|
678
|
+
node.required = value;
|
|
679
|
+
node[AST.LOCATION_SYMBOL].required = symbols;
|
|
670
680
|
break;
|
|
671
681
|
}
|
|
672
682
|
case "presets": {
|
package/dist/semantic.js
CHANGED
|
@@ -41,10 +41,10 @@ const AST = __importStar(require("./ast.js"));
|
|
|
41
41
|
const collectionHasProperty = async (collection, propName, options) => {
|
|
42
42
|
let hasProperty = propName in collection.properties;
|
|
43
43
|
if (!hasProperty) {
|
|
44
|
-
if (options.languageServer) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
44
|
if (collection.extends) {
|
|
45
|
+
if (options.languageServer) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
48
|
const { packageName, symbolName } = collection.extends;
|
|
49
49
|
const { [symbolName]: importedCollection } = await Promise.resolve(`${packageName}`).then(s => __importStar(require(s)));
|
|
50
50
|
if (!(0, common_1.isValidCollection)(importedCollection)) {
|
|
@@ -76,8 +76,8 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
76
76
|
}
|
|
77
77
|
for (const index in node[attributeName]) {
|
|
78
78
|
const propName = node[attributeName][index];
|
|
79
|
-
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
80
79
|
if (!await collectionHasProperty(node, propName, options)) {
|
|
80
|
+
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
81
81
|
const location = parser_js_1.locationMap.get(symbol);
|
|
82
82
|
errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
83
83
|
}
|
|
@@ -89,8 +89,8 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
89
89
|
}
|
|
90
90
|
for (const index in node.property[attributeName]) {
|
|
91
91
|
const propName = node.property[attributeName][index];
|
|
92
|
-
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
93
92
|
if (!(propName in node.property.properties)) {
|
|
93
|
+
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
94
94
|
const location = parser_js_1.locationMap.get(symbol);
|
|
95
95
|
errors.push(new diagnostic_js_1.Diagnostic(`object hasn't such property "${propName}"`, location));
|
|
96
96
|
}
|
|
@@ -136,6 +136,19 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
136
136
|
await checkCollectionLocalProperties(node, 'form');
|
|
137
137
|
await checkCollectionLocalProperties(node, 'table');
|
|
138
138
|
await checkCollectionLocalProperties(node, 'tableMeta');
|
|
139
|
+
if (node.required) {
|
|
140
|
+
const propNames = Array.isArray(node.required)
|
|
141
|
+
? node.required
|
|
142
|
+
: Object.keys(node.required);
|
|
143
|
+
for (const index in propNames) {
|
|
144
|
+
const propName = propNames[index];
|
|
145
|
+
if (!(propName in node.properties)) {
|
|
146
|
+
const symbol = node[AST.LOCATION_SYMBOL].required[index];
|
|
147
|
+
const location = parser_js_1.locationMap.get(symbol);
|
|
148
|
+
errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
139
152
|
for (const propName in node.properties) {
|
|
140
153
|
const subNode = node.properties[propName];
|
|
141
154
|
await recurseProperty(subNode);
|
package/dist/semantic.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import * as AST from "./ast.mjs";
|
|
|
6
6
|
const collectionHasProperty = async (collection, propName, options) => {
|
|
7
7
|
let hasProperty = propName in collection.properties;
|
|
8
8
|
if (!hasProperty) {
|
|
9
|
-
if (options.languageServer) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
9
|
if (collection.extends) {
|
|
10
|
+
if (options.languageServer) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
13
|
const { packageName, symbolName } = collection.extends;
|
|
14
14
|
const { [symbolName]: importedCollection } = await import(packageName);
|
|
15
15
|
if (!isValidCollection(importedCollection)) {
|
|
@@ -41,8 +41,8 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
41
41
|
}
|
|
42
42
|
for (const index in node[attributeName]) {
|
|
43
43
|
const propName = node[attributeName][index];
|
|
44
|
-
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
45
44
|
if (!await collectionHasProperty(node, propName, options)) {
|
|
45
|
+
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
46
46
|
const location = locationMap.get(symbol);
|
|
47
47
|
errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
48
48
|
}
|
|
@@ -54,8 +54,8 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
54
54
|
}
|
|
55
55
|
for (const index in node.property[attributeName]) {
|
|
56
56
|
const propName = node.property[attributeName][index];
|
|
57
|
-
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
58
57
|
if (!(propName in node.property.properties)) {
|
|
58
|
+
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
59
59
|
const location = locationMap.get(symbol);
|
|
60
60
|
errors.push(new Diagnostic(`object hasn't such property "${propName}"`, location));
|
|
61
61
|
}
|
|
@@ -99,6 +99,17 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
99
99
|
await checkCollectionLocalProperties(node, "form");
|
|
100
100
|
await checkCollectionLocalProperties(node, "table");
|
|
101
101
|
await checkCollectionLocalProperties(node, "tableMeta");
|
|
102
|
+
if (node.required) {
|
|
103
|
+
const propNames = Array.isArray(node.required) ? node.required : Object.keys(node.required);
|
|
104
|
+
for (const index in propNames) {
|
|
105
|
+
const propName = propNames[index];
|
|
106
|
+
if (!(propName in node.properties)) {
|
|
107
|
+
const symbol = node[AST.LOCATION_SYMBOL].required[index];
|
|
108
|
+
const location = locationMap.get(symbol);
|
|
109
|
+
errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
102
113
|
for (const propName in node.properties) {
|
|
103
114
|
const subNode = node.properties[propName];
|
|
104
115
|
await recurseProperty(subNode);
|