diff --git a/src/language/parser.js b/src/language/parser.js index 859e8841..bf70f51a 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -472,10 +472,16 @@ module.exports = class Parser { if (parts[0] === `/IF`) { // Directive IF directIfScope += 1; + continue; } else if (parts[0] === `/ENDIF`) { // Directive ENDIF directIfScope -= 1; + continue; + } else + if (directIfScope > 0) { + // Ignore lines inside the IF scope. + continue; } switch (parts[0]) { @@ -777,7 +783,7 @@ module.exports = class Parser { } if (currentItem && [`procedure`, `struct`].includes(currentItem.type)) { - if (currentItem.readParms) { + if (currentItem.readParms && parts.length > 0) { if (parts[0].startsWith(`DCL`)) parts.slice(1); diff --git a/tests/suite/directives.js b/tests/suite/directives.js index 3f75260e..03c34539 100644 --- a/tests/suite/directives.js +++ b/tests/suite/directives.js @@ -217,4 +217,42 @@ module.exports = { }, }); }, + + if1: async () => { + const lines = [ + `**FREE`, + `// Function Return Param Definitions`, + `Dcl-Ds Prp00a Qualified`, + `/IF DEFINED(PRP00A_TEMPLATE_ALL_DS)`, + ` Template`, + `/ENDIF`, + `;`, + ` Address Char(220);`, + ` Emp Packed(6);`, + ` Empname Char(60);`, + ` Phone_w_errm Char(95);`, + ` Phone Char(15) Overlay(Phone_w_errm :1);`, + ` Zipcode_w_errm Char(90);`, + ` Zipcode Char(10) Overlay(Zipcode_w_errm :1);`, + `End-Ds;`, + ``, + `Dcl-Ds Tmplt_EmpFmtAddress Qualified Template;`, + ` Name Char(60);`, + ` Addr1 Char(40);`, + ` Addr2 Char(40);`, + ` Addr3 Char(40);`, + ` Addr4 Char(40);`, + `End-Ds;`, + ].join(`\n`); + + const parser = new Parser(); + const cache = await parser.getDocs(uri, lines); + + assert.strictEqual(cache.structs.length, 2); + + const Prp00a = cache.find(`Prp00a`); + assert.strictEqual(Prp00a.subItems.length, 7); + assert.strictEqual(Prp00a.keyword[`QUALIFIED`], true); + assert.strictEqual(Prp00a.keyword[`TEMPLATE`], undefined); + } } \ No newline at end of file