Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taro covert 页面转换 报错 #2191

Closed
xllily opened this issue Feb 17, 2019 · 4 comments
Closed

taro covert 页面转换 报错 #2191

xllily opened this issue Feb 17, 2019 · 4 comments

Comments

@xllily
Copy link

xllily commented Feb 17, 2019

执行 taro covert 部分页面转换 错误
[问题描述:转换错误的这些页面都采用相同的语法形式,相同的代码共用形式]

复现步骤

  1. 例如, 先写一个 common.js
// common.js
module.exports = {
	obj: {
        str:'string',
        n: 1,
        arr: []
	},
        onLoad: function() {console.log(this._privateProp,this.name,this.data);},
	onShow: function() {console.log('life cycle from common');},
	onReady: function() {console.log('life cycle from common');},
	onHide: function() {console.log('life cycle from common');},
	onUnload: function() {console.log('life cycle from common');},
};
  1. 微信小程序原生创建 page 时, 引用此 common.js
// es6

//比如 pages/home/home.js 

const app = getApp();

const {
	obj,
        onLoad,
	onShow,
	onReady,
	onHide,
	onUnload,
} = require('../../assets/common.js');

Page({
	_privateProp:'private prop',
	name: 'home',
	data: {
	   obj 
	},
	onLoad,
	onShow,
	onReady,
	onHide,
	onUnload
});

期望行为
期望包容这种形式的可以正常运行的微信小程序的原生代码,支持其可以成功转换成 "taro"

报错信息
...
错误 页面转换 pages/home/home.js
TypeError: Property body of ClassMethod expected node to be of a type ["BlockStatement"] but instead got null
at Object.validate (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_babel-types@6.26.0@babel-types\lib\definitions\index.js:109:13)
at validate (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_babel-types@6.26.0@babel-types\lib\index.js:505:9)
at Object.builder (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_babel-types@6.26.0@babel-types\lib\index.js:466:7)
at properties.map.prop (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_@[email protected]@@tarojs\taroize\lib\src\script.js:224:30)
at Array.map ()
at parsePage (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_@[email protected]@@tarojs\taroize\lib\src\script.js:121:32)
at CallExpression (C:\Users\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_@[email protected]@@tarojs\taroize\lib\src\script.js:43:29)
at NodePath._call (C:\Users\xiaoh\AppData\Roaming\nvm\v11.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\xiaoh\AppData\Roaming\nvm\v11.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\xiaoh\AppData\Roaming\nvm\v11.2.0\node_modules@tarojs\cli\node_modules_babel-traverse@6.26.0@babel-traverse\lib\path\context.js:105:12)
...

系统信息
👽 Taro v1.2.13
Taro CLI 1.2.13 environment info:
System:
OS: Windows 10
Binaries:
Node: 11.2.0
npm: 6.4.1

@taro-bot
Copy link

taro-bot bot commented Feb 17, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@yuche
Copy link
Contributor

yuche commented Feb 18, 2019

这种方式做不到,其实你这个写法这样还是复杂了,还可以:

const test = require('..')
Page({
...test, {
 ...
}
})

但是这样也不行,因为 taro convert 是基于语法转换的,所以你必须显示地把所有内容都写出来。

@taro-bot
Copy link

taro-bot bot commented Feb 18, 2019

Hello~

您的问题楼上已经提供了解决方案,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@xllily
Copy link
Author

xllily commented Feb 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants