mh-two-thousand-and-two
2024-04-12 7fc6dbf547b8899d949b67cdec36b96a7d1701c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const t = require('@babel/types')
 
const {
  CLASS_REF,
  CLASS_REF_IN_FOR
} = require('../../../constants')
 
module.exports = function processRef (paths, path, state) {
  const refPath = paths.ref
  if (refPath) {
    if (state.options.platform.name === 'mp-alipay') {
      return [
        t.objectProperty( // data-ref="" ,data-ref-in-for=""
          t.stringLiteral('ref'),
          t.stringLiteral('__r')
        ),
        t.objectProperty( // data-ref="" ,data-ref-in-for=""
          t.stringLiteral(state.inFor ? state.options.platform.refInFor : state.options.platform.ref),
          refPath.node.value
        )
      ]
    }
    const refClass = state.inFor ? CLASS_REF_IN_FOR : CLASS_REF
    const staticClassPath = paths.staticClass
    if (staticClassPath) { // append
      staticClassPath.node.value.value = staticClassPath.node.value.value + ' ' + refClass
    } else { // add staticClass
      path.node.properties.unshift(
        t.objectProperty(t.identifier('staticClass'), t.stringLiteral(refClass))
      )
      paths.staticClass = path.get('properties').find(
        propertyPath => propertyPath.node.key.name === 'staticClass'
      )
    }
    return [
      t.objectProperty( // data-ref="" ,头条 vue-ref
        t.stringLiteral(state.options.platform.ref),
        refPath.node.value
      )
    ]
  }
  return []
}