bitloops / bitloops-language

Open-source transpiled programming language that helps you write clean code, well-designed systems, and build high-quality software that is testable, auditable and maintainable. Like what you see? Don't forget to star! :star: ^^^
https://bitloops.com/bitloops-language
GNU General Public License v3.0
345 stars 17 forks source link

Rule Transformer issue #504

Open ellik95 opened 1 year ago

ellik95 commented 1 year ago

Describe the bug When we create a rule with anonymous function inside or array indexing it produces the below error:


 Transpiling... TypeError: Cannot read properties of undefined (reading 'isLeaf')
    at IntermediateASTTree.traverse (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/ast/core/intermediate-ast/IntermediateASTTree.js:74:25)
    at DomainRuleNodeTSTransformer.lookForParameterUsedAsIdentifierExpression (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/node-transformers/domainRule.js:63:19)
    at DomainRuleNodeTSTransformer.createThisMemberDotExpressionAndReplaceIdentifierExpression (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/node-transformers/domainRule.js:83:44)
    at DomainRuleNodeTSTransformer.prependThisToAllParametersUsedAsStatements (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/node-transformers/domainRule.js:31:22)
    at DomainRuleNodeTSTransformer.run (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/node-transformers/domainRule.js:15:14)
    at file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/index.js:40:37
    at IntermediateASTTree.traverse (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/ast/core/intermediate-ast/IntermediateASTTree.js:77:9)
    at IntermediateASTTree.traverse (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/ast/core/intermediate-ast/IntermediateASTTree.js:80:18)
    at IntermediateModelToASTTargetTransformer.transform (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/typescript-nest/ast/index.js:34:29)
    at TargetGenerator.generateCore (file:///Users/elli/.nvm/versions/node/v16.19.1/lib/node_modules/@bitloops/bitloops-language-cli/node_modules/@bitloops/bl-transpiler/lib/esm/src/target/index.js:19:72)

To Reproduce create a rule like this:

 Rule UnreconciledTransactionsRule(financialTransactions: FinancialTransactionEntity[]) throws DomainErrors.TransactionIsNotUnreconciledError {
     transactionsAreNotUnreconciled: bool = false;
     const transactionsAreNotUnreconciledIds: int32[] = [];
     financialTransactions.forEach((financialTransaction) => {
         ...
     });
     isBrokenIf(transactionsAreNotUnreconciled == true, (transactionsAreNotUnreconciledIds));
 }

or like this:

Rule IsValidDateRule(date: string) throws DomainErrors.InvalidDateError {
    const day: int32 = date.split('-')[0];
    const year: int32 = date.split('-')[2];
    const month: int32 = date.split('-')[1];

    const invalidDay = day <= 0 OR day > 31;
    const invalidYear = year <= 2000 OR year > 2100;
    const invalidMonth = month <= 0 OR month > 12;

    isBrokenIf(invalidDay OR invalidYear OR invalidDay, (date));
}

Expected behavior It is expected to transpile successfully.

Screenshots image