@@ -12,6 +12,7 @@ import {
1212 getValue ,
1313 parseData ,
1414 parseExpression ,
15+ parseThisRequiredExpression ,
1516 parseI18n ,
1617 isEmpty ,
1718 isSchema ,
@@ -83,11 +84,13 @@ export default function baseRendererFactory(): IBaseRenderComponent {
8384 getLocale : any ;
8485 setLocale : any ;
8586 styleElement : any ;
87+ parseExpression : any ;
8688 [ key : string ] : any ;
8789
8890 constructor ( props : IBaseRendererProps , context : IBaseRendererContext ) {
8991 super ( props , context ) ;
9092 this . context = context ;
93+ this . parseExpression = props ?. thisRequiredInJSE ? parseThisRequiredExpression : parseExpression ;
9194 this . __beforeInit ( props ) ;
9295 this . __init ( props ) ;
9396 this . __afterInit ( props ) ;
@@ -112,7 +115,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
112115
113116 if ( func ) {
114117 if ( isJSExpression ( func ) || isJSFunction ( func ) ) {
115- const fn = parseExpression ( func , this ) ;
118+ const fn = props . thisRequiredInJSE ? parseThisRequiredExpression ( func , this ) : parseExpression ( func , this ) ;
116119 return fn ( props , state ) ;
117120 }
118121
@@ -193,7 +196,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
193196 if ( fn ) {
194197 // TODO, cache
195198 if ( isJSExpression ( fn ) || isJSFunction ( fn ) ) {
196- fn = parseExpression ( fn , this ) ;
199+ fn = this . parseExpression ( fn , this ) ;
197200 }
198201 if ( typeof fn !== 'function' ) {
199202 console . error ( `生命周期${ method } 类型不符` , fn ) ;
@@ -219,7 +222,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
219222 this . __customMethodsList = customMethodsList ;
220223 forEach ( __schema . methods , ( val : any , key : string ) => {
221224 if ( isJSExpression ( val ) || isJSFunction ( val ) ) {
222- val = parseExpression ( val , this ) ;
225+ val = this . parseExpression ( val , this ) ;
223226 }
224227 if ( typeof val !== 'function' ) {
225228 console . error ( `自定义函数${ key } 类型不符` , val ) ;
@@ -414,7 +417,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
414417 const { __appHelper : appHelper , __components : components = { } } = this . props || { } ;
415418
416419 if ( isJSExpression ( schema ) ) {
417- return parseExpression ( schema , scope ) ;
420+ return this . parseExpression ( schema , scope ) ;
418421 }
419422 if ( isI18nData ( schema ) ) {
420423 return parseI18n ( schema , scope ) ;
@@ -434,7 +437,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
434437 const _children = this . getSchemaChildren ( schema ) ;
435438 // 解析占位组件
436439 if ( schema ?. componentName === 'Fragment' && _children ) {
437- const tarChildren = isJSExpression ( _children ) ? parseExpression ( _children , scope ) : _children ;
440+ const tarChildren = isJSExpression ( _children ) ? this . parseExpression ( _children , scope ) : _children ;
438441 return this . __createVirtualDom ( tarChildren , scope , parentInfo ) ;
439442 }
440443
@@ -496,7 +499,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
496499 let scopeKey = '' ;
497500 // 判断组件是否需要生成scope,且只生成一次,挂在this.__compScopes上
498501 if ( Comp . generateScope ) {
499- const key = parseExpression ( schema . props ?. key , scope ) ;
502+ const key = this . parseExpression ( schema . props ?. key , scope ) ;
500503 if ( key ) {
501504 // 如果组件自己设置key则使用组件自己的key
502505 scopeKey = key ;
@@ -647,7 +650,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
647650
648651 _children . forEach ( ( _child : any ) => {
649652 const _childVirtualDom = this . __createVirtualDom (
650- isJSExpression ( _child ) ? parseExpression ( _child , scope ) : _child ,
653+ isJSExpression ( _child ) ? this . parseExpression ( _child , scope ) : _child ,
651654 scope ,
652655 {
653656 schema,
@@ -754,7 +757,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
754757 return checkProps ( props ) ;
755758 }
756759 if ( isJSExpression ( props ) ) {
757- props = parseExpression ( props , scope ) ;
760+ props = this . parseExpression ( props , scope ) ;
758761 // 只有当变量解析出来为模型结构的时候才会继续解析
759762 if ( ! isSchema ( props ) && ! isJSSlot ( props ) ) return checkProps ( props ) ;
760763 }
0 commit comments