NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.44k stars 4.78k forks source link

[Feature discussion]原生小程序转 Taro 代码问题收集 #955

Closed luckyadam closed 4 years ago

luckyadam commented 5 years ago

Hello,各位大佬~

Taro 发布了 beta 版本,提供了原生小程序转 Taro 代码的功能

升级 Taro CLI

$ npm i -g @tarojs/cli

随后,在原生小程序项目目录下执行 taro convert 命令即可将原生小程序代码转换成 Taro 代码

欢迎大家试用,并反馈问题与建议~

功能所在分支:https://github.com/NervJS/taro/tree/taroize

目前已知不支持特性:

各位提交报错信息劳烦请带上源代码

更新:

geekwill commented 5 years ago

这个牛逼啦.....,吓的我赶紧试了下。

xiangxiong commented 5 years ago

这个牛逼了

ztfstar commented 5 years ago

还能这样?

liuxiaojiu commented 5 years ago

逆向转译

ztfstar commented 5 years ago

贵团队还招人吗?

tancky commented 5 years ago

刚试了一下有几个报错信息

第一条: TypeError: Cannot read property 'charAt' of undefined at allCamelCase (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:8:35) at parseElement (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:242:37) at parseNode (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:239:12) at Array.map () at parseElement (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:246:168) at parseNode (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:239:12) at Array.map () at parseElement (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:246:168) at parseNode (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:239:12) at Array.map ()

第二条: ReferenceError: Container is falsy at NodePath._replaceWith (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/replacement.js:170:11) at NodePath.replaceWith (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/replacement.js:160:8) at transformLoop (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:152:9) at JSXAttribute (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:49:13) at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:76:18) at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:105:12) at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/context.js:150:16) at TraversalContext.visitMultiple (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/context.js:103:17) at TraversalContext.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/context.js:190:19)

第三条: TypeError: Cannot read property '1' of null at Function.get (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/index.js:90:31) at NodePath.getSibling (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/family.js:95:26) at NodePath.getAllNextSiblings (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/family.js:114:22) at transformIf (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:161:26) at JSXAttribute (/usr/local/lib/node_modules/@tarojs/cli/nodemodules/@tarojs_taroize@1.2.0-alpha.1@@tarojs/taroize/lib/src/wxml.js:48:13) at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:76:18) at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/path/context.js:105:12) at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/context.js:150:16) at TraversalContext.visitMultiple (/usr/local/lib/node_modules/@tarojs/cli/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/context.js:103:17)

geekwill commented 5 years ago

补充楼上: 错误 页面转换 pages/newHouse/fullImg/index.js { SyntaxError: await is a reserved word (78:37) 76 | spread 77 | }; 78 | const { code, data, message } = await newHouseApi.fetchNewHouseInfo(param); | ^ 79 | if (code === 200) { 80 | this.setData({ houseInfo: data }); 81 | } else { at t (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:326) at Object.d [as parse] (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:187968)

yuche commented 5 years ago

大家提交报错信息务必带上源码复现,只有报错信息是没有任何价值的。

如果担心信息泄露可以先简化代码再发出来,这样不管还是 Taro 的开发者,还是使用者,或者是未来的你都能更容易去定位问题。

donson commented 5 years ago
  onLoad(){
    console.log('111');
  },

  onShow: function () {
    console.log('222');
  }

onLoad 会报错:

TypeError: Cannot read property 'body' of undefined
    at properties.map.prop (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:152:82)
    at Array.map (<anonymous>)
    at parsePage (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:101:32)
    at CallExpression (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:54:29)
    at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:192:19)

onShow 正常

yuche commented 5 years ago
  onLoad(){
    console.log('111');
  },

  onShow: function () {
    console.log('222');
  }

onLoad 会报错:

TypeError: Cannot read property 'body' of undefined
    at properties.map.prop (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:152:82)
    at Array.map (<anonymous>)
    at parsePage (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:101:32)
    at CallExpression (/usr/local/lib/node_modules/@tarojs/cli/node_modules/@tarojs/taroize/lib/src/script.js:54:29)
    at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:192:19)

onShow 正常

已经修复,下个版本带上~

nyrf commented 5 years ago

赞一个,taro的更新效率一流,感谢付出。

donson commented 5 years ago

1. 问题一

page.json的

  "usingComponents": {
    "dgd-tips": "../../components/dgdui/dgd-tips/dgd-tips",
    "dgd-header": "/components/dgdui/dgd-header/dgd-header"
  }

使用../../相对地址,能找到component的路径 使用绝对地址,找不到,报如下错

错误  组件转换  /components/dgdui/dgd-header/dgd-header.js
Error: 组件 /components/dgdui/dgd-header/dgd-header 没有 JS 文件!
    at components.forEach.componentObj (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:371:17)
    at Set.forEach (<anonymous>)
    at Convertor.traverseComponents (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:357:16)
    at pages.forEach.page (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:345:14)
    at Set.forEach (<anonymous>)
    at Convertor.traversePages (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:283:16)
    at Convertor.run (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:492:10)
    at Object.<anonymous> (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/bin/taro-convert:12:11)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)

2. 问题二

page里的usingComponents能正常拿到完整的depComponents

Set {
  { name: 'dgd-tips',
    path: '/components/dgd-weui/dgd-tips/dgd-tips' },
  { name: 'dgd-cell',
    path: '/components/dgd-weui/dgd-cell/dgd-cell' },
  { name: 'dgd-realname-button',
    path:  '/components/dgd-weui/dgd-realname-button/dgd-realname-button' } }

但组件里的usingComponents拿到的depComponents格式有问题

Set { '/components/dgdui/dgd-miniprogram-button/dgd-miniprogram-button' }

没有namepath,导致转换时报错:

错误  组件转换  components/dgd-weui/dgd-cell/dgd-cell.js
TypeError: Cannot read property 'charAt' of undefined
    at exports.pascalCase (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/util/index.js:493:35)
    at depComponents.forEach.componentObj (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:142:30)
    at Set.forEach (<anonymous>)
    at exit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:140:29)
    at NodePath._call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:117:8)
    at TraversalContext.visitQueue (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:192:19)
luckyadam commented 5 years ago

补充楼上: 错误 页面转换 pages/newHouse/fullImg/index.js { SyntaxError: await is a reserved word (78:37) 76 | spread 77 | }; 78 | const { code, data, message } = await newHouseApi.fetchNewHouseInfo(param); | ^ 79 | if (code === 200) { 80 | this.setData({ houseInfo: data }); 81 | } else { at t (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:326) at Object.d [as parse] (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:187968)

看下你的页面源码~ async await 是成对出现的么

luckyadam commented 5 years ago

1. 问题一

page.json的

  "usingComponents": {
    "dgd-tips": "../../components/dgdui/dgd-tips/dgd-tips",
    "dgd-header": "/components/dgdui/dgd-header/dgd-header"
  }

使用../../相对地址,能找到component的路径 使用绝对地址,找不到,报如下错

错误  组件转换  /components/dgdui/dgd-header/dgd-header.js
Error: 组件 /components/dgdui/dgd-header/dgd-header 没有 JS 文件!
    at components.forEach.componentObj (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:371:17)
    at Set.forEach (<anonymous>)
    at Convertor.traverseComponents (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:357:16)
    at pages.forEach.page (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:345:14)
    at Set.forEach (<anonymous>)
    at Convertor.traversePages (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:283:16)
    at Convertor.run (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:492:10)
    at Object.<anonymous> (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/bin/taro-convert:12:11)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)

2. 问题二

page里的usingComponents能正常拿到完整的depComponents

Set {
  { name: 'dgd-tips',
    path: '/components/dgd-weui/dgd-tips/dgd-tips' },
  { name: 'dgd-cell',
    path: '/components/dgd-weui/dgd-cell/dgd-cell' },
  { name: 'dgd-realname-button',
    path:  '/components/dgd-weui/dgd-realname-button/dgd-realname-button' } }

但组件里的usingComponents拿到的depComponents格式有问题

Set { '/components/dgdui/dgd-miniprogram-button/dgd-miniprogram-button' }

没有namepath,导致转换时报错:

错误  组件转换  components/dgd-weui/dgd-cell/dgd-cell.js
TypeError: Cannot read property 'charAt' of undefined
    at exports.pascalCase (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/util/index.js:493:35)
    at depComponents.forEach.componentObj (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:142:30)
    at Set.forEach (<anonymous>)
    at exit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/src/convertor.js:140:29)
    at NodePath._call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/path/context.js:117:8)
    at TraversalContext.visitQueue (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taro-cli/node_modules/babel-traverse/lib/context.js:192:19)

修复啦~ 1.2.0-beta.2 版本

donson commented 5 years ago

wxml 嵌套 wx:if 会报错

<view wx:if="{{aaa}}">
  <view wx:if="{{bbb}}">
  </view>
</view>

错误如下:

错误  页面转换  pages/index/index.js
TypeError: Cannot read property '1' of null
    at Function.get (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/index.js:90:31)
    at NodePath.getSibling (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:95:26)
    at NodePath.getAllNextSiblings (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:114:22)
    at transformIf (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:253:26)
    at JSXAttribute (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:50:13)
    at NodePath._call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:103:17)
luckyadam commented 5 years ago

wxml 嵌套 wx:if 会报错

<view wx:if="{{aaa}}">
  <view wx:if="{{bbb}}">
  </view>
</view>

错误如下:

错误  页面转换  pages/index/index.js
TypeError: Cannot read property '1' of null
    at Function.get (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/index.js:90:31)
    at NodePath.getSibling (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:95:26)
    at NodePath.getAllNextSiblings (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:114:22)
    at transformIf (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:253:26)
    at JSXAttribute (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:50:13)
    at NodePath._call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:103:17)

已经修复了,还没发版本,暂时可以写成如下形式来绕过

<view wx:if="{{aaa}}">
  <block>
    <view wx:if="{{bbb}}">
    </view>
  </block>
</view>

wx:for 嵌套也会有这个问题,也可以暂时用一个 <block> 隔离来绕过

donson commented 5 years ago

wxml 嵌套 wx:if 会报错

<view wx:if="{{aaa}}">
  <view wx:if="{{bbb}}">
  </view>
</view>

错误如下:

错误  页面转换  pages/index/index.js
TypeError: Cannot read property '1' of null
    at Function.get (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/index.js:90:31)
    at NodePath.getSibling (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:95:26)
    at NodePath.getAllNextSiblings (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/family.js:114:22)
    at transformIf (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:253:26)
    at JSXAttribute (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/lib/src/wxml.js:50:13)
    at NodePath._call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/dongchengliu/Work/gitlab/taro/taro/packages/taroize/node_modules/babel-traverse/lib/context.js:103:17)

已经修复了,还没发版本,暂时可以写成如下形式来绕过

<view wx:if="{{aaa}}">
  <block>
    <view wx:if="{{bbb}}">
    </view>
  </block>
</view>

wx:for 嵌套也会有这个问题,也可以暂时用一个 <block> 隔离来绕过

好的,还是修复了好,暂时还没正式用上

luckyadam commented 5 years ago

补充楼上: 错误 页面转换 pages/newHouse/fullImg/index.js { SyntaxError: await is a reserved word (78:37) 76 | spread 77 | }; 78 | const { code, data, message } = await newHouseApi.fetchNewHouseInfo(param); | ^ 79 | if (code === 200) { 80 | this.setData({ houseInfo: data }); 81 | } else { at t (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:326) at Object.d [as parse] (/Users/will/.nvm/versions/node/v8.12.0/lib/node_modules/@tarojs/cli/node_modules/prettier/parser-babylon.js:1:187968)

1.2.0-alpha.3 修复了这个问题

824759494 commented 5 years ago

v1.2.0-alpha.3版本

第一种
<swiper wx:if="{{flag}}">
    <block>
        <block wx:for="{{list}}">
        </block>
    </block>
</swiper>

第二种
<swiper wx:if="{{flag}}">
    <block>
        <view wx:for="{{list}}">
        </view>
    </block>
</swiper>

第三种
<swiper wx:if="{{flag}}">
    <view>
        <block wx:for="{{list}}">
        </block>
    </view>
</swiper>

前两种会报错:如下 第三种可以编译过去

components/notice/notice.js
ReferenceError: Container is falsy
    at NodePath._replaceWith (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\replacement.js:170:11)
    at NodePath.replaceWith (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\replacement.js:160:8)
    at exit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_@tarojs_taroize@1.2.0-alpha.3@@tarojs\taroize\lib\src\wxml.js:114:30)
    at NodePath._call (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:76:18)
    at NodePath.call (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:48:17)
    at NodePath.visit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:117:8)
    at TraversalContext.visitQueue (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:150:16)
    at TraversalContext.visitMultiple (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:103:17)
    at TraversalContext.visit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:190:19)
    at Function.traverse.node (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\index.js:114:17)
Blair812 commented 5 years ago

对echart的支持如何?

wubaiqing commented 5 years ago

牛逼了!

xmt1139057136 commented 5 years ago

这个功能真的牛逼!

xmt1139057136 commented 5 years ago

这个功能真的牛逼! 看来我需要写教程了!www.xttblog.com

wangtong12315 commented 5 years ago

项目代码已上传至码云, 地址为:https://gitee.com/wangtong12315/taro-test.git 利用原生小程序代码生成taro项目,然后利用taro项目编译成h5项目,编译报错了,错误信息如下

TypeError: Cannot read property '0' of undefined at new Parser (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babylon/lib/index.js:1577:45) at Object.parse (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babylon/lib/index.js:7305:10) at getAst (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-template/lib/index.js:29:21) at /usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-template/lib/index.js:53:24 at convertSourceStringToAstExpression (/usr/local/lib/node_modules/@tarojs/cli/src/util/ast_convert.js:54:38) at exit (/usr/local/lib/node_modules/@tarojs/cli/src/h5.js:441:32) at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:76:18) at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:117:8) at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:150:16)from at exports.default (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-template/lib/index.js:12:11) at convertSourceStringToAstExpression (/usr/local/lib/node_modules/@tarojs/cli/src/util/ast_convert.js:54:10) at exit (/usr/local/lib/node_modules/@tarojs/cli/src/h5.js:441:32) at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:76:18) at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/path/context.js:117:8) at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:150:16) at TraversalContext.visitSingle (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:108:19) at TraversalContext.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/context.js:192:19) at Function.traverse.node (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babel-traverse/lib/index.js:114:17)

crazyonebyone commented 5 years ago

错误信息

错误  页面转换  pages/goods-details/index.js
{ SyntaxError: Unexpected token, expected , (1:12)
    at Parser.pp$5.raise (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/usr/local/lib/node_modules/@tarojs/cli/node_modules/babylon/lib/index.js:1761:8)

这种错误报了两处,很奇怪

yuche commented 5 years ago

@crazyonebyone 你要有源代码才知道为什么报错

crazyonebyone commented 5 years ago

@crazyonebyone 你要有源代码才知道为什么报错

这个是报错文件的代码

//index.js
//获取应用实例
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');

Page({
  data: {
    autoplay: true,
    interval: 3000,
    duration: 1000,
    goodsDetail:{},
    swiperCurrent: 0,  
    hasMoreSelect:false,
    selectSize:"上课时间选择:",
    selectSizePrice:0,
    shopNum:0,
    hideShopPopup:true,
    buyNumber:0,
    buyNumMin:0,
    buyNumMax:0,

    propertyChildIds:"",
    propertyChildNames:"",
    canSubmit:false, //  选中规格尺寸时候是否允许加入购物车
    shopCarInfo:{},
    modalContent:"",
    modalHidden:true
  },

  //事件处理函数
  swiperchange: function(e) {
      //console.log(e.detail.current)
       this.setData({  
        swiperCurrent: e.detail.current  
    })  
  },
  onLoad: function (e) {
    console.log('onLoad');
    var that = this;
    // 获取购物车数据
    wx.getStorage({
      key: 'shopCarInfo',
      success: function(res) {
        console.log(res.data)
        that.setData({
          shopCarInfo:res.data,
          shopNum:res.data.shopNum
        });
      } 
    })

    wx.request({
      url: 'https://api.it120.cc/'+ app.globalData.subDomain +'/shop/goods/detail',
      data: {
        id: e.id
      },
      success: function(res) {
        var selectSizeTemp = "";
        console.log(res)
        if (res.data.data.properties) {
          for(var i=0;i<res.data.data.properties.length;i++){
            selectSizeTemp = selectSizeTemp + " " + res.data.data.properties[i].name;
          }
          that.setData({
            hasMoreSelect:true,
            selectSize:that.data.selectSize + selectSizeTemp,
            selectSizePrice:res.data.data.basicInfo.minPrice,
          });
        }
        that.data.goodsDetail = res.data.data;
        that.setData({
          goodsDetail:res.data.data,
          selectSizePrice:res.data.data.basicInfo.minPrice,
          buyNumMax:res.data.data.basicInfo.stores,
          buyNumber:(res.data.data.basicInfo.stores>0) ? 1: 0
        });
        WxParse.wxParse('article', 'html', res.data.data.content, that, 15);
      }
    })

  },
  bindGuiGeTap: function() {
     this.setData({  
        hideShopPopup: false 
    })  
  },
  closePopupTap: function() {
     this.setData({  
        hideShopPopup: true 
    })  
  },
  numJianTap: function() {
    //  if(this.data.buyNumber > this.data.buyNumMin){
    //     var currentNum = this.data.buyNumber;
    //     currentNum--; 
    //     this.setData({  
    //         buyNumber: currentNum
    //     })  
    //  }
  },
  numJiaTap: function() {
    //  if(this.data.buyNumber < this.data.buyNumMax){
    //     var currentNum = this.data.buyNumber;
    //     currentNum++ ;
    //     this.setData({  
    //         buyNumber: currentNum
    //     })  
    //  }
  },
  labelItemTap: function(e) {
    var that = this;
    /*
    console.log(e)
    console.log(e.currentTarget.dataset.propertyid)
    console.log(e.currentTarget.dataset.propertyname)
    console.log(e.currentTarget.dataset.propertychildid)
    console.log(e.currentTarget.dataset.propertychildname)
    */
    // 取消该分类下的子栏目所有的选中状态
    var childs = that.data.goodsDetail.properties[e.currentTarget.dataset.propertyindex].childsCurGoods;
    for(var i = 0;i < childs.length;i++){
      that.data.goodsDetail.properties[e.currentTarget.dataset.propertyindex].childsCurGoods[i].active = false;
    }
    // 设置当前选中状态
    that.data.goodsDetail.properties[e.currentTarget.dataset.propertyindex].childsCurGoods[e.currentTarget.dataset.propertychildindex].active = true;
    // 获取所有的选中规格尺寸数据
    var needSelectNum = that.data.goodsDetail.properties.length;
    var curSelectNum = 0;
    var propertyChildIds= "";
    var propertyChildNames = "";
    for (var i = 0;i < that.data.goodsDetail.properties.length;i++) {
      childs = that.data.goodsDetail.properties[i].childsCurGoods;
      for (var j = 0;j < childs.length;j++) {
        if(childs[j].active){
          curSelectNum++;
          propertyChildIds = propertyChildIds + that.data.goodsDetail.properties[i].id + ":"+ childs[j].id +",";
          propertyChildNames = propertyChildNames + that.data.goodsDetail.properties[i].name + ":"+ childs[j].name +"  ";
        }
      }
    }
    var canSubmit = false;
    if (needSelectNum == curSelectNum) {
      canSubmit = true;
    }
    // 计算当前价格
    if (canSubmit) {
      wx.request({
        url: 'https://api.it120.cc/'+ app.globalData.subDomain +'/shop/goods/price',
        data: {
          goodsId: that.data.goodsDetail.basicInfo.id,
          propertyChildIds:propertyChildIds
        },
        success: function(res) {
          that.setData({
            selectSizePrice:res.data.data.price,
            propertyChildIds:propertyChildIds,
            propertyChildNames:propertyChildNames,
            buyNumMax:res.data.data.stores,
            buyNumber:(res.data.data.stores>0) ? 1: 0
          });
        }
      })
    }

    this.setData({
      goodsDetail: that.data.goodsDetail,
      canSubmit:canSubmit
    })  
  },
  addShopCar:function(){
    if (this.data.goodsDetail.properties && !this.data.canSubmit) {
      this.bindGuiGeTap();
      console.log(this.data.goodsDetail.properties);
      console.log(!this.data.canSubmit);
      return;
    }
    if(this.data.buyNumber < 1){
      wx.showModal({
        title: '提示',
        content: '课程爆满了哦~',
        showCancel:false
      })
      return;
    }
    // 加入购物车
    var shopCarMap = {};
    shopCarMap.goodsId=this.data.goodsDetail.basicInfo.id;
    shopCarMap.pic=this.data.goodsDetail.basicInfo.pic;
    shopCarMap.name=this.data.goodsDetail.basicInfo.name;
    // shopCarMap.label=this.data.goodsDetail.basicInfo.id; 规格尺寸 
    shopCarMap.propertyChildIds=this.data.propertyChildIds;
    shopCarMap.label=this.data.propertyChildNames;
    shopCarMap.price=this.data.selectSizePrice;
    shopCarMap.left="";
    shopCarMap.active=true;
    shopCarMap.number = this.data.buyNumber;
    shopCarMap.logisticsType=this.data.goodsDetail.basicInfo.logisticsId;

    var shopCarInfo = this.data.shopCarInfo;
    if (!shopCarInfo.shopNum){
      shopCarInfo.shopNum = 0;
    }
    if (!shopCarInfo.shopList){
      shopCarInfo.shopList = [];
    }
    var hasSameGoodsIndex = -1;
    for (var i = 0;i<shopCarInfo.shopList.length;i++) {
      var tmpShopCarMap = shopCarInfo.shopList[i];
      if (tmpShopCarMap.goodsId == shopCarMap.goodsId && tmpShopCarMap.propertyChildIds == shopCarMap.propertyChildIds) {
        hasSameGoodsIndex = i;
        shopCarMap.number=shopCarMap.number + tmpShopCarMap.number;
        break;
      }
    }

    shopCarInfo.shopNum = shopCarInfo.shopNum + this.data.buyNumber;
    if (hasSameGoodsIndex > -1) {
      shopCarInfo.shopList.splice(hasSameGoodsIndex,1, shopCarMap);
    } else {
       shopCarInfo.shopList.push(shopCarMap);
    }

    this.setData({
      shopCarInfo:shopCarInfo,
      shopNum:shopCarInfo.shopNum
    });

    // 写入本地存储
    wx.setStorage({
      key:"shopCarInfo",
      data:shopCarInfo
    })
    this.closePopupTap();
    wx.showToast({
      title: '加入待确认课程成功',
      icon: 'success',
      duration: 2000
    })
    //console.log(shopCarInfo);

    //shopCarInfo = {shopNum:12,shopList:[]}
  },
  goShopCar:function () {
    wx.navigateTo({
      url: "/pages/shop-cart/index"
    });
  },
  tobuy:function(){
    if (this.data.goodsDetail.properties && !this.data.canSubmit) {
      this.bindGuiGeTap();
      return;
    }

    //临时代码,根据商户需求更改
    this.setData({
      modalContent: '请确认您预定的课程信息\r\n课程名称: ' + this.data.goodsDetail.basicInfo.name + '\r\n上课时间: ' + this.data.propertyChildNames + '\r\n请检查无误后点击确认',
      modalHidden: false
    });

    // if(this.data.buyNumber < 1){
    //   wx.showModal({
    //     title: '提示',
    //     content: '课程爆满了哦~',
    //     showCancel:false
    //   })
    //   return;
    // }
    // this.addShopCar();
    // this.goShopCar();
  },
  modalHide:function () {
    this.setData({
      modalContent: '',
      modalHidden: true
    });
    wx.showModal({
      title: '提示',
      content: '具体预定方式待与商家沟通后继续开发。谢谢配合。',
    })
  },
  modalHideCancle:function (){
    this.setData({
      modalContent: '',
      modalHidden: true
    });
  },
  onShareAppMessage: function () {
    return {
      title: this.data.goodsDetail.basicInfo.name,
      path: '/pages/goods-details/index?id=' + this.data.goodsDetail.basicInfo.id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})
FreeDemons commented 5 years ago

v1.2.0-alpha.3版本

第一种
<swiper wx:if="{{flag}}">
    <block>
        <block wx:for="{{list}}">
        </block>
    </block>
</swiper>

第二种
<swiper wx:if="{{flag}}">
    <block>
        <view wx:for="{{list}}">
        </view>
    </block>
</swiper>

第三种
<swiper wx:if="{{flag}}">
    <view>
        <block wx:for="{{list}}">
        </block>
    </view>
</swiper>

前两种会报错:如下 第三种可以编译过去

components/notice/notice.js
ReferenceError: Container is falsy
   at NodePath._replaceWith (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\replacement.js:170:11)
   at NodePath.replaceWith (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\replacement.js:160:8)
   at exit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_@tarojs_taroize@1.2.0-alpha.3@@tarojs\taroize\lib\src\wxml.js:114:30)
   at NodePath._call (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:76:18)
   at NodePath.call (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:48:17)
   at NodePath.visit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:117:8)
   at TraversalContext.visitQueue (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:150:16)
   at TraversalContext.visitMultiple (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:103:17)
   at TraversalContext.visit (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\context.js:190:19)
   at Function.traverse.node (C:\Users\Administrator\AppData\Roaming\nvm\v10.2.0\node_modules\@tarojs\cli\node_modules\_babel-traverse@6.26.0@babel-traverse\lib\index.js:114:17)

我也是报「Container is falsy」这个错误,看别人的代码,怀疑是条件渲染中夹杂循环渲染引起的报错,版本号是:Taro v1.2.0-beta.4 通过把循环渲染的view外套一层view能解决这个问题。

FreeDemons commented 5 years ago

image 引入第三方插件应该还没有支持吧,这一点应该提醒一下。 另外,我这种目录结构下的image文件夹的图片也是没有反编译过去的。 image

cn-coderl commented 5 years ago

问题描述 执行taro convert命令失败

复现步骤

<view class="abc" wx:if="{{def}}">
    <template is="your-template-name" ></template>
</view>

<template name="your-template-name">
    <view class="class-a {{aaa ? 'class-b': ''}}" ></view>
</template>

绕过方法

//[第一种] 把view的wx:if 去掉
<view class="abc">
    <template is="your-template-name" ></template>
</view>

//[第二种] 把template内容拿出来
<view class="abc" wx:if="{{def}}">
    <view class="class-a {{aaa ? 'class-b': ''}}" ></view>
</view>

//[第三种] 再嵌一层....
<view class="abc">
    <block>
        <template is="your-template-name" ></template>
    </block>
</view>

报错信息

ReferenceError: Container is falsy at NodePath._replaceWith (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\path\replacement.js:170:11) at NodePath.replaceWith (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\path\replacement.js:160:8) at Object.parseTemplate (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\@tarojs\taroize\lib\src\template.js:90:18) at enter (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\@tarojs\taroize\lib\src\wxml.js:90:49) at NodePath._call (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\path\context.js:76:18) at NodePath.call (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\path\context.js:48:17) at NodePath.visit (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\path\context.js:105:12) at TraversalContext.visitQueue (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\context.js:150:16) at TraversalContext.visitMultiple (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\context.js:103:17) at TraversalContext.visit (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babel-traverse\lib\context.js:190:19)

系统信息

yuche commented 5 years ago

@cn-yezi 很快发下一个版本能解决这个问题

cn-coderl commented 5 years ago

问题描述 执行taro convert命令失败

复现步骤

<template is="your-template-name"  data="{{outsideData: true ? 1 : 0}}"></template>

<template name="your-template-name">
    <text>{{outsideData}}</text>
</template>

//问题猜测:如果template内吃这个变量并且你在data的声明中**用了三元运算**就会报错

绕过方法 试了一下引了个wxs写了个函数也不行,只能逻辑写模版里面吧。

报错信息

{ SyntaxError: Unexpected token, expected : (1:10) at Parser.pp$5.raise (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:4454:13) at Parser.pp.unexpected (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:1761:8) at Parser.pp.expect (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:1749:33) at Parser.pp$3.parseConditional (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:3392:10) at Parser.pp$3.parseMaybeConditional (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:3384:15) at Parser.pp$3.parseMaybeAssign (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:3344:19) at Parser.pp$3.parseExpression (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:3306:19) at Parser.pp$3.getExpression (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:3281:19) at Object.parseExpression (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\babylon\lib\index.js:7313:17) at parseAttribute (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\@tarojs\taroize\lib\src\wxml.js:521:97) pos: 10, loc: Position { line: 1, column: 10 } }

系统信息

yuche commented 5 years ago

@cn-yezi

你这样写就不行。所有 handlebars 式 {{ }} 表达式里面的内容给必须是一个合法的 javascript 表达式,你这个恰巧不合法。

wxs 也是1.2.1修复,你找一下 commit 纪录,taroize 作用域的提交。

cjfff commented 5 years ago

问题描述

代码转换问题;

源代码

<template is="select-specification" data="{{act, goodInfo, fightGroupDetailData, spec1Index, spec2Index, spec1, spec2, lotteryData: actLottery.data}}"></template>

image

可以看到。。转换后框架把我传入的参数前面部分当成了 key......

// 源代码
<template wx:if="{{showCouponPopup}}" is="default-coupon-popup" data="{{scene: 'productDetail', data: couponListData}}" />

// convert 
        <DefaultCouponPopupTmpl
          data={{
            scene: ('productDetail', data)
          }}
        />

猜想: 可能是传入参数过长导致?

系统信息

  Taro CLI 1.2.1 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 10.13.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.5.1 - C:\Users\Administrator\AppData\Roaming\npm\yarn.CMD
      npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
yuche commented 5 years ago

@cjfff

其实是我没搞懂

<template is="select-specification" data="{{act, goodInfo, fightGroupDetailData, spec1Index, spec2Index, spec1, spec2, lotteryData: actLottery.data}}"></template>

这样传的意思是什么。 相当于 ES6 的对象简写 + 取消掉的 handlebar 双括号的其中一个括号吗?

你这个情况在你回帖的上一楼就有讲为什么

cjfff commented 5 years ago

handlebar

是这样的,前面的属性就是 对象简写了, lotteryData: actLottery.data 后面这里单纯是为了 多场景服用 template 里面的某个字段,因为我们后端有几个场景的同一字段,在这个模板里对于数据来说都是一个意思... 简而言之就是为了服用

项目中很多地方都用到了这种方式传递属性,但是 convert 解析器 似乎把 : 前面的所有对象简写属性都当成了一个 key... 由于使用到的地方太多,手动改是改不过来了..

楼上看过了,情况不一样,handlebar 里面的不是表达式,我司项目中的确有在 handlebar 里面用表达式的情况,那些都已经自行修复了

而且 case 都不太一样,它是编译都没通过,我们是全部通过编译了,然后编译后的源码有点不符合预期结果...导致没法用 convert 后的代码开发

希望你们能修复一下...

jerryjiao commented 5 years ago
  1. es6 的展开符 '...'好像是不能转换的。
  2. image 这个报错麻烦问下是怎么回事呢?

taro版本 1.2.2

yuche commented 5 years ago

@cjfff 楼上说的是{{}} 里面一定是要是合法的表达式,如果合法的话写 wxs 函数也可以,template data 的用法有时候里面就不是合法的表达式,我猜他多加一个 {} 包住才是合法的表达式,不过也不敢确定,否则改了之后之前的转不了。

@jerryjiao 我说过一万次了,没有代码只有报错等于什么都没说。

jerryjiao commented 5 years ago

@yuche 非常抱歉,我没说清楚。

我是在页面里面引用了template. wxml部分

<import src="../../VictUI/template/vict-form.wxml" />
 <form report-submit data-submit="custom_submit" bindsubmit="_formSubmit">
            <template is="vict-input-group" data="{{...mobile }}"></template>
            <view class="validate-con" wx:if="{{isNeedValidateImg}}">
                <template is="vict-input-group" data="{{...validateCode }}"></template>
                <view class="validate-code" bind:tap="refreshCode">
                    <view class="img"><image src="{{imageCode}}" mode="widthFix"/></view>
                    <view class="icon-font icon-shuaxinx"></view>
                </view>
            </view>
            <view class="sms-con">
                <template is="vict-input-group" data="{{...smsCode }}"></template>
                <view class="count" wx:if="{{isShowCount}}">{{count}}s</view>
                <view class="send-sms" wx:else bind:tap="getSMS">{{sendTxt}}</view>
            </view>
            <view class="custom_submit">
                <template is="vict-btn-submit" data="{{...custom_submit}}"></template>
            </view>
        </form>

js文件代码(不好意思,我现在还没法定位到具体哪里出错,所以全贴上来了)

var app = getApp(), { VICT } = app;
var interval;
Page({
  data: {
    sendTxt: '获取验证码',
    isNeedValidateImg:false,
    imageCode:null,
    isErrorShow:false,

    isShowCount:false,
    count:60,
    mobile: {
      name: 'mobile', value: '', rule: 'required|mobile', label: '手机号码', maxlength: 11,
      placeholder: '',
      state: { active: false, onfocus: false, collapse: false }, valid: 'blur',
      onInput: 'mobile_on_input', onBlur: 'mobile_on_blur',
      validDec: {
        required: '请输入手机号码',
        mobile: '手机号码格式错误',
      }
    },
    validateCode: {
      name: 'validateCode', value: '', rule: 'required', label: '图形验证码', maxlength: 20,
      placeholder: '',
      state: { active: false, onfocus: false, collapse: false }, valid: 'blur',
      validDec: {
        required: '请输入图形验证码'
      }
    },
    smsCode: {
      name: 'smsCode', value: '', rule: 'required|smsCode', label: '短信验证码', maxlength: 20,
      placeholder: '',
      state: { active: false, onfocus: false, collapse: false }, valid: 'blur',
      validDec: {
        required: '请输入短信验证码',
        smsCode: '短信验证码格式有误',
      }
    },
    custom_submit: {
      text: '登录', state: { loading: false }, method: { submit: 'login_form_submit' }
    },
  },
  ...VICT.vict_form,
  onLoad() { },
  getSMS(){
    if(this.data.mobile.value==''&& !this.data.mobile.error){
      this.setData({
        [`mobile.error`]:'请输入手机号码'
      })
      return
    }
    if(this.data.isNeedValidateImg && this.data.validateCode.value==''){
      this.setData({
        [`validateCode.error`]:'请输入图形验证码'
      })
      return
    }
    wx.showLoading({mask: true});
    let postData={};
    postData.cellPhone=this.data.mobile.value
    if(this.data.isNeedValidateImg){postData.imageCode=this.data.validateCode.value}
    app.Request(
      app.apiUrl.validate.sendSmsCode+'register',
      postData
    ).then(res => {
      wx.hideLoading();
      if (res.statusCode == "100000") {
        this.setData({
          isShowCount:true
        })
        let count=this.data.count;
        interval = setInterval(_=>{
          count--
          if(count>0){
            let text = count;
            this.setData({
              count:count
            })
          }else{
            clearInterval(interval)
            this.setData({
              isShowCount:false,
              count:60,
              sendTxt:'重新获取'
            })
          }
        },1000)
      }else if(res.statusCode == "100021"){
        wx.showToast({
          title: '短信验证码获取超过三次,请输入图形验证码',
          duration: 2000,
          mask:true,
          icon:'none'
        })

        this.setData({
          isNeedValidateImg:true,
          imageCode: app.apiUrl.validate.getImageCode+this.data.mobile.value+'/register'
        })

      }else if(res.statusCode == "100022"){
        wx.showToast({
          title: '图形验证码无效',
          duration: 2000,
          mask:true,
          icon:'none'
        })
        this.setData({
          imageCode: []
        })
        this.setData({
          imageCode: app.apiUrl.validate.getImageCode+this.data.mobile.value+'/register'
        })

      }else if(res.statusCode == "100034"){
        wx.showToast({
          title: '短信验证码超过今日最大获取数量',
          duration: 2000,
          mask:true,
          icon:'none'
        })

      }else{
        wx.showToast({
          title: '验证码获取失败,请重新尝试',
          duration: 2000,
          mask:true,
          icon:'none'
        })
      }
    })

  },
  refreshCode(){
    this.setData({
      imageCode: []
    })
    this.setData({
      imageCode: app.apiUrl.validate.getImageCode+this.data.mobile.value+'/register'
    })
  },
  register(){
    let that=this;

    return new Promise(function (resolve, reject) {
      let postData={};
          postData.type=2
          postData.cellPhone=that.data.mobile.value
          postData.verifyCode=that.data.smsCode.value
      app.Request(
        app.apiUrl.member.register,
        postData
      ).then(res => {
        console.log(res)
        if (res.statusCode == "100000") {
          resolve(res)
        }else if(res.statusCode == "100019"){
            that.setData({
              isErrorShow:true
            })
            reject(res)
        }else if(res.statusCode == "100030"){
          wx.showToast({
            title: '登录失败,请重新尝试',
            duration: 2000,
            mask:true,
            icon:'none'
          })
          reject(res)
      }else{
          reject(res)
        }
      })
    });
  },
  goBack(){
    wx.navigateBack();
  },
  mobile_on_input(val, model) { },
  mobile_on_blur(val, model) { },
  login_form_submit(data, hasErr) {
    if(!hasErr){
        this.register().then(_=>{
          console.log('========================',_) 
          wx.reLaunch({
            url: '/pages/report/report'
          });
        }).catch(err=>{console.log(err)})
    }
  }
})

然后报错如图 image

cjfff commented 5 years ago

@cjfff 楼上说的是{{}} 里面一定是要是合法的表达式,如果合法的话写 wxs 函数也可以,template data 的用法有时候里面就不是合法的表达式,我猜他多加一个 {} 包住才是合法的表达式,不过也不敢确定,否则改了之后之前的转不了。

@yuche 现在究其原因就是表达式是否合法对把?那转换没问题的话,是否可以称为合法呢? 另外,你的猜测,可以用代码举个例子吗? [感谢]

yuche commented 5 years ago

@cjfff 转换没问题也不一定是合法的,有可能只是碰巧对了。

例如有这么一个表达式: { a, b, c: d} 那他就是合法的,只要 a, b, d 都有值,这个表达式可以执行。如果是 a, b, c: d 那他就不合法。

当你在 template 的 data 写 data="{{ act, goodInfo, fightGroupDetailData, spec1Index, spec2Index, spec1, spec2, lotteryData: actLottery.data }}" 时,转换器真正拿到的表达式是: act, goodInfo, fightGroupDetailData, spec1Index, spec2Index, spec1, spec2, lotteryData: actLottery.data。显然他不是一个合法的 JavaScript 表达式,但加上了一个括号包住,那他就可以解析了。

xmt1139057136 commented 5 years ago

大家讨论的非常的火啊,我邮箱了不一会就好了好多邮件。 image 大家来这里讨论吧!

cjfff commented 5 years ago

@yuche

道理是懂了(大概是你们解析器拿到的是 {{}} 里面的 字符 ,然后把它当成表达式来判断),但是项目中的问题如何解决呢? image 我上面的使用只是为了给 对应的变量一个别名而已, 大神给个建议吧

yuche commented 5 years ago

@cjfff 你可以在 data 先写一个可以通过编译的,然后再改编译后的文件,或者等我们弄清楚 data 传入的模式之后发下一个版本。

@jerryjiao 你这个问题应该是 import wxml 的问题,你可以删除掉 import 那行看看是不是这样。具体还得看 wxml 有什么内容

jerryjiao commented 5 years ago

@yuchen 删掉以后可以转换。不是js的问题么?

cjfff commented 5 years ago

@cjfff 你可以在 data 先写一个可以通过编译的,然后再改编译后的文件,或者等我们弄清楚 data 传入的模式之后发下一个版本。

好的, 了解!

luodanyalian commented 5 years ago

taro把原生小程序转成多端的时候,编译成h5却发现wx:if没有转换过来,这怎么解决? 源码

<view class="main">
  <switch-tab tab-array="{{['未使用', '已失效']}}" tab-index="{{showTab}}" bind:callback="_switchTab">
    <view slot="slot-1">
      <view class="unused-list coupon-list" wx:if="{{couponList.length > 0}}">
        <view class="coupon coupon-unused" wx:for="{{couponList}}" wx:key="{{index}}" bindtap="_couponDetail" data-id="{{item.id}}">
          <view class="left">
            <view class="price">¥
              <text>{{item.deduct}}</text>
            </view>
            <text class="cate">{{item.type == 1 ? '折扣券' : '抵用券'}}</text>
          </view>
          <view class="right">
            <text class="name">{{item.title}}</text>
            <view class="date">
              <text class="wrap green" wx:if="{{item.expire_days > 7}}">
                <text>{{item.start_date + '-' + item.end_date}}</text>
              </text>
              <text class="wrap red" wx:else>
                <text>{{item.expire_days}}天后过期</text>
              </text>
            </view>
            <text class="desc">{{item.subtitle}}</text>
          </view>
        </view>

      </view>
      <view class="no-data" wx:else>
        <icon class="icon icon-no-coupon"></icon>
        <text>没有优惠券信息</text>
      </view>
     </view>
</switch-tab>
</view>

编译报错: image

mdx86 commented 5 years ago

Taro版本:v1.2.12 问题:

  1. 由于微信小程序组件中内部数据与属性都能使用 this.data 访问,现在我们的小程序源码中也是直接使用 this.data 访问内部数据或属性。但使用taro反编译后 this.data.xxx 这样的代码会原样保留,若this.data.xxx 实际上是要引用属性时会造成引用不到的问题,因而此时需要手动将所有 this.data.xxx 引用属性的代码改成 this.props.xxx。 参考此小程序文档底部Tips

所以现在的问题是 taro 反编译时是否能自动识别原来小程序中 this.data.xxx 代码引用的是内部数据还是属性。若是引用属性时则在反编译时将 this.data.xxx 自动更新为 this.props.xxx,这样我们在反编译小程序后就不需要进行大量的手动更新修复操作。

  1. 微信小程序反编译后原组件中 this.properties.xxx 引用属性的代码,仍为 this.properties.xxx,同样我们需要在反编译后手动将 this.properties.xxx 改成 this.props.xxx。 这个问题和第1个问题相关,若能解决这个问题,我们可以把小程序源码中引用属性的代码 this.data.xxx 都改成 this.properties.xxx,这样也就能避免出现第1个问题的发生。

3.小程序中图片路径若使用了三元运算符,则反编译后不会自动添加 require(xxx) 方式引用。

flyfly6 commented 5 years ago

Taro版本:v1.2.12 template 引用会导致转换后的文件缺少 import 转换前的 wxml:

<import src="../../template/template.wxml" />
<view class="container">
  <view class="userinfo">
    <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
    <block wx:else>
      <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
    </block>
  </view>
  <template is="separator" data="{{separatorData}}"></template>
  <view class="usermotto">
    <text class="user-motto">{{motto}}</text>
  </view>
</view>

转换后的文件中,没有 import Button, Image, Text 这几个组件,去掉 template 引用之后就可以正常转换

import { Block, View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import withWeapp from '@tarojs/with-weapp'
import SeparatorTmpl from '../../imports/SeparatorTmpl.js'
import './index.scss'
//index.js
//获取应用实例
const app = Taro.getApp()

@withWeapp('Page')
class _C extends Taro.Component {
  state = {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: Taro.canIUse('button.open-type.getUserInfo'),
    separatorData: { type: 'block', height: 100 }
  }
  bindViewTap = () => {
    Taro.navigateTo({
      url: '../logs/logs'
    })
  }

  componentWillMount() {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      Taro.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  }

  getUserInfo = e => {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
  config = {}

  render() {
    const {
      hasUserInfo: hasUserInfo,
      canIUse: canIUse,
      userInfo: userInfo,
      separatorData: separatorData,
      motto: motto
    } = this.state
    return (
      <Block>
        {/* index.wxml */}
        <View className="container">
          <View className="userinfo">
            {!hasUserInfo && canIUse ? (
              <Button openType="getUserInfo" onGetuserinfo={this.getUserInfo}>
                获取头像昵称
              </Button>
            ) : (
              <Block>
                <Image
                  onClick={this.bindViewTap}
                  className="userinfo-avatar"
                  src={userInfo.avatarUrl}
                  mode="cover"
                />
                <Text className="userinfo-nickname">{userInfo.nickName}</Text>
              </Block>
            )}
          </View>
          <SeparatorTmpl data={separatorData} />
          <View className="usermotto">
            <Text className="user-motto">{motto}</Text>
          </View>
        </View>
      </Block>
    )
  }
}

export default _C
wangxv commented 5 years ago

@luckyadam 1. image 我安装图中的然后执行taro convert并没有什么反应,在微信群中问了之后,安装的时候是不需要后面的@beta的,是否考虑更新一下上面的文案,不然会引起误会

2.后续会有RN转Taro吗?