@aeriajs/compiler 0.0.4 → 0.0.7
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 +79 -0
- package/dist/ast.js +23 -0
- package/dist/ast.mjs +21 -0
- package/dist/codegen/generateContracts.d.ts +5 -0
- package/dist/codegen/generateContracts.js +84 -0
- package/dist/codegen/generateContracts.mjs +77 -0
- package/dist/codegen/generateExports.d.ts +15 -0
- package/dist/codegen/generateExports.js +41 -0
- package/dist/codegen/generateExports.mjs +32 -0
- package/dist/codegen/generateJSCollections.d.ts +2 -0
- package/dist/codegen/generateJSCollections.js +91 -0
- package/dist/codegen/generateJSCollections.mjs +82 -0
- package/dist/codegen/generateTSCollections.d.ts +2 -0
- package/dist/codegen/generateTSCollections.js +107 -0
- package/dist/codegen/generateTSCollections.mjs +99 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.js +20 -0
- package/dist/codegen/index.mjs +5 -0
- package/dist/codegen/utils.d.ts +29 -0
- package/dist/codegen/utils.js +143 -0
- package/dist/codegen/utils.mjs +122 -0
- package/dist/codegen.d.ts +3 -0
- package/dist/codegen.js +102 -0
- package/dist/codegen.mjs +52 -0
- package/dist/compile.d.ts +21 -0
- package/dist/compile.js +96 -0
- package/dist/compile.mjs +57 -0
- package/dist/diagnostic.d.ts +8 -0
- package/dist/diagnostic.js +22 -0
- package/dist/diagnostic.mjs +16 -0
- package/dist/guards.d.ts +3 -0
- package/dist/guards.js +45 -0
- package/dist/guards.mjs +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/index.mjs +8 -0
- package/dist/lexer.d.ts +14 -0
- package/dist/lexer.js +272 -0
- package/dist/lexer.mjs +270 -0
- package/dist/parser.d.ts +8 -0
- package/dist/parser.js +907 -0
- package/dist/parser.mjs +851 -0
- package/dist/semantic.d.ts +5 -0
- package/dist/semantic.js +149 -0
- package/dist/semantic.mjs +111 -0
- package/dist/token.d.ts +38 -0
- package/dist/token.js +24 -0
- package/dist/token.mjs +22 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +2 -0
- package/dist/utils.mjs +1 -0
- package/package.json +2 -3
package/dist/semantic.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.analyze = void 0;
|
|
37
|
+
const common_1 = require("@aeriajs/common");
|
|
38
|
+
const parser_js_1 = require("./parser.js");
|
|
39
|
+
const diagnostic_js_1 = require("./diagnostic.js");
|
|
40
|
+
const AST = __importStar(require("./ast.js"));
|
|
41
|
+
const collectionHasProperty = async (collection, propName) => {
|
|
42
|
+
let hasProperty = propName in collection.properties;
|
|
43
|
+
if (!hasProperty) {
|
|
44
|
+
if (collection.extends) {
|
|
45
|
+
const { packageName, symbolName } = collection.extends;
|
|
46
|
+
const { [symbolName]: importedCollection } = await Promise.resolve(`${packageName}`).then(s => __importStar(require(s)));
|
|
47
|
+
if (!(0, common_1.isValidCollection)(importedCollection)) {
|
|
48
|
+
throw new Error;
|
|
49
|
+
}
|
|
50
|
+
hasProperty = propName in importedCollection.description.properties;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return hasProperty;
|
|
54
|
+
};
|
|
55
|
+
const analyze = async (ast, errors = []) => {
|
|
56
|
+
const checkCollectionForeignProperties = async (foreignCollection, property, attributeName) => {
|
|
57
|
+
if (!property[attributeName]) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (const foreignPropName of property[attributeName]) {
|
|
61
|
+
if (!await collectionHasProperty(foreignCollection, foreignPropName)) {
|
|
62
|
+
let location;
|
|
63
|
+
if (property[AST.LOCATION_SYMBOL]) {
|
|
64
|
+
location = parser_js_1.locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
|
|
65
|
+
}
|
|
66
|
+
errors.push(new diagnostic_js_1.Diagnostic(`collection "${foreignCollection.name}" hasn't such property "${foreignPropName}"`, location));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const checkCollectionLocalProperties = async (node, attributeName) => {
|
|
71
|
+
if (!node[attributeName]) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
for (const index in node[attributeName]) {
|
|
75
|
+
const propName = node[attributeName][index];
|
|
76
|
+
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
77
|
+
if (!await collectionHasProperty(node, propName)) {
|
|
78
|
+
const location = parser_js_1.locationMap.get(symbol);
|
|
79
|
+
errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const checkObjectLocalProperties = async (node, attributeName) => {
|
|
84
|
+
if (!('properties' in node.property) || !node.property[attributeName]) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const index in node.property[attributeName]) {
|
|
88
|
+
const propName = node.property[attributeName][index];
|
|
89
|
+
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
90
|
+
if (!(propName in node.property.properties)) {
|
|
91
|
+
const location = parser_js_1.locationMap.get(symbol);
|
|
92
|
+
errors.push(new diagnostic_js_1.Diagnostic(`object "xxx" hasn't such property "${propName}"`, location));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const recurseProperty = async (node) => {
|
|
97
|
+
if (node.nestedProperties && 'nestedProperties' in node) {
|
|
98
|
+
await checkObjectLocalProperties(node, 'required');
|
|
99
|
+
await checkObjectLocalProperties(node, 'writable');
|
|
100
|
+
await checkObjectLocalProperties(node, 'form');
|
|
101
|
+
for (const propName in node.nestedProperties) {
|
|
102
|
+
const subProperty = node.nestedProperties[propName];
|
|
103
|
+
await recurseProperty(subProperty);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if ('$ref' in node.property) {
|
|
107
|
+
const refName = node.property.$ref;
|
|
108
|
+
const foreignCollection = ast.collections.find(({ name }) => name === refName);
|
|
109
|
+
if (!foreignCollection) {
|
|
110
|
+
throw new Error;
|
|
111
|
+
}
|
|
112
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, 'indexes');
|
|
113
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, 'populate');
|
|
114
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, 'form');
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
for (const node of ast.collections) {
|
|
118
|
+
await checkCollectionLocalProperties(node, 'indexes');
|
|
119
|
+
await checkCollectionLocalProperties(node, 'filters');
|
|
120
|
+
await checkCollectionLocalProperties(node, 'form');
|
|
121
|
+
await checkCollectionLocalProperties(node, 'table');
|
|
122
|
+
for (const propName in node.properties) {
|
|
123
|
+
const subNode = node.properties[propName];
|
|
124
|
+
await recurseProperty(subNode);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const node of ast.contracts) {
|
|
128
|
+
if (node.payload) {
|
|
129
|
+
await recurseProperty(node.payload);
|
|
130
|
+
}
|
|
131
|
+
if (node.query) {
|
|
132
|
+
await recurseProperty(node.query);
|
|
133
|
+
}
|
|
134
|
+
if (node.response) {
|
|
135
|
+
if (Array.isArray(node.response)) {
|
|
136
|
+
for (const subNode of node.response) {
|
|
137
|
+
await recurseProperty(subNode);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
await recurseProperty(node.response);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
errors,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
exports.analyze = analyze;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { isValidCollection } from "@aeriajs/common";
|
|
3
|
+
import { locationMap } from "./parser.mjs";
|
|
4
|
+
import { Diagnostic } from "./diagnostic.mjs";
|
|
5
|
+
import * as AST from "./ast.mjs";
|
|
6
|
+
const collectionHasProperty = async (collection, propName) => {
|
|
7
|
+
let hasProperty = propName in collection.properties;
|
|
8
|
+
if (!hasProperty) {
|
|
9
|
+
if (collection.extends) {
|
|
10
|
+
const { packageName, symbolName } = collection.extends;
|
|
11
|
+
const { [symbolName]: importedCollection } = await import(packageName);
|
|
12
|
+
if (!isValidCollection(importedCollection)) {
|
|
13
|
+
throw new Error();
|
|
14
|
+
}
|
|
15
|
+
hasProperty = propName in importedCollection.description.properties;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return hasProperty;
|
|
19
|
+
};
|
|
20
|
+
export const analyze = async (ast, errors = []) => {
|
|
21
|
+
const checkCollectionForeignProperties = async (foreignCollection, property, attributeName) => {
|
|
22
|
+
if (!property[attributeName]) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const foreignPropName of property[attributeName]) {
|
|
26
|
+
if (!await collectionHasProperty(foreignCollection, foreignPropName)) {
|
|
27
|
+
let location;
|
|
28
|
+
if (property[AST.LOCATION_SYMBOL]) {
|
|
29
|
+
location = locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
|
|
30
|
+
}
|
|
31
|
+
errors.push(new Diagnostic(`collection "${foreignCollection.name}" hasn't such property "${foreignPropName}"`, location));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const checkCollectionLocalProperties = async (node, attributeName) => {
|
|
36
|
+
if (!node[attributeName]) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const index in node[attributeName]) {
|
|
40
|
+
const propName = node[attributeName][index];
|
|
41
|
+
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
42
|
+
if (!await collectionHasProperty(node, propName)) {
|
|
43
|
+
const location = locationMap.get(symbol);
|
|
44
|
+
errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const checkObjectLocalProperties = async (node, attributeName) => {
|
|
49
|
+
if (!("properties" in node.property) || !node.property[attributeName]) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const index in node.property[attributeName]) {
|
|
53
|
+
const propName = node.property[attributeName][index];
|
|
54
|
+
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
55
|
+
if (!(propName in node.property.properties)) {
|
|
56
|
+
const location = locationMap.get(symbol);
|
|
57
|
+
errors.push(new Diagnostic(`object "xxx" hasn't such property "${propName}"`, location));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const recurseProperty = async (node) => {
|
|
62
|
+
if (node.nestedProperties && "nestedProperties" in node) {
|
|
63
|
+
await checkObjectLocalProperties(node, "required");
|
|
64
|
+
await checkObjectLocalProperties(node, "writable");
|
|
65
|
+
await checkObjectLocalProperties(node, "form");
|
|
66
|
+
for (const propName in node.nestedProperties) {
|
|
67
|
+
const subProperty = node.nestedProperties[propName];
|
|
68
|
+
await recurseProperty(subProperty);
|
|
69
|
+
}
|
|
70
|
+
} else if ("$ref" in node.property) {
|
|
71
|
+
const refName = node.property.$ref;
|
|
72
|
+
const foreignCollection = ast.collections.find(({ name }) => name === refName);
|
|
73
|
+
if (!foreignCollection) {
|
|
74
|
+
throw new Error();
|
|
75
|
+
}
|
|
76
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, "indexes");
|
|
77
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, "populate");
|
|
78
|
+
await checkCollectionForeignProperties(foreignCollection, node.property, "form");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
for (const node of ast.collections) {
|
|
82
|
+
await checkCollectionLocalProperties(node, "indexes");
|
|
83
|
+
await checkCollectionLocalProperties(node, "filters");
|
|
84
|
+
await checkCollectionLocalProperties(node, "form");
|
|
85
|
+
await checkCollectionLocalProperties(node, "table");
|
|
86
|
+
for (const propName in node.properties) {
|
|
87
|
+
const subNode = node.properties[propName];
|
|
88
|
+
await recurseProperty(subNode);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const node of ast.contracts) {
|
|
92
|
+
if (node.payload) {
|
|
93
|
+
await recurseProperty(node.payload);
|
|
94
|
+
}
|
|
95
|
+
if (node.query) {
|
|
96
|
+
await recurseProperty(node.query);
|
|
97
|
+
}
|
|
98
|
+
if (node.response) {
|
|
99
|
+
if (Array.isArray(node.response)) {
|
|
100
|
+
for (const subNode of node.response) {
|
|
101
|
+
await recurseProperty(subNode);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
await recurseProperty(node.response);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
errors
|
|
110
|
+
};
|
|
111
|
+
};
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const TokenType: {
|
|
2
|
+
readonly LineBreak: "LINE_BREAK";
|
|
3
|
+
readonly Comment: "COMMENT";
|
|
4
|
+
readonly LeftBracket: "LEFT_BRACKET";
|
|
5
|
+
readonly RightBracket: "RIGHT_BRACKET";
|
|
6
|
+
readonly LeftParens: "LEFT_PARENS";
|
|
7
|
+
readonly RightParens: "RIGHT_PARENS";
|
|
8
|
+
readonly LeftSquareBracket: "LEFT_SQUARE_BRACKET";
|
|
9
|
+
readonly RightSquareBracket: "RIGHT_SQUARE_BRACKET";
|
|
10
|
+
readonly Pipe: "PIPE";
|
|
11
|
+
readonly Comma: "COMMA";
|
|
12
|
+
readonly Dot: "DOT";
|
|
13
|
+
readonly Number: "NUMBER";
|
|
14
|
+
readonly Boolean: "BOOLEAN";
|
|
15
|
+
readonly Keyword: "KEYWORD";
|
|
16
|
+
readonly Identifier: "IDENTIFIER";
|
|
17
|
+
readonly QuotedString: "QUOTED_STRING";
|
|
18
|
+
readonly AttributeName: "ATTRIBUTE_NAME";
|
|
19
|
+
readonly MacroName: "MACRO_NAME";
|
|
20
|
+
readonly Range: "RANGE";
|
|
21
|
+
};
|
|
22
|
+
export type TokenType = typeof TokenType[keyof typeof TokenType];
|
|
23
|
+
export type TypeMap = {
|
|
24
|
+
[TokenType.Number]: number;
|
|
25
|
+
[TokenType.Boolean]: boolean;
|
|
26
|
+
[TokenType.Range]: readonly [number, number];
|
|
27
|
+
};
|
|
28
|
+
export type Location = {
|
|
29
|
+
index: number;
|
|
30
|
+
line: number;
|
|
31
|
+
start: number;
|
|
32
|
+
end: number;
|
|
33
|
+
};
|
|
34
|
+
export type Token<TTokenType extends TokenType = TokenType, TValue = TTokenType extends keyof TypeMap ? TypeMap[TTokenType] : string> = {
|
|
35
|
+
type: TTokenType;
|
|
36
|
+
location: Location;
|
|
37
|
+
value: TValue;
|
|
38
|
+
};
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenType = void 0;
|
|
4
|
+
exports.TokenType = {
|
|
5
|
+
LineBreak: 'LINE_BREAK',
|
|
6
|
+
Comment: 'COMMENT',
|
|
7
|
+
LeftBracket: 'LEFT_BRACKET',
|
|
8
|
+
RightBracket: 'RIGHT_BRACKET',
|
|
9
|
+
LeftParens: 'LEFT_PARENS',
|
|
10
|
+
RightParens: 'RIGHT_PARENS',
|
|
11
|
+
LeftSquareBracket: 'LEFT_SQUARE_BRACKET',
|
|
12
|
+
RightSquareBracket: 'RIGHT_SQUARE_BRACKET',
|
|
13
|
+
Pipe: 'PIPE',
|
|
14
|
+
Comma: 'COMMA',
|
|
15
|
+
Dot: 'DOT',
|
|
16
|
+
Number: 'NUMBER',
|
|
17
|
+
Boolean: 'BOOLEAN',
|
|
18
|
+
Keyword: 'KEYWORD',
|
|
19
|
+
Identifier: 'IDENTIFIER',
|
|
20
|
+
QuotedString: 'QUOTED_STRING',
|
|
21
|
+
AttributeName: 'ATTRIBUTE_NAME',
|
|
22
|
+
MacroName: 'MACRO_NAME',
|
|
23
|
+
Range: 'RANGE',
|
|
24
|
+
};
|
package/dist/token.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export const TokenType = {
|
|
3
|
+
LineBreak: "LINE_BREAK",
|
|
4
|
+
Comment: "COMMENT",
|
|
5
|
+
LeftBracket: "LEFT_BRACKET",
|
|
6
|
+
RightBracket: "RIGHT_BRACKET",
|
|
7
|
+
LeftParens: "LEFT_PARENS",
|
|
8
|
+
RightParens: "RIGHT_PARENS",
|
|
9
|
+
LeftSquareBracket: "LEFT_SQUARE_BRACKET",
|
|
10
|
+
RightSquareBracket: "RIGHT_SQUARE_BRACKET",
|
|
11
|
+
Pipe: "PIPE",
|
|
12
|
+
Comma: "COMMA",
|
|
13
|
+
Dot: "DOT",
|
|
14
|
+
Number: "NUMBER",
|
|
15
|
+
Boolean: "BOOLEAN",
|
|
16
|
+
Keyword: "KEYWORD",
|
|
17
|
+
Identifier: "IDENTIFIER",
|
|
18
|
+
QuotedString: "QUOTED_STRING",
|
|
19
|
+
AttributeName: "ATTRIBUTE_NAME",
|
|
20
|
+
MacroName: "MACRO_NAME",
|
|
21
|
+
Range: "RANGE"
|
|
22
|
+
};
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./dist/index.
|
|
14
|
-
"require": "./dist/index.js",
|
|
13
|
+
"import": "./dist/index.js",
|
|
15
14
|
"types": "./dist/index.d.ts"
|
|
16
15
|
}
|
|
17
16
|
},
|