ReferenceError: Invalid left-hand side expression in postfix operation


Following is my code i.e., tool3.js

var assert = require('assert');
     const path = require("path");
     const fs = require("fs");
//const  F5 = artifacts.require("F5")
//const ST5= artifacts.require("ST5")

module.exports = async function(callback) {
try {
     var ctr =0;
     const keyWordStr = [];
     const files = new Array("A1.sol");
     const keyWords = new Array("string1",  "string2", "string3","string4", "string5", "string6", "string7");
     const str = 0;
     for (let i = 0; i < files.length; i++) {   
        const contractPath = path.resolve('/home/zulfi/Truffle_programs/search_opcode/','contracts',files[i]);
        const contractCode2 = fs.readFileSync(contractPath, "utf8");
        let lines =   contractCode2.split(/\r\n|\n/); 
        for(var line = 0; line < lines.length-1; line++){
           keyWordStr[ctr] = (lines[line].search(keyWords[ctr] >= 0) ? lines[line] : false);
           console.log("ctr=" + ctr+ "line =" + line + " --> "+ keyWordStr[ctr]);
        }//for (var...)   
  catch(error) {


I am trying to retrieve the lines related to the keywords i.e. “string1”, and “string2” and so on which are not in my file . I am getting following message:

$ truffle exec tool3.js
Using network 'development'.

0 --> pragma solidity ^0.5.8;

ReferenceError: Invalid left-hand side expression in postfix operation
    at new Script (vm.js:83:7)
    at Object.createScript (vm.js:277:10)
    at Object.file (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/require/require.js:93:1)
    at Object.exec (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/require/require.js:121:1)
    at Promise (internal/util.js:274:30)
    at new Promise (<anonymous>)
    at bound exec (internal/util.js:273:12)
    at (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/exec.js:80:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.67 (core: 5.1.67)
Node v10.23.3

Strange thing is that I don’t have the following line:
0 → pragma solidity ^0.5.8;


in A1.sol, but I can’t understand why its printing this line.

Contents of my A1.sol are:

pragma solidity ^0.5.9;
contract Attack1 {       
  constructor() payable public {}
   function getBalance() public view returns(uint) {
        return address(this).balance;
    function selfDestruct(address payable adr) public {
    } }

Somebody please guide me.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.