@mpxjs/webpack-plugin 2.7.52 → 2.8.0-beta.2

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.
Files changed (71) hide show
  1. package/lib/config.js +24 -24
  2. package/lib/dependencies/CommonJsVariableDependency.js +1 -1
  3. package/lib/dependencies/DynamicEntryDependency.js +18 -11
  4. package/lib/extractor.js +1 -1
  5. package/lib/helpers.js +3 -1
  6. package/lib/index.js +24 -21
  7. package/lib/json-compiler/helper.js +1 -1
  8. package/lib/json-compiler/index.js +17 -17
  9. package/lib/json-compiler/plugin.js +3 -2
  10. package/lib/json-compiler/theme.js +1 -1
  11. package/lib/loader.js +3 -3
  12. package/lib/native-loader.js +1 -1
  13. package/lib/platform/json/normalize-test.js +3 -1
  14. package/lib/platform/run-rules.js +2 -2
  15. package/lib/platform/template/wx/component-config/camera.js +3 -3
  16. package/lib/platform/template/wx/component-config/canvas.js +5 -5
  17. package/lib/platform/template/wx/component-config/map.js +5 -5
  18. package/lib/platform/template/wx/component-config/navigator.js +7 -7
  19. package/lib/platform/template/wx/component-config/progress.js +4 -4
  20. package/lib/platform/template/wx/component-config/scroll-view.js +3 -3
  21. package/lib/platform/template/wx/component-config/slider.js +6 -6
  22. package/lib/platform/template/wx/component-config/swiper.js +2 -2
  23. package/lib/platform/template/wx/component-config/video.js +4 -4
  24. package/lib/platform/template/wx/component-config/view.js +4 -4
  25. package/lib/platform/template/wx/index.js +45 -13
  26. package/lib/resolver/PackageEntryPlugin.js +1 -1
  27. package/lib/runtime/components/web/filterTag.js +6 -6
  28. package/lib/runtime/components/web/getInnerListeners.js +1 -1
  29. package/lib/runtime/components/web/mpx-button.vue +0 -1
  30. package/lib/runtime/components/web/mpx-icon.vue +1 -1
  31. package/lib/runtime/components/web/mpx-keep-alive.vue +2 -2
  32. package/lib/runtime/components/web/mpx-picker.vue +1 -1
  33. package/lib/runtime/components/web/mpx-progress.vue +1 -1
  34. package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
  35. package/lib/runtime/env.js +1 -0
  36. package/lib/runtime/i18n.wxs +44 -81
  37. package/lib/runtime/optionProcessor.d.ts +0 -4
  38. package/lib/runtime/optionProcessor.js +15 -13
  39. package/lib/runtime/stringify.wxs +3 -3
  40. package/lib/runtime/swanHelper.wxs +2 -2
  41. package/lib/runtime/{components/web/util.js → utils.js} +8 -5
  42. package/lib/script-setup-compiler/index.js +1163 -0
  43. package/lib/style-compiler/index.js +1 -1
  44. package/lib/style-compiler/plugins/rpx.js +1 -1
  45. package/lib/style-compiler/plugins/vw.js +6 -4
  46. package/lib/template-compiler/bind-this.js +5 -5
  47. package/lib/template-compiler/compiler.js +122 -179
  48. package/lib/template-compiler/index.js +3 -3
  49. package/lib/utils/add-query.js +2 -1
  50. package/lib/utils/gen-component-tag.js +1 -1
  51. package/lib/utils/has-own.js +5 -0
  52. package/lib/utils/is-empty-object.js +2 -1
  53. package/lib/utils/parse-request.js +3 -3
  54. package/lib/utils/{index.js → process-defs.js} +3 -10
  55. package/lib/utils/stringify-query.js +23 -21
  56. package/lib/web/processJSON.js +5 -5
  57. package/lib/web/processScript.js +16 -19
  58. package/lib/web/processTemplate.js +1 -1
  59. package/lib/wxml/loader.js +3 -3
  60. package/lib/wxs/i18n-loader.js +4 -11
  61. package/lib/wxs/pre-loader.js +51 -44
  62. package/lib/wxss/compile-exports.js +4 -4
  63. package/lib/wxss/createResolver.js +3 -3
  64. package/lib/wxss/css-base.js +13 -13
  65. package/lib/wxss/getLocalIdent.js +5 -4
  66. package/lib/wxss/loader.js +1 -1
  67. package/lib/wxss/localsLoader.js +14 -14
  68. package/lib/wxss/processCss.js +10 -7
  69. package/package.json +4 -3
  70. package/lib/utils/env.js +0 -4
  71. package/lib/utils/parse-asset.js +0 -195
@@ -10,15 +10,14 @@ const getRulesRunner = require('../platform/index')
10
10
  const addQuery = require('../utils/add-query')
11
11
  const transDynamicClassExpr = require('./trans-dynamic-class-expr')
12
12
  const dash2hump = require('../utils/hump-dash').dash2hump
13
- const { inBrowser } = require('../utils/env')
14
13
 
15
14
  /**
16
15
  * Make a map and return a function for checking if a key
17
16
  * is in that map.
18
17
  */
19
18
  function makeMap (str, expectsLowerCase) {
20
- let map = Object.create(null)
21
- let list = str.split(',')
19
+ const map = Object.create(null)
20
+ const list = str.split(',')
22
21
  for (let i = 0; i < list.length; i++) {
23
22
  map[list[i]] = true
24
23
  }
@@ -82,28 +81,9 @@ const splitRE = /\r?\n/g
82
81
  const replaceRE = /./g
83
82
  const isSpecialTag = makeMap('script,style,template,json', true)
84
83
 
85
- const ieNSBug = /^xmlns:NS\d+/
86
- const ieNSPrefix = /^NS\d+:/
87
-
88
- /* istanbul ignore next */
89
- function guardIESVGBug (attrs) {
90
- let res = []
91
- for (let i = 0; i < attrs.length; i++) {
92
- let attr = attrs[i]
93
- if (!ieNSBug.test(attr.name)) {
94
- attr.name = attr.name.replace(ieNSPrefix, '')
95
- res.push(attr)
96
- }
97
- }
98
- return res
99
- }
100
-
101
84
  function makeAttrsMap (attrs) {
102
- let map = {}
85
+ const map = {}
103
86
  for (let i = 0, l = attrs.length; i < l; i++) {
104
- // if (map[attrs[i].name] && !isIE && !isEdge) {
105
- // warn$1('duplicate attribute: ' + attrs[i].name)
106
- // }
107
87
  map[attrs[i].name] = attrs[i].value
108
88
  }
109
89
  return map
@@ -130,11 +110,6 @@ function isForbiddenTag (el) {
130
110
  )
131
111
  }
132
112
 
133
- // Browser environment sniffing
134
- const UA = inBrowser && window.navigator.userAgent.toLowerCase()
135
- const isIE = UA && /msie|trident/.test(UA)
136
- // const isEdge = UA && UA.indexOf('edge/') > 0
137
-
138
113
  // configurable state
139
114
  // 由于template处理为纯同步过程,采用闭包变量存储各种状态方便全局访问
140
115
  let warn$1
@@ -172,7 +147,7 @@ function pushForScopes (scope) {
172
147
  }
173
148
 
174
149
  function popForScopes () {
175
- let scope = forScopes.pop()
150
+ const scope = forScopes.pop()
176
151
  updateForScopesMap()
177
152
  return scope
178
153
  }
@@ -208,7 +183,7 @@ function decode (value) {
208
183
  }
209
184
  }
210
185
 
211
- const i18nFuncNames = ['\\$(t)', '\\$(tc)', '\\$(te)', '\\$(d)', '\\$(n)']
186
+ const i18nFuncNames = ['\\$(t)', '\\$(tc)', '\\$(te)', '\\$(tm)', 't', 'tc', 'te', 'tm']
212
187
  const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
213
188
  const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
214
189
  // 添加~前缀避免wxs绝对路径在存在projectRoot时被拼接为错误路径
@@ -233,10 +208,10 @@ function decodeInMustache (value) {
233
208
  }
234
209
 
235
210
  function parseHTML (html, options) {
236
- let stack = []
237
- let expectHTML = options.expectHTML
238
- let isUnaryTag$$1 = options.isUnaryTag || no
239
- let canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no
211
+ const stack = []
212
+ const expectHTML = options.expectHTML
213
+ const isUnaryTag$$1 = options.isUnaryTag || no
214
+ const canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no
240
215
  let index = 0
241
216
  let last, lastTag
242
217
  while (html) {
@@ -247,7 +222,7 @@ function parseHTML (html, options) {
247
222
  if (textEnd === 0) {
248
223
  // Comment:
249
224
  if (comment.test(html)) {
250
- let commentEnd = html.indexOf('-->')
225
+ const commentEnd = html.indexOf('-->')
251
226
 
252
227
  if (commentEnd >= 0) {
253
228
  if (options.shouldKeepComment) {
@@ -260,7 +235,7 @@ function parseHTML (html, options) {
260
235
 
261
236
  // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
262
237
  if (conditionalComment.test(html)) {
263
- let conditionalEnd = html.indexOf(']>')
238
+ const conditionalEnd = html.indexOf(']>')
264
239
 
265
240
  if (conditionalEnd >= 0) {
266
241
  advance(conditionalEnd + 2)
@@ -269,23 +244,23 @@ function parseHTML (html, options) {
269
244
  }
270
245
 
271
246
  // Doctype:
272
- let doctypeMatch = html.match(doctype)
247
+ const doctypeMatch = html.match(doctype)
273
248
  if (doctypeMatch) {
274
249
  advance(doctypeMatch[0].length)
275
250
  continue
276
251
  }
277
252
 
278
253
  // End tag:
279
- let endTagMatch = html.match(endTag)
254
+ const endTagMatch = html.match(endTag)
280
255
  if (endTagMatch) {
281
- let curIndex = index
256
+ const curIndex = index
282
257
  advance(endTagMatch[0].length)
283
258
  parseEndTag(endTagMatch[1], curIndex, index)
284
259
  continue
285
260
  }
286
261
 
287
262
  // Start tag:
288
- let startTagMatch = parseStartTag()
263
+ const startTagMatch = parseStartTag()
289
264
  if (startTagMatch) {
290
265
  handleStartTag(startTagMatch)
291
266
  if (shouldIgnoreFirstNewline(lastTag, html)) {
@@ -295,9 +270,7 @@ function parseHTML (html, options) {
295
270
  }
296
271
  }
297
272
 
298
- let text = (void 0)
299
- let rest = (void 0)
300
- let next = (void 0)
273
+ let text, rest, next
301
274
  if (textEnd >= 0) {
302
275
  rest = html.slice(textEnd)
303
276
  while (!endTag.test(rest) && !startTagOpen.test(rest) && !comment.test(rest) && !conditionalComment.test(rest)) {
@@ -323,9 +296,9 @@ function parseHTML (html, options) {
323
296
  }
324
297
  } else {
325
298
  let endTagLength = 0
326
- let stackedTag = lastTag.toLowerCase()
327
- let reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
328
- let rest$1 = html.replace(reStackedTag, function (all, text, endTag) {
299
+ const stackedTag = lastTag.toLowerCase()
300
+ const reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
301
+ const rest$1 = html.replace(reStackedTag, function (all, text, endTag) {
329
302
  endTagLength = endTag.length
330
303
  if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {
331
304
  text = text
@@ -363,9 +336,9 @@ function parseHTML (html, options) {
363
336
  }
364
337
 
365
338
  function parseStartTag () {
366
- let start = html.match(startTagOpen)
339
+ const start = html.match(startTagOpen)
367
340
  if (start) {
368
- let match = {
341
+ const match = {
369
342
  tagName: start[1],
370
343
  attrs: [],
371
344
  start: index
@@ -386,8 +359,8 @@ function parseHTML (html, options) {
386
359
  }
387
360
 
388
361
  function handleStartTag (match) {
389
- let tagName = match.tagName
390
- let unarySlash = match.unarySlash
362
+ const tagName = match.tagName
363
+ const unarySlash = match.unarySlash
391
364
 
392
365
  if (expectHTML) {
393
366
  if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
@@ -398,12 +371,12 @@ function parseHTML (html, options) {
398
371
  }
399
372
  }
400
373
 
401
- let unary = isUnaryTag$$1(tagName) || !!unarySlash
374
+ const unary = isUnaryTag$$1(tagName) || !!unarySlash
402
375
 
403
- let l = match.attrs.length
404
- let attrs = new Array(l)
376
+ const l = match.attrs.length
377
+ const attrs = new Array(l)
405
378
  for (let i = 0; i < l; i++) {
406
- let args = match.attrs[i]
379
+ const args = match.attrs[i]
407
380
  // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
408
381
  if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
409
382
  if (args[3] === '') {
@@ -500,7 +473,7 @@ function parseComponent (content, options) {
500
473
  env = options.env
501
474
  filePath = options.filePath
502
475
 
503
- let sfc = {
476
+ const sfc = {
504
477
  template: null,
505
478
  script: null,
506
479
  json: null,
@@ -517,8 +490,8 @@ function parseComponent (content, options) {
517
490
  content: '',
518
491
  start: end,
519
492
  attrs: attrs.reduce(function (cumulated, ref) {
520
- let name = ref.name
521
- let value = ref.value
493
+ const name = ref.name
494
+ const value = ref.value
522
495
  cumulated[name] = value || true
523
496
  return cumulated
524
497
  }, {})
@@ -584,7 +557,7 @@ function parseComponent (content, options) {
584
557
 
585
558
  function checkAttrs (block, attrs) {
586
559
  for (let i = 0; i < attrs.length; i++) {
587
- let attr = attrs[i]
560
+ const attr = attrs[i]
588
561
  if (attr.name === 'lang') {
589
562
  block.lang = attr.value
590
563
  }
@@ -606,6 +579,9 @@ function parseComponent (content, options) {
606
579
  if (attr.name === 'env') {
607
580
  block.env = attr.value
608
581
  }
582
+ if (attr.name === 'setup') {
583
+ block.setup = true
584
+ }
609
585
  }
610
586
  }
611
587
 
@@ -628,8 +604,8 @@ function parseComponent (content, options) {
628
604
  if (pad === 'space') {
629
605
  return content.slice(0, block.start).replace(replaceRE, ' ')
630
606
  } else {
631
- let offset = content.slice(0, block.start).split(splitRE).length
632
- let padChar = '\n'
607
+ const offset = content.slice(0, block.start).split(splitRE).length
608
+ const padChar = '\n'
633
609
  return Array(offset).join(padChar)
634
610
  }
635
611
  }
@@ -688,13 +664,13 @@ function parse (template, options) {
688
664
 
689
665
  platformGetTagNamespace = options.getTagNamespace || no
690
666
 
691
- let stack = []
667
+ const stack = []
692
668
  let root
693
- let meta = {}
669
+ const meta = {}
694
670
  let currentParent
695
671
  let multiRootError
696
672
  // 用于记录模板用到的组件,匹配引用组件,看是否有冗余
697
- let tagNames = new Set()
673
+ const tagNames = new Set()
698
674
 
699
675
  function genTempRoot () {
700
676
  // 使用临时节点作为root,处理multi root的情况
@@ -711,15 +687,9 @@ function parse (template, options) {
711
687
  start: function start (tag, attrs, unary) {
712
688
  // check namespace.
713
689
  // inherit parent ns if there is one
714
- let ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
715
-
716
- // handle IE svg bug
717
- /* istanbul ignore if */
718
- if (isIE && ns === 'svg') {
719
- attrs = guardIESVGBug(attrs)
720
- }
690
+ const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
721
691
 
722
- let element = createASTElement(tag, attrs, currentParent)
692
+ const element = createASTElement(tag, attrs, currentParent)
723
693
  if (ns) {
724
694
  element.ns = ns
725
695
  }
@@ -752,9 +722,9 @@ function parse (template, options) {
752
722
 
753
723
  end: function end () {
754
724
  // remove trailing whitespace
755
- let element = stack[stack.length - 1]
725
+ const element = stack[stack.length - 1]
756
726
  if (element) {
757
- let lastNode = element.children[element.children.length - 1]
727
+ const lastNode = element.children[element.children.length - 1]
758
728
  if (lastNode && lastNode.type === 3 && lastNode.text === ' ') {
759
729
  element.children.pop()
760
730
  }
@@ -767,16 +737,8 @@ function parse (template, options) {
767
737
 
768
738
  chars: function chars (text) {
769
739
  if (!currentParent) genTempRoot()
770
- // IE textarea placeholder bug
771
- /* istanbul ignore if */
772
- if (isIE &&
773
- currentParent.tag === 'textarea' &&
774
- currentParent.attrsMap.placeholder === text
775
- ) {
776
- return
777
- }
778
740
 
779
- let children = currentParent.children
741
+ const children = currentParent.children
780
742
  if (currentParent.tag !== 'text') {
781
743
  text = text.trim()
782
744
  }
@@ -787,7 +749,7 @@ function parse (template, options) {
787
749
 
788
750
  if (text) {
789
751
  if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
790
- let el = {
752
+ const el = {
791
753
  type: 3,
792
754
  // 支付宝小程序模板解析中未对Mustache进行特殊处理,无论是否decode都会解析失败,无解,只能支付宝侧进行修复
793
755
  text: decodeInMustache(text),
@@ -816,11 +778,8 @@ function parse (template, options) {
816
778
  }
817
779
 
818
780
  if (hasI18n) {
819
- if (i18n.useComputed) {
820
- if (!meta.computed) {
821
- meta.computed = []
822
- }
823
- meta.computed = meta.computed.concat(i18nInjectableComputed)
781
+ if (i18nInjectableComputed.length) {
782
+ meta.computed = (meta.computed || []).concat(i18nInjectableComputed)
824
783
  } else {
825
784
  injectWxs(meta, i18nModuleName, i18nWxsRequest)
826
785
  }
@@ -886,16 +845,13 @@ function addAttrs (el, attrs) {
886
845
  const map = el.attrsMap
887
846
  for (let i = 0, l = attrs.length; i < l; i++) {
888
847
  list.push(attrs[i])
889
- // if (map[attrs[i].name] && !isIE && !isEdge) {
890
- // warn$1('duplicate attribute: ' + attrs[i].name)
891
- // }
892
848
  map[attrs[i].name] = attrs[i].value
893
849
  }
894
850
  }
895
851
 
896
852
  function modifyAttr (el, name, val) {
897
853
  el.attrsMap[name] = val
898
- let list = el.attrsList
854
+ const list = el.attrsList
899
855
  for (let i = 0, l = list.length; i < l; i++) {
900
856
  if (list[i].name === name) {
901
857
  list[i].value = val
@@ -1005,7 +961,7 @@ function processComponentIs (el, options) {
1005
961
  warn$1('Component in which <component> tag is used must have a nonblank usingComponents field')
1006
962
  }
1007
963
 
1008
- let is = getAndRemoveAttr(el, 'is').val
964
+ const is = getAndRemoveAttr(el, 'is').val
1009
965
  if (is) {
1010
966
  el.is = parseMustache(is).result
1011
967
  } else {
@@ -1016,8 +972,8 @@ function processComponentIs (el, options) {
1016
972
  const eventIdentifier = '__mpx_event__'
1017
973
 
1018
974
  function parseFuncStr2 (str) {
1019
- let funcRE = /^([^()]+)(\((.*)\))?/
1020
- let match = funcRE.exec(str)
975
+ const funcRE = /^([^()]+)(\((.*)\))?/
976
+ const match = funcRE.exec(str)
1021
977
  if (match) {
1022
978
  const funcName = parseMustache(match[1]).result
1023
979
  const hasArgs = !!match[2]
@@ -1039,9 +995,9 @@ function parseFuncStr2 (str) {
1039
995
  }
1040
996
 
1041
997
  function stringifyWithResolveComputed (modelValue) {
1042
- let result = []
998
+ const result = []
1043
999
  let inString = false
1044
- let computedStack = []
1000
+ const computedStack = []
1045
1001
  let fragment = ''
1046
1002
 
1047
1003
  for (let i = 0; i < modelValue.length; i++) {
@@ -1081,12 +1037,12 @@ function stringifyWithResolveComputed (modelValue) {
1081
1037
  function processBindEvent (el, options) {
1082
1038
  const eventConfigMap = {}
1083
1039
  el.attrsList.forEach(function (attr) {
1084
- let parsedEvent = config[mode].event.parseEvent(attr.name)
1040
+ const parsedEvent = config[mode].event.parseEvent(attr.name)
1085
1041
 
1086
1042
  if (parsedEvent) {
1087
- let type = parsedEvent.eventName
1088
- let modifiers = (parsedEvent.modifier || '').split('.')
1089
- let parsedFunc = parseFuncStr2(attr.value)
1043
+ const type = parsedEvent.eventName
1044
+ const modifiers = (parsedEvent.modifier || '').split('.')
1045
+ const parsedFunc = parseFuncStr2(attr.value)
1090
1046
  if (parsedFunc) {
1091
1047
  if (!eventConfigMap[type]) {
1092
1048
  eventConfigMap[type] = {
@@ -1102,9 +1058,9 @@ function processBindEvent (el, options) {
1102
1058
  }
1103
1059
  })
1104
1060
 
1105
- let modelExp = getAndRemoveAttr(el, config[mode].directive.model).val
1061
+ const modelExp = getAndRemoveAttr(el, config[mode].directive.model).val
1106
1062
  if (modelExp) {
1107
- let match = tagRE.exec(modelExp)
1063
+ const match = tagRE.exec(modelExp)
1108
1064
  if (match) {
1109
1065
  const modelProp = getAndRemoveAttr(el, config[mode].directive.modelProp).val || config[mode].event.defaultModelProp
1110
1066
  const modelEvent = getAndRemoveAttr(el, config[mode].directive.modelEvent).val || config[mode].event.defaultModelEvent
@@ -1125,8 +1081,8 @@ function processBindEvent (el, options) {
1125
1081
  warn$1(`EventName ${modelEvent} which is used in ${config[mode].directive.model} must be a valid identifier!`)
1126
1082
  return
1127
1083
  }
1128
- let modelValue = match[1].trim()
1129
- let stringifiedModelValue = stringifyWithResolveComputed(modelValue)
1084
+ const modelValue = match[1].trim()
1085
+ const stringifiedModelValue = stringifyWithResolveComputed(modelValue)
1130
1086
  // if (forScopes.length) {
1131
1087
  // stringifiedModelValue = stringifyWithResolveComputed(modelValue)
1132
1088
  // } else {
@@ -1151,7 +1107,7 @@ function processBindEvent (el, options) {
1151
1107
  }
1152
1108
  }
1153
1109
 
1154
- for (let type in eventConfigMap) {
1110
+ for (const type in eventConfigMap) {
1155
1111
  let needBind = false
1156
1112
  let { configs, rawName, proxy } = eventConfigMap[type]
1157
1113
  if (proxy) {
@@ -1206,11 +1162,11 @@ function wrapMustache (val) {
1206
1162
  function parseMustache (raw = '') {
1207
1163
  let replaced = false
1208
1164
  if (tagRE.test(raw)) {
1209
- let ret = []
1165
+ const ret = []
1210
1166
  let lastLastIndex = 0
1211
1167
  let match
1212
1168
  while (match = tagREG.exec(raw)) {
1213
- let pre = raw.substring(lastLastIndex, match.index)
1169
+ const pre = raw.substring(lastLastIndex, match.index)
1214
1170
  if (pre) {
1215
1171
  ret.push(stringify(pre))
1216
1172
  }
@@ -1228,27 +1184,28 @@ function parseMustache (raw = '') {
1228
1184
  })
1229
1185
 
1230
1186
  if (i18n) {
1231
- i18nFuncNames.forEach((i18nFuncName) => {
1187
+ for (const i18nFuncName of i18nFuncNames) {
1232
1188
  const funcNameRE = new RegExp(`${i18nFuncName}\\(`)
1233
1189
  const funcNameREG = new RegExp(`${i18nFuncName}\\(`, 'g')
1234
1190
  if (funcNameRE.test(exp)) {
1235
- if (i18n.useComputed) {
1191
+ if (i18n.useComputed || !i18nFuncName.startsWith('\\$')) {
1236
1192
  const i18nInjectComputedKey = `_i${i18nInjectableComputed.length + 1}`
1237
- i18nInjectableComputed.push(`${i18nInjectComputedKey}: function(){\nreturn ${exp.trim()}}`)
1193
+ i18nInjectableComputed.push(`${i18nInjectComputedKey} () {\nreturn ${exp.trim()}}`)
1238
1194
  exp = i18nInjectComputedKey
1239
1195
  } else {
1240
- exp = exp.replace(funcNameREG, `${i18nModuleName}.$1(mpxLocale, `)
1196
+ exp = exp.replace(funcNameREG, `${i18nModuleName}.$1(null, _l, _fl, `)
1241
1197
  }
1242
1198
  hasI18n = true
1243
1199
  replaced = true
1200
+ break
1244
1201
  }
1245
- })
1202
+ }
1246
1203
  }
1247
1204
 
1248
1205
  ret.push(`(${exp.trim()})`)
1249
1206
  lastLastIndex = tagREG.lastIndex
1250
1207
  }
1251
- let post = raw.substring(lastLastIndex)
1208
+ const post = raw.substring(lastLastIndex)
1252
1209
  if (post) {
1253
1210
  ret.push(stringify(post))
1254
1211
  }
@@ -1286,14 +1243,14 @@ function processIf (el) {
1286
1243
  let val = getAndRemoveAttr(el, config[mode].directive.if).val
1287
1244
  if (val) {
1288
1245
  if (mode === 'swan') val = wrapMustache(val)
1289
- let parsed = parseMustache(val)
1246
+ const parsed = parseMustache(val)
1290
1247
  el.if = {
1291
1248
  raw: parsed.val,
1292
1249
  exp: parsed.result
1293
1250
  }
1294
1251
  } else if (val = getAndRemoveAttr(el, config[mode].directive.elseif).val) {
1295
1252
  if (mode === 'swan') val = wrapMustache(val)
1296
- let parsed = parseMustache(val)
1253
+ const parsed = parseMustache(val)
1297
1254
  el.elseif = {
1298
1255
  raw: parsed.val,
1299
1256
  exp: parsed.result
@@ -1335,7 +1292,7 @@ function processFor (el) {
1335
1292
  }
1336
1293
  } else {
1337
1294
  if (mode === 'swan') val = wrapMustache(val)
1338
- let parsed = parseMustache(val)
1295
+ const parsed = parseMustache(val)
1339
1296
  el.for = {
1340
1297
  raw: parsed.val,
1341
1298
  exp: parsed.result
@@ -1358,13 +1315,13 @@ function processFor (el) {
1358
1315
  }
1359
1316
 
1360
1317
  function processRef (el, options, meta) {
1361
- let val = getAndRemoveAttr(el, config[mode].directive.ref).val
1362
- let type = isComponentNode(el, options) ? 'component' : 'node'
1318
+ const val = getAndRemoveAttr(el, config[mode].directive.ref).val
1319
+ const type = isComponentNode(el, options) ? 'component' : 'node'
1363
1320
  if (val) {
1364
1321
  if (!meta.refs) {
1365
1322
  meta.refs = []
1366
1323
  }
1367
- let all = !!forScopes.length
1324
+ const all = !!forScopes.length
1368
1325
  // swan的page中进行selectComponent匹配时会将类名前面的__去除掉,refClassName用__开头会导致swan在page中的组件refs失效
1369
1326
  let refClassName = `ref_${val}_${++refId}`
1370
1327
  // 支付宝中对于node进行的my.createSelectorQuery是在全局范围内进行的,需添加运行时组件id确保selector唯一
@@ -1411,7 +1368,7 @@ function addWxsContent (meta, module, content) {
1411
1368
 
1412
1369
  function postProcessWxs (el, meta) {
1413
1370
  if (el.tag === config[mode].wxs.tag) {
1414
- let module = el.attrsMap[config[mode].wxs.module]
1371
+ const module = el.attrsMap[config[mode].wxs.module]
1415
1372
  if (module) {
1416
1373
  let src, content
1417
1374
  if (el.attrsMap[config[mode].wxs.src]) {
@@ -1446,8 +1403,8 @@ function processAttrs (el, options) {
1446
1403
  el.attrsList.forEach((attr) => {
1447
1404
  const isTemplateData = el.tag === 'template' && attr.name === 'data'
1448
1405
  const needWrap = isTemplateData && mode !== 'swan'
1449
- let value = needWrap ? `{${attr.value}}` : attr.value
1450
- let parsed = parseMustache(value)
1406
+ const value = needWrap ? `{${attr.value}}` : attr.value
1407
+ const parsed = parseMustache(value)
1451
1408
  if (parsed.hasBinding) {
1452
1409
  // 该属性判断用于提供给运行时对于计算属性作为props传递时提出警告
1453
1410
  const isProps = isComponentNode(el, options) && !(attr.name === 'class' || attr.name === 'style')
@@ -1474,7 +1431,7 @@ function postProcessFor (el) {
1474
1431
  el = block
1475
1432
  }
1476
1433
 
1477
- let attrs = [
1434
+ const attrs = [
1478
1435
  {
1479
1436
  name: config[mode].directive.for,
1480
1437
  value: el.for.raw
@@ -1586,7 +1543,7 @@ function processText (el) {
1586
1543
  if (el.type !== 3 || el.isComment) {
1587
1544
  return
1588
1545
  }
1589
- let parsed = parseMustache(el.text)
1546
+ const parsed = parseMustache(el.text)
1590
1547
  if (parsed.hasBinding) {
1591
1548
  addExp(el, parsed.result)
1592
1549
  }
@@ -1610,7 +1567,7 @@ function injectWxs (meta, module, src) {
1610
1567
  if (addWxsModule(meta, module, src)) {
1611
1568
  return
1612
1569
  }
1613
- let wxsNode = createASTElement(config[mode].wxs.tag, [
1570
+ const wxsNode = createASTElement(config[mode].wxs.tag, [
1614
1571
  {
1615
1572
  name: config[mode].wxs.module,
1616
1573
  value: module
@@ -1627,12 +1584,12 @@ function processClass (el, meta) {
1627
1584
  const type = 'class'
1628
1585
  const needEx = el.tag.startsWith('th-')
1629
1586
  const targetType = needEx ? 'ex-' + type : type
1630
- let dynamicClass = getAndRemoveAttr(el, config[mode].directive.dynamicClass).val
1587
+ const dynamicClass = getAndRemoveAttr(el, config[mode].directive.dynamicClass).val
1631
1588
  let staticClass = getAndRemoveAttr(el, type).val || ''
1632
1589
  staticClass = staticClass.replace(/\s+/g, ' ')
1633
1590
  if (dynamicClass) {
1634
- let staticClassExp = parseMustache(staticClass).result
1635
- let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
1591
+ const staticClassExp = parseMustache(staticClass).result
1592
+ const dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
1636
1593
  error: error$1
1637
1594
  })
1638
1595
  addAttrs(el, [{
@@ -1663,12 +1620,12 @@ function processClass (el, meta) {
1663
1620
  function processStyle (el, meta) {
1664
1621
  const type = 'style'
1665
1622
  const targetType = el.tag.startsWith('th-') ? 'ex-' + type : type
1666
- let dynamicStyle = getAndRemoveAttr(el, config[mode].directive.dynamicStyle).val
1623
+ const dynamicStyle = getAndRemoveAttr(el, config[mode].directive.dynamicStyle).val
1667
1624
  let staticStyle = getAndRemoveAttr(el, type).val || ''
1668
1625
  staticStyle = staticStyle.replace(/\s+/g, ' ')
1669
1626
  if (dynamicStyle) {
1670
- let staticStyleExp = parseMustache(staticStyle).result
1671
- let dynamicStyleExp = parseMustache(dynamicStyle).result
1627
+ const staticStyleExp = parseMustache(staticStyle).result
1628
+ const dynamicStyleExp = parseMustache(dynamicStyle).result
1672
1629
  addAttrs(el, [{
1673
1630
  name: targetType,
1674
1631
  value: `{{${stringifyModuleName}.stringifyStyle(${staticStyleExp}, ${dynamicStyleExp})}}`
@@ -1715,7 +1672,7 @@ function processAliExternalClassesHack (el, options) {
1715
1672
 
1716
1673
  if (options.hasScoped && isComponent) {
1717
1674
  options.externalClasses.forEach((className) => {
1718
- let externalClass = getAndRemoveAttr(el, className).val
1675
+ const externalClass = getAndRemoveAttr(el, className).val
1719
1676
  if (externalClass) {
1720
1677
  addAttrs(el, [{
1721
1678
  name: className,
@@ -1762,7 +1719,7 @@ function processWebExternalClassesHack (el, options) {
1762
1719
  const isComponent = isComponentNode(el, options)
1763
1720
  if (isComponent) {
1764
1721
  options.externalClasses.forEach((classLikeAttrName) => {
1765
- let classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
1722
+ const classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
1766
1723
  if (classLikeAttrValue) {
1767
1724
  const classNames = classLikeAttrValue.split(/\s+/)
1768
1725
  const replacements = []
@@ -1828,8 +1785,8 @@ function processAliAddComponentRootView (el, options) {
1828
1785
  const processAppendAttrsRules = [
1829
1786
  { name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1830
1787
  ]
1831
- let newElAttrs = []
1832
- let allAttrs = cloneAttrsList(el.attrsList)
1788
+ const newElAttrs = []
1789
+ const allAttrs = cloneAttrsList(el.attrsList)
1833
1790
 
1834
1791
  function processClone (attr) {
1835
1792
  newElAttrs.push(attr)
@@ -1865,7 +1822,7 @@ function processAliAddComponentRootView (el, options) {
1865
1822
  })
1866
1823
 
1867
1824
  processAppendRules(el)
1868
- let componentWrapView = createASTElement('view', newElAttrs)
1825
+ const componentWrapView = createASTElement('view', newElAttrs)
1869
1826
  moveBaseDirective(componentWrapView, el)
1870
1827
  if (el.is && el.components) {
1871
1828
  el = postProcessComponentIs(el)
@@ -1957,7 +1914,7 @@ function postProcessTemplate (el) {
1957
1914
  }
1958
1915
  }
1959
1916
 
1960
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,noMode')
1917
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd')
1961
1918
 
1962
1919
  const wrapRE = /^\((.*)\)$/
1963
1920
 
@@ -1989,46 +1946,32 @@ function processAtMode (el) {
1989
1946
  return
1990
1947
  }
1991
1948
 
1992
- const conditionMap = new Map()
1949
+ const conditionMap = {}
1950
+
1993
1951
  modeStr.split('|').forEach(item => {
1994
1952
  const arr = item.split(':')
1995
- const key = arr[0] || 'noMode'
1996
- conditionMap.set(key, arr.slice(1))
1953
+ const key = arr[0] || mode
1954
+ conditionMap[key] = arr.slice(1)
1997
1955
  })
1998
1956
 
1999
- const modeArr = [...conditionMap.keys()]
1957
+ const modeArr = Object.keys(conditionMap)
2000
1958
 
2001
1959
  if (modeArr.every(i => isValidMode(i))) {
2002
1960
  const attrValue = getAndRemoveAttr(el, attrName).val
2003
1961
  const replacedAttrName = attrArr.join('@')
2004
- const processedAttr = { name: replacedAttrName, value: attrValue }
2005
1962
 
2006
- for (let [defineMode, defineEnvArr] of conditionMap.entries()) {
2007
- if (defineMode === 'noMode' || defineMode === mode) {
2008
- // 命中 env 规则(没有定义env 或者定义的envArr包含当前env)
2009
- if (!defineEnvArr.length || defineEnvArr.includes(env)) {
2010
- el._atModeStatus = ''
2011
- if (!replacedAttrName) {
2012
- // 若defineMode 为 noMode,则不论是element,还是attr,都需要经过规则转换
2013
- if (defineMode !== 'noMode') {
2014
- el._atModeStatus = 'match'
2015
- }
2016
- } else {
2017
- // 如果命中了指定的mode,则先存在el上,等跑完转换后再挂回去
2018
- el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
2019
- }
2020
- // 命中mode,命中env,完成匹配,直接退出
2021
- break
2022
- } else if (!replacedAttrName) {
2023
- // 命中mode规则,没有命中当前env规则,设置为 'mismatch'
2024
- el._atModeStatus = 'mismatch'
2025
- }
2026
- } else if (!replacedAttrName) {
2027
- // 没有命中当前mode规则,设置为 'mismatch'
2028
- el._atModeStatus = 'mismatch'
1963
+ const processedAttr = { name: replacedAttrName, value: attrValue }
1964
+ if (modeArr.includes(mode) && (!conditionMap[mode].length || conditionMap[mode].includes(env))) {
1965
+ if (!replacedAttrName) {
1966
+ el._atModeStatus = 'match'
2029
1967
  } else {
2030
- // 如果没命中指定的mode,则该属性删除
1968
+ // 如果命中了指定的mode,则先存在el上,等跑完转换后再挂回去
1969
+ el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
2031
1970
  }
1971
+ } else if (!replacedAttrName) {
1972
+ el._atModeStatus = 'mismatch'
1973
+ } else {
1974
+ // 如果没命中指定的mode,则该属性删除
2032
1975
  }
2033
1976
  }
2034
1977
  })
@@ -2199,7 +2142,7 @@ function postProcessComponentIs (el) {
2199
2142
  }
2200
2143
  el.components.forEach(function (component) {
2201
2144
  if (range.length > 0 && !range.includes(component)) return
2202
- let newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
2145
+ const newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
2203
2146
  newChild.if = {
2204
2147
  raw: `{{${el.is} === ${stringify(component)}}}`,
2205
2148
  exp: `${el.is} === ${stringify(component)}`
@@ -2258,7 +2201,7 @@ function serialize (root) {
2258
2201
  result += '<' + node.tag
2259
2202
  node.attrsList.forEach(function (attr) {
2260
2203
  result += ' ' + attr.name
2261
- let value = attr.value
2204
+ const value = attr.value
2262
2205
  if (value != null) {
2263
2206
  result += '=' + stringifyAttr(value)
2264
2207
  }
@@ -2286,11 +2229,11 @@ function serialize (root) {
2286
2229
  }
2287
2230
 
2288
2231
  function findPrevNode (node) {
2289
- let parent = node.parent
2232
+ const parent = node.parent
2290
2233
  if (parent) {
2291
2234
  let index = parent.children.indexOf(node)
2292
2235
  while (index--) {
2293
- let preNode = parent.children[index]
2236
+ const preNode = parent.children[index]
2294
2237
  if (preNode.type === 1) {
2295
2238
  return preNode
2296
2239
  }
@@ -2300,9 +2243,9 @@ function findPrevNode (node) {
2300
2243
 
2301
2244
  function replaceNode (node, newNode, reserveNode) {
2302
2245
  if (!reserveNode) deleteErrorInResultMap(node)
2303
- let parent = node.parent
2246
+ const parent = node.parent
2304
2247
  if (parent) {
2305
- let index = parent.children.indexOf(node)
2248
+ const index = parent.children.indexOf(node)
2306
2249
  if (index !== -1) {
2307
2250
  parent.children.splice(index, 1, newNode)
2308
2251
  newNode.parent = parent
@@ -2313,9 +2256,9 @@ function replaceNode (node, newNode, reserveNode) {
2313
2256
 
2314
2257
  function removeNode (node, reserveNode) {
2315
2258
  if (!reserveNode) deleteErrorInResultMap(node)
2316
- let parent = node.parent
2259
+ const parent = node.parent
2317
2260
  if (parent) {
2318
- let index = parent.children.indexOf(node)
2261
+ const index = parent.children.indexOf(node)
2319
2262
  if (index !== -1) {
2320
2263
  parent.children.splice(index, 1)
2321
2264
  return true
@@ -2334,7 +2277,7 @@ function genElseif (node) {
2334
2277
  error$1(`wx:elif (wx:elif="${node.elseif.raw}") invalidly used on the for-list <"${node.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the if-directive to it`)
2335
2278
  return
2336
2279
  }
2337
- let preNode = findPrevNode(node)
2280
+ const preNode = findPrevNode(node)
2338
2281
  if (preNode && (preNode.if || preNode.elseif)) {
2339
2282
  return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
2340
2283
  } else {
@@ -2348,7 +2291,7 @@ function genElse (node) {
2348
2291
  error$1(`wx:else invalidly used on the for-list <"${node.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the if-directive to it`)
2349
2292
  return
2350
2293
  }
2351
- let preNode = findPrevNode(node)
2294
+ const preNode = findPrevNode(node)
2352
2295
  if (preNode && (preNode.if || preNode.elseif)) {
2353
2296
  return `else{\n${genNode(node)}}\n`
2354
2297
  } else {
@@ -2364,8 +2307,8 @@ function genExps (node) {
2364
2307
 
2365
2308
  function genFor (node) {
2366
2309
  node.forProcessed = true
2367
- let index = node.for.index || 'index'
2368
- let item = node.for.item || 'item'
2310
+ const index = node.for.index || 'index'
2311
+ const item = node.for.item || 'item'
2369
2312
  return `this._i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
2370
2313
  }
2371
2314