( attrName: string, attrValue: IPublicTypeCompositeValue, scope: IScope, config?: NodeGeneratorConfig, )
| 76 | } |
| 77 | |
| 78 | function generateAttr( |
| 79 | attrName: string, |
| 80 | attrValue: IPublicTypeCompositeValue, |
| 81 | scope: IScope, |
| 82 | config?: NodeGeneratorConfig, |
| 83 | ): CodePiece[] { |
| 84 | let pieces: CodePiece[]; |
| 85 | if (config?.attrPlugins) { |
| 86 | pieces = executeFunctionStack<AttrData, CodePiece[], NodeGeneratorConfig>( |
| 87 | { attrName, attrValue }, |
| 88 | scope, |
| 89 | config.attrPlugins, |
| 90 | generateAttrValue, |
| 91 | config, |
| 92 | ); |
| 93 | } else { |
| 94 | pieces = generateAttrValue({ attrName, attrValue }, scope, config); |
| 95 | } |
| 96 | |
| 97 | pieces = pieces.map((p) => { |
| 98 | // FIXME: 在经过 generateCompositeType 处理过之后,其实已经无法通过传入值的类型判断传出值是否为纯字面值字符串了(可能包裹了加工函数之类的) |
| 99 | // 因此这个处理最好的方式是对传出值做语法分析,判断以哪种模版产出 Attr 值 |
| 100 | let newValue: string; |
| 101 | if (p.value && isPureString(p.value)) { |
| 102 | // 似乎多次一举,目前的诉求是处理多种引号类型字符串的 case,正确处理转义 |
| 103 | const content = getStaticExprValue<string>(p.value); |
| 104 | newValue = JSON.stringify(encodeJsxStringNode(content)); |
| 105 | } else { |
| 106 | newValue = `{${p.value}}`; |
| 107 | } |
| 108 | |
| 109 | return { |
| 110 | value: `${p.name}=${newValue}`, |
| 111 | type: PIECE_TYPE.ATTR, |
| 112 | }; |
| 113 | }); |
| 114 | |
| 115 | return pieces; |
| 116 | } |
| 117 | |
| 118 | function generateAttrs( |
| 119 | nodeItem: IPublicTypeNodeSchema, |
no test coverage detected
searching dependent graphs…