Skip to content

Commit

Permalink
fix: support "setup" attribute in <script> tag in vue 3 (#667)
Browse files Browse the repository at this point in the history
In Vue 3, when <script> tag has "setup" attribute, SFC parser assigned script block to a separate field called "scriptSetup"

✅ Closes: #665
  • Loading branch information
piotr-oles committed Oct 19, 2021
1 parent 34ebcd8 commit 2cfe45f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Expand Up @@ -112,8 +112,8 @@ function createTypeScriptVueExtension(
} else if (isVueTemplateCompilerV3(compiler)) {
const parsed = compiler.parse(vueSourceText);

if (parsed.descriptor && parsed.descriptor.script) {
const scriptV3 = parsed.descriptor.script;
if (parsed.descriptor && (parsed.descriptor.script || parsed.descriptor.scriptSetup)) {
const scriptV3 = (parsed.descriptor.script || parsed.descriptor.scriptSetup)!;

// map newer version of SFCScriptBlock to the generic one
script = {
Expand Down
Expand Up @@ -23,6 +23,7 @@ interface SFCDescriptor {
filename: string;
template: SFCBlock | null;
script: SFCBlock | null;
scriptSetup: SFCBlock | null;
styles: SFCBlock[];
customBlocks: SFCBlock[];
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/implementation/typescript-vue.fixture
Expand Up @@ -92,7 +92,7 @@ h1 {
</p>
</template>

<script lang="ts">
<script setup lang="ts">
import User, { getUserName } from '@/model/User';

export default {
Expand Down

0 comments on commit 2cfe45f

Please sign in to comment.