@dcloudio/uni-template-compiler 2.0.1-alpha-34020211231002 → 2.0.1-alpha-33720220111002
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
|
@@ -117,6 +117,7 @@ module.exports = {
|
|
|
117
117
|
PREFIX_CLASS: 'c',
|
|
118
118
|
PREFIX_STYLE: 's',
|
|
119
119
|
PREFIX_EVENT: 'e',
|
|
120
|
+
PREFIX_TEXT: 't',
|
|
120
121
|
IDENTIFIER_FOR: '__$$for$$__',
|
|
121
122
|
IDENTIFIER_ATTR: '__$$attr$$__',
|
|
122
123
|
IDENTIFIER_METHOD: '__$$method$$__',
|
|
@@ -124,5 +125,6 @@ module.exports = {
|
|
|
124
125
|
IDENTIFIER_CLASS: '__$$class$$__',
|
|
125
126
|
IDENTIFIER_STYLE: '__$$style$$__',
|
|
126
127
|
IDENTIFIER_EVENT: '__$$event$$__',
|
|
127
|
-
IDENTIFIER_GLOBAL: '__$$global$$__'
|
|
128
|
+
IDENTIFIER_GLOBAL: '__$$global$$__',
|
|
129
|
+
IDENTIFIER_TEXT: '__$$text$$__'
|
|
128
130
|
}
|
|
@@ -3,18 +3,24 @@ const {
|
|
|
3
3
|
} = require('../../../constants')
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
isSimpleObjectExpression
|
|
6
|
+
isSimpleObjectExpression,
|
|
7
|
+
hasEscapeQuote
|
|
7
8
|
} = require('../../../util')
|
|
8
9
|
|
|
9
10
|
const getMemberExpr = require('../member-expr')
|
|
10
11
|
|
|
12
|
+
function checkObjectExpression (path) {
|
|
13
|
+
return path.isObjectExpression() && !isSimpleObjectExpression(path.node)
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
module.exports = function processAttrs (paths, path, state, isComponent, tagName) {
|
|
12
17
|
const attrsPath = paths.attrs
|
|
13
18
|
if (attrsPath) {
|
|
14
19
|
attrsPath.get('value.properties').forEach(propertyPath => {
|
|
15
20
|
const valuePath = propertyPath.get('value')
|
|
16
21
|
// 对于简单的ObjectExpression不再单独处理,改为在转换temlplte时用()包裹(微信、QQ)
|
|
17
|
-
|
|
22
|
+
// 属性中包含转义引号时部分小程序平台报错或显示异常
|
|
23
|
+
if (checkObjectExpression(valuePath) || hasEscapeQuote(valuePath)) {
|
|
18
24
|
valuePath.replaceWith(getMemberExpr(path, IDENTIFIER_ATTR, valuePath.node, state))
|
|
19
25
|
}
|
|
20
26
|
})
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
IDENTIFIER_STYLE,
|
|
13
13
|
IDENTIFIER_EVENT,
|
|
14
14
|
IDENTIFIER_GLOBAL,
|
|
15
|
+
IDENTIFIER_TEXT,
|
|
15
16
|
PREFIX_ATTR,
|
|
16
17
|
PREFIX_GLOBAL,
|
|
17
18
|
PREFIX_METHOD,
|
|
@@ -19,7 +20,8 @@ const {
|
|
|
19
20
|
PREFIX_FOR,
|
|
20
21
|
PREFIX_CLASS,
|
|
21
22
|
PREFIX_STYLE,
|
|
22
|
-
PREFIX_EVENT
|
|
23
|
+
PREFIX_EVENT,
|
|
24
|
+
PREFIX_TEXT
|
|
23
25
|
} = require('../../constants')
|
|
24
26
|
|
|
25
27
|
const {
|
|
@@ -63,6 +65,10 @@ function reIdentifier (identifierArray) {
|
|
|
63
65
|
[IDENTIFIER_ATTR]: {
|
|
64
66
|
prefix: PREFIX_ATTR,
|
|
65
67
|
id: 0
|
|
68
|
+
},
|
|
69
|
+
[IDENTIFIER_TEXT]: {
|
|
70
|
+
prefix: PREFIX_TEXT,
|
|
71
|
+
id: 0
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
// TODO order
|
|
@@ -11,7 +11,8 @@ const {
|
|
|
11
11
|
METHOD_RESOLVE_SCOPED_SLOTS,
|
|
12
12
|
IDENTIFIER_FILTER,
|
|
13
13
|
IDENTIFIER_METHOD,
|
|
14
|
-
IDENTIFIER_GLOBAL
|
|
14
|
+
IDENTIFIER_GLOBAL,
|
|
15
|
+
IDENTIFIER_TEXT
|
|
15
16
|
} = require('../../constants')
|
|
16
17
|
|
|
17
18
|
const {
|
|
@@ -22,7 +23,8 @@ const {
|
|
|
22
23
|
hasOwn,
|
|
23
24
|
hyphenate,
|
|
24
25
|
traverseFilter,
|
|
25
|
-
getComponentName
|
|
26
|
+
getComponentName,
|
|
27
|
+
hasEscapeQuote
|
|
26
28
|
} = require('../../util')
|
|
27
29
|
|
|
28
30
|
const traverseData = require('./data')
|
|
@@ -186,7 +188,13 @@ module.exports = {
|
|
|
186
188
|
break
|
|
187
189
|
case METHOD_TO_STRING:
|
|
188
190
|
{
|
|
189
|
-
const
|
|
191
|
+
const stringPath = path.get('arguments.0')
|
|
192
|
+
if (hasEscapeQuote(stringPath)) {
|
|
193
|
+
// 属性中包含转义引号时部分小程序平台报错或显示异常
|
|
194
|
+
// TODO 简单情况翻转外层引号
|
|
195
|
+
stringPath.replaceWith(getMemberExpr(path, IDENTIFIER_TEXT, stringPath.node, this))
|
|
196
|
+
}
|
|
197
|
+
const stringNodes = stringPath.node
|
|
190
198
|
stringNodes.$toString = true
|
|
191
199
|
path.replaceWith(stringNodes)
|
|
192
200
|
}
|
package/lib/util.js
CHANGED
|
@@ -232,6 +232,34 @@ function isSimpleObjectExpression (node) {
|
|
|
232
232
|
}) => !t.isIdentifier(key) || !(t.isIdentifier(value) || t.isStringLiteral(value) || t.isBooleanLiteral(value) ||
|
|
233
233
|
t.isNumericLiteral(value) || t.isNullLiteral(value)))
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* 是否包含转义引号
|
|
237
|
+
* @param {*} path
|
|
238
|
+
* @returns {boolean}
|
|
239
|
+
*/
|
|
240
|
+
function hasEscapeQuote (path) {
|
|
241
|
+
let has = false
|
|
242
|
+
function hasEscapeQuote (node) {
|
|
243
|
+
const quote = node.extra ? node.extra.raw[0] : '"'
|
|
244
|
+
if (node.value.includes(quote)) {
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (path.isStringLiteral()) {
|
|
249
|
+
return hasEscapeQuote(path.node)
|
|
250
|
+
} else {
|
|
251
|
+
path.traverse({
|
|
252
|
+
noScope: true,
|
|
253
|
+
StringLiteral (path) {
|
|
254
|
+
if (hasEscapeQuote(path.node)) {
|
|
255
|
+
has = true
|
|
256
|
+
path.stop()
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
return has
|
|
262
|
+
}
|
|
235
263
|
|
|
236
264
|
module.exports = {
|
|
237
265
|
hasOwn,
|
|
@@ -263,5 +291,6 @@ module.exports = {
|
|
|
263
291
|
}),
|
|
264
292
|
processMemberExpression,
|
|
265
293
|
getForIndexIdentifier,
|
|
266
|
-
isSimpleObjectExpression
|
|
294
|
+
isSimpleObjectExpression,
|
|
295
|
+
hasEscapeQuote
|
|
267
296
|
}
|
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-33720220111002",
|
|
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": "6fcc582dd805b52cd3c8f7d828ca12c2e2f4cedd"
|
|
26
26
|
}
|