vba-runner 0.1.1-alpha.2 → 0.1.1-alpha.3

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.
@@ -2521,7 +2521,7 @@ var Parser = class _Parser {
2521
2521
  parseEventDeclaration(scope) {
2522
2522
  this.advance();
2523
2523
  const idToken = this.advance();
2524
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2524
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2525
2525
  const name = { type: "Identifier", name: idToken.value };
2526
2526
  const parameters = [];
2527
2527
  if (this.match(128 /* OperatorLParen */)) {
@@ -2539,7 +2539,7 @@ var Parser = class _Parser {
2539
2539
  parseRaiseEventStatement() {
2540
2540
  this.advance();
2541
2541
  const idToken = this.advance();
2542
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2542
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2543
2543
  const eventName = { type: "Identifier", name: idToken.value };
2544
2544
  const args = [];
2545
2545
  if (this.match(128 /* OperatorLParen */)) {
@@ -2864,6 +2864,21 @@ function evaluateCCExpr(expr, resolve) {
2864
2864
  }
2865
2865
  return parseOr();
2866
2866
  }
2867
+ function stripVBAFileHeader(source) {
2868
+ const lines = source.split("\n");
2869
+ if (!lines[0]?.trimEnd().toUpperCase().startsWith("VERSION")) return source;
2870
+ const result = [...lines];
2871
+ let i = 0;
2872
+ result[i] = "";
2873
+ i++;
2874
+ while (i < result.length) {
2875
+ const trimmed = result[i].trimEnd().toUpperCase();
2876
+ result[i] = "";
2877
+ i++;
2878
+ if (trimmed === "END") break;
2879
+ }
2880
+ return result.join("\n");
2881
+ }
2867
2882
 
2868
2883
  // ../../test-libs/vba-analyzer.ts
2869
2884
  var fs = __toESM(require("fs"), 1);
@@ -4379,7 +4394,9 @@ function analyzeGotoInProc(proc) {
4379
4394
  };
4380
4395
  }
4381
4396
  function analyzeFile(filePath) {
4382
- const src = fs.readFileSync(filePath, "utf-8");
4397
+ const ext = path.extname(filePath).toLowerCase();
4398
+ const raw = fs.readFileSync(filePath, "utf-8");
4399
+ const src = stripVBAFileHeader(raw);
4383
4400
  const lines = src.split("\n");
4384
4401
  const warnings = [];
4385
4402
  let ast;
@@ -2508,7 +2508,7 @@ var Parser = class _Parser {
2508
2508
  parseEventDeclaration(scope) {
2509
2509
  this.advance();
2510
2510
  const idToken = this.advance();
2511
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2511
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2512
2512
  const name = { type: "Identifier", name: idToken.value };
2513
2513
  const parameters = [];
2514
2514
  if (this.match(128 /* OperatorLParen */)) {
@@ -2526,7 +2526,7 @@ var Parser = class _Parser {
2526
2526
  parseRaiseEventStatement() {
2527
2527
  this.advance();
2528
2528
  const idToken = this.advance();
2529
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2529
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2530
2530
  const eventName = { type: "Identifier", name: idToken.value };
2531
2531
  const args = [];
2532
2532
  if (this.match(128 /* OperatorLParen */)) {
@@ -2604,6 +2604,23 @@ var Parser = class _Parser {
2604
2604
  }
2605
2605
  };
2606
2606
 
2607
+ // ../../src/engine/preprocessor.ts
2608
+ function stripVBAFileHeader(source) {
2609
+ const lines = source.split("\n");
2610
+ if (!lines[0]?.trimEnd().toUpperCase().startsWith("VERSION")) return source;
2611
+ const result = [...lines];
2612
+ let i = 0;
2613
+ result[i] = "";
2614
+ i++;
2615
+ while (i < result.length) {
2616
+ const trimmed = result[i].trimEnd().toUpperCase();
2617
+ result[i] = "";
2618
+ i++;
2619
+ if (trimmed === "END") break;
2620
+ }
2621
+ return result.join("\n");
2622
+ }
2623
+
2607
2624
  // ../../test-libs/vba-parse-check.ts
2608
2625
  var fs = __toESM(require("fs"), 1);
2609
2626
  var path = __toESM(require("path"), 1);
@@ -2613,7 +2630,9 @@ var VERSION = "0.1.1-alpha.1";
2613
2630
 
2614
2631
  // ../../test-libs/vba-parse-check.ts
2615
2632
  function checkFile(filePath) {
2616
- const src = fs.readFileSync(filePath, "utf8");
2633
+ const ext = path.extname(filePath).toLowerCase();
2634
+ const raw = fs.readFileSync(filePath, "utf8");
2635
+ const src = stripVBAFileHeader(raw);
2617
2636
  const diags = [];
2618
2637
  const lexer = new Lexer(src);
2619
2638
  let tokens;
@@ -2510,7 +2510,7 @@ var Parser = class _Parser {
2510
2510
  parseEventDeclaration(scope) {
2511
2511
  this.advance();
2512
2512
  const idToken = this.advance();
2513
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2513
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2514
2514
  const name = { type: "Identifier", name: idToken.value };
2515
2515
  const parameters = [];
2516
2516
  if (this.match(128 /* OperatorLParen */)) {
@@ -2528,7 +2528,7 @@ var Parser = class _Parser {
2528
2528
  parseRaiseEventStatement() {
2529
2529
  this.advance();
2530
2530
  const idToken = this.advance();
2531
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2531
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2532
2532
  const eventName = { type: "Identifier", name: idToken.value };
2533
2533
  const args = [];
2534
2534
  if (this.match(128 /* OperatorLParen */)) {
@@ -9707,6 +9707,21 @@ function evaluateCCExpr(expr, resolve2) {
9707
9707
  }
9708
9708
  return parseOr();
9709
9709
  }
9710
+ function stripVBAFileHeader(source) {
9711
+ const lines = source.split("\n");
9712
+ if (!lines[0]?.trimEnd().toUpperCase().startsWith("VERSION")) return source;
9713
+ const result = [...lines];
9714
+ let i = 0;
9715
+ result[i] = "";
9716
+ i++;
9717
+ while (i < result.length) {
9718
+ const trimmed = result[i].trimEnd().toUpperCase();
9719
+ result[i] = "";
9720
+ i++;
9721
+ if (trimmed === "END") break;
9722
+ }
9723
+ return result.join("\n");
9724
+ }
9710
9725
 
9711
9726
  // ../../test-libs/version.ts
9712
9727
  var VERSION = "0.1.1-alpha.1";
@@ -9754,8 +9769,10 @@ function main(args) {
9754
9769
  for (const file of files) {
9755
9770
  const moduleName = path4.basename(file, path4.extname(file));
9756
9771
  ev.setSourceModule(moduleName);
9757
- const src = preprocess(fs2.readFileSync(file, "utf-8"));
9758
9772
  const ext = path4.extname(file).toLowerCase();
9773
+ let src = fs2.readFileSync(file, "utf-8");
9774
+ src = stripVBAFileHeader(src);
9775
+ src = preprocess(src);
9759
9776
  const isRawCls = ext === ".cls" && !src.trim().toLowerCase().startsWith("class ") && !src.toLowerCase().includes("end class");
9760
9777
  const ast = new Parser(new Lexer(src).tokenize(), isRawCls ? { parseAsClass: moduleName } : {}).parse();
9761
9778
  ev.evaluateModule(ast);
@@ -2500,7 +2500,7 @@ var Parser = class _Parser {
2500
2500
  parseEventDeclaration(scope) {
2501
2501
  this.advance();
2502
2502
  const idToken = this.advance();
2503
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2503
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2504
2504
  const name = { type: "Identifier", name: idToken.value };
2505
2505
  const parameters = [];
2506
2506
  if (this.match(128 /* OperatorLParen */)) {
@@ -2518,7 +2518,7 @@ var Parser = class _Parser {
2518
2518
  parseRaiseEventStatement() {
2519
2519
  this.advance();
2520
2520
  const idToken = this.advance();
2521
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2521
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2522
2522
  const eventName = { type: "Identifier", name: idToken.value };
2523
2523
  const args = [];
2524
2524
  if (this.match(128 /* OperatorLParen */)) {
@@ -9697,6 +9697,21 @@ function evaluateCCExpr(expr, resolve2) {
9697
9697
  }
9698
9698
  return parseOr();
9699
9699
  }
9700
+ function stripVBAFileHeader(source) {
9701
+ const lines = source.split("\n");
9702
+ if (!lines[0]?.trimEnd().toUpperCase().startsWith("VERSION")) return source;
9703
+ const result = [...lines];
9704
+ let i = 0;
9705
+ result[i] = "";
9706
+ i++;
9707
+ while (i < result.length) {
9708
+ const trimmed = result[i].trimEnd().toUpperCase();
9709
+ result[i] = "";
9710
+ i++;
9711
+ if (trimmed === "END") break;
9712
+ }
9713
+ return result.join("\n");
9714
+ }
9700
9715
 
9701
9716
  // ../../test-libs/version.ts
9702
9717
  var VERSION = "0.1.1-alpha.1";
@@ -9744,8 +9759,10 @@ function main(args) {
9744
9759
  for (const file of files) {
9745
9760
  const moduleName = path4.basename(file, path4.extname(file));
9746
9761
  ev.setSourceModule(moduleName);
9747
- const src = preprocess(fs2.readFileSync(file, "utf-8"));
9748
9762
  const ext = path4.extname(file).toLowerCase();
9763
+ let src = fs2.readFileSync(file, "utf-8");
9764
+ src = stripVBAFileHeader(src);
9765
+ src = preprocess(src);
9749
9766
  const isRawCls = ext === ".cls" && !src.trim().toLowerCase().startsWith("class ") && !src.toLowerCase().includes("end class");
9750
9767
  const ast = new Parser(new Lexer(src).tokenize(), isRawCls ? { parseAsClass: moduleName } : {}).parse();
9751
9768
  ev.evaluateModule(ast);
@@ -11271,7 +11288,9 @@ function analyzeGotoInProc(proc) {
11271
11288
  };
11272
11289
  }
11273
11290
  function analyzeFile(filePath) {
11274
- const src = fs3.readFileSync(filePath, "utf-8");
11291
+ const ext = path5.extname(filePath).toLowerCase();
11292
+ const raw = fs3.readFileSync(filePath, "utf-8");
11293
+ const src = stripVBAFileHeader(raw);
11275
11294
  const lines = src.split("\n");
11276
11295
  const warnings = [];
11277
11296
  let ast;
@@ -12730,7 +12749,9 @@ if (process.argv[1]?.includes("vba-formatter")) main3(process.argv.slice(2));
12730
12749
  var fs5 = __toESM(require("fs"), 1);
12731
12750
  var path7 = __toESM(require("path"), 1);
12732
12751
  function checkFile(filePath) {
12733
- const src = fs5.readFileSync(filePath, "utf8");
12752
+ const ext = path7.extname(filePath).toLowerCase();
12753
+ const raw = fs5.readFileSync(filePath, "utf8");
12754
+ const src = stripVBAFileHeader(raw);
12734
12755
  const diags = [];
12735
12756
  const lexer = new Lexer(src);
12736
12757
  let tokens;
package/dist/lib.cjs CHANGED
@@ -2522,7 +2522,7 @@ var Parser = class _Parser {
2522
2522
  parseEventDeclaration(scope) {
2523
2523
  this.advance();
2524
2524
  const idToken = this.advance();
2525
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2525
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'Event' at line ${idToken.line}`);
2526
2526
  const name = { type: "Identifier", name: idToken.value };
2527
2527
  const parameters = [];
2528
2528
  if (this.match(128 /* OperatorLParen */)) {
@@ -2540,7 +2540,7 @@ var Parser = class _Parser {
2540
2540
  parseRaiseEventStatement() {
2541
2541
  this.advance();
2542
2542
  const idToken = this.advance();
2543
- if (!this.isIdentifier(idToken) && !this.isNameToken(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2543
+ if (!this.isIdentifier(idToken)) this.throwError(`Expected identifier after 'RaiseEvent' at line ${idToken.line}`);
2544
2544
  const eventName = { type: "Identifier", name: idToken.value };
2545
2545
  const args = [];
2546
2546
  if (this.match(128 /* OperatorLParen */)) {
@@ -9666,6 +9666,21 @@ function evaluateCCExpr(expr, resolve2) {
9666
9666
  }
9667
9667
  return parseOr();
9668
9668
  }
9669
+ function stripVBAFileHeader(source) {
9670
+ const lines = source.split("\n");
9671
+ if (!lines[0]?.trimEnd().toUpperCase().startsWith("VERSION")) return source;
9672
+ const result = [...lines];
9673
+ let i = 0;
9674
+ result[i] = "";
9675
+ i++;
9676
+ while (i < result.length) {
9677
+ const trimmed = result[i].trimEnd().toUpperCase();
9678
+ result[i] = "";
9679
+ i++;
9680
+ if (trimmed === "END") break;
9681
+ }
9682
+ return result.join("\n");
9683
+ }
9669
9684
 
9670
9685
  // ../../test-libs/mock-loader.ts
9671
9686
  var fs = __toESM(require("fs"), 1);
@@ -9720,7 +9735,8 @@ function loadVbaMock(file, evaluator) {
9720
9735
  const source = fs.readFileSync(file, "utf-8");
9721
9736
  const ext = path4.extname(file).toLowerCase();
9722
9737
  const moduleName = path4.basename(file, ext);
9723
- const processed = preprocess(source);
9738
+ const stripped = stripVBAFileHeader(source);
9739
+ const processed = preprocess(stripped);
9724
9740
  const isRawCls = ext === ".cls" && !processed.trim().toLowerCase().startsWith("class ") && !processed.toLowerCase().includes("end class");
9725
9741
  const parseOpts = isRawCls ? { parseAsClass: moduleName } : {};
9726
9742
  const classesBefore = evaluator.getRegisteredClassNames();
@@ -10577,8 +10593,9 @@ var VBARunner = class {
10577
10593
  try {
10578
10594
  const moduleName = path5.basename(file, path5.extname(file));
10579
10595
  this.evaluator.setSourceModule(moduleName);
10580
- source = preprocess(source, config.compilerConstants);
10581
10596
  const ext = path5.extname(file).toLowerCase();
10597
+ source = stripVBAFileHeader(source);
10598
+ source = preprocess(source, config.compilerConstants);
10582
10599
  const isRawCls = ext === ".cls" && !source.trim().toLowerCase().startsWith("class ") && !source.toLowerCase().includes("end class");
10583
10600
  const parseOpts = isRawCls ? { parseAsClass: moduleName } : {};
10584
10601
  const ast = new Parser(new Lexer(source).tokenize(), parseOpts).parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vba-runner",
3
- "version": "0.1.1-alpha.2",
3
+ "version": "0.1.1-alpha.3",
4
4
  "description": "VBA execution engine with test runner and CLI tools (analyzer, formatter, parse-check)",
5
5
  "type": "module",
6
6
  "license": "MIT",