@aeriajs/compiler 0.0.32 → 0.0.34
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/codegen/generateJSCollections.js +2 -0
- package/dist/codegen/generateJSCollections.mjs +2 -0
- package/dist/codegen/generateTSCollections.js +5 -0
- package/dist/codegen/generateTSCollections.mjs +5 -0
- package/dist/codegen/utils.d.ts +3 -1
- package/dist/codegen/utils.js +9 -5
- package/dist/codegen/utils.mjs +9 -5
- package/dist/parser.js +0 -4
- package/dist/parser.mjs +0 -2
- package/dist/semantic.js +3 -3
- package/dist/semantic.mjs +3 -3
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ const generateJSCollections = (ast) => {
|
|
|
10
10
|
let javascriptCode = '';
|
|
11
11
|
const importsResult = (0, utils_js_1.makeASTImports)(ast, {
|
|
12
12
|
[utils_js_1.PACKAGE_NAME]: new Set(initialImportedFunctions),
|
|
13
|
+
}, {
|
|
14
|
+
includeRuntimeOnlyImports: true,
|
|
13
15
|
});
|
|
14
16
|
javascriptCode += importsResult.code.join('\n') + '\n\n';
|
|
15
17
|
javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + '\n\n';
|
|
@@ -8,6 +8,8 @@ export const generateJSCollections = (ast) => {
|
|
|
8
8
|
let javascriptCode = "";
|
|
9
9
|
const importsResult = makeASTImports(ast, {
|
|
10
10
|
[PACKAGE_NAME]: new Set(initialImportedFunctions)
|
|
11
|
+
}, {
|
|
12
|
+
includeRuntimeOnlyImports: true
|
|
11
13
|
});
|
|
12
14
|
javascriptCode += importsResult.code.join("\n") + "\n\n";
|
|
13
15
|
javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + "\n\n";
|
|
@@ -66,6 +66,11 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
66
66
|
case 'owned':
|
|
67
67
|
collectionSchema.description.owned = collectionNode[key];
|
|
68
68
|
break;
|
|
69
|
+
case 'middlewares':
|
|
70
|
+
collectionSchema.middlewares = {
|
|
71
|
+
[utils_js_1.UnquotedSymbol]: 'import(\'@aeriajs/types\').CollectionMiddleware<unknown>[]',
|
|
72
|
+
};
|
|
73
|
+
break;
|
|
69
74
|
case 'functions':
|
|
70
75
|
collectionSchema.functions = makeTSFunctions(collectionNode[key]);
|
|
71
76
|
collectionSchema.exposedFunctions = (0, utils_js_1.getExposedFunctions)(collectionNode[key]);
|
|
@@ -61,6 +61,11 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
61
61
|
case "owned":
|
|
62
62
|
collectionSchema.description.owned = collectionNode[key];
|
|
63
63
|
break;
|
|
64
|
+
case "middlewares":
|
|
65
|
+
collectionSchema.middlewares = {
|
|
66
|
+
[UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]"
|
|
67
|
+
};
|
|
68
|
+
break;
|
|
64
69
|
case "functions":
|
|
65
70
|
collectionSchema.functions = makeTSFunctions(collectionNode[key]);
|
|
66
71
|
collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export declare const getExposedFunctions: (astFunctions: NonNullable<AST.Collect
|
|
|
10
10
|
/**
|
|
11
11
|
* Obs: It will save and return any modified symbols to avoid name duplication later
|
|
12
12
|
*/
|
|
13
|
-
export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<string, Set<string
|
|
13
|
+
export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<string, Set<string>>, options?: {
|
|
14
|
+
includeRuntimeOnlyImports: boolean;
|
|
15
|
+
}) => {
|
|
14
16
|
code: string[];
|
|
15
17
|
modifiedSymbols: Record<string, string>;
|
|
16
18
|
};
|
package/dist/codegen/utils.js
CHANGED
|
@@ -25,7 +25,9 @@ exports.getExposedFunctions = getExposedFunctions;
|
|
|
25
25
|
/**
|
|
26
26
|
* Obs: It will save and return any modified symbols to avoid name duplication later
|
|
27
27
|
*/
|
|
28
|
-
const makeASTImports = (ast, initialImports
|
|
28
|
+
const makeASTImports = (ast, initialImports, options = {
|
|
29
|
+
includeRuntimeOnlyImports: false,
|
|
30
|
+
}) => {
|
|
29
31
|
const modifiedSymbols = {};
|
|
30
32
|
const toImport = ast.reduce((imports, node) => {
|
|
31
33
|
if (node.kind === 'collection') {
|
|
@@ -46,10 +48,12 @@ const makeASTImports = (ast, initialImports) => {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (options.includeRuntimeOnlyImports) {
|
|
52
|
+
if (node.middlewares) {
|
|
53
|
+
imports[exports.MIDDLEWARES_RUNTIME_PATH] ??= new Set();
|
|
54
|
+
for (const middleware of node.middlewares) {
|
|
55
|
+
imports[exports.MIDDLEWARES_RUNTIME_PATH].add(middleware);
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
}
|
package/dist/codegen/utils.mjs
CHANGED
|
@@ -19,7 +19,9 @@ export const getExposedFunctions = (astFunctions) => {
|
|
|
19
19
|
value.accessCondition
|
|
20
20
|
]));
|
|
21
21
|
};
|
|
22
|
-
export const makeASTImports = (ast, initialImports
|
|
22
|
+
export const makeASTImports = (ast, initialImports, options = {
|
|
23
|
+
includeRuntimeOnlyImports: false
|
|
24
|
+
}) => {
|
|
23
25
|
const modifiedSymbols = {};
|
|
24
26
|
const toImport = ast.reduce((imports, node) => {
|
|
25
27
|
if (node.kind === "collection") {
|
|
@@ -40,10 +42,12 @@ export const makeASTImports = (ast, initialImports) => {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (options.includeRuntimeOnlyImports) {
|
|
46
|
+
if (node.middlewares) {
|
|
47
|
+
imports[MIDDLEWARES_RUNTIME_PATH] ??= /* @__PURE__ */ new Set();
|
|
48
|
+
for (const middleware of node.middlewares) {
|
|
49
|
+
imports[MIDDLEWARES_RUNTIME_PATH].add(middleware);
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
}
|
package/dist/parser.js
CHANGED
|
@@ -713,13 +713,10 @@ const parse = (tokens) => {
|
|
|
713
713
|
case 'required': {
|
|
714
714
|
node.required = parseArrayBlockWithAttributes(['if'], (attributeName, array, identifier) => {
|
|
715
715
|
switch (attributeName) {
|
|
716
|
-
/* eslint-disable-next-line */
|
|
717
716
|
case 'if': {
|
|
718
|
-
consume(token_js_1.TokenType.LeftParens);
|
|
719
717
|
const ifTerms = [];
|
|
720
718
|
array[identifier] = parseCondition(ifTerms);
|
|
721
719
|
node[AST.LOCATION_SYMBOL].requiredTerms = ifTerms;
|
|
722
|
-
consume(token_js_1.TokenType.RightParens);
|
|
723
720
|
break;
|
|
724
721
|
}
|
|
725
722
|
}
|
|
@@ -816,7 +813,6 @@ const parse = (tokens) => {
|
|
|
816
813
|
if (match(token_js_1.TokenType.MacroName)) {
|
|
817
814
|
const { value: macroName } = consume(token_js_1.TokenType.MacroName, ['include']);
|
|
818
815
|
switch (macroName) {
|
|
819
|
-
/* eslint-disable-next-line */
|
|
820
816
|
case 'include': {
|
|
821
817
|
const { value: functionSetName, location } = consume(token_js_1.TokenType.Identifier);
|
|
822
818
|
const functionset = ast.functionsets.find((node) => node.name === functionSetName);
|
package/dist/parser.mjs
CHANGED
|
@@ -660,11 +660,9 @@ export const parse = (tokens) => {
|
|
|
660
660
|
node.required = parseArrayBlockWithAttributes(["if"], (attributeName, array, identifier) => {
|
|
661
661
|
switch (attributeName) {
|
|
662
662
|
case "if": {
|
|
663
|
-
consume(TokenType.LeftParens);
|
|
664
663
|
const ifTerms = [];
|
|
665
664
|
array[identifier] = parseCondition(ifTerms);
|
|
666
665
|
node[AST.LOCATION_SYMBOL].requiredTerms = ifTerms;
|
|
667
|
-
consume(TokenType.RightParens);
|
|
668
666
|
break;
|
|
669
667
|
}
|
|
670
668
|
}
|
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)) {
|
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)) {
|