question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to document a Component inside "script setup" blocks?

See original GitHub issue

Hi there!

How to document it? Slots, props and events are working fine. But how to set the basic Component description?

<script setup lang="ts">
/**
 * This should show up somewhere.
 */
...
</script>

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ducletcommented, Dec 19, 2022

I didn’t go too much further and just went with this in the configs. To also not need to do much processing, I went with this style of doc for the component:

    /*@component
    This is the doc for the component.
    It does not have that * prefix for each line but you can probably easily fix parser.
    */
    apiOptions: {
        addScriptHandlers: [
            function (
                documentation,
                componentDefinition,
                astPath,
                opt
            ) {
                const componentDoc = astPath.tokens.filter(token => token.type === 'CommentBlock' && token.value.includes('@component')).find(() => true);
                if (componentDoc) {
                    const lines = componentDoc.value.split('\n');

                    documentation.set('description', lines.filter(line => !line.includes('@component')).map(line => line.substring(componentDoc.loc.indent)).join('\n'));
                }
            }
        ]
    },
1reaction
David-Muellercommented, Dec 19, 2022

FYI for us, the <docs>...</docs> block worked fine with a vite plugin:

export const vueDocsPlugin = () => ({
  name: 'vue-docs',
  transform(code, id) {
    if (!/vue&type=docs/.test(id))
      return;
    return `export default ''`;
  }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

<script setup> | Vue.js
To opt-in to the syntax, add the setup attribute to the <script> block: ... The code inside is compiled as the content of...
Read more >
The 101 guide to Script Setup in Vue 3 - VueDose
Don't you know about Script Setup yet? Check out this short article now and learn the nicest way to define a Vue component...
Read more >
Vue 3.2 - Using Composition API with Script Setup
Within the script block, we export an object with three keys: name, computed, and methods. If you are familiar with Vue, this should...
Read more >
Explaining The New script setup Type in Vue 3 - LearnVue
<script setup>import HelloWorld from './components/HelloWorld.vue'// This starter template is using Vue 3 experimental <script setup> SFCs// ...
Read more >
Using Script Setup for Vue 3 - Azilen Technologies
The <script setup> block will execute every time an instance of a component gets created. We can organize the code as per the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found