Giter VIP home page Giter VIP logo

vue-template-babel-compiler's Introduction

vue-template-babel-compiler · Maintenance PRs Welcome

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel.

Downloads Size Version LastCommit CIStatus

DEMO

Visit Online Playground →

DEMO

Features

Usage

1. Install

npm install vue-template-babel-compiler --save-dev

2. Config

Vue-CLI Online Example Project
// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.compiler = require('vue-template-babel-compiler')
        return options
      })
  }
}
Nuxt.js Online Example Project
// nuxt.config.js
export default {
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    loaders: {
      vue: {
        compiler: require('vue-template-babel-compiler')
      }
    },
  },
  // ...
}

Welcome for Issues && PR, see CONTRIBUTING.md for detail.

vue-template-babel-compiler's People

Contributors

dandandq avatar juniortour avatar lsdsjy avatar merceyz avatar vip30 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-template-babel-compiler's Issues

[Bug] Use object spread in template not work

Description

Using object spread in template got error

<template>
  <div class="hello">
   .
   .
   .
   <h3 v-if="{...a}">Installed CLI Plugins</h3>
</template>

Current behavior

Throw error message

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "ReferenceError: _objectSpread is not defined"

found in

---> <HelloWorld> at src/components/HelloWorld.vue
       <App> at src/App.vue
         <Root>

Expected behavior

Object spread can be used

[Bug] Indexing object with v-for variable generates incorrect code.

When using an element of iteration within the loop as an indexer, the iteration variable gets incorrectly generated as an access off of _vm.

In the example below, the particular issue is all occurrences of _vm.actionKey, which should just be actionKey. $$i and $$a also get incorrectly transformed into accesses off of _vm.

Current behavior

With vue-template-babel-compiler 1.0.4:

var render = function() {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h

  return _c(
    "div",
    _vm._l(_vm.actionKeys, function(actionKey) {
      return _c("div", [
        _c("input", {
          directives: [
            {
              name: "model",
              rawName: "v-model",
              value: _vm.enabled[actionKey],
              expression: "enabled[actionKey]"
            }
          ],
          attrs: {
            type: "checkbox"
          },
          domProps: {
            checked: Array.isArray(_vm.enabled[actionKey])
              ? _vm._i(_vm.enabled[actionKey], null) > -1
              : _vm.enabled[actionKey]
          },
          on: {
            change: function change($event) {
              var $$a = _vm.enabled[actionKey],
                $$el = $event.target,
                $$c = $$el.checked ? true : false

              if (Array.isArray($$a)) {
                var $$v = null,
                  $$i = _vm._i($$a, $$v)

                if ($$el.checked) {
                  _vm.$$i < 0 &&
                    _vm.$set(
                      _vm.enabled,
                      _vm.actionKey,
                      _vm.$$a.concat([_vm.$$v])
                    )
                } else {
                  _vm.$$i > -1 &&
                    _vm.$set(
                      _vm.enabled,
                      _vm.actionKey,
                      _vm.$$a
                        .slice(0, _vm.$$i)
                        .concat(_vm.$$a.slice(_vm.$$i + 1))
                    )
                }
              } else {
                _vm.$set(_vm.enabled, _vm.actionKey, $$c)
              }
            }
          }
        })
      ])
    }),
    0
  )
}

Expected behavior

With vue-template-compiler 2.6.11:

function render() {
  var _vm = this;
  var _h = _vm.$createElement;
  var _c = _vm._self._c || _h;
  return _c(
    'div',
    _vm._l(_vm.actionKeys, function (actionKey) {
      return _c('div', [
        _c('input', {
          directives: [
            {
              name: 'model',
              rawName: 'v-model',
              value: _vm.enabled[actionKey],
              expression: 'enabled[actionKey]',
            },
          ],
          attrs: {
            type: 'checkbox',
          },
          domProps: {
            checked: Array.isArray(_vm.enabled[actionKey])
              ? _vm._i(_vm.enabled[actionKey], null) > -1
              : _vm.enabled[actionKey],
          },
          on: {
            change: function ($event) {
              var $$a = _vm.enabled[actionKey],
                $$el = $event.target,
                $$c = $$el.checked ? true : false;
              if (Array.isArray($$a)) {
                var $$v = null,
                  $$i = _vm._i($$a, $$v);
                if ($$el.checked) {
                  $$i < 0 &&
                    _vm.$set(_vm.enabled, actionKey, $$a.concat([$$v]));
                } else {
                  $$i > -1 &&
                    _vm.$set(
                      _vm.enabled,
                      actionKey,
                      $$a.slice(0, $$i).concat($$a.slice($$i + 1))
                    );
                }
              } else {
                _vm.$set(_vm.enabled, actionKey, $$c);
              }
            },
          },
        }),
      ]);
    }),
    0
  );
}

Diff between the two:

diff --git "a/.\\stock.js" "b/.\\babel.js"
index 9a9e5b8..5d4fc7b 100644
--- "a/.\\stock.js"
+++ "b/.\\babel.js"
@@ -2,6 +2,7 @@ var render = function () {
   var _vm = this;
   var _h = _vm.$createElement;
   var _c = _vm._self._c || _h;
+
   return _c(
     'div',
     _vm._l(_vm.actionKeys, function (actionKey) {
@@ -15,33 +16,43 @@ var render = function () {
               expression: 'enabled[actionKey]',
             },
           ],
-          attrs: { type: 'checkbox' },
+          attrs: {
+            type: 'checkbox',
+          },
           domProps: {
             checked: Array.isArray(_vm.enabled[actionKey])
               ? _vm._i(_vm.enabled[actionKey], null) > -1
               : _vm.enabled[actionKey],
           },
           on: {
-            change: function ($event) {
+            change: function change($event) {
               var $$a = _vm.enabled[actionKey],
                 $$el = $event.target,
                 $$c = $$el.checked ? true : false;
+
               if (Array.isArray($$a)) {
                 var $$v = null,
                   $$i = _vm._i($$a, $$v);
+
                 if ($$el.checked) {
-                  $$i < 0 &&
-                    _vm.$set(_vm.enabled, actionKey, $$a.concat([$$v]));
+                  _vm.$$i < 0 &&
+                    _vm.$set(
+                      _vm.enabled,
+                      _vm.actionKey,
+                      _vm.$$a.concat([_vm.$$v])
+                    );
                 } else {
-                  $$i > -1 &&
+                  _vm.$$i > -1 &&
                     _vm.$set(
                       _vm.enabled,
-                      actionKey,
-                      $$a.slice(0, $$i).concat($$a.slice($$i + 1))
+                      _vm.actionKey,
+                      _vm.$$a
+                        .slice(0, _vm.$$i)
+                        .concat(_vm.$$a.slice(_vm.$$i + 1))
                     );
                 }
               } else {
-                _vm.$set(_vm.enabled, actionKey, $$c);
+                _vm.$set(_vm.enabled, _vm.actionKey, $$c);
               }
             },
           },

Usage

<template>
  <div>
    <div v-for="actionKey in actionKeys">
      <input type="checkbox" v-model="enabled[actionKey]" />
    </div>
  </div>
</template>

Extra

[Question] nullish coalescing (??) only work for Node.js version >= 14

  • [yes ] Would you like to work on a fix?

Current behavior

// your code goes here
<div>输出:{{info.aaa ?? 'empty'}}</div>

https://github.com/LYSSION/vue-demo

环境:nodejs12.22.1

复现步骤
1.拉取仓库代码
2.npm run serve
3.向app.vue中添加

输出:{{info.aaa ?? 'empty'}}

4.输出错误

 ERROR  Failed to compile with 1 error                                                                        3:47:11 PM

 error  in ./src/App.vue?vue&type=template&id=7ba5bd90&

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error)

  Errors compiling template:

  invalid expression: Unexpected token '?' in

    "输出:"+_s(info.aaa ?? 'empty')

  Raw expression: 输出:{{info.aaa ?? 'empty'}}


  2  |  <div id="app">
  3  |    <img alt="Vue logo" src="./assets/logo.png">
  4  |    <div>输出:{{info.aaa ?? 'empty'}}</div>
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  5  |    <!-- <div>输出:{{info.title ?? 'empty'}}</div> -->
  6  |    <!-- <div>输出:{{info?.title?.text}}</div> -->


 @ ./src/App.vue?vue&type=template&id=7ba5bd90& 1:0-396 1:0-396
 @ ./src/App.vue
 @ ./src/main.js

[Fixed Bug] Array spreading and string interpolation not working correctly

Array Spreading

Current behavior

Vue Code

          <FormGroup
            v-model="filters.subMeterId"
            :options="[
              { label: 'All', value: '' },
              ...(selectedAccount.subMeters || []).map(subMeter => ({ label: subMeter.name, value: subMeter._id }))
            ]"
          />

Compiled Code

_c("FormGroup", {
                    staticClass: "mb-0",
                    attrs: {
                      id: "search",
                      type: "select",
                      options: [
                        {
                          label: "All",
                          value: ""
                        }
                      ].concat(
                        _toConsumableArray(
                          (_vm.selectedAccount.subMeters || []).map(function(
                            subMeter
                          ) {
                            return {
                              label: subMeter.name,
                              value: subMeter._id
                            }
                          })
                        )
                      ),
                      disabled: _vm.loadingAction.getReadings
                    },
                    on: {
                      input: _vm.refresh
                    },
                    model: {
                      value: _vm.filters.subMeterId,
                      callback: function callback($$v) {
                        _vm.$set(_vm.filters, "subMeterId", $$v)
                      },
                      expression: "filters.subMeterId"
                    }
                  })

Error

vue.runtime.esm.js?2b0e:1888 ReferenceError: _toConsumableArray is not defined
    at Proxy.render (AssetAccountReadings.vue?dcaa:201:1)
    at VueComponent.Vue._render (vue.runtime.esm.js?2b0e:3548:1)
    at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4066:1)
    at Watcher.get (vue.runtime.esm.js?2b0e:4479:1)
    at Watcher.run (vue.runtime.esm.js?2b0e:4554:1)
    at flushSchedulerQueue (vue.runtime.esm.js?2b0e:4310:1)
    at Array.eval (vue.runtime.esm.js?2b0e:1980:1)
    at flushCallbacks (vue.runtime.esm.js?2b0e:1906:1)

Expected behavior

No error and the array should be created as expected.

String interpolation

Current behavior

Vue Code

            <div
              class="d-flex justify-content-center"
              :class="{ [`spinner-${size}`]: size !== 'md', spinner: size === 'md', [`spinner-${variant}`]: variant }"
            ></div>

Compiled Code

        {
          staticClass: "d-flex justify-content-center",
          class:
            ((_class = {}),
            _defineProperty(
              _class,
              "spinner-".concat(_vm.size),
              _vm.size !== "md"
            ),
            _defineProperty(_class, "spinner", _vm.size === "md"),
            _defineProperty(
              _class,
              "spinner-".concat(_vm.variant),
              _vm.variant
            ),
            _class)
        }

Error

vue.runtime.esm.js?2b0e:1888 ReferenceError: _defineProperty is not defined
    at Proxy.render (VM36652 Spinner.vue:17:22)
    at VueComponent.Vue._render (vue.runtime.esm.js?2b0e:3548:1)
    at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4066:1)
    at Watcher.get (vue.runtime.esm.js?2b0e:4479:1)
    at new Watcher (vue.runtime.esm.js?2b0e:4468:1)
    at mountComponent (vue.runtime.esm.js?2b0e:4073:1)
    at VueComponent.Vue.$mount (vue.runtime.esm.js?2b0e:8415:1)
    at init (vue.runtime.esm.js?2b0e:3118:1)
    at createComponent (vue.runtime.esm.js?2b0e:5978:1)
    at createElm (vue.runtime.esm.js?2b0e:5925:1)
    at updateChildren (vue.runtime.esm.js?2b0e:6216:1)
    at patchVnode (vue.runtime.esm.js?2b0e:6319:1)
    at updateChildren (vue.runtime.esm.js?2b0e:6193:1)
    at patchVnode (vue.runtime.esm.js?2b0e:6319:1)
    at VueComponent.patch [as __patch__] (vue.runtime.esm.js?2b0e:6482:1)
    at VueComponent.Vue._update (vue.runtime.esm.js?2b0e:3948:1)

Expected behavior

No error and the class should have correct keys

Extras

Using the latest version v1.1.3

[Resolved Question] vue-jest usage

Optional chaining works greats in my Nuxt application, however, when I run my Jest unit tests, I get the following error message:

Jest encountered an unexpected token

In my jest.config.js file I have the following in my transform property

 transform: {
    '^.+\\.js$': 'babel-jest',
    '.*\\.(vue)$': 'vue-jest'
  },

Can I assume I will need to update the transform property?

[Bug] When value set to null it gives "not defined" error on change

Current behavior

<template>
    <div>
        {{some_value}}
        <label>
            <input type="checkbox" value="1" v-model="some_value">
            test
        </label>
    </div>
</template>

<script>
    export default {
        data() {
            return{
                some_value: null,
            }
        }
    }
</script>

it gives error:

Error in v-on handler: "ReferenceError: some_value is not defined"

but it works fine if

 some_value: '',

[Bug] Unexpected token, expected "," (comma) when compiling for Production | Vue2 + Laravel Mix

Current behavior

when compiling for dev, the compiler seems to work great

when compiling for prod, i get the following error (38 times, for different vue components)

ERROR in ./resources/js/app_next/pages/search/ResultsPage.vue?vue&type=template&id=fbf64694& (./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib/index.js??vue-loader-options!./resources/js/app_next/pages/search/ResultsPage.vue?vue&type=template&id=fbf64694&)
Module build failed (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
SyntaxError: /root/LinuxBindMounted/wright/app/VueTemplateBabelCompiler: Unexpected token, expected "," (8:0)

  6 |   var _c=_vm._self._c||_h;
  7 | return _c("div",[_c("h1",[_vm._v("search results page")])])}
> 8 | var __staticRenderFns__ = []
    | ^
    at instantiate (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:72:32)
    at constructor (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:358:12)
    at Object.raise (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:3334:19)
    at Object.unexpected (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:3372:16)
    at Object.expect (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:4001:28)
    at Object.parseExprList (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:13895:14)
    at Object.parseArrayLike (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:13785:26)
    at Object.parseExprAtom (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12878:23)
    at Object.parseExprAtom (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:8033:20)
    at Object.parseExprSubscripts (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12539:23)
    at Object.parseUpdate (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12518:21)
    at Object.parseMaybeUnary (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12489:23)
    at Object.parseMaybeUnaryOrPrivate (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12283:61)
    at Object.parseExprOps (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12290:23)
    at Object.parseMaybeConditional (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12260:23)
    at Object.parseMaybeAssign (/root/LinuxBindMounted/wright/app/node_modules/@babel/parser/lib/index.js:12213:21)
ModuleBuildError: Module build failed (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
SyntaxError: /root/LinuxBindMounted/wright/app/VueTemplateBabelCompiler: Unexpected token, expected "," (8:0)

SearchResults.vue: (i thought it was the break tags causing an issue so i commented them out, but the issue remains)

<template>
    <div>
        <!-- <br/><br/><br/><br/><br/><br/><br/><br/> -->
        <h1>search results page</h1>
    </div>
</template>

<script>
export default {

}
</script>

Expected behavior

should compile without errors

Extra

node v14.16.1

webpack: 5.70.0
webpack-cli: 4.9.2
webpack-dev-server 4.7.4

"babel-preset-minify": "^0.5.1",
"@babel/core": "^7.17.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/polyfill": "^7.12.1",
"@babel/register": "^7.12.10",
"@babel/runtime": "^7.16.3",
"@types/babel__core": "^7.1.18",

"@vue/cli-plugin-babel": "^4.5.15",
"@inertiajs/inertia-vue": "^0.7.2",
"@vue/cli-service": "^5.0.1",
"vue": "^2.6.14",
"vue-loader": "^15.9.8",
"vue-server-renderer": "^2.6.12",
"vue-template-babel-compiler": "^1.1.3",
"vue-template-compiler": "^2.6.12",
"vuex": "^3.6.0",

"laravel-mix-merge-manifest": "^2.0.0",
"laravel-mix": "^6.0.43",

Laravel Mix / Webpack Config:

mix.override((webpackConfig)=>{
      webpackConfig.module.rules = _.map(webpackConfig.module.rules, function (rule) {
        if(rule.test == "/\\.vue$/"){
            // console.log('overwriting',JSON.stringify(rule));
            rule.use[0].loader = 'vue-loader'
            rule.use[0].options.compiler = require('vue-template-babel-compiler')
        }
        return rule
      })
    })
    .vue({ version: 2, extractStyles: false, useVueStyleLoader: true, optimizeSSR: true })

[Bug] Doesn't work properly with v-for

Current behavior

<div class="card mb-0" v-for="(n,i) in amount " v-if="!reload">
   <div class="card-header d-flex align-items-center" @click="show(i)">
   </div>
</div>

amount is integer

Getting error on click:

Property or method "i" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Vite support

Hi,
how can I install this great package for Vite? Is it compatible? Thanks

[Bug] data-class="" causes the compiler to break unfortunately

Minor bug When and div has a data attribute like data-class the compiler can not compile and reports unexpected token :(

<li> <a class="btn js-waves-off" data-action="toggle" data-class="nav-function-fixed" href="#" title="Lock Navigation"> <i class="ni ni-lock-nav" /> </a> </li>

not working on node12

在反复切换node版本后确定,只在node14上生效
node12上还是会报错

invalid expression: Unexpected token '.' in

    name?.value !== 1

[Bug] support for jest >= 29?

  • Would you like to work on a fix?

Current behavior

I'm using jest 29 and vue2-jest 29, do you have any plans to support?

Screenshot 2023-04-10 at 16 21 51

module.exports = {
  testEnvironment: 'jsdom',
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js'
  },
  moduleFileExtensions: ['js', 'vue', 'json'],
  transform: {
    '^.+\\.js$': 'babel-jest',
    '^.+\\.vue$': '@vue/vue2-jest',
    '^.+\\.svg$': '<rootDir>/libs/svg-transformer.js'
  },
  globals: {
    '@vue/vue2-jest': {
      templateCompiler: {
        compiler: require('vue-template-babel-compiler')
      }
    }
  },
  collectCoverage: true,
  coverageReporters: ['html', 'text-summary'],
  collectCoverageFrom: [
    '<rootDir>/components/**/*.vue',
    '<rootDir>/pages/**/*.vue'
  ]
};

Extra

  • Usage: Nuxt.js 2
  • Node.js Version: 16.14.2
  • Babel Version: ?

[Resolved Question] functional component usage

Description

Filename: Functional.vue

<template functional>
<div>
    {{ props.msg }}
</div>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  name: 'Functional',
  props: {
    msg: String,
  },
});
</script>

Current behavior

Throw error message

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading '$createElement')"

found in

---> <App> at src/App.vue
       <Root>
warn @ vue.runtime.esm.js?2b0e:619
vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading '$createElement')
    at render (Functional.vue?09b6:3)
    at options.render (index.js?6435:83)
    at createFunctionalComponent (vue.runtime.esm.js?2b0e:3077)
    at createComponent (vue.runtime.esm.js?2b0e:3250)
    at _createElement (vue.runtime.esm.js?2b0e:3443)
    at createElement (vue.runtime.esm.js?2b0e:3374)
    at vm._c (vue.runtime.esm.js?2b0e:3512)
    at Proxy.render (App.vue?17b1:20)
    at VueComponent.Vue._render (vue.runtime.esm.js?2b0e:3569)
    at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4081)

Expected behavior

Can be used

[Fixed Bug] argument undefined in function call of scoped slot

Facing some issue when running this compiler in Nuxt. Trying to call a function on click of a component, but unable to retrieve the argument.

<component @click.prevent(greet('hello'))>

methods: {
greet(message) {
console.log(message) // return undefined
}
}

[Bug] Call typeof in template return Reference Error

Version

image

What is expected?

Can call typeof in template

What is actually happening?

Return ReferenceError: _typeof is not defined

Steps to Reproduce

  1. Set config following docs
    image
  2. Call typeof for debugging in template
    image
  3. This error appear in console, and page doesn't load because this error
    image

[Question] Build Nuxt application in production mode

I want to build my nuxt application without dev packages for production deployment.

My steps:

  • Clone repo git clone https://github.com/JuniorTour/vue-template-babel-compiler-nuxt-project.git .
  • Install prod dependencies yarn install --prod
  • Build application nuxt build. Here I got an error Cannot find module 'vue-template-babel-compiler'
Detailed error
yarn run v1.22.10
$ nuxt build

 FATAL  Cannot find module 'vue-template-babel-compiler'                                                                                                                                                                                                   11:49:44
Require stack:
- /Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/nuxt.config.js

  Require stack:
  - nuxt.config.js
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
  at Function.resolve (node:internal/modules/cjs/helpers:99:19)
  at p (node_modules/jiti/dist/jiti.js:1:52987)
  at v (node_modules/jiti/dist/jiti.js:1:53886)
  at nuxt.config.js:6:19
  at v (node_modules/jiti/dist/jiti.js:1:54801)
  at Object.loadNuxtConfig (node_modules/@nuxt/config/dist/config.js:1082:15)
  at loadNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:338:32)
  at NuxtCommand.getNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:463:26)
  at Object.run (node_modules/@nuxt/cli/dist/cli-build.js:90:30)


   ╭───────────────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                               │
   │   ✖ Nuxt Fatal Error                                                                          │
   │                                                                                               │
   │   Error: Cannot find module 'vue-template-babel-compiler'                                     │
   │   Require stack:                                                                              │
   │   - /Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/nuxt.config.js   │
   │                                                                                               │
   ╰───────────────────────────────────────────────────────────────────────────────────────────────╯

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Should I install vue-template-babel-compiler as prod dependency instead? The documentation says that I should install the package as a dev dependency: npm install vue-template-babel-compiler --save-dev.

[Fixed Bug] template里面写对象方法的简写形式报错

<div :rules="[{ transform(value) { return +value} }]"></div>

改成这样就不报错

<div :rules="[{ transform: function(value) { return +value} }]"></div>

报错信息:

[vite-plugin-vue2] /Users/admin/work/code/brick/esop2-support/VueTemplateBabelCompiler: Property key of ObjectMethod expected node to be of a type ["Identifier","StringLiteral","NumericLiteral"] but instead got "MemberExpression"

[Fixed Bug] Array deconstructing error in template

My devDependencies:
image

Then use array deconstructing in template like this:
image

Run dev server by vue-cli with command "vue-cli-service serve".
The browser shows errors: ReferenceError: _maybeArrayLike is not defined.
image

I've tried array deconstructing after removing this dependency "vue-template-babel-compiler",everything works fine.

[Feature] Pipeline operator support

Are there any plans to add support for the Babel pipeline operator proposal?

We have a (pretty huge) Vue@2 project and would like a way to support these as we migrate to Vue@3.

I had a look at the source and tried appending

["@babel/plugin-proposal-pipeline-operator", {
	"proposal": "fsharp"
}]

... into the plugin stack but suspect there is more to the RegExp matching process to correctly detect the |> code structure.

  • Would you like to work on a fix?

Happy to if you could point me in the right direction on where to start.

Current behaviour

<!-- In a template: -->
There are
{{myBigNumber |> app.filter.number}}
issues pending,
{{myBigNumber |> v => app.filter.number(v, {comma: ','})}}
of these are closed

Expected behavior

Compiles to native JS within template as the syntax breaking vm._f(\"> app.filter.number\") inline function.

[Bug] ?.使用不符合预期

  • Would you like to work on a fix?

Current behavior

// your code goes here

image
image
applytime属性不存在的时候应该直接返回‘-’,而不是再读取substring方法

Expected behavior

Usage

Extra

Any idea how to get this to use babel-plugin-istanbul for coverage in templates?

I'm trying to do this in Webpack:

use: {
    loader: 'vue-loader',
    options: {
        compiler: require('vue-template-babel-compiler'),
        compilerOptions: {
            babelOptions: {
              plugins: [['babel-plugin-istanbul', {
                  extension: ['.js', '.vue'],
                  excludeNodeModules: false
              }]]
            }
        }
    }
};

hoping it will, for example, add coverage instrumentation for JS expressions inside <template>, but no luck.

Any ideas?

Any idea how to avoid inserting counters in template, only script, when I use babel-plugin-istanbul for coverage?

I'm tring to use babel-plugin-istanbul for coverage, and I only care about the script part of the .vue file. In some vue projects, it's ok. But there are some vue projects, which will be inserted counters by babel-plugin-istanbul in both script and template parts. I'm very confused about this.

const babelConfig = {
  presets: [
    [
      '@vue/babel-preset-app',
      {
        // 需要兼容低版本例如Android<7,ios<9 请打开注释
        exclude: ['es.symbol', 'es.symbol.description', 'es.object.to-string'],
      },
    ],
  ],
  plugins: [
    'babel-plugin-istanbul',
    '@babel/plugin-proposal-export-default-from',
    '@babel/plugin-syntax-export-default-from',
  ],
};

[Bug] Using object with props or data will not transpile correctly

Current behavior

<template>
<div>
     <span>{{ data[msg] }}</span>
</div>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  name: 'Test',
  props: {
    msg: String,
  },
  data: ()=> ({
      "data": {
          "test": true,
      }
  })
});
</script>

will generate

[_c("span", [_vm._v(_vm._s(_vm.data[msg]))])]

Expected behavior

[_c("span", [_vm._v(_vm._s(_vm.data[_vm.msg]))])]

Extra

Hence vue throws an error

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "ReferenceError: msg is not defined"

found in

---> <Test> at src/components/Test.vue
         <App> at src/App.vue
           <Root>

14-09-2021 Updated:
Seems not related to slot

[Bug] Optional function call as event handler

  • Would you like to work on a fix?

Current behavior

<div @click="handler?.()" />

will be transformed to:

var render = function () {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h

  return _c("div", {
    on: {
      click: function click($event) {
        var _vm$handler, _vm

        ;(_vm$handler = (_vm = _vm).handler) === null || _vm$handler === void 0
          ? void 0
          : _vm$handler.call(_vm)
      },
    },
  })
}

Inside function click, babel transforms optional function call expression using a temporary variable _vm, which collides with the _vm declaration outside. So the inner _vm will be undefined, leading to a reading property of undefined error.

Note: this error only occurs in event handler, because in Vue2 if event handler is not a single identifier, the expression will be wrapped with a function, which may lose this.

Expected behavior

Work as intended.

Usage

Extra

If we use babel repl, we can see _vm.a?.() will be transformed into:

"use strict";

var _vm$a, _vm2;

(_vm$a = (_vm2 = _vm).a) === null || _vm$a === void 0 ? void 0 : _vm$a.call(_vm2);

Babel used a different identifier _vm2 to avoid collision. But in this project, when using parseWithStatementToVm, babel behaves differently.

After debugging, I found babel will go through a crawling process on the original source code when transformSync is called, during which the _vm will be added to the current scope as global identifier:

So when babel knows _vm can't be used as a temporary variable. But in this project, _vm. is prepended to handler by the custom plugin on the run (and the _vm declaration is inserted after all the transforms), which missed the crawling process.

So maybe we should call addGlobal manually to fix this?
(Or we should insert var _vm = this before all the transformation happens?)

I will create a PR soon.

[Bug] dynamic class bind error

Current behavior

<template>
  <div :class="{[`${componentCls}__single`]: true}">

    </div>
</template>

动态class绑定时控制台报错,
vue.esm.js:628 [Vue warn]: Error in render: "ReferenceError: _defineProperty is not defined"

Expected behavior

期望正常解析

Usage

vue2.0

Extra

[Feature] NuxtJS server side rendering support

Do you have any plans to add server side rendering support?

I've tried to change ssr: true for nuxt.config.js in Demo Nuxt.js project and got a compile error.

Error details
$> yarn build
yarn run v1.22.10
$ nuxt build
ℹ Production build                                                                                        19:04:54
ℹ Bundling for server and client side                                                                     19:04:54
ℹ Target: static                                                                                          19:04:54

ℹ Using components loader to optimize imports                                                             19:04:54
ℹ Discovered Components: .nuxt/components/readme.md                                                       19:04:54
✔ Builder initialized                                                                                     19:04:54
✔ Nuxt files generated                                                                                    19:04:54

✔ Client
  Compiled successfully in 6.29s

✖ Server
  Compiled with some errors in 537.80ms


Hash: 5ed4402cc1e1c388c3e0
Version: webpack 4.46.0
Time: 538ms
Built at: 08/29/2021 7:05:02 PM
                  Asset      Size  Chunks  Chunk Names
components/nuxt-logo.js  5.89 KiB       1  components/nuxt-logo
 components/tutorial.js  6.84 KiB       2  components/tutorial
         pages/index.js  8.53 KiB    3, 2  pages/index
              server.js  80.6 KiB       0  app
 + 4 hidden assets
Entrypoint app = server.js server.js.map

ERROR in ./components/Tutorial.vue?vue&type=template&id=54971afc& (./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./components/Tutorial.vue?vue&type=template&id=54971afc&)
Module build failed (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
SyntaxError: Unexpected token (1:3663)
    at Parser.pp$4.raise (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2757:13)
    at Parser.pp.unexpected (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:647:8)
    at Parser.pp$3.parseExprAtom (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2196:10)
    at Parser.<anonymous> (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:6003:24)
    at Parser.parseExprAtom (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:6129:31)
    at Parser.pp$3.parseExprSubscripts (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2047:19)
    at Parser.pp$3.parseMaybeUnary (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2024:17)
    at Parser.pp$3.parseExprOps (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:1966:19)
    at Parser.pp$3.parseMaybeConditional (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:1949:19)
    at Parser.pp$3.parseMaybeAssign (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:1925:19)
    at Parser.pp$3.parseMaybeConditional (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:1954:28)
    at Parser.pp$3.parseMaybeAssign (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:1925:19)
    at Parser.pp$3.parseExprList (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2663:20)
    at Parser.pp$3.parseSubscripts (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2075:29)
    at Parser.pp$3.parseExprSubscripts (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2050:21)
    at Parser.pp$3.parseMaybeUnary (/Users/macbook/WebstormProjects/vue-template-babel-compiler-nuxt-project/node_modules/vue-template-es2015-compiler/buble.js:2024:17)
 @ ./components/Tutorial.vue?vue&type=template&id=54971afc& 1:0-258 1:0-258
 @ ./components/Tutorial.vue
 @ ./.nuxt/components/plugin.js
 @ ./.nuxt/index.js
 @ ./.nuxt/server.js
 @ multi ./node_modules/@nuxt/components/lib/installComponents.js ./.nuxt/server.js

Hash: 9418a4671194c9a47db9
Version: webpack 4.46.0
Time: 6288ms
Built at: 08/29/2021 7:05:01 PM
                         Asset       Size  Chunks                         Chunk Names
../server/client.manifest.json   8.37 KiB          [emitted]
                    49aa76d.js    199 KiB       1  [emitted] [immutable]  commons/app
                    5b69c18.js   2.32 KiB       5  [emitted] [immutable]  runtime
                    643dd80.js   7.36 KiB    4, 3  [emitted] [immutable]  pages/index
                    85598a0.js   57.2 KiB       0  [emitted] [immutable]  app
                    9496627.js    7.1 KiB       3  [emitted] [immutable]  components/tutorial
                      LICENSES  407 bytes          [emitted]
                    aba0182.js   1.85 KiB       2  [emitted] [immutable]  components/nuxt-logo
 + 2 hidden assets
Entrypoint app = 5b69c18.js 49aa76d.js 85598a0.js

 FATAL  Nuxt build error                                                                                  19:05:02

  at WebpackBundler.webpackCompile (node_modules/@nuxt/webpack/dist/webpack.js:2127:21)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:2076:5)
  at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:327:5)
  at async Object.run (node_modules/@nuxt/cli/dist/cli-build.js:110:7)
  at async NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:413:7)


   ╭─────────────────────────────╮
   │                             │
   │   ✖ Nuxt Fatal Error        │
   │                             │
   │   Error: Nuxt build error   │
   │                             │
   ╰─────────────────────────────╯

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

[Bug] support for jest >= 27?

  • Would you like to work on a fix?

Current behavior

I'm using jest 28 and vue2-jest 28. Do you have any plans to support?

// or write your error code here

Expected behavior

Extra

  • Usage: Vue-CLI || Nuxt.js || Webpack || ...
  • Node.js Version: ?
  • Babel Version: ?

vuejs CLI error

currently, receiving the following error and I really cant solve it any idea?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.