@aeriajs/compiler 0.0.34 → 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 CHANGED
@@ -79,6 +79,7 @@ export type CollectionNode = NodeBase<'collection'> & {
79
79
  arrays: {
80
80
  [P in ArrayProperties<CollectionNode>]?: symbol[];
81
81
  };
82
+ required?: symbol[];
82
83
  requiredTerms?: readonly [string, symbol][];
83
84
  };
84
85
  };
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
- return hasAttributes
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
- node.required = parseArrayBlockWithAttributes(['if'], (attributeName, array, identifier) => {
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
- return hasAttributes ? array : Object.keys(array);
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
- node.required = parseArrayBlockWithAttributes(["if"], (attributeName, array, identifier) => {
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
@@ -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
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",