JetBrains / web-types

JSON standard for documenting web component libraries for IDEs, documentation generators and other tools
Apache License 2.0
279 stars 25 forks source link

Vue: extract default value function as string #22

Closed BeniRupp closed 3 years ago

BeniRupp commented 3 years ago

The default value of a property can be defined as a function. If such a function returns for example a random value, it is not helpful to extract a random value as the default value for the web-types definition. It would be better to see the function instead to get an idea of what kind of value will be returned.

Therefore, default value functions are returned as a string, if they do not initialize an empty Array or Object.

Examples default: () => String(Math.round(Math.random() * 10000000)) should be extracted as "default": "() => { return String(Math.round(Math.random() * 10000000)); }" instead of "default": "\"9489845\""

default: () => String(_id++) should be extracted as "default": "() => { return String(_id++); }" instead of "default": "\"1\""

default: () => [] or default: () => ({}) should be extracted as "default": "[]" or "default": "{}"

Open Question I am not sure, how the changes affect the following lines:

 // discard GUID name from quasar framework
 && (value.match(/[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+/)
         // and date from vuetify framework
         || value.match(/[0-9]+-[0-9]+-[0-9]+/)))) {

If the GUID and date are returned in functions, this code will not work anymore, right? I was searching for such a date default value in the vuetify code but could not find anything. Maybe we can store value and value() as separate variables and check if one of them matches the given RegEx?

piotrtomiak commented 3 years ago

LGTM. The code is no longer used for quasar as they ship web-types with the library. This was used to generate web-types for older version.