(pre: ICodeStruct)
| 38 | const { nodeTypeMapping } = cfg; |
| 39 | |
| 40 | const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { |
| 41 | const next: ICodeStruct = { |
| 42 | ...pre, |
| 43 | }; |
| 44 | |
| 45 | const { tolerateEvalErrors = true, evalErrorsHandler = '' } = next.contextData; |
| 46 | |
| 47 | // 这里会将内部的一些子上下文的访问(this.xxx)转换为 __$$context.xxx 的形式 |
| 48 | // 与 Rax 所不同的是,这里不会将最顶层的 this 转换掉 |
| 49 | const customHandlers: HandlerSet<string> = { |
| 50 | expression(input: IPublicTypeJSExpression, scope: IScope, config) { |
| 51 | return transformJsExpr(generateExpression(input, scope), scope, { |
| 52 | dontWrapEval: !(config?.tolerateEvalErrors ?? tolerateEvalErrors), |
| 53 | dontTransformThis2ContextAtRootScope: true, |
| 54 | }); |
| 55 | }, |
| 56 | function(input, scope: IScope) { |
| 57 | return transformThis2Context( |
| 58 | generateCompositeType( |
| 59 | { |
| 60 | type: 'JSFunction', |
| 61 | value: input.value || 'function () {}', |
| 62 | }, |
| 63 | Scope.createRootScope(), |
| 64 | ), |
| 65 | scope, |
| 66 | { ignoreRootScope: true }, |
| 67 | ); |
| 68 | }, |
| 69 | }; |
| 70 | |
| 71 | const generatorPlugins: NodeGeneratorConfig = { |
| 72 | handlers: customHandlers, |
| 73 | tagMapping: (v) => nodeTypeMapping[v] || v, |
| 74 | tolerateEvalErrors, |
| 75 | }; |
| 76 | |
| 77 | if (next.contextData.useRefApi) { |
| 78 | generatorPlugins.attrPlugins = [ |
| 79 | (attrData, scope, pluginCfg, nextFunc) => { |
| 80 | if (attrData.attrName === 'ref') { |
| 81 | return [ |
| 82 | { |
| 83 | name: attrData.attrName, |
| 84 | value: `this._refsManager.linkRef('${attrData.attrValue}')`, |
| 85 | type: PIECE_TYPE.ATTR, |
| 86 | }, |
| 87 | ]; |
| 88 | } |
| 89 | |
| 90 | return nextFunc ? nextFunc(attrData, scope, pluginCfg) : []; |
| 91 | }, |
| 92 | ]; |
| 93 | } |
| 94 | |
| 95 | const generator = createReactNodeGenerator(generatorPlugins); |
| 96 | |
| 97 | const ir = next.ir as IContainerInfo; |
nothing calls this directly
no test coverage detected
searching dependent graphs…