@irrelon/battlescript 3.1.5 → 3.1.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"functionality.d.ts","sourceRoot":"","sources":["../../bin/functionality.ts"],"names":[],"mappings":"AAgBA,wBAAsB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,gBAgBjE;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,OAgB/D;AAED,wBAAsB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAYlE;AAED,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAYpE;AAED,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAiBnE;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAe1E;AAED,wBAAsB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAUrE;AAcD,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAWvE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIxE"}
1
+ {"version":3,"file":"functionality.d.ts","sourceRoot":"","sources":["../../bin/functionality.ts"],"names":[],"mappings":"AAyBA,wBAAsB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,gBAgBjE;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,OAoB/D;AAED,wBAAsB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAYlE;AAED,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAYpE;AAED,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAiBnE;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAe1E;AAED,wBAAsB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAUrE;AAcD,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAWvE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIxE"}
package/dist/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import require$$0 from 'assert';
2
2
  import require$$0$1 from 'util';
3
3
  import { join, dirname } from 'path';
4
- import 'fs/promises';
5
- import { readFileSync } from 'fs';
6
- import { writeFileSync } from 'node:fs';
7
4
 
8
5
  var ATNDeserializer = {};
9
6
 
@@ -27937,25 +27934,9 @@ function getAllNativeLibraryFunctions(rootNode) {
27937
27934
  ];
27938
27935
  }
27939
27936
 
27940
- var version = "3.1.5";
27937
+ var version = "3.1.6";
27941
27938
  var binaryVersion = 7;
27942
27939
 
27943
- function toAstSync(inputPath, outputPath) {
27944
- console.log(`[BattleScript ${version}] toAstSync: ${inputPath}`);
27945
- try {
27946
- const sourceCode = readFileSync(inputPath, "utf-8");
27947
- const ast = fromSourceCodeToFullAst(sourceCode, { filePath: inputPath, includeMetaData: true });
27948
- if (outputPath) ;
27949
- else {
27950
- return ast;
27951
- }
27952
- }
27953
- catch (error) {
27954
- console.error(`[BattleScript ${version}] Error:`, error.stack);
27955
- process.exit(1);
27956
- }
27957
- }
27958
-
27959
27940
  const RootNodeLayout = [{
27960
27941
  key: "kind",
27961
27942
  shape: [EnumNodeLayoutEntry.LAYOUT_POINTER_KIND],
@@ -27993,7 +27974,12 @@ const rootToAstNode = (instance, ctx) => {
27993
27974
  // Check we can locate the file
27994
27975
  console.log(`[BattleScript ${version}] Processing import compilation unit: `, importNode.source.value);
27995
27976
  const filePath = join(dirname(instance._filePath), importNode.source.value);
27996
- const importedAst = toAstSync(filePath);
27977
+ const importedSourceCode = instance.resolveSourceCode(filePath);
27978
+ const importedAst = fromSourceCodeToFullAst(importedSourceCode, {
27979
+ filePath,
27980
+ includeMetaData: true,
27981
+ sourceResolver: instance._sourceResolver
27982
+ });
27997
27983
  return importedAst.body;
27998
27984
  }).concat(standardLibraryDeclarations).filter((astNode) => {
27999
27985
  // TODO: We should move this to just before we complete the AST generation
@@ -28270,7 +28256,7 @@ function getMetaData(ctx, extra) {
28270
28256
  };
28271
28257
  }
28272
28258
  class BattleScriptToAST extends AbstractParseTreeVisitorExports.AbstractParseTreeVisitor {
28273
- constructor(filePath, sourceCode) {
28259
+ constructor(filePath, sourceCode, sourceResolver) {
28274
28260
  super();
28275
28261
  this._options = {
28276
28262
  includeMetaData: true
@@ -28288,6 +28274,16 @@ class BattleScriptToAST extends AbstractParseTreeVisitorExports.AbstractParseTre
28288
28274
  return;
28289
28275
  this._sourceCode = newSourceCode;
28290
28276
  };
28277
+ this.resolveSourceCode = (filePath) => {
28278
+ if (this._sourceResolver) {
28279
+ const resolved = this._sourceResolver(filePath);
28280
+ if (resolved !== undefined) {
28281
+ return resolved;
28282
+ }
28283
+ throw new Error(`Source resolver could not resolve source code for file: ${filePath}`);
28284
+ }
28285
+ throw new Error(`Could not resolve source code for file: ${filePath}. No source resolver provided.`);
28286
+ };
28291
28287
  this.extractInlineComment = (ctx) => {
28292
28288
  if (!ctx)
28293
28289
  return;
@@ -28517,6 +28513,7 @@ class BattleScriptToAST extends AbstractParseTreeVisitorExports.AbstractParseTre
28517
28513
  };
28518
28514
  this._filePath = filePath;
28519
28515
  this._sourceCode = sourceCode;
28516
+ this._sourceResolver = sourceResolver;
28520
28517
  }
28521
28518
  visit(node, options) {
28522
28519
  if (options) {
@@ -39079,7 +39076,7 @@ function fromSourceCodeToFullAst(inputText, options) {
39079
39076
  const parser = getParser(inputText);
39080
39077
  const tree = parser.root();
39081
39078
  console.log(`[BattleScript ${version}] Transforming source code -> AST...`);
39082
- const transformer = new BattleScriptToAST(options?.filePath || "-", inputText);
39079
+ const transformer = new BattleScriptToAST(options?.filePath || "-", inputText, options?.sourceResolver);
39083
39080
  transformer.filePath(options?.filePath);
39084
39081
  transformer.sourceCode(inputText);
39085
39082
  return transformer.visit(tree, options);
@@ -39112,7 +39109,7 @@ function fromSourceCodeToByteCode(source, options = { includeMetaData: true }) {
39112
39109
  if (typeof source === "string") {
39113
39110
  const parser = getParser(source);
39114
39111
  const tree = parser.root();
39115
- const transformer = new BattleScriptToAST(options?.filePath || "-", source);
39112
+ const transformer = new BattleScriptToAST(options?.filePath || "-", source, options?.sourceResolver);
39116
39113
  transformer.sourceCode(source);
39117
39114
  transformer.visit(tree, options);
39118
39115
  }