@mpxjs/webpack-plugin 2.10.16 → 2.10.17
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/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/helpers.js +2 -0
- package/lib/index.js +40 -15
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +14 -54
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +10 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +24 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/button.js +12 -3
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/react/index.js +2 -0
- package/lib/react/processJSON.js +39 -71
- package/lib/react/processStyles.js +3 -2
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -16
- package/lib/react/style-helper.js +10 -2
- package/lib/runtime/components/react/context.ts +12 -6
- package/lib/runtime/components/react/dist/context.d.ts +75 -0
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
- package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +107 -57
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +58 -50
- package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +10 -2
- package/lib/runtime/components/react/dist/parser.d.ts +40 -0
- package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts +123 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.jsx +16 -6
- package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +130 -77
- package/lib/runtime/components/react/mpx-input.tsx +38 -15
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -49
- package/lib/runtime/components/react/mpx-nav.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
- package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +3 -2
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +10 -2
- package/lib/style-compiler/strip-conditional-loader.js +177 -15
- package/lib/template-compiler/compiler.js +268 -70
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +5 -5
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +44 -16
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +6 -4
- package/lib/web/script-helper.js +19 -9
- package/lib/wxs/pre-loader.js +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +15 -5
- package/lib/utils/chain-assign.js +0 -47
|
@@ -1,7 +1,7 @@
|
|
|
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, PARENT_MODULE_ID } = require('../utils/const')
|
|
4
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID, MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
6
|
const { normalizeCondition } = require('../utils/match-condition')
|
|
7
7
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
@@ -15,7 +15,8 @@ const { isNonPhrasingTag } = require('../utils/dom-tag-config')
|
|
|
15
15
|
const setBaseWxml = require('../runtime-render/base-wxml')
|
|
16
16
|
const { parseExp } = require('./parse-exps')
|
|
17
17
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
18
|
-
const { isReact, isWeb } = require('../utils/env')
|
|
18
|
+
const { isReact, isWeb, isNoMode } = require('../utils/env')
|
|
19
|
+
const { capitalToHyphen } = require('../utils/string')
|
|
19
20
|
|
|
20
21
|
const no = function () {
|
|
21
22
|
return false
|
|
@@ -119,6 +120,8 @@ const rulesResultMap = new Map()
|
|
|
119
120
|
let usingComponents = []
|
|
120
121
|
let usingComponentsInfo = {}
|
|
121
122
|
let componentGenerics = {}
|
|
123
|
+
// 跨平台语法检测的配置,在模块加载时初始化一次
|
|
124
|
+
let crossPlatformConfig = null
|
|
122
125
|
|
|
123
126
|
function updateForScopesMap () {
|
|
124
127
|
forScopesMap = {}
|
|
@@ -147,11 +150,11 @@ const deleteErrorInResultMap = (node) => {
|
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
function baseWarn (msg) {
|
|
150
|
-
console.warn(('[template
|
|
153
|
+
console.warn(('[Mpx template warning]: ' + msg))
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
function baseError (msg) {
|
|
154
|
-
console.error(('[template
|
|
157
|
+
console.error(('[Mpx template error]: ' + msg))
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
const decodeMap = {
|
|
@@ -637,8 +640,9 @@ function parse (template, options) {
|
|
|
637
640
|
processingTemplate = false
|
|
638
641
|
rulesResultMap.clear()
|
|
639
642
|
componentGenerics = options.componentGenerics || {}
|
|
643
|
+
// 初始化跨平台语法检测配置(每次解析时只初始化一次)
|
|
644
|
+
crossPlatformConfig = initCrossPlatformConfig()
|
|
640
645
|
|
|
641
|
-
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
642
646
|
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
643
647
|
usingComponentsInfo = options.usingComponentsInfo
|
|
644
648
|
|
|
@@ -681,7 +685,6 @@ function parse (template, options) {
|
|
|
681
685
|
meta.options.virtualHost = true
|
|
682
686
|
}
|
|
683
687
|
let currentParent
|
|
684
|
-
let multiRootError
|
|
685
688
|
// 用于记录模板用到的组件,匹配引用组件,看是否有冗余
|
|
686
689
|
const tagNames = new Set()
|
|
687
690
|
|
|
@@ -760,7 +763,10 @@ function parse (template, options) {
|
|
|
760
763
|
if (!currentParent) genTempRoot()
|
|
761
764
|
|
|
762
765
|
const children = currentParent.children
|
|
763
|
-
|
|
766
|
+
|
|
767
|
+
const isTextLikeParent = currentParent.tag === 'text' || currentParent.tag === 'mpx-text' || currentParent.tag === 'Text' || currentParent.tag === 'mpx-simple-text'
|
|
768
|
+
|
|
769
|
+
if (!isTextLikeParent) {
|
|
764
770
|
text = text.trim()
|
|
765
771
|
} else {
|
|
766
772
|
text = text.trim() ? text : ''
|
|
@@ -793,9 +799,10 @@ function parse (template, options) {
|
|
|
793
799
|
}
|
|
794
800
|
})
|
|
795
801
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
802
|
+
// multiRoot
|
|
803
|
+
// if (root.tag === 'temp-node' && root.children && root.children.filter(node => node.tag !== 'temp-node').length > 1) {
|
|
804
|
+
// error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
|
|
805
|
+
// }
|
|
799
806
|
|
|
800
807
|
if (hasI18n) {
|
|
801
808
|
if (i18nInjectableComputed.length) {
|
|
@@ -1000,12 +1007,34 @@ function processComponentIs (el, options) {
|
|
|
1000
1007
|
}
|
|
1001
1008
|
|
|
1002
1009
|
const range = getAndRemoveAttr(el, 'range').val
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1010
|
+
|
|
1011
|
+
// Map<CurrentName, SourceName>
|
|
1012
|
+
let ranges
|
|
1013
|
+
if (range) {
|
|
1014
|
+
ranges = range.split(',').map(i => i.trim()).filter(i => i)
|
|
1015
|
+
} else {
|
|
1016
|
+
// 根据原始用户写的usingComponents字段生成ranges
|
|
1017
|
+
ranges = options.originalUsingComponents || []
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
const rangeMap = new Map()
|
|
1021
|
+
ranges.forEach(name => {
|
|
1022
|
+
rangeMap.set(['ali', 'swan'].includes(mode) ? capitalToHyphen(name) : name, name)
|
|
1007
1023
|
})
|
|
1008
|
-
|
|
1024
|
+
|
|
1025
|
+
// Map<CurrentName, SourceName>
|
|
1026
|
+
el.componentMap = new Map()
|
|
1027
|
+
usingComponents.forEach((name) => {
|
|
1028
|
+
if (rangeMap.size === 0) {
|
|
1029
|
+
el.componentMap.set(name, name)
|
|
1030
|
+
} else {
|
|
1031
|
+
if (rangeMap.has(name)) {
|
|
1032
|
+
el.componentMap.set(name, rangeMap.get(name))
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
})
|
|
1036
|
+
|
|
1037
|
+
if (el.componentMap.size === 0) {
|
|
1009
1038
|
warn$1('Component in which <component> tag is used must have a non blank usingComponents field')
|
|
1010
1039
|
}
|
|
1011
1040
|
|
|
@@ -1592,7 +1621,7 @@ function parseOptionalChaining (str) {
|
|
|
1592
1621
|
}
|
|
1593
1622
|
if (grammarMap.checkState() && haveNotGetValue) {
|
|
1594
1623
|
// 值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
|
|
1595
|
-
throw new Error('[
|
|
1624
|
+
throw new Error('[Mpx template error]: optionChain option value illegal!!!')
|
|
1596
1625
|
}
|
|
1597
1626
|
haveNotGetValue = true
|
|
1598
1627
|
let keyValue = ''
|
|
@@ -1642,7 +1671,7 @@ function parseOptionalChaining (str) {
|
|
|
1642
1671
|
}
|
|
1643
1672
|
if (grammarMap.checkState() && haveNotGetValue) {
|
|
1644
1673
|
// key值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
|
|
1645
|
-
throw new Error('[
|
|
1674
|
+
throw new Error('[Mpx template error]: optionChain option key illegal!!!')
|
|
1646
1675
|
}
|
|
1647
1676
|
if (keyValue) {
|
|
1648
1677
|
chainKey += `,'${keyValue}'`
|
|
@@ -1855,24 +1884,25 @@ function processRefReact (el, meta) {
|
|
|
1855
1884
|
/**
|
|
1856
1885
|
* selectorsConf: [type, [[prefix, selector], [prefix, selector]]]
|
|
1857
1886
|
*/
|
|
1858
|
-
if (
|
|
1859
|
-
const rawId = el.attrsMap.id
|
|
1860
|
-
const rawClass = el.attrsMap.class
|
|
1861
|
-
const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
|
|
1862
|
-
|
|
1863
|
-
if (rawId) {
|
|
1864
|
-
const staticId = parseMustacheWithContext(rawId).result
|
|
1865
|
-
selectors.push({ prefix: '#', selector: `${staticId}` })
|
|
1866
|
-
}
|
|
1867
|
-
if (rawClass || rawDynamicClass) {
|
|
1868
|
-
const staticClass = parseMustacheWithContext(rawClass).result
|
|
1869
|
-
const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
|
|
1870
|
-
selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
|
|
1871
|
-
}
|
|
1872
|
-
} else {
|
|
1887
|
+
if (val) {
|
|
1873
1888
|
meta.refs.push(refConf)
|
|
1874
1889
|
selectors.push({ prefix: '', selector: `"${refConf.key}"` })
|
|
1875
1890
|
}
|
|
1891
|
+
|
|
1892
|
+
const rawId = el.attrsMap.id
|
|
1893
|
+
const rawClass = el.attrsMap.class
|
|
1894
|
+
const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
|
|
1895
|
+
|
|
1896
|
+
if (rawId) {
|
|
1897
|
+
const staticId = parseMustacheWithContext(rawId).result
|
|
1898
|
+
selectors.push({ prefix: '#', selector: `${staticId}` })
|
|
1899
|
+
}
|
|
1900
|
+
if (rawClass || rawDynamicClass) {
|
|
1901
|
+
const staticClass = parseMustacheWithContext(rawClass).result
|
|
1902
|
+
const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
|
|
1903
|
+
selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1876
1906
|
const selectorsConf = selectors.map(item => `["${item.prefix}", ${item.selector}]`)
|
|
1877
1907
|
const refFnId = forScopes.reduce((preV, curV) => {
|
|
1878
1908
|
return `${preV} + "_" + ${curV.index}`
|
|
@@ -2084,13 +2114,24 @@ function postProcessIf (el) {
|
|
|
2084
2114
|
replaceNode(el, getTempNode())._if = false
|
|
2085
2115
|
}
|
|
2086
2116
|
} else {
|
|
2117
|
+
el._if = null
|
|
2087
2118
|
attrs = [{
|
|
2088
2119
|
name: config[mode].directive.if,
|
|
2089
2120
|
value: el.if.raw
|
|
2090
2121
|
}]
|
|
2091
2122
|
}
|
|
2092
2123
|
} else if (el.elseif) {
|
|
2124
|
+
if (el.for) {
|
|
2125
|
+
error$1(`wx:elif (wx:elif="${el.elseif.raw}") invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the elif-directive to it`)
|
|
2126
|
+
return
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2093
2129
|
prevNode = findPrevNode(el)
|
|
2130
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2131
|
+
error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2132
|
+
return
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2094
2135
|
if (prevNode._if === true) {
|
|
2095
2136
|
removeNode(el)
|
|
2096
2137
|
} else if (prevNode._if === false) {
|
|
@@ -2110,6 +2151,7 @@ function postProcessIf (el) {
|
|
|
2110
2151
|
removeNode(el)
|
|
2111
2152
|
}
|
|
2112
2153
|
} else {
|
|
2154
|
+
el._if = null
|
|
2113
2155
|
attrs = [{
|
|
2114
2156
|
name: config[mode].directive.elseif,
|
|
2115
2157
|
value: el.elseif.raw
|
|
@@ -2117,7 +2159,17 @@ function postProcessIf (el) {
|
|
|
2117
2159
|
}
|
|
2118
2160
|
}
|
|
2119
2161
|
} else if (el.else) {
|
|
2162
|
+
if (el.for) {
|
|
2163
|
+
error$1(`wx:else invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the else-directive to it`)
|
|
2164
|
+
return
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2120
2167
|
prevNode = findPrevNode(el)
|
|
2168
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2169
|
+
error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2170
|
+
return
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2121
2173
|
if (prevNode._if === true) {
|
|
2122
2174
|
removeNode(el)
|
|
2123
2175
|
} else if (prevNode._if === false) {
|
|
@@ -2141,23 +2193,100 @@ function addIfCondition (el, condition) {
|
|
|
2141
2193
|
el.ifConditions.push(condition)
|
|
2142
2194
|
}
|
|
2143
2195
|
|
|
2196
|
+
function getIfConditions (el) {
|
|
2197
|
+
return el?.ifConditions || []
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2144
2200
|
function postProcessIfReact (el) {
|
|
2145
|
-
let prevNode
|
|
2201
|
+
let prevNode, ifNode, result, ifConditions
|
|
2146
2202
|
if (el.if) {
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2203
|
+
// 取值
|
|
2204
|
+
// false -> 节点变为temp-node,并添加_if=false
|
|
2205
|
+
// true -> 添加_if=true,移除if
|
|
2206
|
+
// dynamic -> addIfCondition
|
|
2207
|
+
result = evalExp(el.if.exp)
|
|
2208
|
+
if (result.success) {
|
|
2209
|
+
if (result.result) {
|
|
2210
|
+
el._if = true
|
|
2211
|
+
delete el.if
|
|
2212
|
+
} else {
|
|
2213
|
+
replaceNode(el, getTempNode())._if = false
|
|
2214
|
+
}
|
|
2215
|
+
} else {
|
|
2216
|
+
el._if = null
|
|
2217
|
+
addIfCondition(el, {
|
|
2218
|
+
exp: el.if.exp,
|
|
2156
2219
|
block: el
|
|
2157
2220
|
})
|
|
2158
|
-
|
|
2221
|
+
}
|
|
2222
|
+
} else if (el.elseif) {
|
|
2223
|
+
if (el.for) {
|
|
2224
|
+
error$1(`wx:elif (wx:elif="${el.elseif.raw}") invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the elif-directive to it`)
|
|
2225
|
+
return
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
ifNode = findPrevNode(el)
|
|
2229
|
+
ifConditions = getIfConditions(ifNode)
|
|
2230
|
+
prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
|
|
2231
|
+
|
|
2232
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2233
|
+
error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2234
|
+
return
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
if (prevNode._if === true) {
|
|
2238
|
+
removeNode(el)
|
|
2239
|
+
} else if (prevNode._if === false) {
|
|
2240
|
+
el.if = el.elseif
|
|
2241
|
+
delete el.elseif
|
|
2242
|
+
postProcessIfReact(el)
|
|
2159
2243
|
} else {
|
|
2160
|
-
|
|
2244
|
+
result = evalExp(el.elseif.exp)
|
|
2245
|
+
if (result.success) {
|
|
2246
|
+
if (result.result) {
|
|
2247
|
+
delete el.elseif
|
|
2248
|
+
el._if = true
|
|
2249
|
+
addIfCondition(ifNode, {
|
|
2250
|
+
exp: el.elseif.exp,
|
|
2251
|
+
block: el
|
|
2252
|
+
})
|
|
2253
|
+
removeNode(el, true)
|
|
2254
|
+
} else {
|
|
2255
|
+
removeNode(el)
|
|
2256
|
+
}
|
|
2257
|
+
} else {
|
|
2258
|
+
el._if = null
|
|
2259
|
+
addIfCondition(ifNode, {
|
|
2260
|
+
exp: el.elseif.exp,
|
|
2261
|
+
block: el
|
|
2262
|
+
})
|
|
2263
|
+
removeNode(el, true)
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
} else if (el.else) {
|
|
2267
|
+
if (el.for) {
|
|
2268
|
+
error$1(`wx:else invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the else-directive to it`)
|
|
2269
|
+
return
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
ifNode = findPrevNode(el)
|
|
2273
|
+
ifConditions = getIfConditions(ifNode)
|
|
2274
|
+
prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
|
|
2275
|
+
|
|
2276
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2277
|
+
error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2278
|
+
return
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
if (prevNode._if === true) {
|
|
2282
|
+
removeNode(el)
|
|
2283
|
+
} else if (prevNode._if === false) {
|
|
2284
|
+
delete el.else
|
|
2285
|
+
} else {
|
|
2286
|
+
addIfCondition(ifNode, {
|
|
2287
|
+
block: el
|
|
2288
|
+
})
|
|
2289
|
+
removeNode(el, true)
|
|
2161
2290
|
}
|
|
2162
2291
|
}
|
|
2163
2292
|
}
|
|
@@ -2524,6 +2653,16 @@ function getVirtualHostRoot (options, meta) {
|
|
|
2524
2653
|
if (isWeb(mode) && ctorType === 'page') {
|
|
2525
2654
|
return createASTElement('page')
|
|
2526
2655
|
}
|
|
2656
|
+
if (isReact(mode) && ctorType === 'page') {
|
|
2657
|
+
const rootView = createASTElement('view', [
|
|
2658
|
+
{
|
|
2659
|
+
name: 'class',
|
|
2660
|
+
value: MPX_TAG_PAGE_SELECTOR
|
|
2661
|
+
}
|
|
2662
|
+
])
|
|
2663
|
+
processElement(rootView, rootView, options, meta)
|
|
2664
|
+
return rootView
|
|
2665
|
+
}
|
|
2527
2666
|
}
|
|
2528
2667
|
return getTempNode()
|
|
2529
2668
|
}
|
|
@@ -2717,6 +2856,78 @@ function processNoTransAttrs (el) {
|
|
|
2717
2856
|
}
|
|
2718
2857
|
}
|
|
2719
2858
|
|
|
2859
|
+
function initCrossPlatformConfig () {
|
|
2860
|
+
// 定义平台与前缀的双向映射关系
|
|
2861
|
+
const platformPrefixMap = {
|
|
2862
|
+
wx: 'wx:',
|
|
2863
|
+
ali: 'a:',
|
|
2864
|
+
swan: 's-',
|
|
2865
|
+
qq: 'qq:',
|
|
2866
|
+
tt: 'tt:',
|
|
2867
|
+
dd: 'dd:',
|
|
2868
|
+
jd: 'jd:',
|
|
2869
|
+
qa: 'qa:',
|
|
2870
|
+
web: 'v-'
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
if (isNoMode(mode)) {
|
|
2874
|
+
return null
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
return {
|
|
2878
|
+
currentPrefix: platformPrefixMap[mode] || 'wx:',
|
|
2879
|
+
platformPrefixMap
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
// 检测跨平台语法使用情况并给出警告
|
|
2884
|
+
function processCrossPlatformSyntaxWarning (el) {
|
|
2885
|
+
// 使用转换后的属性列表进行检查
|
|
2886
|
+
if (!el.attrsList || el.attrsList.length === 0) {
|
|
2887
|
+
return
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
// 如果配置为空,说明不需要检测
|
|
2891
|
+
if (!crossPlatformConfig) {
|
|
2892
|
+
return
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
const { currentPrefix, platformPrefixMap } = crossPlatformConfig
|
|
2896
|
+
|
|
2897
|
+
// 检查转换后的属性列表
|
|
2898
|
+
el.attrsList.forEach(attr => {
|
|
2899
|
+
const attrName = attr.name
|
|
2900
|
+
|
|
2901
|
+
// 检查是否使用了平台前缀
|
|
2902
|
+
for (const [platformName, prefix] of Object.entries(platformPrefixMap)) {
|
|
2903
|
+
if (attrName.startsWith(prefix)) {
|
|
2904
|
+
if (isReact(mode)) {
|
|
2905
|
+
// React Native 平台:只允许使用 wx: 前缀,其他前缀报错
|
|
2906
|
+
if (prefix !== 'wx:') {
|
|
2907
|
+
error$1(
|
|
2908
|
+
`React Native mode "${mode}" does not support "${prefix}" prefix. ` +
|
|
2909
|
+
`Use "wx:" prefix instead. Found: "${attrName}"`
|
|
2910
|
+
)
|
|
2911
|
+
}
|
|
2912
|
+
} else {
|
|
2913
|
+
// 小程序平台:检测跨平台语法使用
|
|
2914
|
+
if (platformName !== mode) {
|
|
2915
|
+
// 构建建议的正确属性名
|
|
2916
|
+
const suffixPart = attrName.substring(prefix.length)
|
|
2917
|
+
const suggestedAttr = currentPrefix + suffixPart
|
|
2918
|
+
|
|
2919
|
+
warn$1(
|
|
2920
|
+
`Your target mode is "${mode}", but used "${attrName}". ` +
|
|
2921
|
+
`Did you mean "${suggestedAttr}"?`
|
|
2922
|
+
)
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
break
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
})
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2720
2931
|
function processMpxTagName (el) {
|
|
2721
2932
|
const mpxTagName = getAndRemoveAttr(el, 'mpxTagName').val
|
|
2722
2933
|
if (mpxTagName) {
|
|
@@ -2746,6 +2957,9 @@ function processElement (el, root, options, meta) {
|
|
|
2746
2957
|
|
|
2747
2958
|
processDuplicateAttrsList(el)
|
|
2748
2959
|
|
|
2960
|
+
// 检测跨平台语法使用情况并给出警告
|
|
2961
|
+
processCrossPlatformSyntaxWarning(el)
|
|
2962
|
+
|
|
2749
2963
|
processInjectWxs(el, meta, options)
|
|
2750
2964
|
|
|
2751
2965
|
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
@@ -2890,7 +3104,7 @@ function cloneAttrsList (attrsList) {
|
|
|
2890
3104
|
}
|
|
2891
3105
|
|
|
2892
3106
|
function postProcessComponentIs (el, postProcessChild) {
|
|
2893
|
-
if (el.is && el.
|
|
3107
|
+
if (el.is && el.componentMap && el.componentMap.size > 0) {
|
|
2894
3108
|
let tempNode
|
|
2895
3109
|
if (el.for || el.if || el.elseif || el.else) {
|
|
2896
3110
|
tempNode = createASTElement('block')
|
|
@@ -2900,11 +3114,12 @@ function postProcessComponentIs (el, postProcessChild) {
|
|
|
2900
3114
|
replaceNode(el, tempNode, true)
|
|
2901
3115
|
postMoveBaseDirective(tempNode, el)
|
|
2902
3116
|
|
|
2903
|
-
|
|
2904
|
-
|
|
3117
|
+
// Map<CurrentName, SourceName>
|
|
3118
|
+
el.componentMap.forEach((source, name) => {
|
|
3119
|
+
const newChild = createASTElement(name, cloneAttrsList(el.attrsList), tempNode)
|
|
2905
3120
|
newChild.if = {
|
|
2906
|
-
raw: `{{${el.is} === ${stringify(
|
|
2907
|
-
exp: `${el.is} === ${stringify(
|
|
3121
|
+
raw: `{{${el.is} === ${stringify(source)}}}`,
|
|
3122
|
+
exp: `${el.is} === ${stringify(source)}`
|
|
2908
3123
|
}
|
|
2909
3124
|
el.children.forEach((child) => {
|
|
2910
3125
|
addChild(newChild, cloneNode(child))
|
|
@@ -3029,30 +3244,12 @@ function genIf (node) {
|
|
|
3029
3244
|
|
|
3030
3245
|
function genElseif (node) {
|
|
3031
3246
|
node.elseifProcessed = true
|
|
3032
|
-
if
|
|
3033
|
-
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`)
|
|
3034
|
-
return
|
|
3035
|
-
}
|
|
3036
|
-
const preNode = findPrevNode(node)
|
|
3037
|
-
if (preNode && (preNode.if || preNode.elseif)) {
|
|
3038
|
-
return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
|
|
3039
|
-
} else {
|
|
3040
|
-
error$1(`wx:elif (wx:elif="${node.elseif.raw}") invalidly used on the element <"${node.tag}"> without corresponding wx:if or wx:elif.`)
|
|
3041
|
-
}
|
|
3247
|
+
return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
|
|
3042
3248
|
}
|
|
3043
3249
|
|
|
3044
3250
|
function genElse (node) {
|
|
3045
3251
|
node.elseProcessed = true
|
|
3046
|
-
|
|
3047
|
-
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`)
|
|
3048
|
-
return
|
|
3049
|
-
}
|
|
3050
|
-
const preNode = findPrevNode(node)
|
|
3051
|
-
if (preNode && (preNode.if || preNode.elseif)) {
|
|
3052
|
-
return `else{\n${genNode(node)}}\n`
|
|
3053
|
-
} else {
|
|
3054
|
-
error$1(`wx:else invalidly used on the element <"${node.tag}"> without corresponding wx:if or wx:elif.`)
|
|
3055
|
-
}
|
|
3252
|
+
return `else{\n${genNode(node)}}\n`
|
|
3056
3253
|
}
|
|
3057
3254
|
|
|
3058
3255
|
function genExps (node) {
|
|
@@ -3263,5 +3460,6 @@ module.exports = {
|
|
|
3263
3460
|
findPrevNode,
|
|
3264
3461
|
removeNode,
|
|
3265
3462
|
replaceNode,
|
|
3266
|
-
createASTElement
|
|
3463
|
+
createASTElement,
|
|
3464
|
+
evalExp
|
|
3267
3465
|
}
|
|
@@ -9,7 +9,8 @@ function genIfConditions (conditions) {
|
|
|
9
9
|
if (!conditions.length) return 'null'
|
|
10
10
|
const condition = conditions.shift()
|
|
11
11
|
if (condition.exp) {
|
|
12
|
-
|
|
12
|
+
// 此处 condition.exp 无需括号包裹,condition.exp本身已经包含括号
|
|
13
|
+
return `${condition.exp}?${genNode(condition.block)}:${genIfConditions(conditions)}`
|
|
13
14
|
} else {
|
|
14
15
|
return genNode(condition.block)
|
|
15
16
|
}
|
|
@@ -30,7 +31,7 @@ function mapAttrName (name) {
|
|
|
30
31
|
return name
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function genNode (node) {
|
|
34
|
+
function genNode (node, isRoot = false) {
|
|
34
35
|
let exp = ''
|
|
35
36
|
if (node) {
|
|
36
37
|
if (node.type === 3) {
|
|
@@ -72,18 +73,29 @@ function genNode (node) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
if (!node.unary && node.children.length) {
|
|
75
|
-
|
|
76
|
-
exp += node.children.map((child) => {
|
|
76
|
+
const childNode = node.children.map((child) => {
|
|
77
77
|
return genNode(child)
|
|
78
78
|
}).filter(fragment => fragment).join(',')
|
|
79
|
+
|
|
80
|
+
// child可能为temp-node等无效节点,所以增加判断确保存在childNode再添加逗号
|
|
81
|
+
if (childNode) {
|
|
82
|
+
exp += ','
|
|
83
|
+
exp += childNode
|
|
84
|
+
}
|
|
79
85
|
}
|
|
80
86
|
exp += ')'
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
} else {
|
|
84
|
-
|
|
90
|
+
const nodes = node.children.map((child) => {
|
|
85
91
|
return genNode(child)
|
|
86
|
-
}).filter(fragment => fragment
|
|
92
|
+
}).filter(fragment => fragment && fragment !== 'null')
|
|
93
|
+
if (isRoot && nodes.length > 1) {
|
|
94
|
+
// 如果存在多个根节点,使用 block 包裹
|
|
95
|
+
exp = `createElement(getComponent("block"), null, ${nodes.join(',')})`
|
|
96
|
+
} else {
|
|
97
|
+
exp += nodes.join(',')
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
}
|
|
@@ -24,14 +24,15 @@ module.exports = function (raw) {
|
|
|
24
24
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
25
25
|
const wxsContentMap = mpx.wxsContentMap
|
|
26
26
|
const optimizeRenderRules = mpx.optimizeRenderRules
|
|
27
|
-
const usingComponentsInfo = queryObj.usingComponentsInfo
|
|
27
|
+
const usingComponentsInfo = queryObj.usingComponentsInfo ? JSON.parse(queryObj.usingComponentsInfo) : {}
|
|
28
|
+
const originalUsingComponents = queryObj.originalUsingComponents ? JSON.parse(queryObj.originalUsingComponents) : []
|
|
28
29
|
const componentPlaceholder = queryObj.componentPlaceholder || []
|
|
29
30
|
const hasComment = queryObj.hasComment
|
|
30
31
|
const isNative = queryObj.isNative
|
|
31
32
|
const ctorType = queryObj.ctorType
|
|
32
33
|
const hasScoped = queryObj.hasScoped
|
|
33
34
|
const runtimeCompile = queryObj.isDynamic
|
|
34
|
-
const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath)
|
|
35
|
+
const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath, false, queryObj.moduleId ? null : this)
|
|
35
36
|
|
|
36
37
|
let optimizeRenderLevel = 0
|
|
37
38
|
for (const rule of optimizeRenderRules) {
|
|
@@ -43,13 +44,13 @@ module.exports = function (raw) {
|
|
|
43
44
|
|
|
44
45
|
const warn = (msg) => {
|
|
45
46
|
this.emitWarning(
|
|
46
|
-
new Error('[template
|
|
47
|
+
new Error('[Mpx template warning][' + this.resource + ']: ' + msg)
|
|
47
48
|
)
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const error = (msg) => {
|
|
51
52
|
this.emitError(
|
|
52
|
-
new Error('[template
|
|
53
|
+
new Error('[Mpx template error][' + this.resource + ']: ' + msg)
|
|
53
54
|
)
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -70,6 +71,7 @@ module.exports = function (raw) {
|
|
|
70
71
|
hasScoped,
|
|
71
72
|
moduleId,
|
|
72
73
|
usingComponentsInfo,
|
|
74
|
+
originalUsingComponents,
|
|
73
75
|
// 这里需传递rawResourcePath和wxsContentMap保持一致
|
|
74
76
|
filePath: rawResourcePath,
|
|
75
77
|
i18n,
|
package/lib/utils/const.js
CHANGED
|
@@ -74,10 +74,10 @@ const isNativeMiniTag = makeMap(
|
|
|
74
74
|
*/
|
|
75
75
|
const isBuildInWebTag = makeMap(
|
|
76
76
|
'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
|
|
77
|
-
'mpx-swiper-item,mpx-video,mpx-button,mpx-
|
|
77
|
+
'mpx-swiper-item,mpx-video,mpx-button,mpx-progress,' +
|
|
78
78
|
'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
|
|
79
79
|
'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
|
|
80
|
-
'mpx-
|
|
80
|
+
'mpx-form,mpx-navigator,mpx-rich-text,' +
|
|
81
81
|
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
|
|
82
82
|
)
|
|
83
83
|
|
|
@@ -86,11 +86,11 @@ const isBuildInWebTag = makeMap(
|
|
|
86
86
|
*/
|
|
87
87
|
const isBuildInReactTag = makeMap(
|
|
88
88
|
'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
|
|
89
|
-
'mpx-swiper,mpx-swiper-item,mpx-
|
|
89
|
+
'mpx-swiper,mpx-swiper-item,mpx-scroll-view,' +
|
|
90
90
|
'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
|
|
91
|
-
'mpx-movable-area,mpx-label,mpx-
|
|
91
|
+
'mpx-movable-area,mpx-label,mpx-input,' +
|
|
92
92
|
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
|
-
'mpx-rich-text,mpx-
|
|
93
|
+
'mpx-rich-text,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
94
|
'mpx-icon,mpx-canvas'
|
|
95
95
|
)
|
|
96
96
|
|
package/lib/utils/env.js
CHANGED