@dcloudio/uni-template-compiler 2.0.1-33520211229001 → 2.0.1-33920220121002

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
  }
package/lib/mp.js CHANGED
@@ -58,7 +58,8 @@ const tags = {
58
58
  'login',
59
59
  'inline-payment-panel'
60
60
  ],
61
- 'mp-weixin': [
61
+ 'mp-weixin': [
62
+ 'page-container',
62
63
  'page-meta',
63
64
  'navigation-bar',
64
65
  'match-media'
@@ -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
- if (valuePath.isObjectExpression() && !isSimpleObjectExpression(valuePath.node)) {
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 stringNodes = path.node.arguments[0]
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
  }
@@ -231,7 +231,7 @@ function traverseDataNode (dataNode, state, node) {
231
231
  let key
232
232
  // 自定义组件不支持 hidden 属性
233
233
  const platform = state.options.platform.name
234
- const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao', 'mp-lark']
234
+ const platforms = ['mp-weixin', 'mp-qq', 'mp-jd', 'mp-toutiao', 'mp-lark']
235
235
  if (isComponent(node.type) && platforms.includes(platform)) {
236
236
  // 字节跳动|飞书小程序自定义属性不会反应在DOM上,只能使用事件格式
237
237
  key = `${platform === 'mp-toutiao' || platform === 'mp-lark' ? 'bind:-' : ''}${ATTE_DATA_CUSTOM_HIDDEN}`
package/lib/util.js CHANGED
@@ -232,6 +232,40 @@ 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
+ TemplateElement (path) {
260
+ if (path.node.value.cooked.includes('\'')) {
261
+ has = true
262
+ path.stop()
263
+ }
264
+ }
265
+ })
266
+ }
267
+ return has
268
+ }
235
269
 
236
270
  module.exports = {
237
271
  hasOwn,
@@ -263,5 +297,6 @@ module.exports = {
263
297
  }),
264
298
  processMemberExpression,
265
299
  getForIndexIdentifier,
266
- isSimpleObjectExpression
300
+ isSimpleObjectExpression,
301
+ hasEscapeQuote
267
302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-template-compiler",
3
- "version": "2.0.1-33520211229001",
3
+ "version": "2.0.1-33920220121002",
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": "d53f68995da33f6d65b5276f68a2c9563e548e15"
25
+ "gitHead": "2bd26ff3115ec3c3c8b4a9ade025eb4d82d9e06f"
26
26
  }