Skip to content

Always allow Babel to transform expressions in templates #6307

@Justineo

Description

@Justineo

Version

2.4.2

Reproduction link

https://github.com/Justineo/vue-esnext-in-template

Steps to reproduce

vue init webpack esnext-in-template

src/components/Hello.vue:

<template>
<div :class="{ a: true, ...b }"></div>
</template>

<script>
export default {
  data () {
    return { b: true }
  }
}
</script>

(babel-preset-stage-2 is already enabled after initializing with vue-cli.)

What is expected?

The class value should be a b.

What is actually happening?

Error compiling template:

- invalid expression: :class="{ a: true, ...b }"

vue-template-compiler seems to be validating the expression before it goes through Babel with trying to evaluate new Function(exp). This makes ES features that can be used in templates limited to those Node supports and causes confusion: I can translate spread operators for arrays both in templates and elsewhere but I can translate spread operators for objects anywhere except in templates. I think this might not be intentional so I mark this as a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions