@mpxjs/webpack-plugin 2.6.115 → 2.7.0-alpha

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 (129) hide show
  1. package/LICENSE +433 -0
  2. package/README.md +1 -1
  3. package/lib/config.js +14 -0
  4. package/lib/dependencies/AddEntryDependency.js +24 -0
  5. package/lib/dependencies/AppEntryDependency.js +58 -0
  6. package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
  7. package/lib/dependencies/CommonJsVariableDependency.js +81 -0
  8. package/lib/dependencies/DynamicEntryDependency.js +171 -0
  9. package/lib/dependencies/FlagPluginDependency.js +24 -0
  10. package/lib/dependencies/InjectDependency.js +43 -0
  11. package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
  12. package/lib/dependencies/RecordIndependentDependency.js +44 -0
  13. package/lib/dependencies/RecordResourceMapDependency.js +62 -0
  14. package/lib/dependencies/RemoveEntryDependency.js +40 -0
  15. package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
  16. package/lib/dependencies/ResolveDependency.js +88 -0
  17. package/lib/extractor.js +82 -178
  18. package/lib/file-loader.js +7 -19
  19. package/lib/helpers.js +39 -334
  20. package/lib/independent-loader.js +52 -0
  21. package/lib/index.js +889 -525
  22. package/lib/json-compiler/helper.js +156 -0
  23. package/lib/json-compiler/index.js +245 -451
  24. package/lib/json-compiler/plugin.js +150 -0
  25. package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
  26. package/lib/loader.js +178 -241
  27. package/lib/native-loader.js +71 -133
  28. package/lib/parser.js +1 -2
  29. package/lib/partial-compile/index.js +35 -0
  30. package/lib/platform/json/wx/index.js +1 -1
  31. package/lib/platform/template/normalize-component-rules.js +2 -3
  32. package/lib/platform/template/wx/component-config/button.js +14 -2
  33. package/lib/platform/template/wx/component-config/image.js +4 -0
  34. package/lib/platform/template/wx/component-config/input.js +4 -0
  35. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  36. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  37. package/lib/platform/template/wx/component-config/switch.js +4 -0
  38. package/lib/platform/template/wx/component-config/text.js +4 -0
  39. package/lib/platform/template/wx/component-config/textarea.js +5 -0
  40. package/lib/platform/template/wx/component-config/view.js +4 -0
  41. package/lib/platform/template/wx/index.js +149 -3
  42. package/lib/record-loader.js +11 -0
  43. package/lib/resolve-loader.js +6 -0
  44. package/lib/resolver/AddEnvPlugin.js +4 -3
  45. package/lib/resolver/AddModePlugin.js +4 -3
  46. package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
  47. package/lib/resolver/PackageEntryPlugin.js +23 -36
  48. package/lib/runtime/base.styl +5 -0
  49. package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
  50. package/lib/runtime/components/tenon/tenon-button.vue +305 -0
  51. package/lib/runtime/components/tenon/tenon-image.vue +61 -0
  52. package/lib/runtime/components/tenon/tenon-input.vue +99 -0
  53. package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
  54. package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
  55. package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
  56. package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
  57. package/lib/runtime/components/tenon/tenon-text.vue +64 -0
  58. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  59. package/lib/runtime/components/tenon/util.js +44 -0
  60. package/lib/runtime/components/web/getInnerListeners.js +1 -3
  61. package/lib/runtime/components/web/mpx-image.vue +20 -5
  62. package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
  63. package/lib/runtime/components/web/mpx-swiper.vue +18 -3
  64. package/lib/runtime/i18n.wxs +31 -11
  65. package/lib/runtime/optionProcessor.js +48 -3
  66. package/lib/runtime/optionProcessor.tenon.js +386 -0
  67. package/lib/selector.js +29 -10
  68. package/lib/style-compiler/index.js +16 -24
  69. package/lib/style-compiler/load-postcss-config.js +3 -1
  70. package/lib/style-compiler/plugins/conditional-strip.js +68 -65
  71. package/lib/style-compiler/plugins/hm.js +20 -0
  72. package/lib/style-compiler/plugins/rpx.js +43 -37
  73. package/lib/style-compiler/plugins/scope-id.js +79 -72
  74. package/lib/style-compiler/plugins/trans-special.js +25 -18
  75. package/lib/style-compiler/plugins/trim.js +13 -7
  76. package/lib/style-compiler/plugins/vw.js +22 -16
  77. package/lib/template-compiler/compiler.js +106 -199
  78. package/lib/template-compiler/index.js +52 -139
  79. package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
  80. package/lib/tenon/index.js +105 -0
  81. package/lib/tenon/processJSON.js +356 -0
  82. package/lib/tenon/processScript.js +261 -0
  83. package/lib/tenon/processStyles.js +21 -0
  84. package/lib/tenon/processTemplate.js +133 -0
  85. package/lib/url-loader.js +11 -29
  86. package/lib/utils/add-query.js +1 -1
  87. package/lib/utils/const.js +10 -0
  88. package/lib/utils/emit-file.js +10 -0
  89. package/lib/utils/eval-json-js.js +31 -0
  90. package/lib/utils/get-entry-name.js +13 -0
  91. package/lib/utils/get-json-content.js +42 -0
  92. package/lib/utils/get-relative-path.js +25 -0
  93. package/lib/utils/is-url-request.js +10 -1
  94. package/lib/utils/match-condition.js +4 -1
  95. package/lib/utils/normalize.js +4 -15
  96. package/lib/utils/parse-request.js +3 -3
  97. package/lib/utils/resolve.js +13 -0
  98. package/lib/utils/set.js +47 -0
  99. package/lib/utils/stringify-loaders-resource.js +25 -0
  100. package/lib/utils/stringify-query.js +4 -0
  101. package/lib/web/processJSON.js +113 -144
  102. package/lib/web/processScript.js +47 -34
  103. package/lib/web/processTemplate.js +57 -40
  104. package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
  105. package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
  106. package/lib/wxs/WxsParserPlugin.js +2 -2
  107. package/lib/wxs/WxsPlugin.js +4 -8
  108. package/lib/wxs/WxsTemplatePlugin.js +46 -92
  109. package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
  110. package/lib/wxs/loader.js +142 -0
  111. package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
  112. package/lib/wxss/loader.js +31 -43
  113. package/lib/wxss/localsLoader.js +1 -5
  114. package/lib/wxss/processCss.js +107 -103
  115. package/package.json +21 -18
  116. package/lib/built-in-loader.js +0 -49
  117. package/lib/content-loader.js +0 -13
  118. package/lib/dependency/ChildCompileDependency.js +0 -24
  119. package/lib/dependency/InjectDependency.js +0 -26
  120. package/lib/dependency/RemovedModuleDependency.js +0 -23
  121. package/lib/dependency/ResolveDependency.js +0 -49
  122. package/lib/path-loader.js +0 -3
  123. package/lib/plugin-loader.js +0 -287
  124. package/lib/staticConfig.js +0 -4
  125. package/lib/utils/get-main-compilation.js +0 -6
  126. package/lib/utils/read-json-for-src.js +0 -34
  127. package/lib/utils/try-require.js +0 -16
  128. package/lib/wxs/wxs-loader.js +0 -117
  129. package/lib/wxss/getImportPrefix.js +0 -30
@@ -1,16 +1,16 @@
1
1
  const JSON5 = require('json5')
2
2
  const he = require('he')
3
3
  const config = require('../config')
4
- const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../staticConfig')
4
+ const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
5
5
  const normalize = require('../utils/normalize')
6
6
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
7
7
  const isEmptyObject = require('../utils/is-empty-object')
8
- const mpxJSON = require('../utils/mpx-json')
9
8
  const getRulesRunner = require('../platform/index')
10
9
  const addQuery = require('../utils/add-query')
11
10
  const transDynamicClassExpr = require('./trans-dynamic-class-expr')
12
11
  const dash2hump = require('../utils/hump-dash').dash2hump
13
12
  const { inBrowser } = require('../utils/env')
13
+ const { matchCondition } = require('../utils/match-condition')
14
14
 
15
15
  /**
16
16
  * Make a map and return a function for checking if a key
@@ -130,107 +130,6 @@ function isForbiddenTag (el) {
130
130
  )
131
131
  }
132
132
 
133
- // mpx special comments
134
- // example
135
- /*
136
- {
137
- 'tt,swan': {
138
- remove: [
139
- 'open-type',
140
- // src mode attr
141
- 'wx:if'
142
- ],
143
- add: {
144
- type: 'primary',
145
- // attr name only
146
- foo: null,
147
- }
148
- }
149
- }
150
- */
151
- let curMpxComment = null
152
-
153
- function evalMpxCommentExp (exp) {
154
- /* eslint-disable no-new-func */
155
- const f = new Function(`return ${exp};`)
156
- return f()
157
- }
158
-
159
- function isMpxCommentAttrs (content) {
160
- return /@mpx-attrs/.test(content)
161
- }
162
-
163
- function normalizePlatformMpxAttrsOpts (opts) {
164
- const ret = {}
165
- // Array to map for removing attributes
166
- ret.remove = (opts.remove || []).reduce((acc, val) => {
167
- acc[val] = true
168
- return acc
169
- }, {})
170
- // Default adding map
171
- ret.add = opts.add || {}
172
- return ret
173
- }
174
-
175
- function produceMpxCommentAttrs (content) {
176
- const exp = /@mpx-attrs[^(]*?\(([\s\S]*)\)/.exec(content)[1].trim()
177
- const tmpOpts = evalMpxCommentExp(exp)
178
- // normalize
179
- Object.keys(tmpOpts).forEach(k => {
180
- Object.assign(tmpOpts[k], normalizePlatformMpxAttrsOpts(tmpOpts[k]))
181
-
182
- if (k.indexOf(',') > -1) {
183
- const modes = k.split(',')
184
- modes.forEach(mode => {
185
- tmpOpts[mode] = tmpOpts[k]
186
- })
187
- delete tmpOpts[k]
188
- }
189
- })
190
- curMpxComment = tmpOpts
191
- }
192
-
193
- function modifyAttrsFromCurMpxAttrOptions (attrs, curModeMpxComment) {
194
- const removeMap = curModeMpxComment.remove
195
- const addMap = curModeMpxComment.add
196
-
197
- const newAttrs = []
198
- attrs.forEach(attr => {
199
- if (!removeMap[attr.name]) {
200
- newAttrs.push(attr)
201
- }
202
- })
203
-
204
- Object.keys(addMap).forEach(name => {
205
- newAttrs.push({
206
- name,
207
- value: addMap[name]
208
- })
209
- })
210
-
211
- return newAttrs
212
- }
213
-
214
- function consumeMpxCommentAttrs (attrs, mode) {
215
- let ret = attrs
216
- if (curMpxComment) {
217
- const curModeMpxComment = curMpxComment[mode]
218
- if (curModeMpxComment) {
219
- ret = modifyAttrsFromCurMpxAttrOptions(attrs, curModeMpxComment)
220
- }
221
-
222
- // reset
223
- curMpxComment = null
224
- }
225
- return ret
226
- }
227
-
228
- function assertMpxCommentAttrsEnd () {
229
- if (curMpxComment) {
230
- error$1('No target for @mpx-attrs!')
231
- }
232
- }
233
-
234
133
  // Browser environment sniffing
235
134
  const UA = inBrowser && window.navigator.userAgent.toLowerCase()
236
135
  const isIE = UA && /msie|trident/.test(UA)
@@ -254,6 +153,9 @@ let forScopesMap = {}
254
153
  let hasI18n = false
255
154
  let i18nInjectableComputed = []
256
155
  let env
156
+ let platformGetTagNamespace
157
+ let filePath
158
+ let refId
257
159
 
258
160
  function updateForScopesMap () {
259
161
  forScopes.forEach((scope) => {
@@ -280,9 +182,6 @@ const deleteErrorInResultMap = (node) => {
280
182
  rulesResultMap.delete(node)
281
183
  Array.isArray(node.children) && node.children.forEach(item => deleteErrorInResultMap(item))
282
184
  }
283
- let platformGetTagNamespace
284
- let basename
285
- let refId
286
185
 
287
186
  function baseWarn (msg) {
288
187
  console.warn(('[template compiler]: ' + msg))
@@ -311,7 +210,7 @@ function decode (value) {
311
210
 
312
211
  const i18nFuncNames = ['\\$(t)', '\\$(tc)', '\\$(te)', '\\$(d)', '\\$(n)']
313
212
  const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
314
- const i18nWxsLoaderPath = normalize.lib('wxs/wxs-i18n-loader.js')
213
+ const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
315
214
  // 添加~前缀避免wxs绝对路径在存在projectRoot时被拼接为错误路径
316
215
  const i18nWxsRequest = '~' + i18nWxsLoaderPath + '!' + i18nWxsPath
317
216
  const i18nModuleName = '__i18n__'
@@ -598,8 +497,8 @@ function parseHTML (html, options) {
598
497
 
599
498
  function parseComponent (content, options) {
600
499
  mode = options.mode || 'wx'
601
- defs = options.defs || {}
602
500
  env = options.env
501
+ filePath = options.filePath
603
502
 
604
503
  let sfc = {
605
504
  template: null,
@@ -649,6 +548,9 @@ function parseComponent (content, options) {
649
548
  if (/^application\/json/.test(currentBlock.type) || currentBlock.name === 'json') {
650
549
  tag = 'json'
651
550
  }
551
+ if (currentBlock.name === 'json') {
552
+ currentBlock.useJSONJS = true
553
+ }
652
554
  }
653
555
  if (currentBlock.mode && currentBlock.env) {
654
556
  if (currentBlock.mode === mode && currentBlock.env === env) {
@@ -692,9 +594,6 @@ function parseComponent (content, options) {
692
594
  if (attr.name === 'scoped') {
693
595
  block.scoped = true
694
596
  }
695
- if (attr.name === 'module') {
696
- block.module = attr.value || true
697
- }
698
597
  if (attr.name === 'src') {
699
598
  block.src = attr.value
700
599
  }
@@ -710,20 +609,15 @@ function parseComponent (content, options) {
710
609
  }
711
610
  }
712
611
 
713
- function end (tag, start, end) {
612
+ function end (tag, start) {
714
613
  if (depth === 1 && currentBlock) {
715
614
  currentBlock.end = start
716
615
  let text = content.slice(currentBlock.start, currentBlock.end)
717
616
  // pad content so that linters and pre-processors can output correct
718
617
  // line numbers in errors and warnings
719
- if (currentBlock.tag !== 'template' && options.pad) {
618
+ if (options.pad) {
720
619
  text = padContent(currentBlock, options.pad) + text
721
620
  }
722
-
723
- // 对于<script name="json">的标签,传参调用函数,其返回结果作为json的内容
724
- if (currentBlock.tag === 'script' && !/^application\/json/.test(currentBlock.type) && currentBlock.name === 'json') {
725
- text = mpxJSON.compileMPXJSONText({ source: text, defs, filePath: options.filePath })
726
- }
727
621
  currentBlock.content = text
728
622
  currentBlock = null
729
623
  }
@@ -774,7 +668,7 @@ function parse (template, options) {
774
668
  defs = options.defs || {}
775
669
  srcMode = options.srcMode || mode
776
670
  isNative = options.isNative
777
- basename = options.basename
671
+ filePath = options.filePath
778
672
  i18n = options.i18n
779
673
  refId = 0
780
674
 
@@ -825,16 +719,6 @@ function parse (template, options) {
825
719
  attrs = guardIESVGBug(attrs)
826
720
  }
827
721
 
828
- if (options.globalMpxAttrsFilter) {
829
- attrs = modifyAttrsFromCurMpxAttrOptions(attrs, normalizePlatformMpxAttrsOpts(options.globalMpxAttrsFilter({
830
- tagName: tag,
831
- attrs,
832
- __mpx_mode__: mode,
833
- filePath: options.filePath
834
- }) || {}))
835
- }
836
- attrs = consumeMpxCommentAttrs(attrs, mode)
837
-
838
722
  let element = createASTElement(tag, attrs, currentParent)
839
723
  if (ns) {
840
724
  element.ns = ns
@@ -849,27 +733,11 @@ function parse (template, options) {
849
733
  )
850
734
  }
851
735
 
852
- // single root
853
- // // gen root
854
- // if (!root) {
855
- // root = element
856
- // } else {
857
- // // mount element
858
- // if (currentParent) {
859
- // currentParent.children.push(element)
860
- // element.parent = currentParent
861
- // } else {
862
- // multiRootError = true
863
- // return
864
- // }
865
- // }
866
-
867
736
  // multi root
868
737
  if (!currentParent) genTempRoot()
869
738
 
870
739
  currentParent.children.push(element)
871
740
  element.parent = currentParent
872
-
873
741
  processElement(element, root, options, meta)
874
742
  tagNames.add(element.tag)
875
743
 
@@ -932,10 +800,7 @@ function parse (template, options) {
932
800
  },
933
801
  comment: function comment (text) {
934
802
  if (!currentParent) genTempRoot()
935
- // special comments should not be output
936
- if (isMpxCommentAttrs(text)) {
937
- produceMpxCommentAttrs(text)
938
- } else if (options.hasComment) {
803
+ if (options.hasComment) {
939
804
  currentParent.children.push({
940
805
  type: 3,
941
806
  text: text,
@@ -946,8 +811,6 @@ function parse (template, options) {
946
811
  }
947
812
  })
948
813
 
949
- assertMpxCommentAttrsEnd()
950
-
951
814
  if (multiRootError) {
952
815
  error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
953
816
  }
@@ -1041,6 +904,19 @@ function modifyAttr (el, name, val) {
1041
904
  }
1042
905
  }
1043
906
 
907
+ function moveBaseDirective (target, from, isDelete = true) {
908
+ target.for = from.for
909
+ target.if = from.if
910
+ target.elseif = from.elseif
911
+ target.else = from.else
912
+ if (isDelete) {
913
+ delete from.for
914
+ delete from.if
915
+ delete from.elseif
916
+ delete from.else
917
+ }
918
+ }
919
+
1044
920
  function stringify (str) {
1045
921
  return JSON.stringify(str)
1046
922
  }
@@ -1137,15 +1013,6 @@ function processComponentIs (el, options) {
1137
1013
  }
1138
1014
  }
1139
1015
 
1140
- // function processComponentDepth (el, options) {
1141
- // if (isComponentNode(el,options)) {
1142
- // addAttrs(el, [{
1143
- // name: 'mpxDepth',
1144
- // value: '{{mpxDepth + 1}}'
1145
- // }])
1146
- // }
1147
- // }
1148
-
1149
1016
  const eventIdentifier = '__mpx_event__'
1150
1017
 
1151
1018
  function parseFuncStr2 (str) {
@@ -1553,9 +1420,13 @@ function postProcessWxs (el, meta) {
1553
1420
  content = el.children.filter((child) => {
1554
1421
  return child.type === 3 && !child.isComment
1555
1422
  }).map(child => child.text).join('\n')
1556
- src = addQuery('./' + basename, {
1423
+
1424
+ const fakeRequest = filePath + config[mode].wxs.ext
1425
+
1426
+ src = addQuery(`~${fakeRequest}!=!${filePath}`, {
1557
1427
  wxsModule: module
1558
1428
  })
1429
+
1559
1430
  addAttrs(el, [{
1560
1431
  name: config[mode].wxs.src,
1561
1432
  value: src
@@ -1636,9 +1507,9 @@ function postProcessFor (el) {
1636
1507
  }
1637
1508
 
1638
1509
  function evalExp (exp) {
1639
- // eslint-disable-next-line no-new-func
1640
1510
  let result = { success: false }
1641
1511
  try {
1512
+ // eslint-disable-next-line no-new-func
1642
1513
  const fn = new Function(`return ${exp};`)
1643
1514
  result = {
1644
1515
  success: true,
@@ -1942,36 +1813,57 @@ function processBuiltInComponents (el, meta) {
1942
1813
  }
1943
1814
  }
1944
1815
 
1816
+ function processAliEventHack (el, options, root) {
1817
+ // 只处理组件根节点
1818
+ if (!(options.isComponent && el === root && isRealNode(el))) {
1819
+ return
1820
+ }
1821
+ const { proxyComponentEventsRules } = options
1822
+ let fallThroughEvents = ['onTap']
1823
+ // 判断当前文件是否在范围中
1824
+ const filePath = options.filePath
1825
+ for (let item of proxyComponentEventsRules) {
1826
+ const {
1827
+ include,
1828
+ exclude
1829
+ } = item || {}
1830
+
1831
+ if (matchCondition(filePath, {
1832
+ include,
1833
+ exclude
1834
+ })) {
1835
+ const eventsRaw = item.events
1836
+ const events = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
1837
+ fallThroughEvents = Array.from(new Set(fallThroughEvents.concat(events)))
1838
+ break
1839
+ }
1840
+ }
1841
+
1842
+ fallThroughEvents.forEach((type) => {
1843
+ addAttrs(el, [{
1844
+ name: type,
1845
+ value: '__proxyEvent'
1846
+ }])
1847
+ })
1848
+ }
1849
+
1945
1850
  function processAliStyleClassHack (el, options, root) {
1946
- let processor
1947
- // 处理组件标签
1948
- if (isComponentNode(el, options)) processor = ({ value, typeName }) => [typeName, value]
1949
1851
  // 处理组件根节点
1950
1852
  if (options.isComponent && el === root && isRealNode(el)) {
1951
- processor = ({ name, value, typeName }) => {
1952
- let sep = name === 'style' ? ';' : ' '
1953
- value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
1954
- return [name, value]
1955
- }
1956
- }
1957
- // 非上述两种不处理
1958
- if (!processor) return
1959
- // 处理style、class
1960
- ['style', 'class'].forEach((type) => {
1961
- let exp = getAndRemoveAttr(el, type).val
1962
- let typeName = 'mpx' + type.replace(/^./, (matched) => matched.toUpperCase())
1963
- let [newName, newValue] = processor({
1964
- name: type,
1965
- value: exp,
1966
- typeName
1853
+ ['style', 'class'].forEach((type) => {
1854
+ let exp = getAndRemoveAttr(el, type).val
1855
+ let typeName = type === 'class' ? 'className' : type
1856
+ let sep = type === 'style' ? ';' : ' '
1857
+ let newValue = exp ? `{{${typeName}||''}}${sep}${exp}` : `{{${typeName}||''}}`
1858
+
1859
+ if (newValue !== undefined) {
1860
+ addAttrs(el, [{
1861
+ name: type,
1862
+ value: newValue
1863
+ }])
1864
+ }
1967
1865
  })
1968
- if (newValue !== undefined) {
1969
- addAttrs(el, [{
1970
- name: newName,
1971
- value: newValue
1972
- }])
1973
- }
1974
- })
1866
+ }
1975
1867
  }
1976
1868
 
1977
1869
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -2180,10 +2072,22 @@ function processElement (el, root, options, meta) {
2180
2072
  processComponentGenericsForWeb(el, options, meta)
2181
2073
  return
2182
2074
  }
2075
+ if (mode === 'tenon') {
2076
+ // 收集内建组件
2077
+ processBuiltInComponents(el, meta)
2078
+ // 预处理代码维度条件编译
2079
+ processIfForWeb(el)
2080
+ // processWebExternalClassesHack(el, options)
2081
+ // processComponentGenericsForWeb(el, options, meta)
2082
+ return
2083
+ }
2183
2084
 
2184
2085
  const pass = isNative || processTemplate(el) || processingTemplate
2185
2086
 
2186
- processScoped(el, options)
2087
+ // 仅ali平台需要scoped模拟样式隔离
2088
+ if (mode === 'ali') {
2089
+ processScoped(el, options)
2090
+ }
2187
2091
 
2188
2092
  if (transAli) {
2189
2093
  processAliExternalClassesHack(el, options)
@@ -2199,9 +2103,9 @@ function processElement (el, root, options, meta) {
2199
2103
  processShow(el, options, root)
2200
2104
  }
2201
2105
 
2202
- // 当mode为ali不管是不是跨平台都需要进行此处理,以保障ali当中的refs相关增强能力正常运行
2203
- if (mode === 'ali') {
2106
+ if (transAli) {
2204
2107
  processAliStyleClassHack(el, options, root)
2108
+ processAliEventHack(el, options, root)
2205
2109
  }
2206
2110
 
2207
2111
  if (!pass) {
@@ -2214,7 +2118,7 @@ function processElement (el, root, options, meta) {
2214
2118
 
2215
2119
  function closeElement (el, meta) {
2216
2120
  postProcessAtMode(el)
2217
- if (mode === 'web') {
2121
+ if (mode === 'web' || mode === 'tenon') {
2218
2122
  postProcessWxs(el, meta)
2219
2123
  // 处理代码维度条件编译移除死分支
2220
2124
  postProcessIf(el)
@@ -2262,14 +2166,16 @@ function postProcessComponentIs (el) {
2262
2166
  let tempNode
2263
2167
  if (el.for || el.if || el.elseif || el.else) {
2264
2168
  tempNode = createASTElement('block', [])
2265
- tempNode.for = el.for
2266
- tempNode.if = el.if
2267
- tempNode.elseif = el.elseif
2268
- tempNode.else = el.else
2169
+ moveBaseDirective(tempNode, el)
2269
2170
  } else {
2270
2171
  tempNode = getTempNode()
2271
2172
  }
2173
+ let range = []
2174
+ if (el.attrsMap.range) {
2175
+ range = getAndRemoveAttr(el, 'range').val.split(',')
2176
+ }
2272
2177
  el.components.forEach(function (component) {
2178
+ if (range.length > 0 && !range.includes(component)) return
2273
2179
  let newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
2274
2180
  newChild.if = {
2275
2181
  raw: `{{${el.is} === ${stringify(component)}}}`,
@@ -2286,7 +2192,7 @@ function postProcessComponentIs (el) {
2286
2192
  if (!el.parent) {
2287
2193
  error$1('Dynamic component can not be the template root, considering wrapping it with <view> or <text> tag!')
2288
2194
  } else {
2289
- el = replaceNode(el, tempNode) || el
2195
+ el = replaceNode(el, tempNode, true) || el
2290
2196
  }
2291
2197
  }
2292
2198
  return el
@@ -2321,7 +2227,7 @@ function serialize (root) {
2321
2227
  result += node.text
2322
2228
  }
2323
2229
  }
2324
- if (node.tag === 'wxs' && mode === 'web') {
2230
+ if (node.tag === 'wxs' && (mode === 'web' || mode === 'tenon')) {
2325
2231
  return result
2326
2232
  }
2327
2233
  if (node.type === 1) {
@@ -2486,5 +2392,6 @@ module.exports = {
2486
2392
  makeAttrsMap,
2487
2393
  stringifyAttr,
2488
2394
  parseMustache,
2489
- stringifyWithResolveComputed
2395
+ stringifyWithResolveComputed,
2396
+ addAttrs
2490
2397
  }