Git Product home page Git Product logo

Comments (7)

tunnckoCore avatar tunnckoCore commented on May 20, 2024

Hey, very thanks! I'll look into it, I think we just should look more on acorn ast.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 20, 2024

I'm starting to think it may be acorn issue.

acorn.parse(EqualityChecker.prototype.isEqual.toString(), {ecmaVersion: 7})

throws a syntax error. Or maybe this is the reason why acorn.parse_dammit exists. And that's why I using it, because such cases. I'm looking on ast that parse_dammit returns for that, may need more ifs in the walk :)

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 20, 2024

There are few ways:

  1. detect if result of toString() begins with function or at least the letter f and if not prepend it
  2. add if in the walk to listen to CallExpression

Second feels kinda wrong to me and I'm thinking it would mess the things more than it solve them.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 20, 2024

What you think about the fix?

edit: Ooops, labels should stay.

from parse-function.

rkaw92 avatar rkaw92 commented on May 20, 2024

As much as I am bewildered by the choice of substring check mechanism ([0] and [1] - I assume it's for performance reasons), this is exactly the workaround that I did in my code:

let functionString = methodFunction.toString();
if (functionString.slice(0, 8) !== 'function') {
    functionString = 'function ' + functionString;
}

I agree that it is the sane thing to do. Checking for function calls is probably best left alone - there is another npm module for that (extracts call parameters), and it may be wise not to expand into that field.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 20, 2024

Yea.

extracts call parameters

You can try http://npm.im/function-arguments, it works for regular, generator and arrow functions. If you need support only for regular functions can use Sindre's fn-args, it's lighter and probably faster.

It would be better choice to use one of them if you only need getting arguments.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 20, 2024

Oh sorry, i forget to publish. I doing it now :) v2.3.2

from parse-function.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.