Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse accessor function when using arrow functions with a block body #584

Open
masquo opened this issue Apr 15, 2024 · 2 comments

Comments

@masquo
Copy link

masquo commented Apr 15, 2024

I'm submitting a bug report

  • Library Version:
    2.0.0

  • Operating System:
    Windows 10

  • Node Version:
    20.11.1

  • NPM Version:
    10.2.4
  • JSPM OR Webpack AND Version
    webpack 5.90.3
  • Browser:
    all

  • Language:
    TypeScript 5.4.2

Current behavior:
I'm using Webpack 5 with new AureliaPlugin({dist: "es2015}) and typescript target: "es6".
This config causes a runtime error when using arrow functions with a block body as accessor functions:

Inner Error:
Message: Unable to parse accessor function:
(model) => {
            return model.name;
        }
Inner Error Stack:
Error: Unable to parse accessor function:
(model) => {
            return model.name;
        }
    at getAccessorExpression (webpack-internal:///aurelia-validation:569:15)
    at PropertyAccessorParser.parse (webpack-internal:///aurelia-validation:552:30)
    at FluentEnsure.ensure (webpack-internal:///aurelia-validation:1651:44)
    at ValidationRules.ensure (webpack-internal:///aurelia-validation:1715:58)

Workaround: instead of using

// failing accessor function
.ensure((model) => {
  return model.name;
})

it is possible to use the old fashioned style or the one-liner

// working accessor functions
.ensure(function(model) {
  return model.name;
})

.ensure((model) => model.name)

Expected/desired behavior:

  • What is the expected behavior?
    Update arrow function regex to allow arrow functions with a function body. This could be handy to support automatically formatted code.
    const arrow = /^\(?[$_\w\d]+\)?\s*=>\s*[$_\w\d]+\.([$_\w\d]+)$/;
@Sayan751
Copy link
Member

Hi @masquo, thank you for the issue. Would appreciate a pull request, if you feel like contributing.

@masquo
Copy link
Author

masquo commented Apr 16, 2024

OK, i will look in to it at the end of the week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants