fix: 🐛 经验证发现小程序里面还是得包上 eval 否则 Rax 框架会误把 context 发送到渲染进程而出错

This commit is contained in:
牧毅 2020-08-21 13:30:11 +08:00
parent 8d198bd2a9
commit c7a10c035c
3 changed files with 4 additions and 12 deletions

View File

@ -194,14 +194,6 @@ function transformJsExpr(expr: string, handlers: CustomHandlerSet) {
case 'FunctionExpression': case 'FunctionExpression':
return transformThis2Context(exprAst, handlers); return transformThis2Context(exprAst, handlers);
// 对于直接访问 this.xxx, this.utils.xxx, this.state.xxx 的也不用再包下
case 'MemberExpression':
if (isSimpleDirectlyAccessingThis(exprAst) || isSimpleDirectlyAccessingSafeProperties(exprAst)) {
return transformThis2Context(exprAst, handlers);
}
break;
default: default:
break; break;
} }

View File

@ -83,13 +83,13 @@ class Home$$Page extends Component {
<View> <View>
<Text>=== User Info: ===</Text> <Text>=== User Info: ===</Text>
</View> </View>
{__$$context.state.user && ( {__$$eval(() => __$$context.state.user) && (
<View style={{ flexDirection: 'row' }}> <View style={{ flexDirection: 'row' }}>
<Image <Image
source={{ uri: __$$eval(() => __$$context.state.user.avatar) }} source={{ uri: __$$eval(() => __$$context.state.user.avatar) }}
style={{ width: '32px', height: '32px' }} style={{ width: '32px', height: '32px' }}
/> />
<View onClick={__$$context.hello}> <View onClick={__$$eval(() => __$$context.hello)}>
<Text>{__$$eval(() => __$$context.state.user.name)}</Text> <Text>{__$$eval(() => __$$context.state.user.name)}</Text>
<Text>{__$$eval(() => __$$context.state.user.age)}</Text> <Text>{__$$eval(() => __$$context.state.user.age)}</Text>
</View> </View>
@ -132,7 +132,7 @@ class Home$$Page extends Component {
}); });
}} }}
> >
<Text>点击次数{__$$context.state.clickCount}(点击加 1)</Text> <Text>点击次数{__$$eval(() => __$$context.state.clickCount)}(点击加 1)</Text>
</View> </View>
<View> <View>
<Text>操作提示</Text> <Text>操作提示</Text>

View File

@ -47,7 +47,7 @@ class Home$$Page extends Component {
__$$context.setLocale(__$$context.getLocale() === 'en-US' ? 'zh-CN' : 'en-US'); __$$context.setLocale(__$$context.getLocale() === 'en-US' ? 'zh-CN' : 'en-US');
}} }}
> >
{__$$context.i18n['hello-world']} {__$$eval(() => __$$context.i18n['hello-world'])}
</Text> </Text>
</Page> </Page>
); );