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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 3: "v-else" conditional compilation error in Pug template (SFC) #7756

Closed
npulidom opened this issue Feb 24, 2022 · 3 comments 路 Fixed by #8051
Closed

Vue 3: "v-else" conditional compilation error in Pug template (SFC) #7756

npulidom opened this issue Feb 24, 2022 · 3 comments 路 Fixed by #8051

Comments

@npulidom
Copy link

馃悰 bug report

Compile a simple Vue 3 app with Parcel 2 (watch mode) and use a v-if and v-else conditional statement in a Pug template, Vue Transformer will output a parse error.

Single File Component Example:

<template lang="pug">

.wrapper

	p(v-if="false") foo
	p(v-else) bug

</template>

Error:

@parcel/transformer-vue: Error parsing JavaScript expression: Unexpected token (1:3)

Also I noticed, using instead v-else="" the template compiles successfully.

馃帥 Configuration (.babelrc, package.json, cli command)

{
	"name": "vue-parcel",
	"description": "Simple boilerplate for building static SPA's with VueJs 3.",
	"license": "UNLICENSED",
	"main": "app/app.js",
	"repository": "https://github.com/npulidom/vue-parcel",
	"scripts": {
		"watch": "rm -rf dist && parcel app/index.pug --dist-dir dist --cache-dir .parcel --no-source-maps",
		"build": "rm -rf dist && parcel build app/index.pug --dist-dir dist --cache-dir .parcel --no-source-maps --detailed-report 20",
		"clean": "rm -rf dist .parcel"
	},
	"browserslist": "> 0.5%, last 2 versions, not dead",
	"devDependencies": {
		"@parcel/config-default": "~2.3.2",
		"@parcel/core": "~2.3.2",
		"@parcel/optimizer-cssnano": "~2.3.2",
		"@parcel/transformer-pug": "~2.3.2",
		"@parcel/transformer-stylus": "~2.3.2",
		"@parcel/transformer-vue": "~2.3.2",
		"@vue/component-compiler-utils": "~3.3.0",
		"autoprefixer": "~10.4.2",
		"cssnano": "~5.0.17",
		"parcel-resolver-vue3-runtime": "~2.0.2",
		"postcss": "~8.4.6",
		"pug": "~3.0.2",
		"stylus": "~0.57.0"
	},
	"dependencies": {
		"modern-normalize": "~1.1.0",
		"vue": "~3.2.31",
		"vue-router": "~4.0.12",
		"vuex": "~4.0.2"
	}
}

馃 Expected Behavior

Vue Transformer should support v-else in Pug templates.

馃槸 Current Behavior

Compilation Error

馃毃 Build failed.

@parcel/transformer-vue: Error parsing JavaScript expression: Unexpected token (1:3)

SyntaxError: Error parsing JavaScript expression: Unexpected token (1:3)

馃拋 Possible Solution

Check v-else statement in pug template of SFCs.

馃敠 Context

Compile a simple Vue 3 application using a Pug template in a SFC.

馃捇 Code Sample

Simple reproduction here.

馃實 Your Environment

Software Version(s)
Parcel 2.3.2
Node 14.18.1
npm/Yarn yarn 1.22.17
Operating System Manjaro Linux
@Jengamon
Copy link
Contributor

Jengamon commented May 3, 2022

Found the error source

content = await preprocessor.render(content, {});

Because Vue templates are a partial, pug doesn't make any assumption of the doctype, so it will mirror the attribute.

Because of this, you will end up with the attribute v-else="v-else", which will error (idk where).

If you specify doctype: "html" in the options argument of the line above, pug will know not to mirror the attribute, but this would lock in Parcel's pug output to HTML5 (which I'm not sure is an argument at this point, but idk).

@Jengamon
Copy link
Contributor

Jengamon commented May 3, 2022

Ok, so I PR'd the fix, because pug will prefer a doctype declared in a template over the doctype declared in options, so if you ever want to break this example again, it would take explicit effort, by manually making the example HTML 4 or something with a doctype declaration. (I think HTML5 only as restrictive, but HTML5 by default as quite reasonable given the web landscape of today.)

@npulidom
Copy link
Author

npulidom commented May 4, 2022

Thanks @Jengamon! hope this PR fix will be included in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants