Improving Function parser for JavaScript functions



  • Current Function List for JavaScript includes all asynchronous calls into the function list.

    For example,
    setTimeout(function (req, res) { });

    will be recognized as a function with the name function() in the list. How to alter functionList.xml to exclude functions without names in Function List?



  • Hello Edtech-Everywhere,
    actually, if I paste your example into the editor, I don’t have the function listed, even
    after pressing refresh multiple times.
    Are you sure you do not use an modified functionList.xml?

    Cheers
    Claudia



  • Hi Claudia,

    Thanks. I agree that exact example was not correct. Please try to insert a space between setTimeout and function:

    setTimeOut( function(x){ });

    functionList.xml is from original distribution.



  • Hello @Edtech-Everywhere,

    ok, I tried to understand the mainExpr regex but must say I’m not really sure if I did, nevertheless
    when inserting \K after function it seems to work, atleast it did work with my example shown below.

    Old:

    "((^|[\s]+|[;\}\.])([_A-Za-z][\w_]*\.)*[_A-Za-z][\w_]*[\s]*[=:]|^|[\s;\}]+)[\s]*function([\s]+[_A-Za-z]?[\w_]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{"
    

    New:

    "((^|[\s]+|[;\}\.])([_A-Za-z][\w_]*\.)*[_A-Za-z][\w_]*[\s]*[=:]|^|[\s;\}]+)[\s]*function\K([\s]+[_A-Za-z]?[\w_]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{"
    

    Example:

    hello();
    function hello() {document.write('Hello');}
    
    setTimeOut( function(x){ });
    
    <HTML>
        <HEAD>
            <TITLE>Estate Agent 2</TITLE>
            <SCRIPT>
                function House(name,rooms,price,garage) {
                    this.name=name;
                    this.rooms=rooms;
                    this.price=price;
                    this.garage=garage;
                    this.view=view;
                }
                function view() {
                    with (this) document.write(name+' has '+rooms+' rooms, '+(garage?'a':'no')+' garage, and costs £'+price+'<BR>');
                }
                house1=new House('House 1',4,100000,false);
                house2=new House('Big House',5,200000,true);
                house1.view();
                house2.view();
            </SCRIPT>
        </HEAD>
    </HTML>
    

    May I ask you to test this extensively and report back if it does what it should and
    no other thing has been broken?

    Cheers
    Claudia



  • Hi Claudia!

    Thanks!

    It seems that the issue has been solved. I will keep you updated if I found any bugs.



  • @Edtech-Everywhere

    thank you for the feedback and testing.

    Cheers
    Claudia


Log in to reply