question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[2.0] Backticks in class attribute not correctly compiled

See original GitHub issue

Vue.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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LinusBorgcommented, Aug 16, 2016

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.

0reactions
robinvdvleutencommented, Aug 16, 2016

@yyx990803 thanks for the explanation! I’ve fixed it by moving the class generation to a component’s method.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found