@aeriajs/compiler 0.0.16 → 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/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) {
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) {
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 FILE_PRECEDENCE: string[];
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 generateScaffolding: (options: CompilationOptions) => Promise<string[]>;
6
- export declare const compileFromFiles: (globPattern: 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,18 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.compileFromFiles = exports.generateScaffolding = exports.parseAndCheck = exports.FILE_PRECEDENCE = void 0;
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.FILE_PRECEDENCE = ['contract'];
43
+ exports.GLOB_PATTERN = '**/*.aeria';
45
44
  const parseAndCheck = async (sources, options = {}) => {
46
45
  const errors = [];
47
- let ast;
48
46
  const allTokens = [];
49
47
  for (const fileName in sources) {
50
48
  diagnostic_js_1.Diagnostic.currentFile = fileName;
@@ -54,8 +52,8 @@ const parseAndCheck = async (sources, options = {}) => {
54
52
  }
55
53
  allTokens.push(...tokens);
56
54
  }
57
- const { errors: parserErrors, ast: currentAst } = (0, parser_js_1.parse)(allTokens);
58
- const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(currentAst, options);
55
+ const { errors: parserErrors, ast } = (0, parser_js_1.parse)(allTokens);
56
+ const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(ast, options);
59
57
  errors.push(...parserErrors.concat(semanticErrors));
60
58
  return {
61
59
  success: errors.length === 0,
@@ -65,31 +63,11 @@ const parseAndCheck = async (sources, options = {}) => {
65
63
  };
66
64
  };
67
65
  exports.parseAndCheck = parseAndCheck;
68
- const generateScaffolding = async (options) => {
69
- const directories = [path.join(options.outDir, 'collections')];
70
- for (const dir of directories) {
71
- await fs.promises.mkdir(dir, {
72
- recursive: true,
73
- });
74
- }
75
- return directories;
76
- };
77
- exports.generateScaffolding = generateScaffolding;
78
- const compileFromFiles = async (globPattern, options) => {
79
- const fileList = await Array.fromAsync(fs.promises.glob(globPattern));
80
- const sortedFileList = fileList.sort((a, b) => {
81
- const aIndex = exports.FILE_PRECEDENCE.findIndex((file) => a.split('/').at(-1).startsWith(file));
82
- const bIndex = exports.FILE_PRECEDENCE.findIndex((file) => b.split('/').at(-1).startsWith(file));
83
- if (!~aIndex && !~bIndex) {
84
- return 1;
85
- }
86
- return aIndex > bIndex
87
- ? 1
88
- : -1;
89
- });
66
+ const compileFromFiles = async (options) => {
67
+ const fileList = await Array.fromAsync(fs.promises.glob(exports.GLOB_PATTERN));
90
68
  const sources = {};
91
- for (const file of sortedFileList) {
92
- sources[file] = await fs.promises.readFile(file, {
69
+ for (const fileName of fileList) {
70
+ sources[fileName] = await fs.promises.readFile(fileName, {
93
71
  encoding: 'utf-8',
94
72
  });
95
73
  }
@@ -97,10 +75,13 @@ const compileFromFiles = async (globPattern, options) => {
97
75
  if (!result.ast || result.errorCount > 0) {
98
76
  return result;
99
77
  }
100
- const emittedFiles = await (0, codegen_js_1.generateCode)(result.ast, options);
101
- return {
102
- ...result,
103
- emittedFiles,
104
- };
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;
105
86
  };
106
87
  exports.compileFromFiles = compileFromFiles;
package/dist/compile.mjs CHANGED
@@ -4,12 +4,10 @@ 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 FILE_PRECEDENCE = ["contract"];
8
+ export const GLOB_PATTERN = "**/*.aeria";
10
9
  export const parseAndCheck = async (sources, options = {}) => {
11
10
  const errors = [];
12
- let ast;
13
11
  const allTokens = [];
14
12
  for (const fileName in sources) {
15
13
  Diagnostic.currentFile = fileName;
@@ -19,8 +17,8 @@ export const parseAndCheck = async (sources, options = {}) => {
19
17
  }
20
18
  allTokens.push(...tokens);
21
19
  }
22
- const { errors: parserErrors, ast: currentAst } = parse(allTokens);
23
- const { errors: semanticErrors } = await analyze(currentAst, options);
20
+ const { errors: parserErrors, ast } = parse(allTokens);
21
+ const { errors: semanticErrors } = await analyze(ast, options);
24
22
  errors.push(...parserErrors.concat(semanticErrors));
25
23
  return {
26
24
  success: errors.length === 0,
@@ -29,28 +27,11 @@ export const parseAndCheck = async (sources, options = {}) => {
29
27
  ast
30
28
  };
31
29
  };
32
- export const generateScaffolding = async (options) => {
33
- const directories = [path.join(options.outDir, "collections")];
34
- for (const dir of directories) {
35
- await fs.promises.mkdir(dir, {
36
- recursive: true
37
- });
38
- }
39
- return directories;
40
- };
41
- export const compileFromFiles = async (globPattern, options) => {
42
- const fileList = await Array.fromAsync(fs.promises.glob(globPattern));
43
- const sortedFileList = fileList.sort((a, b) => {
44
- const aIndex = FILE_PRECEDENCE.findIndex((file) => a.split("/").at(-1).startsWith(file));
45
- const bIndex = FILE_PRECEDENCE.findIndex((file) => b.split("/").at(-1).startsWith(file));
46
- if (!~aIndex && !~bIndex) {
47
- return 1;
48
- }
49
- return aIndex > bIndex ? 1 : -1;
50
- });
30
+ export const compileFromFiles = async (options) => {
31
+ const fileList = await Array.fromAsync(fs.promises.glob(GLOB_PATTERN));
51
32
  const sources = {};
52
- for (const file of sortedFileList) {
53
- sources[file] = await fs.promises.readFile(file, {
33
+ for (const fileName of fileList) {
34
+ sources[fileName] = await fs.promises.readFile(fileName, {
54
35
  encoding: "utf-8"
55
36
  });
56
37
  }
@@ -58,9 +39,12 @@ export const compileFromFiles = async (globPattern, options) => {
58
39
  if (!result.ast || result.errorCount > 0) {
59
40
  return result;
60
41
  }
61
- const emittedFiles = await generateCode(result.ast, options);
62
- return {
63
- ...result,
64
- emittedFiles
65
- };
42
+ if (options.outDir) {
43
+ const emittedFiles = await generateCode(result.ast, options);
44
+ return {
45
+ ...result,
46
+ emittedFiles
47
+ };
48
+ }
49
+ return result;
66
50
  };
package/dist/parser.js CHANGED
@@ -380,7 +380,6 @@ const parse = (tokens) => {
380
380
  let nestedProperties;
381
381
  let modifierToken;
382
382
  const typeSymbol = Symbol();
383
- exports.locationMap.set(typeSymbol, next().location);
384
383
  if (match(token_js_1.TokenType.LeftSquareBracket)) {
385
384
  consume(token_js_1.TokenType.LeftSquareBracket);
386
385
  const arrayProperty = {
@@ -428,6 +427,7 @@ const parse = (tokens) => {
428
427
  ...arrayProperty,
429
428
  items,
430
429
  };
430
+ exports.locationMap.set(typeSymbol, current().location);
431
431
  return {
432
432
  kind: 'property',
433
433
  property,
@@ -441,6 +441,7 @@ const parse = (tokens) => {
441
441
  modifierToken = consume(token_js_1.TokenType.Identifier);
442
442
  }
443
443
  }
444
+ exports.locationMap.set(typeSymbol, current().location);
444
445
  if (match(token_js_1.TokenType.LeftBracket)) {
445
446
  consume(token_js_1.TokenType.LeftBracket);
446
447
  property = {
package/dist/parser.mjs CHANGED
@@ -338,7 +338,6 @@ export const parse = (tokens) => {
338
338
  let nestedProperties;
339
339
  let modifierToken;
340
340
  const typeSymbol = Symbol();
341
- locationMap.set(typeSymbol, next().location);
342
341
  if (match(TokenType.LeftSquareBracket)) {
343
342
  consume(TokenType.LeftSquareBracket);
344
343
  const arrayProperty = {
@@ -384,6 +383,7 @@ export const parse = (tokens) => {
384
383
  ...arrayProperty,
385
384
  items
386
385
  };
386
+ locationMap.set(typeSymbol, current().location);
387
387
  return {
388
388
  kind: "property",
389
389
  property,
@@ -397,6 +397,7 @@ export const parse = (tokens) => {
397
397
  modifierToken = consume(TokenType.Identifier);
398
398
  }
399
399
  }
400
+ locationMap.set(typeSymbol, current().location);
400
401
  if (match(TokenType.LeftBracket)) {
401
402
  consume(TokenType.LeftBracket);
402
403
  property = {
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@ export type CompilationResult = {
7
7
  errorCount: number;
8
8
  };
9
9
  export type CompilationOptions = {
10
- outDir: string;
10
+ outDir?: string;
11
11
  dryRun?: boolean;
12
12
  languageServer?: boolean;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.16",
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
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
15
  }
16
16
  },
17
17
  "keywords": [],