@aeriajs/compiler 0.0.8 → 0.0.9
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.d.ts +2 -2
- package/dist/compile.d.ts +3 -13
- package/dist/compile.js +3 -3
- package/dist/compile.mjs +3 -3
- package/dist/lexer.d.ts +1 -1
- package/dist/lexer.js +2 -1
- package/dist/lexer.mjs +2 -1
- package/dist/semantic.d.ts +2 -1
- package/dist/semantic.js +7 -4
- package/dist/semantic.mjs +7 -4
- package/dist/types.d.ts +13 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +1 -1
package/dist/codegen.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import type * as AST from './ast.js';
|
|
2
|
+
import type { CompilationOptions } from './types.js';
|
|
3
3
|
export declare const generateCode: (ast: AST.ProgramNode, options: CompilationOptions) => Promise<Record<string, string>>;
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { CompilationOptions, CompilationResult } from './types.js';
|
|
2
2
|
import { Diagnostic } from './diagnostic.js';
|
|
3
|
-
export
|
|
4
|
-
success: boolean;
|
|
5
|
-
ast?: AST.ProgramNode;
|
|
6
|
-
errors: Diagnostic[];
|
|
7
|
-
errorCount: number;
|
|
8
|
-
};
|
|
9
|
-
export type CompilationOptions = {
|
|
10
|
-
outDir: string;
|
|
11
|
-
dryRun?: true;
|
|
12
|
-
};
|
|
13
|
-
export declare const parseAndCheck: (sources: Record<string, string>) => Promise<CompilationResult>;
|
|
3
|
+
export declare const parseAndCheck: (sources: Record<string, string>, options?: Pick<CompilationOptions, "languageServer">) => Promise<CompilationResult>;
|
|
14
4
|
export declare const generateScaffolding: (options: CompilationOptions) => Promise<string[]>;
|
|
15
5
|
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<CompilationResult | {
|
|
16
6
|
emittedFiles: Record<string, string>;
|
|
17
7
|
success: boolean;
|
|
18
|
-
ast?:
|
|
8
|
+
ast?: import("./ast.js").ProgramNode;
|
|
19
9
|
errors: Diagnostic[];
|
|
20
10
|
errorCount: number;
|
|
21
11
|
}>;
|
package/dist/compile.js
CHANGED
|
@@ -41,7 +41,7 @@ const semantic_js_1 = require("./semantic.js");
|
|
|
41
41
|
const codegen_js_1 = require("./codegen.js");
|
|
42
42
|
const path = __importStar(require("node:path"));
|
|
43
43
|
const fs = __importStar(require("node:fs"));
|
|
44
|
-
const parseAndCheck = async (sources) => {
|
|
44
|
+
const parseAndCheck = async (sources, options = {}) => {
|
|
45
45
|
const errors = [];
|
|
46
46
|
let errorCount = 0;
|
|
47
47
|
let ast;
|
|
@@ -49,7 +49,7 @@ const parseAndCheck = async (sources) => {
|
|
|
49
49
|
diagnostic_js_1.Diagnostic.currentFile = fileName;
|
|
50
50
|
const { errors: lexerErrors, tokens } = (0, lexer_js_1.tokenize)(sources[fileName]);
|
|
51
51
|
const { errors: parserErrors, ast: currentAst } = (0, parser_js_1.parse)(Array.from(tokens));
|
|
52
|
-
const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(currentAst);
|
|
52
|
+
const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(currentAst, options);
|
|
53
53
|
errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
|
|
54
54
|
errorCount += errors.length;
|
|
55
55
|
if (!ast) {
|
|
@@ -87,7 +87,7 @@ const compileFromFiles = async (schemaDir, options) => {
|
|
|
87
87
|
encoding: 'utf-8',
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
const result = await (0, exports.parseAndCheck)(sources);
|
|
90
|
+
const result = await (0, exports.parseAndCheck)(sources, options);
|
|
91
91
|
if (!result.ast) {
|
|
92
92
|
return result;
|
|
93
93
|
}
|
package/dist/compile.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { analyze } from "./semantic.mjs";
|
|
|
6
6
|
import { generateCode } from "./codegen.mjs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
8
|
import * as fs from "node:fs";
|
|
9
|
-
export const parseAndCheck = async (sources) => {
|
|
9
|
+
export const parseAndCheck = async (sources, options = {}) => {
|
|
10
10
|
const errors = [];
|
|
11
11
|
let errorCount = 0;
|
|
12
12
|
let ast;
|
|
@@ -14,7 +14,7 @@ export const parseAndCheck = async (sources) => {
|
|
|
14
14
|
Diagnostic.currentFile = fileName;
|
|
15
15
|
const { errors: lexerErrors, tokens } = tokenize(sources[fileName]);
|
|
16
16
|
const { errors: parserErrors, ast: currentAst } = parse(Array.from(tokens));
|
|
17
|
-
const { errors: semanticErrors } = await analyze(currentAst);
|
|
17
|
+
const { errors: semanticErrors } = await analyze(currentAst, options);
|
|
18
18
|
errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
|
|
19
19
|
errorCount += errors.length;
|
|
20
20
|
if (!ast) {
|
|
@@ -49,7 +49,7 @@ export const compileFromFiles = async (schemaDir, options) => {
|
|
|
49
49
|
encoding: "utf-8"
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
const result = await parseAndCheck(sources);
|
|
52
|
+
const result = await parseAndCheck(sources, options);
|
|
53
53
|
if (!result.ast) {
|
|
54
54
|
return result;
|
|
55
55
|
}
|
package/dist/lexer.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const CONTRACT_KEYWORDS: readonly ["payload", "query", "response"
|
|
|
8
8
|
export declare const TOPLEVEL_KEYWORDS: readonly ["collection", "contract", "functionset"];
|
|
9
9
|
export declare const MISC_KEYWORDS: readonly ["extends"];
|
|
10
10
|
export declare const KEYWORDS: Keyword[];
|
|
11
|
-
export declare const tokenize: (
|
|
11
|
+
export declare const tokenize: (rawInput: string) => {
|
|
12
12
|
tokens: Token[];
|
|
13
13
|
errors: Diagnostic[];
|
|
14
14
|
};
|
package/dist/lexer.js
CHANGED
|
@@ -156,7 +156,8 @@ const TOKENS = [
|
|
|
156
156
|
valueExtractor: (value) => value.slice(1),
|
|
157
157
|
},
|
|
158
158
|
];
|
|
159
|
-
const tokenize = function (
|
|
159
|
+
const tokenize = function (rawInput) {
|
|
160
|
+
const input = rawInput.replace(/\r\n/g, '\n');
|
|
160
161
|
let index = 0, line = 1, start = 0, end = 0;
|
|
161
162
|
const tokens = [];
|
|
162
163
|
const errors = [];
|
package/dist/lexer.mjs
CHANGED
|
@@ -161,7 +161,8 @@ const TOKENS = [
|
|
|
161
161
|
valueExtractor: (value) => value.slice(1)
|
|
162
162
|
}
|
|
163
163
|
];
|
|
164
|
-
export const tokenize = function(
|
|
164
|
+
export const tokenize = function(rawInput) {
|
|
165
|
+
const input = rawInput.replace(/\r\n/g, "\n");
|
|
165
166
|
let index = 0, line = 1, start = 0, end = 0;
|
|
166
167
|
const tokens = [];
|
|
167
168
|
const errors = [];
|
package/dist/semantic.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CompilationOptions } from './types.js';
|
|
1
2
|
import { Diagnostic } from './diagnostic.js';
|
|
2
3
|
import * as AST from './ast.js';
|
|
3
|
-
export declare const analyze: (ast: AST.ProgramNode, errors?: Diagnostic[]) => Promise<{
|
|
4
|
+
export declare const analyze: (ast: AST.ProgramNode, options: Pick<CompilationOptions, "languageServer">, errors?: Diagnostic[]) => Promise<{
|
|
4
5
|
errors: Diagnostic[];
|
|
5
6
|
}>;
|
package/dist/semantic.js
CHANGED
|
@@ -38,9 +38,12 @@ const common_1 = require("@aeriajs/common");
|
|
|
38
38
|
const parser_js_1 = require("./parser.js");
|
|
39
39
|
const diagnostic_js_1 = require("./diagnostic.js");
|
|
40
40
|
const AST = __importStar(require("./ast.js"));
|
|
41
|
-
const collectionHasProperty = async (collection, propName) => {
|
|
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
|
+
}
|
|
44
47
|
if (collection.extends) {
|
|
45
48
|
const { packageName, symbolName } = collection.extends;
|
|
46
49
|
const { [symbolName]: importedCollection } = await Promise.resolve(`${packageName}`).then(s => __importStar(require(s)));
|
|
@@ -52,13 +55,13 @@ const collectionHasProperty = async (collection, propName) => {
|
|
|
52
55
|
}
|
|
53
56
|
return hasProperty;
|
|
54
57
|
};
|
|
55
|
-
const analyze = async (ast, errors = []) => {
|
|
58
|
+
const analyze = async (ast, options, errors = []) => {
|
|
56
59
|
const checkCollectionForeignProperties = async (foreignCollection, property, attributeName) => {
|
|
57
60
|
if (!property[attributeName]) {
|
|
58
61
|
return;
|
|
59
62
|
}
|
|
60
63
|
for (const foreignPropName of property[attributeName]) {
|
|
61
|
-
if (!await collectionHasProperty(foreignCollection, foreignPropName)) {
|
|
64
|
+
if (!await collectionHasProperty(foreignCollection, foreignPropName, options)) {
|
|
62
65
|
let location;
|
|
63
66
|
if (property[AST.LOCATION_SYMBOL]) {
|
|
64
67
|
location = parser_js_1.locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
|
|
@@ -74,7 +77,7 @@ const analyze = async (ast, errors = []) => {
|
|
|
74
77
|
for (const index in node[attributeName]) {
|
|
75
78
|
const propName = node[attributeName][index];
|
|
76
79
|
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
77
|
-
if (!await collectionHasProperty(node, propName)) {
|
|
80
|
+
if (!await collectionHasProperty(node, propName, options)) {
|
|
78
81
|
const location = parser_js_1.locationMap.get(symbol);
|
|
79
82
|
errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
80
83
|
}
|
package/dist/semantic.mjs
CHANGED
|
@@ -3,9 +3,12 @@ import { isValidCollection } from "@aeriajs/common";
|
|
|
3
3
|
import { locationMap } from "./parser.mjs";
|
|
4
4
|
import { Diagnostic } from "./diagnostic.mjs";
|
|
5
5
|
import * as AST from "./ast.mjs";
|
|
6
|
-
const collectionHasProperty = async (collection, propName) => {
|
|
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
|
+
}
|
|
9
12
|
if (collection.extends) {
|
|
10
13
|
const { packageName, symbolName } = collection.extends;
|
|
11
14
|
const { [symbolName]: importedCollection } = await import(packageName);
|
|
@@ -17,13 +20,13 @@ const collectionHasProperty = async (collection, propName) => {
|
|
|
17
20
|
}
|
|
18
21
|
return hasProperty;
|
|
19
22
|
};
|
|
20
|
-
export const analyze = async (ast, errors = []) => {
|
|
23
|
+
export const analyze = async (ast, options, errors = []) => {
|
|
21
24
|
const checkCollectionForeignProperties = async (foreignCollection, property, attributeName) => {
|
|
22
25
|
if (!property[attributeName]) {
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
25
28
|
for (const foreignPropName of property[attributeName]) {
|
|
26
|
-
if (!await collectionHasProperty(foreignCollection, foreignPropName)) {
|
|
29
|
+
if (!await collectionHasProperty(foreignCollection, foreignPropName, options)) {
|
|
27
30
|
let location;
|
|
28
31
|
if (property[AST.LOCATION_SYMBOL]) {
|
|
29
32
|
location = locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
|
|
@@ -39,7 +42,7 @@ export const analyze = async (ast, errors = []) => {
|
|
|
39
42
|
for (const index in node[attributeName]) {
|
|
40
43
|
const propName = node[attributeName][index];
|
|
41
44
|
const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
42
|
-
if (!await collectionHasProperty(node, propName)) {
|
|
45
|
+
if (!await collectionHasProperty(node, propName, options)) {
|
|
43
46
|
const location = locationMap.get(symbol);
|
|
44
47
|
errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
|
|
45
48
|
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as AST from './ast.js';
|
|
2
|
+
import { type Diagnostic } from './diagnostic.js';
|
|
3
|
+
export type CompilationResult = {
|
|
4
|
+
success: boolean;
|
|
5
|
+
ast?: AST.ProgramNode;
|
|
6
|
+
errors: Diagnostic[];
|
|
7
|
+
errorCount: number;
|
|
8
|
+
};
|
|
9
|
+
export type CompilationOptions = {
|
|
10
|
+
outDir: string;
|
|
11
|
+
dryRun?: boolean;
|
|
12
|
+
languageServer?: boolean;
|
|
13
|
+
};
|
package/dist/types.js
ADDED
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|