vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.78k stars 390 forks source link

`export default` component after defining it with `<script>` AND `<script setup>` #3748

Open rijenkii opened 10 months ago

rijenkii commented 10 months ago

Today I have tried doing the following:

<script lang="ts">
import { defineComponent } from 'vue';

const Comp = defineComponent({});
export default Comp;
</script>

<script setup lang="ts">
const a = 1;
</script>

playground

Surprisingly, Volar started yelling at this code:

A module cannot have multiple default exports.ts(2528)
App.vue(5, 16): The first export default is here.

However in generated JS there are no multiple default exports:

/* Analyzed bindings: {
  "defineComponent": "setup-const",
  "Comp": "setup-maybe-ref",
  "a": "setup-const"
} */
import { defineComponent as _defineComponent } from 'vue'

import { defineComponent } from 'vue';

const Comp = defineComponent({});
const __default__ = Comp;

const __sfc__ = _defineComponent({
  ...__default__,
  __name: 'App',
  setup(__props) {

const a = 1;

return () => {}
}

})
__sfc__.__file = "src/App.vue"
export default __sfc__

Also, this does not work either, with the same error:

<script lang="ts">
import { defineComponent } from 'vue';

export default Object.assign(defineComponent({}), { foo: "bar" });
</script>

<script setup lang="ts">
const a = 1;
</script>

playground

so1ve commented 10 months ago

Blocked by https://github.com/vuejs/core/pull/9556 because currently we are unable to extract the original component definition