-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: 将style中的属性转换为合法的style={{}}格式 #179
fix: 将style中的属性转换为合法的style={{}}格式 #179
Conversation
packages/taroize/src/wxml.ts
Outdated
styleAttrs.forEach((attr) => { | ||
const [attrName, value] = attr.split(':') | ||
if (attrName) { | ||
styleKeys.push({ attrName, value }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里命名不太合适,改成styleAttrsMap是不是更好
packages/taroize/src/wxml.ts
Outdated
styleKeys.push({ attrName, value }) | ||
} | ||
}) | ||
styleNameToCamelCase(styleKeys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数名可改为convertStyleAttrs
packages/taroize/src/wxml.ts
Outdated
|
||
// 把 style 中 {{}} 转为 ${} 格式 | ||
if (name.name === 'style' && t.isStringLiteral(path.node.value)) { | ||
const styleValue = path.node.value as any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以封装成一个函数parseStyleAttrs,解析样式属性,下面的函数是转换样式属性
packages/taroize/src/wxml.ts
Outdated
const matchs = attrValueReg.exec(attr.value) | ||
if (matchs !== null) { | ||
// 获取{{}}模版左右位置的值 | ||
const tempLeftValue = attr.value.split('{{') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是可以用正则的分组来获取,上面都做了匹配了
这个 PR 做了什么? (简要描述所做更改)
convertor在做转换时并没有对style的静态内联样式和动态内联样式做转换,该commit主要对style属性名转小驼峰。而对于含有变量的属性值转换为${}形式。对于静态内联样式则是将其转换为react识别的style={{}}格式
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台: