[2.0] Backticks in class attribute not correctly compiled
See original GitHub issueVue.js version
2.0.0-rc.2
Reproduction Link
https://github.com/robinvdvleuten/vue-bug
Steps to reproduce
Clone and install repository then run npm run build
to get uglify error.
What is Expected?
I expect that the backtick expression is correctly compiled to ES5 Javascript.
What is actually happening?
If I have the following Vue component:
<template>
<div id="app" :class="{ [`class-${test}`]: true }">
Hello, Vue 2.0!
</div>
</template>
<script>
export default {
data () {
return {
property: 'test'
}
}
}
</script>
The template parser doesn’t seem to recognize the expression and generates the following (reproducible by running npm run build:without-uglify
):
module.exports={render:function(){with(this) {
return _h('div', {
class: {
[`class-${test}`]: true
},
attrs: {
"id": "app"
}
}, ["\n Hello, Vue 2.0!\n"])
}},staticRenderFns: []}
Which causes Uglify to throw the error;
ERROR in bundle.js from UglifyJs
Unexpected character '`' [bundle.js:5089,7]
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Errors when using template literals in Vue - Stack Overflow
HTML attribute values need to be surrounded by single or double quotes, not backticks. Attribute values can span multiple lines without ...
Read more >CoffeeScript
Compile the JavaScript without the top-level function safety wrapper. --no-header, Suppress the “Generated by CoffeeScript” header. --nodejs, The node ...
Read more >Don't Use The Placeholder Attribute - Smashing Magazine
Placeholder help content is limited to just a string of static text, and that may not always be sufficient to communicate the message....
Read more >Writing R Extensions - The Comprehensive R Archive Network
Compilation is not a correct term for a package. ... important to include S4-using packages (as their class definitions can change and the...
Read more >Type.GetType Method (System) - Microsoft Learn
Version 2.0 or later of the common language runtime is currently loaded, and the assembly was ... Custom attributes are not part of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, reopening this. It actually works with the standalone build: https://jsfiddle.net/Linusborg/chw886jk/1/
So it should work with runtime-only and precomiled templates. Seems like a bug indeed.
Sorry for the premature close.
@yyx990803 thanks for the explanation! I’ve fixed it by moving the class generation to a component’s method.