Skip to content

Commit

Permalink
fix(vue3): <script setup> use bindingMetadata instead of inlineTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckFreiburger committed Mar 19, 2021
1 parent 16e737b commit ce47cc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/createVue3SFCModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,14 @@ export async function createSFCModule(source : string, filename : string, option
babelParserPlugins,
// doc: https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md#inline-template-mode
// vue-loader next : https://github.com/vuejs/vue-loader/blob/12aaf2ea77add8654c50c8751bad135f1881e53f/src/resolveScript.ts#L59
inlineTemplate: true,
inlineTemplate: false,
templateOptions: compileTemplateOptions,
});

// see https://github.com/vuejs/vue-loader/blob/12aaf2ea77add8654c50c8751bad135f1881e53f/src/templateLoader.ts#L54
if ( compileTemplateOptions !== null )
compileTemplateOptions.compilerOptions.bindingMetadata = scriptBlock.bindings;

let ast;
if ( true /*!scriptBlock.scriptAst*/ ) {

Expand Down Expand Up @@ -183,7 +187,6 @@ export async function createSFCModule(source : string, filename : string, option
ast = t.file(t.program(scriptBlock.scriptAst, [], 'module'));
}


renameDynamicImport(ast);
const depsList = parseDeps(ast);

Expand Down
23 changes: 23 additions & 0 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,31 @@ const { defaultFilesFactory, createPage } = require('./testsTools.js');
await expect(versions[0]).toBe(versions[1]);
});

if ( vueTarget === 3 ) { // Vue 3 does not have <script setup>

test('should properly handle components in <script setup>', async () => {

const { page, output } = await createPage({
files: {
...files,
'/component.vue': `
<template>a<comp/>e</template>
<script setup>
import comp from "./comp.vue";
</script>
`,
'/comp.vue': `
<template>b{{ foo }}d</template>
<script setup>
const foo = 'c'
</script>
`,
}
});

await expect(page.$eval('#app', el => el.textContent.trim())).resolves.toBe('abcde');
});
}

});

Expand Down

0 comments on commit ce47cc1

Please sign in to comment.