aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 129 forks source link

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

Open masquo opened 2 months ago

masquo commented 2 months ago

I'm submitting a bug report

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:

Sayan751 commented 2 months ago

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

masquo commented 2 months ago

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