Skip to content

parse-function fails for async class method containing a nested arrow function #152

@Neaox

Description

@Neaox

Support plan

  • which support plan is this issue covered by? (e.g. Community, Sponsor, or
    Enterprise): Community
  • is this issue currently blocking your project? (yes/no): No
  • is this issue affecting a production system? (yes/no): No

Context

  • node version: v12.19.0
  • module version: 5.6.10
  • environment (e.g. node, browser, native): node
  • used with (i.e. popular names of modules): typescript
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

This seems to only occur under these specific curcumstances

  • Must be a class method
  • Must be async
  • Must contain a nested arrow function

If any of the above are not true, the issue does not occur.

Demo: https://repl.it/join/yibjtdqc-neaox

Code:

const parseFunction = require("parse-function");

class TestClass {
    async TestFunction() {
       () => true;
    }
}

const app = parseFunction();
app.parse(TestClass.prototype.TestFunction)

What was the result you got?

SyntaxError: Unexpected token, expected "=>" (1:18)

What result did you expect?

The function to parse correctly.

Workaround

Use a function declaration within the class method instead of an arrow function:

const parseFunction = require("parse-function");

class TestClass {
    async TestFunction() {
       function nested() { return true; }
    }
}

const app = parseFunction();
app.parse(TestClass.prototype.TestFunction)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pkg: parse-functionPriority: HighAfter critical issues are fixed, these should be dealt with before any further issues.Status: AcceptedIt's clear what the subject of the issue is about, and what the resolution should be.Status: AvailableNo one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions