Vue: Optional Chaining Error with Babel

Created on 28 Sep 2018  路  3Comments  路  Source: vuejs/vue

Version

2.5.17

Reproduction link

https://codesandbox.io/s/m674vkw2j

Steps to reproduce

Use the optional chaining operator in a template:

{{ user?.id }}

What is expected?

Output the users id in the template or blank for undefined

What is actually happening?

  • invalid expression: Unexpected token . in "\n " _s(user?.id) "\n " Raw expression: {{ user?.id }}

Optional chaining works just fine in the script section of a SFC Vue component but does not work in the template section.

For reference, this is in an Nuxt.js 2.0 project stock settings with the babel optional chaining plugin

Version is actually 15.4.2 with Vue 2.5.17

Most helpful comment

The template section does not go through the same Babel configuration of your script section. I don't think there's an easy way to do this in the 2.x compiler setup, but we should consider configurable post-processing of render functions in the 3.0 compiler.

All 3 comments

Babel is actually not used for in-template strings: See https://github.com/vuejs/vue/issues/6307
Not sure if anything changed regarding this 馃

The template section does not go through the same Babel configuration of your script section. I don't think there's an easy way to do this in the 2.x compiler setup, but we should consider configurable post-processing of render functions in the 3.0 compiler.

@yyx990803 Did you do it? :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

finico picture finico  路  3Comments

paulpflug picture paulpflug  路  3Comments

franciscolourenco picture franciscolourenco  路  3Comments

robertleeplummerjr picture robertleeplummerjr  路  3Comments

loki0609 picture loki0609  路  3Comments