Vue-styleguidist: Parsing of 'validator' fails when using a function reference

Created on 26 Aug 2020  路  2Comments  路  Source: vue-styleguidist/vue-styleguidist

Current behavior

The vue-docgen-api parser fails to parse the prop validator function with TypeError: Cannot read property '0' of undefined.

Screenshot_20200826_105548

Since the parsing fails, the respective component will be ignored from the guide.

To reproduce

This happens when a prop validator is defined through a variable name rather than an inline function or lambda.

  • Create a function called myValidator
function myValidator(value) {
    return value.length = 3;
}
  • Add a validator to a component prop using this syntax:
props: {
    color: {
        type: String,
    validator: myValidator,
    },
},

Expected behavior

The parsing of the validator function should work even if it is not written inline.

bug

Most helpful comment

Thank you @lopis,
This is super helpful.
I will create a PR today.

All 2 comments

I've hit this same issue using Vue and Storybook and tracked it down to this line:

https://github.com/vue-styleguidist/vue-styleguidist/blob/025ad018a646e6a74d37f6cf85bade8e11348c60/packages/vue-docgen-api/src/script-handlers/utils/parseValidator.ts#L34

For future reference, the error I was getting was

[vue-docgen-loader] failed to parse the component file with docgen-api: Cannot read property '0' of undefined

Thank you @lopis,
This is super helpful.
I will create a PR today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lancetharper picture lancetharper  路  5Comments

ozum picture ozum  路  4Comments

fishkes picture fishkes  路  7Comments

navidshad picture navidshad  路  3Comments

elevatebart picture elevatebart  路  4Comments