tintinweb / solgrep

🧠 A scriptable semantic grep utility for solidity
https://www.npmjs.com/package/solgrep
142 stars 17 forks source link

Exception on small source #6

Closed mrx23dot closed 2 years ago

mrx23dot commented 2 years ago

solgrep dummy.sol --find="function.name"

gives

/usr/local/lib/node_modules/solgrep/src/rules/builtin.js:33
            return p.replaceAll(remapFunction, '_function.')
                     ^
TypeError: p.replaceAll is not a function
    at /usr/local/lib/node_modules/solgrep/src/rules/builtin.js:33:22
    at Array.map (<anonymous>)
    at GenericGrep._normalizePatterns (/usr/local/lib/node_modules/solgrep/src/rules/builtin.js:29:20)
    at new GenericGrep (/usr/local/lib/node_modules/solgrep/src/rules/builtin.js:23:30)
    at main (/usr/local/lib/node_modules/solgrep/bin/main.js:90:30)
    at Object.<anonymous> (/usr/local/lib/node_modules/solgrep/bin/main.js:161:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)

tested on windows/linux SolGrep v0.0.7

installed with sudo npm install solgrep -g

simple source dummy.zip

stats works, but everything else fails, like --find="function.name == 'fallback'"

tintinweb commented 2 years ago

πŸ€” cannot reproduce

image

you can match the fallback function with:

function.isFallback == 'true' or function.name == '__fallback__' (similar for constructor)

Here're some fields you can test for:

      β”‚     β”œβ”€ visibility: default
      β”‚     β”œβ”€ modifiers
      β”‚     β”œβ”€ override
      β”‚     β”œβ”€ isConstructor: false
      β”‚     β”œβ”€ isReceiveEther: false
      β”‚     β”œβ”€ isFallback: false
      β”‚     β”œβ”€ isVirtual: false
      β”‚     └─ stateMutability
mrx23dot commented 2 years ago

I started up a brand new VPS at linode with debian10:

sudo apt update 
sudo apt install npm
# npm@7.5.2
sudo npm install solgrep -g
solgrep --version # 0.0.7
nano dummy.sol    # added content
sudo solgrep dummy.sol --find="function.name" 
same error.

Internet says
"TypeError: replaceAll is not a function" it is likely due to the method not implemented/supported by the browser/npm version String.prototype.replaceAll() method was added in ES2021/ES12. (2021 jun in npm)

Solution for anything older than 1year, changing:

posNumbString.replaceAll('-', 'i');
to
posNumbString.replace(/-/g, 'i');

https://discourse.threejs.org/t/replaceall-is-not-a-function/14585

Server OSs don't have the latest from everything, but stable versions. Any chance you could swap these?

mrx23dot commented 2 years ago

There is only one instance in the repo :) some solution: https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript