@aeriajs/compiler 0.0.63 → 0.0.64
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/semantic.js +12 -10
- package/package.json +1 -1
package/dist/semantic.js
CHANGED
|
@@ -2,8 +2,11 @@ import { isValidCollection } from '@aeriajs/common';
|
|
|
2
2
|
import { locationMap } from './parser.js';
|
|
3
3
|
import { Diagnostic } from './diagnostic.js';
|
|
4
4
|
import * as AST from './ast.js';
|
|
5
|
+
const containsPropertyWithId = (propName, properties) => {
|
|
6
|
+
return propName === '_id' || propName in properties;
|
|
7
|
+
};
|
|
5
8
|
const collectionHasProperty = async (collection, propName, options = {}) => {
|
|
6
|
-
let hasProperty = propName
|
|
9
|
+
let hasProperty = containsPropertyWithId(propName, collection.properties);
|
|
7
10
|
if (!hasProperty) {
|
|
8
11
|
if (collection.extends) {
|
|
9
12
|
if (options.languageServer) {
|
|
@@ -14,7 +17,7 @@ const collectionHasProperty = async (collection, propName, options = {}) => {
|
|
|
14
17
|
if (!isValidCollection(importedCollection)) {
|
|
15
18
|
throw new Error;
|
|
16
19
|
}
|
|
17
|
-
hasProperty = propName
|
|
20
|
+
hasProperty = containsPropertyWithId(propName, importedCollection.description.properties);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
return hasProperty;
|
|
@@ -56,7 +59,6 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
56
59
|
if (!(propName in node.nestedProperties)) {
|
|
57
60
|
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
58
61
|
const location = locationMap.get(symbol);
|
|
59
|
-
console.log(JSON.stringify(node));
|
|
60
62
|
errors.push(new Diagnostic(`object hasn't such property "${propName}"`, location));
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -115,7 +117,7 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
115
117
|
: Object.keys(node.required);
|
|
116
118
|
for (const index in propNames) {
|
|
117
119
|
const propName = propNames[index];
|
|
118
|
-
if (!(propName
|
|
120
|
+
if (!containsPropertyWithId(propName, node.properties)) {
|
|
119
121
|
const symbol = node[AST.LOCATION_SYMBOL].required[index];
|
|
120
122
|
const location = locationMap.get(symbol);
|
|
121
123
|
errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
@@ -128,7 +130,7 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
128
130
|
}
|
|
129
131
|
if (node[AST.LOCATION_SYMBOL].requiredTerms) {
|
|
130
132
|
for (const [name, symbol] of node[AST.LOCATION_SYMBOL].requiredTerms) {
|
|
131
|
-
if (!(name
|
|
133
|
+
if (!containsPropertyWithId(name, node.properties)) {
|
|
132
134
|
const location = locationMap.get(symbol);
|
|
133
135
|
errors.push(new Diagnostic(`invalid left operand "${name}"`, location));
|
|
134
136
|
}
|
|
@@ -140,14 +142,14 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
140
142
|
const option = node.layout.options[name];
|
|
141
143
|
if (Array.isArray(option)) {
|
|
142
144
|
for (const [i, propName] of option.entries()) {
|
|
143
|
-
if (!(propName
|
|
145
|
+
if (!containsPropertyWithId(propName, node.properties)) {
|
|
144
146
|
const location = locationMap.get(value[i]);
|
|
145
147
|
errors.push(new Diagnostic(`invalid property "${propName}"`, location));
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
else {
|
|
150
|
-
if (!(option
|
|
152
|
+
if (!containsPropertyWithId(option, node.properties)) {
|
|
151
153
|
const location = locationMap.get(value);
|
|
152
154
|
errors.push(new Diagnostic(`invalid property "${option}"`, location));
|
|
153
155
|
}
|
|
@@ -158,7 +160,7 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
158
160
|
if (node.formLayout) {
|
|
159
161
|
if (node.formLayout.fields) {
|
|
160
162
|
for (const [name, value] of Object.entries(node.formLayout[AST.LOCATION_SYMBOL].fields)) {
|
|
161
|
-
if (!(name
|
|
163
|
+
if (!containsPropertyWithId(name, node.properties)) {
|
|
162
164
|
const location = locationMap.get(value.name);
|
|
163
165
|
errors.push(new Diagnostic(`invalid property "${name}"`, location));
|
|
164
166
|
}
|
|
@@ -166,7 +168,7 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
166
168
|
}
|
|
167
169
|
if (node.formLayout[AST.LOCATION_SYMBOL].terms) {
|
|
168
170
|
for (const [name, symbol] of node.formLayout[AST.LOCATION_SYMBOL].terms) {
|
|
169
|
-
if (!(name
|
|
171
|
+
if (!containsPropertyWithId(name, node.properties)) {
|
|
170
172
|
const location = locationMap.get(symbol);
|
|
171
173
|
errors.push(new Diagnostic(`invalid left operand "${name}"`, location));
|
|
172
174
|
}
|
|
@@ -176,7 +178,7 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
176
178
|
if (node.search) {
|
|
177
179
|
for (const [i, symbol] of node[AST.LOCATION_SYMBOL].searchIndexes.entries()) {
|
|
178
180
|
const propName = node.search.indexes[i];
|
|
179
|
-
if (!(propName
|
|
181
|
+
if (!containsPropertyWithId(propName, node.properties)) {
|
|
180
182
|
const location = locationMap.get(symbol);
|
|
181
183
|
errors.push(new Diagnostic(`invalid property "${propName}"`, location));
|
|
182
184
|
}
|