JuniorTour / vue-template-babel-compiler

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel
https://www.npmjs.com/package/vue-template-babel-compiler
118 stars 9 forks source link

fix: Identifier in computed OptionalMemberExpression #26

Closed lsdsjy closed 2 years ago

lsdsjy commented 2 years ago

This case should be consistent with the MemberExpression case, where Identifiers in computed OptionalMemberExpression Property should be prepended with "vm".

JuniorTour commented 2 years ago

Thanks for your contribution!

Do you have interest to add a test case for this PR?

You can refer to these commit and make another PR:

lsdsjy commented 2 years ago

Yeah sure. See #27 Don't know if the test case description is clear enough though.

xiaoxiangmoe commented 2 years ago

@lsdsjy also we need support foo?.bar.c ?? d?.(e)?.[f].

JuniorTour commented 2 years ago

@lsdsjy also we need support foo?.bar.c ?? d?.(e)?.[f].

@xiaoxiangmoe Thank you for your feedback, I just tried the code below:

<template>
  <div id="app">
    <h1>2021年12月02日11:05:55</h1>
    <h2>{{obj?.prop.nullish ?? optional?.(chainingKey)?.[chainingKey]}}</h2>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      optional: function (key) {
          console.log(key)  // 'chainingKey'
          return {
            chainingKey: 'inner chainingKey'
          }
      },
      obj: {
        prop: {
          nullish: null,
        }
      },
      chainingKey: 'chainingKey',
    }
  }
}
</script>

It works find after this PR: image

I will publish a new version later, try it.

If you still have any problem, open an issue or comment, just let me know.

JuniorTour commented 2 years ago

v1.0.7 just published after this PR.

You can try it by:

npm install vue-template-babel-compiler --save-dev
// or 
yarn add vue-template-babel-compiler --save-dev