@aeriajs/compiler 0.0.15 → 0.0.17
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/codegen/generateContracts.d.ts +1 -1
- package/dist/codegen/generateContracts.js +1 -1
- package/dist/codegen/generateContracts.mjs +1 -1
- package/dist/codegen/generateExports.d.ts +3 -3
- package/dist/codegen/generateExports.js +3 -3
- package/dist/codegen/generateExports.mjs +3 -3
- package/dist/codegen/generateJSCollections.js +2 -2
- package/dist/codegen/generateJSCollections.mjs +2 -2
- package/dist/codegen/utils.d.ts +1 -1
- package/dist/codegen.js +5 -5
- package/dist/codegen.mjs +5 -5
- package/dist/compile.d.ts +2 -3
- package/dist/compile.js +23 -47
- package/dist/compile.mjs +22 -42
- package/dist/parser.js +12 -5
- package/dist/parser.mjs +13 -6
- package/dist/semantic.js +3 -1
- package/dist/semantic.mjs +3 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
package/dist/ast.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type PropertyNode = NodeBase<'property'> & {
|
|
|
23
23
|
modifier?: keyof typeof PropertyModifiers;
|
|
24
24
|
property: Property & {
|
|
25
25
|
[LOCATION_SYMBOL]?: {
|
|
26
|
+
type: symbol;
|
|
26
27
|
attributes: Record<string, symbol>;
|
|
27
28
|
arrays: {
|
|
28
29
|
[P in ArrayProperties<Extract<Property, {
|
|
@@ -2,14 +2,14 @@ import type * as AST from '../ast.js';
|
|
|
2
2
|
export declare const generateExports: (ast: AST.ProgramNode, hasContracts?: boolean) => {
|
|
3
3
|
main: {
|
|
4
4
|
js: string;
|
|
5
|
-
|
|
5
|
+
dts: string;
|
|
6
6
|
};
|
|
7
7
|
collections: {
|
|
8
8
|
js: string;
|
|
9
|
-
|
|
9
|
+
dts: string;
|
|
10
10
|
};
|
|
11
11
|
contracts?: {
|
|
12
12
|
js: string;
|
|
13
|
-
|
|
13
|
+
dts: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
@@ -15,7 +15,7 @@ const generateExports = (ast, hasContracts = false) => {
|
|
|
15
15
|
const exports = {
|
|
16
16
|
collections: {
|
|
17
17
|
js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
|
|
18
|
-
|
|
18
|
+
dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
|
|
19
19
|
},
|
|
20
20
|
main: {
|
|
21
21
|
js: (hasContracts
|
|
@@ -23,7 +23,7 @@ const generateExports = (ast, hasContracts = false) => {
|
|
|
23
23
|
: '') +
|
|
24
24
|
'export * as collections from \'./collections/index.js\'\n' +
|
|
25
25
|
`export { ${symbolsToExport.map((symbol) => symbol.extend).join(', ')} } from './collections/collections.js'`,
|
|
26
|
-
|
|
26
|
+
dts: (hasContracts
|
|
27
27
|
? 'export * as contracts from \'./contracts/index.js\'\n'
|
|
28
28
|
: '') +
|
|
29
29
|
'export * as collections from \'./collections/index.js\'\n' +
|
|
@@ -33,7 +33,7 @@ const generateExports = (ast, hasContracts = false) => {
|
|
|
33
33
|
if (hasContracts) {
|
|
34
34
|
exports.contracts = {
|
|
35
35
|
js: 'export * from \'./contracts.js\'',
|
|
36
|
-
|
|
36
|
+
dts: 'export * from \'./contracts.js\'',
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
return exports;
|
|
@@ -13,19 +13,19 @@ export const generateExports = (ast, hasContracts = false) => {
|
|
|
13
13
|
const exports = {
|
|
14
14
|
collections: {
|
|
15
15
|
js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`,
|
|
16
|
-
|
|
16
|
+
dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`
|
|
17
17
|
},
|
|
18
18
|
main: {
|
|
19
19
|
js: (hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
|
|
20
20
|
export { ${symbolsToExport.map((symbol) => symbol.extend).join(", ")} } from './collections/collections.mjs'`,
|
|
21
|
-
|
|
21
|
+
dts: (hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
|
|
22
22
|
export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(", ")} } from './collections/collections.mjs'`
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
if (hasContracts) {
|
|
26
26
|
exports.contracts = {
|
|
27
27
|
js: "export * from './contracts.mjs'",
|
|
28
|
-
|
|
28
|
+
dts: "export * from './contracts.mjs'"
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
return exports;
|
|
@@ -47,10 +47,10 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
47
47
|
}
|
|
48
48
|
switch (key) {
|
|
49
49
|
case 'properties':
|
|
50
|
-
collectionSchema.description
|
|
50
|
+
collectionSchema.description[key] = (0, utils_js_1.getProperties)(collectionNode[key]);
|
|
51
51
|
break;
|
|
52
52
|
case 'owned':
|
|
53
|
-
collectionSchema.description
|
|
53
|
+
collectionSchema.description[key] = collectionNode[key];
|
|
54
54
|
break;
|
|
55
55
|
case 'functions':
|
|
56
56
|
collectionSchema.functions = {
|
|
@@ -40,10 +40,10 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
40
40
|
}
|
|
41
41
|
switch (key) {
|
|
42
42
|
case "properties":
|
|
43
|
-
collectionSchema.description
|
|
43
|
+
collectionSchema.description[key] = getProperties(collectionNode[key]);
|
|
44
44
|
break;
|
|
45
45
|
case "owned":
|
|
46
|
-
collectionSchema.description
|
|
46
|
+
collectionSchema.description[key] = collectionNode[key];
|
|
47
47
|
break;
|
|
48
48
|
case "functions":
|
|
49
49
|
collectionSchema.functions = {
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<s
|
|
|
15
15
|
};
|
|
16
16
|
export declare const propertyToSchema: ({ property, nestedProperties }: Pick<AST.PropertyNode, "property" | "nestedProperties">) => Property;
|
|
17
17
|
/** Transforms the AST properties to the format of aeria schema properties */
|
|
18
|
-
export declare const getProperties: <TProperties extends Record<string, AST.PropertyNode | AST.PropertyNode[]>, TReturnType = TProperties[keyof TProperties] extends unknown
|
|
18
|
+
export declare const getProperties: <TProperties extends Record<string, AST.PropertyNode | AST.PropertyNode[]>, TReturnType = TProperties[keyof TProperties] extends Array<unknown> ? Record<string, Property[]> : Record<string, Property>>(properties: TProperties) => TReturnType;
|
|
19
19
|
export declare const UnquotedSymbol: unique symbol;
|
|
20
20
|
/** Serves to know if the value must be unquoted on strinfigy function */
|
|
21
21
|
export type StringifyProperty = unknown | {
|
package/dist/codegen.js
CHANGED
|
@@ -51,7 +51,7 @@ const path = __importStar(require("node:path"));
|
|
|
51
51
|
* ['outDir/folderX/folderY/file']: ...
|
|
52
52
|
* }
|
|
53
53
|
*/
|
|
54
|
-
const generateFileMap = async (fileTree, outDir) => {
|
|
54
|
+
const generateFileMap = async (fileTree, outDir = '.') => {
|
|
55
55
|
const mappedPaths = {};
|
|
56
56
|
const mapPathTree = async (tree, previousPath) => {
|
|
57
57
|
for (const treePath in tree) {
|
|
@@ -77,17 +77,17 @@ const generateCode = async (ast, options) => {
|
|
|
77
77
|
['collections']: {
|
|
78
78
|
['collections.d.ts']: (0, index_js_1.generateTSCollections)(ast.collections),
|
|
79
79
|
['collections.js']: (0, index_js_1.generateJSCollections)(ast.collections),
|
|
80
|
-
['index.d.ts']: exports.collections.
|
|
80
|
+
['index.d.ts']: exports.collections.dts,
|
|
81
81
|
['index.js']: exports.collections.js,
|
|
82
82
|
},
|
|
83
|
-
['index.d.ts']: exports.main.
|
|
83
|
+
['index.d.ts']: exports.main.dts,
|
|
84
84
|
['index.js']: exports.main.js,
|
|
85
85
|
};
|
|
86
86
|
if (contracts) {
|
|
87
87
|
fileTree.contracts = {
|
|
88
88
|
['contracts.js']: contracts.js,
|
|
89
|
-
['contracts.d.ts']: contracts.
|
|
90
|
-
['index.d.ts']: exports.contracts.
|
|
89
|
+
['contracts.d.ts']: contracts.dts,
|
|
90
|
+
['index.d.ts']: exports.contracts.dts,
|
|
91
91
|
['index.js']: exports.contracts.js,
|
|
92
92
|
};
|
|
93
93
|
}
|
package/dist/codegen.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { generateContracts, generateExports, generateJSCollections, generateTSCollections } from "./codegen/index.mjs";
|
|
3
3
|
import * as fsPromises from "node:fs/promises";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
const generateFileMap = async (fileTree, outDir) => {
|
|
5
|
+
const generateFileMap = async (fileTree, outDir = ".") => {
|
|
6
6
|
const mappedPaths = {};
|
|
7
7
|
const mapPathTree = async (tree, previousPath) => {
|
|
8
8
|
for (const treePath in tree) {
|
|
@@ -28,17 +28,17 @@ export const generateCode = async (ast, options) => {
|
|
|
28
28
|
["collections"]: {
|
|
29
29
|
["collections.d.ts"]: generateTSCollections(ast.collections),
|
|
30
30
|
["collections.mjs"]: generateJSCollections(ast.collections),
|
|
31
|
-
["index.d.ts"]: exports.collections.
|
|
31
|
+
["index.d.ts"]: exports.collections.dts,
|
|
32
32
|
["index.mjs"]: exports.collections.js
|
|
33
33
|
},
|
|
34
|
-
["index.d.ts"]: exports.main.
|
|
34
|
+
["index.d.ts"]: exports.main.dts,
|
|
35
35
|
["index.mjs"]: exports.main.js
|
|
36
36
|
};
|
|
37
37
|
if (contracts) {
|
|
38
38
|
fileTree.contracts = {
|
|
39
39
|
["contracts.mjs"]: contracts.js,
|
|
40
|
-
["contracts.d.ts"]: contracts.
|
|
41
|
-
["index.d.ts"]: exports.contracts.
|
|
40
|
+
["contracts.d.ts"]: contracts.dts,
|
|
41
|
+
["index.d.ts"]: exports.contracts.dts,
|
|
42
42
|
["index.mjs"]: exports.contracts.js
|
|
43
43
|
};
|
|
44
44
|
}
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { CompilationOptions, CompilationResult } from './types.js';
|
|
2
2
|
import { Diagnostic } from './diagnostic.js';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const GLOB_PATTERN = "**/*.aeria";
|
|
4
4
|
export declare const parseAndCheck: (sources: Record<string, string>, options?: Pick<CompilationOptions, "languageServer">) => Promise<CompilationResult>;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<CompilationResult | {
|
|
5
|
+
export declare const compileFromFiles: (options: CompilationOptions) => Promise<CompilationResult | {
|
|
7
6
|
emittedFiles: Record<string, string>;
|
|
8
7
|
success: boolean;
|
|
9
8
|
ast?: import("./ast.js").ProgramNode;
|
package/dist/compile.js
CHANGED
|
@@ -33,68 +33,41 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.compileFromFiles = exports.
|
|
36
|
+
exports.compileFromFiles = exports.parseAndCheck = exports.GLOB_PATTERN = void 0;
|
|
37
37
|
const diagnostic_js_1 = require("./diagnostic.js");
|
|
38
38
|
const lexer_js_1 = require("./lexer.js");
|
|
39
39
|
const parser_js_1 = require("./parser.js");
|
|
40
40
|
const semantic_js_1 = require("./semantic.js");
|
|
41
41
|
const codegen_js_1 = require("./codegen.js");
|
|
42
|
-
const path = __importStar(require("node:path"));
|
|
43
42
|
const fs = __importStar(require("node:fs"));
|
|
44
|
-
exports.
|
|
43
|
+
exports.GLOB_PATTERN = '**/*.aeria';
|
|
45
44
|
const parseAndCheck = async (sources, options = {}) => {
|
|
46
45
|
const errors = [];
|
|
47
|
-
|
|
48
|
-
let ast;
|
|
46
|
+
const allTokens = [];
|
|
49
47
|
for (const fileName in sources) {
|
|
50
48
|
diagnostic_js_1.Diagnostic.currentFile = fileName;
|
|
51
49
|
const { errors: lexerErrors, tokens } = (0, lexer_js_1.tokenize)(sources[fileName]);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
|
|
55
|
-
errorCount += errors.length;
|
|
56
|
-
if (!ast) {
|
|
57
|
-
ast = currentAst;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
ast.collections.push(...currentAst.collections);
|
|
61
|
-
ast.contracts.push(...currentAst.contracts);
|
|
62
|
-
ast.functionsets.push(...currentAst.functionsets);
|
|
50
|
+
if (lexerErrors.length > 0) {
|
|
51
|
+
errors.push(...lexerErrors);
|
|
63
52
|
}
|
|
53
|
+
allTokens.push(...tokens);
|
|
64
54
|
}
|
|
55
|
+
const { errors: parserErrors, ast } = (0, parser_js_1.parse)(allTokens);
|
|
56
|
+
const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(ast, options);
|
|
57
|
+
errors.push(...parserErrors.concat(semanticErrors));
|
|
65
58
|
return {
|
|
66
|
-
success:
|
|
59
|
+
success: errors.length === 0,
|
|
67
60
|
errors,
|
|
68
|
-
errorCount,
|
|
61
|
+
errorCount: errors.length,
|
|
69
62
|
ast,
|
|
70
63
|
};
|
|
71
64
|
};
|
|
72
65
|
exports.parseAndCheck = parseAndCheck;
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
for (const dir of directories) {
|
|
76
|
-
await fs.promises.mkdir(dir, {
|
|
77
|
-
recursive: true,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return directories;
|
|
81
|
-
};
|
|
82
|
-
exports.generateScaffolding = generateScaffolding;
|
|
83
|
-
const compileFromFiles = async (schemaDir, options) => {
|
|
84
|
-
const fileList = await Array.fromAsync(fs.promises.glob(`${schemaDir}/*.aeria`));
|
|
85
|
-
const sortedFileList = fileList.sort((a, b) => {
|
|
86
|
-
const aIndex = exports.FILE_PRECEDENCE.findIndex((file) => a.split('/').at(-1).startsWith(file));
|
|
87
|
-
const bIndex = exports.FILE_PRECEDENCE.findIndex((file) => b.split('/').at(-1).startsWith(file));
|
|
88
|
-
if (!~aIndex && !~bIndex) {
|
|
89
|
-
return 1;
|
|
90
|
-
}
|
|
91
|
-
return aIndex > bIndex
|
|
92
|
-
? 1
|
|
93
|
-
: -1;
|
|
94
|
-
});
|
|
66
|
+
const compileFromFiles = async (options) => {
|
|
67
|
+
const fileList = await Array.fromAsync(fs.promises.glob(exports.GLOB_PATTERN));
|
|
95
68
|
const sources = {};
|
|
96
|
-
for (const
|
|
97
|
-
sources[
|
|
69
|
+
for (const fileName of fileList) {
|
|
70
|
+
sources[fileName] = await fs.promises.readFile(fileName, {
|
|
98
71
|
encoding: 'utf-8',
|
|
99
72
|
});
|
|
100
73
|
}
|
|
@@ -102,10 +75,13 @@ const compileFromFiles = async (schemaDir, options) => {
|
|
|
102
75
|
if (!result.ast || result.errorCount > 0) {
|
|
103
76
|
return result;
|
|
104
77
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
78
|
+
if (options.outDir) {
|
|
79
|
+
const emittedFiles = await (0, codegen_js_1.generateCode)(result.ast, options);
|
|
80
|
+
return {
|
|
81
|
+
...result,
|
|
82
|
+
emittedFiles,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
110
86
|
};
|
|
111
87
|
exports.compileFromFiles = compileFromFiles;
|
package/dist/compile.mjs
CHANGED
|
@@ -4,57 +4,34 @@ import { tokenize } from "./lexer.mjs";
|
|
|
4
4
|
import { parse } from "./parser.mjs";
|
|
5
5
|
import { analyze } from "./semantic.mjs";
|
|
6
6
|
import { generateCode } from "./codegen.mjs";
|
|
7
|
-
import * as path from "node:path";
|
|
8
7
|
import * as fs from "node:fs";
|
|
9
|
-
export const
|
|
8
|
+
export const GLOB_PATTERN = "**/*.aeria";
|
|
10
9
|
export const parseAndCheck = async (sources, options = {}) => {
|
|
11
10
|
const errors = [];
|
|
12
|
-
|
|
13
|
-
let ast;
|
|
11
|
+
const allTokens = [];
|
|
14
12
|
for (const fileName in sources) {
|
|
15
13
|
Diagnostic.currentFile = fileName;
|
|
16
14
|
const { errors: lexerErrors, tokens } = tokenize(sources[fileName]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
|
|
20
|
-
errorCount += errors.length;
|
|
21
|
-
if (!ast) {
|
|
22
|
-
ast = currentAst;
|
|
23
|
-
} else {
|
|
24
|
-
ast.collections.push(...currentAst.collections);
|
|
25
|
-
ast.contracts.push(...currentAst.contracts);
|
|
26
|
-
ast.functionsets.push(...currentAst.functionsets);
|
|
15
|
+
if (lexerErrors.length > 0) {
|
|
16
|
+
errors.push(...lexerErrors);
|
|
27
17
|
}
|
|
18
|
+
allTokens.push(...tokens);
|
|
28
19
|
}
|
|
20
|
+
const { errors: parserErrors, ast } = parse(allTokens);
|
|
21
|
+
const { errors: semanticErrors } = await analyze(ast, options);
|
|
22
|
+
errors.push(...parserErrors.concat(semanticErrors));
|
|
29
23
|
return {
|
|
30
|
-
success:
|
|
24
|
+
success: errors.length === 0,
|
|
31
25
|
errors,
|
|
32
|
-
errorCount,
|
|
26
|
+
errorCount: errors.length,
|
|
33
27
|
ast
|
|
34
28
|
};
|
|
35
29
|
};
|
|
36
|
-
export const
|
|
37
|
-
const
|
|
38
|
-
for (const dir of directories) {
|
|
39
|
-
await fs.promises.mkdir(dir, {
|
|
40
|
-
recursive: true
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return directories;
|
|
44
|
-
};
|
|
45
|
-
export const compileFromFiles = async (schemaDir, options) => {
|
|
46
|
-
const fileList = await Array.fromAsync(fs.promises.glob(`${schemaDir}/*.aeria`));
|
|
47
|
-
const sortedFileList = fileList.sort((a, b) => {
|
|
48
|
-
const aIndex = FILE_PRECEDENCE.findIndex((file) => a.split("/").at(-1).startsWith(file));
|
|
49
|
-
const bIndex = FILE_PRECEDENCE.findIndex((file) => b.split("/").at(-1).startsWith(file));
|
|
50
|
-
if (!~aIndex && !~bIndex) {
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
53
|
-
return aIndex > bIndex ? 1 : -1;
|
|
54
|
-
});
|
|
30
|
+
export const compileFromFiles = async (options) => {
|
|
31
|
+
const fileList = await Array.fromAsync(fs.promises.glob(GLOB_PATTERN));
|
|
55
32
|
const sources = {};
|
|
56
|
-
for (const
|
|
57
|
-
sources[
|
|
33
|
+
for (const fileName of fileList) {
|
|
34
|
+
sources[fileName] = await fs.promises.readFile(fileName, {
|
|
58
35
|
encoding: "utf-8"
|
|
59
36
|
});
|
|
60
37
|
}
|
|
@@ -62,9 +39,12 @@ export const compileFromFiles = async (schemaDir, options) => {
|
|
|
62
39
|
if (!result.ast || result.errorCount > 0) {
|
|
63
40
|
return result;
|
|
64
41
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
if (options.outDir) {
|
|
43
|
+
const emittedFiles = await generateCode(result.ast, options);
|
|
44
|
+
return {
|
|
45
|
+
...result,
|
|
46
|
+
emittedFiles
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
70
50
|
};
|
package/dist/parser.js
CHANGED
|
@@ -379,6 +379,7 @@ const parse = (tokens) => {
|
|
|
379
379
|
let property;
|
|
380
380
|
let nestedProperties;
|
|
381
381
|
let modifierToken;
|
|
382
|
+
const typeSymbol = Symbol();
|
|
382
383
|
if (match(token_js_1.TokenType.LeftSquareBracket)) {
|
|
383
384
|
consume(token_js_1.TokenType.LeftSquareBracket);
|
|
384
385
|
const arrayProperty = {
|
|
@@ -387,6 +388,7 @@ const parse = (tokens) => {
|
|
|
387
388
|
while (!match(token_js_1.TokenType.RightSquareBracket)) {
|
|
388
389
|
const attributeSymbol = Symbol();
|
|
389
390
|
arrayProperty[AST.LOCATION_SYMBOL] ??= {
|
|
391
|
+
type: typeSymbol,
|
|
390
392
|
attributes: {},
|
|
391
393
|
arrays: {},
|
|
392
394
|
};
|
|
@@ -425,6 +427,7 @@ const parse = (tokens) => {
|
|
|
425
427
|
...arrayProperty,
|
|
426
428
|
items,
|
|
427
429
|
};
|
|
430
|
+
exports.locationMap.set(typeSymbol, current().location);
|
|
428
431
|
return {
|
|
429
432
|
kind: 'property',
|
|
430
433
|
property,
|
|
@@ -438,12 +441,14 @@ const parse = (tokens) => {
|
|
|
438
441
|
modifierToken = consume(token_js_1.TokenType.Identifier);
|
|
439
442
|
}
|
|
440
443
|
}
|
|
444
|
+
exports.locationMap.set(typeSymbol, current().location);
|
|
441
445
|
if (match(token_js_1.TokenType.LeftBracket)) {
|
|
442
446
|
consume(token_js_1.TokenType.LeftBracket);
|
|
443
447
|
property = {
|
|
444
448
|
type: 'object',
|
|
445
449
|
properties: {},
|
|
446
450
|
[AST.LOCATION_SYMBOL]: {
|
|
451
|
+
type: typeSymbol,
|
|
447
452
|
attributes: {},
|
|
448
453
|
arrays: {},
|
|
449
454
|
},
|
|
@@ -471,7 +476,7 @@ const parse = (tokens) => {
|
|
|
471
476
|
consume(token_js_1.TokenType.RightBracket);
|
|
472
477
|
}
|
|
473
478
|
else {
|
|
474
|
-
const { value: identifier
|
|
479
|
+
const { value: identifier } = consume(token_js_1.TokenType.Identifier);
|
|
475
480
|
if (guards.isNativePropertyType(identifier)) {
|
|
476
481
|
switch (identifier) {
|
|
477
482
|
case 'enum': {
|
|
@@ -507,12 +512,13 @@ const parse = (tokens) => {
|
|
|
507
512
|
}
|
|
508
513
|
}
|
|
509
514
|
else {
|
|
510
|
-
const collection = ast.collections.find((node) => node.name === identifier);
|
|
511
|
-
if (!collection) {
|
|
512
|
-
throw new diagnostic_js_1.Diagnostic(`invalid reference "${identifier}"`, location);
|
|
513
|
-
}
|
|
514
515
|
property = {
|
|
515
516
|
$ref: identifier,
|
|
517
|
+
[AST.LOCATION_SYMBOL]: {
|
|
518
|
+
type: typeSymbol,
|
|
519
|
+
attributes: {},
|
|
520
|
+
arrays: {},
|
|
521
|
+
},
|
|
516
522
|
};
|
|
517
523
|
}
|
|
518
524
|
}
|
|
@@ -523,6 +529,7 @@ const parse = (tokens) => {
|
|
|
523
529
|
const attributeSymbol = Symbol();
|
|
524
530
|
exports.locationMap.set(attributeSymbol, next().location);
|
|
525
531
|
property[AST.LOCATION_SYMBOL] ??= {
|
|
532
|
+
type: typeSymbol,
|
|
526
533
|
attributes: {},
|
|
527
534
|
arrays: {},
|
|
528
535
|
};
|
package/dist/parser.mjs
CHANGED
|
@@ -337,6 +337,7 @@ export const parse = (tokens) => {
|
|
|
337
337
|
let property;
|
|
338
338
|
let nestedProperties;
|
|
339
339
|
let modifierToken;
|
|
340
|
+
const typeSymbol = Symbol();
|
|
340
341
|
if (match(TokenType.LeftSquareBracket)) {
|
|
341
342
|
consume(TokenType.LeftSquareBracket);
|
|
342
343
|
const arrayProperty = {
|
|
@@ -345,6 +346,7 @@ export const parse = (tokens) => {
|
|
|
345
346
|
while (!match(TokenType.RightSquareBracket)) {
|
|
346
347
|
const attributeSymbol = Symbol();
|
|
347
348
|
arrayProperty[AST.LOCATION_SYMBOL] ??= {
|
|
349
|
+
type: typeSymbol,
|
|
348
350
|
attributes: {},
|
|
349
351
|
arrays: {}
|
|
350
352
|
};
|
|
@@ -381,6 +383,7 @@ export const parse = (tokens) => {
|
|
|
381
383
|
...arrayProperty,
|
|
382
384
|
items
|
|
383
385
|
};
|
|
386
|
+
locationMap.set(typeSymbol, current().location);
|
|
384
387
|
return {
|
|
385
388
|
kind: "property",
|
|
386
389
|
property,
|
|
@@ -394,12 +397,14 @@ export const parse = (tokens) => {
|
|
|
394
397
|
modifierToken = consume(TokenType.Identifier);
|
|
395
398
|
}
|
|
396
399
|
}
|
|
400
|
+
locationMap.set(typeSymbol, current().location);
|
|
397
401
|
if (match(TokenType.LeftBracket)) {
|
|
398
402
|
consume(TokenType.LeftBracket);
|
|
399
403
|
property = {
|
|
400
404
|
type: "object",
|
|
401
405
|
properties: {},
|
|
402
406
|
[AST.LOCATION_SYMBOL]: {
|
|
407
|
+
type: typeSymbol,
|
|
403
408
|
attributes: {},
|
|
404
409
|
arrays: {}
|
|
405
410
|
}
|
|
@@ -426,7 +431,7 @@ export const parse = (tokens) => {
|
|
|
426
431
|
}
|
|
427
432
|
consume(TokenType.RightBracket);
|
|
428
433
|
} else {
|
|
429
|
-
const { value: identifier
|
|
434
|
+
const { value: identifier } = consume(TokenType.Identifier);
|
|
430
435
|
if (guards.isNativePropertyType(identifier)) {
|
|
431
436
|
switch (identifier) {
|
|
432
437
|
case "enum": {
|
|
@@ -461,12 +466,13 @@ export const parse = (tokens) => {
|
|
|
461
466
|
};
|
|
462
467
|
}
|
|
463
468
|
} else {
|
|
464
|
-
const collection = ast.collections.find((node2) => node2.name === identifier);
|
|
465
|
-
if (!collection) {
|
|
466
|
-
throw new Diagnostic(`invalid reference "${identifier}"`, location);
|
|
467
|
-
}
|
|
468
469
|
property = {
|
|
469
|
-
$ref: identifier
|
|
470
|
+
$ref: identifier,
|
|
471
|
+
[AST.LOCATION_SYMBOL]: {
|
|
472
|
+
type: typeSymbol,
|
|
473
|
+
attributes: {},
|
|
474
|
+
arrays: {}
|
|
475
|
+
}
|
|
470
476
|
};
|
|
471
477
|
}
|
|
472
478
|
}
|
|
@@ -477,6 +483,7 @@ export const parse = (tokens) => {
|
|
|
477
483
|
const attributeSymbol = Symbol();
|
|
478
484
|
locationMap.set(attributeSymbol, next().location);
|
|
479
485
|
property[AST.LOCATION_SYMBOL] ??= {
|
|
486
|
+
type: typeSymbol,
|
|
480
487
|
attributes: {},
|
|
481
488
|
arrays: {}
|
|
482
489
|
};
|
package/dist/semantic.js
CHANGED
|
@@ -110,7 +110,9 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
110
110
|
const refName = node.property.$ref;
|
|
111
111
|
const foreignCollection = ast.collections.find(({ name }) => name === refName);
|
|
112
112
|
if (!foreignCollection) {
|
|
113
|
-
|
|
113
|
+
const location = parser_js_1.locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
|
|
114
|
+
errors.push(new diagnostic_js_1.Diagnostic(`invalid reference "${refName}"`, location));
|
|
115
|
+
return;
|
|
114
116
|
}
|
|
115
117
|
await checkCollectionForeignProperties(foreignCollection, node.property, 'indexes');
|
|
116
118
|
await checkCollectionForeignProperties(foreignCollection, node.property, 'populate');
|
package/dist/semantic.mjs
CHANGED
|
@@ -74,7 +74,9 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
74
74
|
const refName = node.property.$ref;
|
|
75
75
|
const foreignCollection = ast.collections.find(({ name }) => name === refName);
|
|
76
76
|
if (!foreignCollection) {
|
|
77
|
-
|
|
77
|
+
const location = locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
|
|
78
|
+
errors.push(new Diagnostic(`invalid reference "${refName}"`, location));
|
|
79
|
+
return;
|
|
78
80
|
}
|
|
79
81
|
await checkCollectionForeignProperties(foreignCollection, node.property, "indexes");
|
|
80
82
|
await checkCollectionForeignProperties(foreignCollection, node.property, "populate");
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|