nuxtlabs / nuxt-component-meta

Gather Nuxt components metadata on build time and make them available on production.
69 stars 6 forks source link

extract typescript props/emits metadata from AST #23

Closed stafyniaksacha closed 1 year ago

stafyniaksacha commented 2 years ago

Extracting props from compiled sfc will always return base runtimes types because defineProps and defineEmits will be resolved into defineComponent props and emits options. compileScript.ts#L1763-L1848

Also, we can note that compiler-sfc use babel parser internally and not typescript.

The idea would be to walk through original typescript ASTs to retrieve as much information as the developer provided (we may have typed strings, typed objects/arrays, reuse other components props, ...)

A better way would be to create a program context instead of using ASTs, so typescript can resolve imports for us and resolve type for anything for us, more precisely that we can do with AST).

This would require to use vue-typescript from volar which needs some tweaks before (see https://github.com/johnsoncodehk/volar/issues/1506)

Atinux commented 2 years ago

I let you review @farnabaz once you got some time :)

farnabaz commented 1 year ago

We need to iterate on resolving non-primitive types. Importing external types, enums...

@stafyniaksacha Do you think this should wait for vue-typescript?

stafyniaksacha commented 1 year ago

Do you think this should wait for vue-typescript?

Hum, I think not, we can not have any ETA for this, so it can be a good thing to start iterate without it.

stafyniaksacha commented 1 year ago

@Atinux @farnabaz I did some improvements I'm finally happy with props detection done in https://github.com/johnsoncodehk/volar/pull/1637

What do you think about the schema format?

Atinux commented 1 year ago

cc @kevinmarrec as well for the visual editor

Atinux commented 1 year ago

Also @Tahul

Atinux commented 1 year ago

So far I like the schema, seems a bit verbose but give nice informations :rocket:

kevinmarrec commented 1 year ago

I'm fine with any schema, we'll adapt our editor and can benefit of extra information :)

stafyniaksacha commented 1 year ago

There is still an issue when resolving inline type aliases (see: https://github.com/johnsoncodehk/volar/blob/master/packages/vue-component-meta/tests/index.spec.ts#L237-L251 / https://github.com/johnsoncodehk/volar/blob/master/packages/vue-component-meta/src/index.ts#L80)

So many things are objects, so it comes with a recursive nightmare.

Also, the defaults values are still not available