attrs.js 915 字节
Newer Older
1
const t = require('@babel/types')
fxy060608's avatar
fxy060608 已提交
2

3 4 5 6 7
const {
  IDENTIFIER_ATTR
} = require('../../../constants')

const getMemberExpr = require('../member-expr')
fxy060608's avatar
fxy060608 已提交
8 9

module.exports = function processAttrs (paths, path, state, isComponent, tagName) {
10 11 12 13 14
  const attrsPath = paths.attrs
  if (attrsPath) {
    attrsPath.get('value.properties').forEach(propertyPath => {
      const valuePath = propertyPath.get('value')
      // 对于普通的ObjectExpression不再单独处理,改为在转换temlplte时用()包裹(微信、QQ)
15
      if (valuePath.isObjectExpression() && valuePath.node.properties.find(({ key, value }) => !t.isIdentifier(key) || !(t.isIdentifier(value) || t.isStringLiteral(value) || t.isBooleanLiteral(value) || t.isNumericLiteral(value) || t.isNullLiteral(value)))) {
16 17 18 19
        valuePath.replaceWith(getMemberExpr(path, IDENTIFIER_ATTR, valuePath.node, state))
      }
    })
  }
fxy060608's avatar
fxy060608 已提交
20
  return []
21
}