@mpxjs/webpack-plugin 2.6.112 → 2.6.113

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.
@@ -120,6 +120,8 @@ function stringifyArray (value) {
120
120
  }
121
121
 
122
122
  var mpxDashReg = genRegExp('(.+)MpxDash$')
123
+ // 转义字符在wxs正则中存在平台兼容性问题,用[$]规避使用转义字符
124
+ var mpxDashReplaceReg = genRegExp('[$]', 'g')
123
125
 
124
126
  function stringifyObject (value) {
125
127
  var res = ''
@@ -129,7 +131,7 @@ function stringifyObject (value) {
129
131
  if (value[key]) {
130
132
  if (res) res += ' '
131
133
  if (mpxDashReg.test(key)) {
132
- key = hump2dash(mpxDashReg.exec(key)[1])
134
+ key = mpxDashReg.exec(key)[1].replace(mpxDashReplaceReg, '-')
133
135
  }
134
136
  res += key
135
137
  }
@@ -1761,7 +1761,9 @@ function processClass (el, meta) {
1761
1761
  staticClass = staticClass.replace(/\s+/g, ' ')
1762
1762
  if (dynamicClass) {
1763
1763
  let staticClassExp = parseMustache(staticClass).result
1764
- let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result)
1764
+ let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
1765
+ error: error$1
1766
+ })
1765
1767
  addAttrs(el, [{
1766
1768
  name: targetType,
1767
1769
  // swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效
@@ -1,27 +1,32 @@
1
1
  const babylon = require('@babel/parser')
2
2
  const t = require('@babel/types')
3
3
  const generate = require('@babel/generator').default
4
- const dash2hump = require('../utils/hump-dash').dash2hump
5
4
 
6
- module.exports = function transDynamicClassExpr (expr) {
7
- expr = babylon.parseExpression(expr, {
8
- plugins: [
9
- 'objectRestSpread'
10
- ]
11
- })
12
- if (t.isObjectExpression(expr)) {
13
- expr.properties.forEach((property) => {
14
- if (t.isObjectProperty(property) && !property.computed) {
15
- const propertyName = property.key.name || property.key.value
16
- if (/-/.test(propertyName)) {
17
- property.key = t.identifier(dash2hump(propertyName) + 'MpxDash')
18
- } else {
19
- property.key = t.identifier(propertyName)
20
- }
21
- }
5
+ module.exports = function transDynamicClassExpr (expr, { error } = {}) {
6
+ try {
7
+ const ast = babylon.parseExpression(expr, {
8
+ plugins: [
9
+ 'objectRestSpread'
10
+ ]
22
11
  })
12
+ if (t.isObjectExpression(ast)) {
13
+ ast.properties.forEach((property) => {
14
+ if (t.isObjectProperty(property) && !property.computed) {
15
+ const propertyName = property.key.name || property.key.value
16
+ if (/-/.test(propertyName)) {
17
+ if (/\$/.test(propertyName)) {
18
+ error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
19
+ } else {
20
+ property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
21
+ }
22
+ }
23
+ }
24
+ })
25
+ }
26
+ return generate(ast, {
27
+ compact: true
28
+ }).code
29
+ } catch (e) {
30
+ return expr
23
31
  }
24
- return generate(expr, {
25
- compact: true
26
- }).code
27
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.6.112",
3
+ "version": "2.6.113",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -81,5 +81,5 @@
81
81
  "@types/babel-traverse": "^6.25.4",
82
82
  "@types/babel-types": "^7.0.4"
83
83
  },
84
- "gitHead": "961b7a70cba62f8192ecf6b4007a0d7a9c52f97e"
84
+ "gitHead": "05ebd038f9f72d8a12dbae6c6f7685dbfa19f1b8"
85
85
  }