@dcloudio/uni-template-compiler 2.0.1-alpha-33820220114001 → 2.0.1-alpha-33820220118001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/constants.js
CHANGED
|
@@ -28,6 +28,7 @@ const INTERNAL_GET_EVENT = '__get_event'
|
|
|
28
28
|
const INTERNAL_GET_REFS = '__get_refs'
|
|
29
29
|
const INTERNAL_EVENT_PROXY = '__e'
|
|
30
30
|
const INTERNAL_EVENT_LINK = '__l'
|
|
31
|
+
const INTERNAL_EVENT_WRAP = '__w'
|
|
31
32
|
|
|
32
33
|
const ALLOWED_GLOBAL_OBJECT = [
|
|
33
34
|
'Math',
|
|
@@ -63,6 +64,7 @@ module.exports = {
|
|
|
63
64
|
ATTR_DATA_EVENT_OPTS: 'data-event-opts',
|
|
64
65
|
ATTR_DATA_COM_TYPE: 'data-com-type',
|
|
65
66
|
ATTR_DATA_EVENT_PARAMS: 'data-event-params',
|
|
67
|
+
ATTR_DATA_EVENT_LIST: 'data-event-list',
|
|
66
68
|
ATTE_DATA_CUSTOM_HIDDEN: 'data-custom-hidden',
|
|
67
69
|
INTERNAL_GET_ORIG,
|
|
68
70
|
INTERNAL_GET_CLASS,
|
|
@@ -71,6 +73,7 @@ module.exports = {
|
|
|
71
73
|
INTERNAL_GET_REFS,
|
|
72
74
|
INTERNAL_EVENT_PROXY,
|
|
73
75
|
INTERNAL_EVENT_LINK,
|
|
76
|
+
INTERNAL_EVENT_WRAP,
|
|
74
77
|
INTERNAL_SET_MODEL,
|
|
75
78
|
INTERNAL_SET_SYNC,
|
|
76
79
|
METHOD_BUILT_IN: [
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
const t = require('@babel/types')
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
METHOD_CREATE_ELEMENT,
|
|
5
|
+
ATTR_DATA_EVENT_OPTS,
|
|
6
|
+
ATTR_DATA_COM_TYPE,
|
|
7
|
+
ATTR_DATA_EVENT_LIST,
|
|
8
|
+
ATTR_DATA_EVENT_PARAMS,
|
|
9
|
+
ATTE_DATA_CUSTOM_HIDDEN,
|
|
10
|
+
INTERNAL_EVENT_WRAP
|
|
5
11
|
} = require('../../../constants')
|
|
6
12
|
|
|
7
13
|
const processRef = require('./ref')
|
|
@@ -37,7 +43,8 @@ module.exports = function traverseData (path, state, tagName) {
|
|
|
37
43
|
})
|
|
38
44
|
|
|
39
45
|
// 该组件是引入的小程序组件
|
|
40
|
-
|
|
46
|
+
const wxComponent = state.options.wxComponents[tagName]
|
|
47
|
+
if (wxComponent) {
|
|
41
48
|
addAttrProperties.push(
|
|
42
49
|
t.objectProperty(
|
|
43
50
|
t.stringLiteral(ATTR_DATA_COM_TYPE),
|
|
@@ -51,6 +58,81 @@ module.exports = function traverseData (path, state, tagName) {
|
|
|
51
58
|
t.stringLiteral('__r')
|
|
52
59
|
)
|
|
53
60
|
)
|
|
61
|
+
const properties = path.node.properties.find(prop => prop.key.name === 'on').value.properties
|
|
62
|
+
const list = []
|
|
63
|
+
for (let index = 0; index < properties.length; index++) {
|
|
64
|
+
const element = properties[index]
|
|
65
|
+
if (element.value.value === '__e') {
|
|
66
|
+
list.push(element.key.value)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
addAttrProperties.push(
|
|
70
|
+
t.objectProperty(
|
|
71
|
+
t.stringLiteral(ATTR_DATA_EVENT_LIST),
|
|
72
|
+
t.stringLiteral(list.join(','))
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
if (wxComponent.startsWith('plugin://')) {
|
|
76
|
+
const wrapperTag = 'plugin-wrapper'
|
|
77
|
+
const orgPath = path.parentPath
|
|
78
|
+
const orgNode = orgPath.node
|
|
79
|
+
const args = orgNode.arguments
|
|
80
|
+
const orgTag = args[0]
|
|
81
|
+
orgTag.$mpPlugin = true
|
|
82
|
+
args[0] = t.stringLiteral(wrapperTag)
|
|
83
|
+
const orgOptions = args[1]
|
|
84
|
+
const orgOptionsProps = orgOptions.properties
|
|
85
|
+
const targetAttrs = []
|
|
86
|
+
const targetOptionsProps = [
|
|
87
|
+
t.objectProperty(t.identifier('attrs'), t.objectExpression(targetAttrs))
|
|
88
|
+
]
|
|
89
|
+
const uniAttrs = [
|
|
90
|
+
ATTR_DATA_EVENT_OPTS,
|
|
91
|
+
ATTR_DATA_COM_TYPE,
|
|
92
|
+
ATTR_DATA_EVENT_PARAMS,
|
|
93
|
+
ATTR_DATA_EVENT_LIST,
|
|
94
|
+
ATTE_DATA_CUSTOM_HIDDEN,
|
|
95
|
+
'vue-id'
|
|
96
|
+
]
|
|
97
|
+
for (let a = orgOptionsProps.length - 1; a >= 0; a--) {
|
|
98
|
+
const prop = orgOptionsProps[a]
|
|
99
|
+
if (prop.key.name === 'attrs') {
|
|
100
|
+
const attrs = prop.value.properties
|
|
101
|
+
for (let b = attrs.length - 1; b >= 0; b--) {
|
|
102
|
+
const element = attrs[b]
|
|
103
|
+
const key = element.key.value
|
|
104
|
+
if (!uniAttrs.includes(key)) {
|
|
105
|
+
attrs.splice(b, 1)
|
|
106
|
+
targetAttrs.push(element)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
attrs.push(t.objectProperty(t.stringLiteral('onPluginWrap'), t.stringLiteral(INTERNAL_EVENT_WRAP)))
|
|
110
|
+
} else if (prop.key.name === 'on') {
|
|
111
|
+
const ons = prop.value.properties
|
|
112
|
+
ons.forEach(item => {
|
|
113
|
+
const attrs = path.node.properties.find(prop => prop.key.name === 'attrs').value.properties
|
|
114
|
+
const vueId = attrs.find(prop => prop.key.value === 'vue-id').value
|
|
115
|
+
const eventName = item.key.value
|
|
116
|
+
targetAttrs.push(t.objectProperty(t.stringLiteral(eventName), t.binaryExpression('+', t.stringLiteral(eventName), vueId)))
|
|
117
|
+
})
|
|
118
|
+
} else {
|
|
119
|
+
orgOptionsProps.splice(a, 1)
|
|
120
|
+
targetOptionsProps.push(prop)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const orgChild = args[2]
|
|
124
|
+
const targetOptions = t.objectExpression(targetOptionsProps)
|
|
125
|
+
targetOptions.$mpProcessed = true
|
|
126
|
+
const targetArguments = [
|
|
127
|
+
orgTag,
|
|
128
|
+
targetOptions
|
|
129
|
+
]
|
|
130
|
+
if (orgChild) {
|
|
131
|
+
targetArguments.push(orgChild)
|
|
132
|
+
}
|
|
133
|
+
const targetNode = t.callExpression(t.identifier(METHOD_CREATE_ELEMENT), targetArguments)
|
|
134
|
+
args[2] = targetNode
|
|
135
|
+
}
|
|
54
136
|
}
|
|
55
137
|
}
|
|
56
138
|
|
|
@@ -167,7 +167,8 @@ module.exports = {
|
|
|
167
167
|
tagNode.value = getComponentName(hyphenate(tagName))
|
|
168
168
|
|
|
169
169
|
// 组件增加 vueId
|
|
170
|
-
|
|
170
|
+
// 跳过支付宝插件组件
|
|
171
|
+
if (this.options.platform.isComponent(tagNode.value) && !tagNode.$mpPlugin) {
|
|
171
172
|
addVueId(path, this)
|
|
172
173
|
}
|
|
173
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-template-compiler",
|
|
3
|
-
"version": "2.0.1-alpha-
|
|
3
|
+
"version": "2.0.1-alpha-33820220118001",
|
|
4
4
|
"description": "uni-template-compiler",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@babel/types": "^7.3.3",
|
|
23
23
|
"vue-template-compiler": "^2.6.10"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "72093467a67e62aca16e80ff02f0683e729be75b"
|
|
26
26
|
}
|