Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Vue 3 <script setup> #8045

Merged
merged 24 commits into from May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d28004e
Preliminary support for Vue 3 <script setup>
Jengamon May 2, 2022
6899655
Adjust id to get something working?
Jengamon May 3, 2022
284d988
Revert "Adjust id to get something working?"
Jengamon May 3, 2022
1838d7c
Fix asset id
Jengamon May 3, 2022
84e1a6d
Merge branch 'parcel-bundler:v2' into v2
Jengamon May 3, 2022
d0846d0
Send script bindings to template to properly render script setup chil…
Jengamon May 3, 2022
a1f86a4
Fix custom block test
Jengamon May 3, 2022
1578c92
Fix script id
Jengamon May 3, 2022
3d614da
Add rudimentary test
Jengamon May 3, 2022
e083c4a
Formatting pattern
Jengamon May 3, 2022
8b1d3c0
Merge branch 'parcel-bundler:v2' into v2
Jengamon May 3, 2022
3a35615
Switch from double ! to != null
Jengamon May 3, 2022
dcd868f
Merge branch 'v2' of github.com:Jengamon/parcel into v2
Jengamon May 3, 2022
ff9b954
Propagate isProd through the style compiler
Jengamon May 3, 2022
ff10996
Propagate isProd through the template compiler
Jengamon May 3, 2022
a37d6ce
Merge branch 'v2' into v2
Jengamon May 4, 2022
8c11f12
Fix duplicate compilerOptions
Jengamon May 4, 2022
42e4760
Merge branch 'v2' into v2
Jengamon May 4, 2022
f8c08c8
Merge branch 'v2' into v2
Jengamon May 5, 2022
16c9eb9
Adjust id generation
Jengamon May 6, 2022
5acca0c
Merge branch 'v2' of github.com:Jengamon/parcel into v2
Jengamon May 6, 2022
e8d244d
Restore id generation behaviour
Jengamon May 6, 2022
7aba930
Merge branch 'v2' into v2
Jengamon May 6, 2022
a6e99c5
Merge branch 'v2' into v2
Jengamon May 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,9 @@
<script setup>
import { ref } from 'vue';

const name = ref("parcel");
</script>

<template>
<p>Hello {{ name }}</p>
</template>
8 changes: 8 additions & 0 deletions packages/core/integration-tests/test/vue.js
Expand Up @@ -105,4 +105,12 @@ describe('vue', function () {
assert(contents.includes('h2:hover'));
assert(contents.includes('.box p'));
});
it('should load <script setup> component files', async function () {
let b = await bundle(
path.join(__dirname, '/integration/vue-script-setup/App.vue'),
);
let output = (await run(b)).default;
assert.equal(typeof output.render, 'function');
assert.equal(typeof output.setup, 'function');
});
});
38 changes: 28 additions & 10 deletions packages/transformers/vue/src/VueTransformer.js
Expand Up @@ -49,7 +49,7 @@ export default (new Transformer({
canReuseAST({ast}) {
return ast.type === 'vue' && semver.satisfies(ast.version, '^3.0.0');
},
async parse({asset}) {
async parse({asset, options}) {
// TODO: This parses the vue component multiple times. Fix?
let code = await asset.getCode();
let parsed = compiler.parse(code, {
Expand All @@ -64,22 +64,35 @@ export default (new Transformer({
});
}

const descriptor = parsed.descriptor;
let id = hashObject({
filePath: asset.filePath,
source: options.mode === 'production' ? code : null,
}).slice(-6);

return {
type: 'vue',
version: '3.0.0',
program: parsed.descriptor,
program: {
...descriptor,
script:
descriptor.script != null || descriptor.scriptSetup != null
? compiler.compileScript(descriptor, {
id,
isProd: options.mode === 'production',
})
: null,
id,
},
};
},
async transform({asset, options, resolve, config}) {
let id = hashObject({
filePath: asset.filePath,
}).slice(-6);
let {template, script, styles, customBlocks, id} = nullthrows(
await asset.getAST(),
).program;
let scopeId = 'data-v-' + id;
let hmrId = id + '-hmr';
let basePath = basename(asset.filePath);
let {template, script, styles, customBlocks} = nullthrows(
await asset.getAST(),
).program;
if (asset.pipeline != null) {
return processPipeline({
asset,
Expand Down Expand Up @@ -230,8 +243,12 @@ async function processPipeline({
inMap: template.src ? undefined : template.map,
scoped: styles.some(style => style.scoped),
isFunctional,
compilerOptions: {
...config.compilerOptions,
bindingMetadata: script ? script.bindings : undefined,
},
isProd: options.mode === 'production',
id,
compilerOptions: config.compilerOptions,
});
if (templateComp.errors.length) {
throw new ThrowableDiagnostic({
Expand Down Expand Up @@ -351,7 +368,8 @@ ${
modules: style.module,
preprocessLang: style.lang || 'css',
scoped: style.scoped,
map: style.src ? undefined : style.map,
inMap: style.src ? undefined : style.map,
isProd: options.mode === 'production',
id,
});
if (styleComp.errors.length) {
Expand Down