@mpxjs/webpack-plugin 2.10.15-prelease.1 → 2.10.16-beta.10
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/config.js +60 -0
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +13 -3
- 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 +16 -56
- 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 +30 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +21 -5
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +10 -0
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +19 -2
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- 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 +13 -6
- package/lib/runtime/components/react/dist/context.d.ts +76 -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-camera.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +197 -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/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 +81 -37
- 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 +51 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +37 -11
- 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 +61 -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-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-swiper.jsx +9 -5
- 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 +1 -1
- 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-camera.tsx +275 -0
- package/lib/runtime/components/react/mpx-image.tsx +89 -42
- package/lib/runtime/components/react/mpx-input.tsx +44 -17
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +69 -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-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
- 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 +1 -1
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- package/lib/runtime/components/web/mpx-input.vue +0 -14
- package/lib/runtime/stringify.wxs +2 -2
- 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 +178 -15
- package/lib/template-compiler/bind-this.js +2 -2
- package/lib/template-compiler/compiler.js +267 -71
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +12 -10
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -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 +1 -1
- package/lib/wxss/loader.js +1 -9
- package/package.json +15 -4
|
@@ -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,6 +763,7 @@ function parse (template, options) {
|
|
|
760
763
|
if (!currentParent) genTempRoot()
|
|
761
764
|
|
|
762
765
|
const children = currentParent.children
|
|
766
|
+
|
|
763
767
|
if (currentParent.tag !== 'text') {
|
|
764
768
|
text = text.trim()
|
|
765
769
|
} else {
|
|
@@ -793,9 +797,10 @@ function parse (template, options) {
|
|
|
793
797
|
}
|
|
794
798
|
})
|
|
795
799
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
800
|
+
// multiRoot
|
|
801
|
+
// if (root.tag === 'temp-node' && root.children && root.children.filter(node => node.tag !== 'temp-node').length > 1) {
|
|
802
|
+
// error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
|
|
803
|
+
// }
|
|
799
804
|
|
|
800
805
|
if (hasI18n) {
|
|
801
806
|
if (i18nInjectableComputed.length) {
|
|
@@ -1000,12 +1005,34 @@ function processComponentIs (el, options) {
|
|
|
1000
1005
|
}
|
|
1001
1006
|
|
|
1002
1007
|
const range = getAndRemoveAttr(el, 'range').val
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1008
|
+
|
|
1009
|
+
// Map<CurrentName, SourceName>
|
|
1010
|
+
let ranges
|
|
1011
|
+
if (range) {
|
|
1012
|
+
ranges = range.split(',').map(i => i.trim()).filter(i => i)
|
|
1013
|
+
} else {
|
|
1014
|
+
// 根据原始用户写的usingComponents字段生成ranges
|
|
1015
|
+
ranges = options.originalUsingComponents
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const rangeMap = new Map()
|
|
1019
|
+
ranges.forEach(name => {
|
|
1020
|
+
rangeMap.set(['ali', 'swan'].includes(mode) ? capitalToHyphen(name) : name, name)
|
|
1021
|
+
})
|
|
1022
|
+
|
|
1023
|
+
// Map<CurrentName, SourceName>
|
|
1024
|
+
el.componentMap = new Map()
|
|
1025
|
+
usingComponents.forEach((name) => {
|
|
1026
|
+
if (rangeMap.size === 0) {
|
|
1027
|
+
el.componentMap.set(name, name)
|
|
1028
|
+
} else {
|
|
1029
|
+
if (rangeMap.has(name)) {
|
|
1030
|
+
el.componentMap.set(name, rangeMap.get(name))
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1007
1033
|
})
|
|
1008
|
-
|
|
1034
|
+
|
|
1035
|
+
if (el.componentMap.size === 0) {
|
|
1009
1036
|
warn$1('Component in which <component> tag is used must have a non blank usingComponents field')
|
|
1010
1037
|
}
|
|
1011
1038
|
|
|
@@ -1592,7 +1619,7 @@ function parseOptionalChaining (str) {
|
|
|
1592
1619
|
}
|
|
1593
1620
|
if (grammarMap.checkState() && haveNotGetValue) {
|
|
1594
1621
|
// 值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
|
|
1595
|
-
throw new Error('[
|
|
1622
|
+
throw new Error('[Mpx template error]: optionChain option value illegal!!!')
|
|
1596
1623
|
}
|
|
1597
1624
|
haveNotGetValue = true
|
|
1598
1625
|
let keyValue = ''
|
|
@@ -1642,7 +1669,7 @@ function parseOptionalChaining (str) {
|
|
|
1642
1669
|
}
|
|
1643
1670
|
if (grammarMap.checkState() && haveNotGetValue) {
|
|
1644
1671
|
// key值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
|
|
1645
|
-
throw new Error('[
|
|
1672
|
+
throw new Error('[Mpx template error]: optionChain option key illegal!!!')
|
|
1646
1673
|
}
|
|
1647
1674
|
if (keyValue) {
|
|
1648
1675
|
chainKey += `,'${keyValue}'`
|
|
@@ -1855,24 +1882,25 @@ function processRefReact (el, meta) {
|
|
|
1855
1882
|
/**
|
|
1856
1883
|
* selectorsConf: [type, [[prefix, selector], [prefix, selector]]]
|
|
1857
1884
|
*/
|
|
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 {
|
|
1885
|
+
if (val) {
|
|
1873
1886
|
meta.refs.push(refConf)
|
|
1874
1887
|
selectors.push({ prefix: '', selector: `"${refConf.key}"` })
|
|
1875
1888
|
}
|
|
1889
|
+
|
|
1890
|
+
const rawId = el.attrsMap.id
|
|
1891
|
+
const rawClass = el.attrsMap.class
|
|
1892
|
+
const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
|
|
1893
|
+
|
|
1894
|
+
if (rawId) {
|
|
1895
|
+
const staticId = parseMustacheWithContext(rawId).result
|
|
1896
|
+
selectors.push({ prefix: '#', selector: `${staticId}` })
|
|
1897
|
+
}
|
|
1898
|
+
if (rawClass || rawDynamicClass) {
|
|
1899
|
+
const staticClass = parseMustacheWithContext(rawClass).result
|
|
1900
|
+
const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
|
|
1901
|
+
selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1876
1904
|
const selectorsConf = selectors.map(item => `["${item.prefix}", ${item.selector}]`)
|
|
1877
1905
|
const refFnId = forScopes.reduce((preV, curV) => {
|
|
1878
1906
|
return `${preV} + "_" + ${curV.index}`
|
|
@@ -2084,13 +2112,24 @@ function postProcessIf (el) {
|
|
|
2084
2112
|
replaceNode(el, getTempNode())._if = false
|
|
2085
2113
|
}
|
|
2086
2114
|
} else {
|
|
2115
|
+
el._if = null
|
|
2087
2116
|
attrs = [{
|
|
2088
2117
|
name: config[mode].directive.if,
|
|
2089
2118
|
value: el.if.raw
|
|
2090
2119
|
}]
|
|
2091
2120
|
}
|
|
2092
2121
|
} else if (el.elseif) {
|
|
2122
|
+
if (el.for) {
|
|
2123
|
+
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`)
|
|
2124
|
+
return
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2093
2127
|
prevNode = findPrevNode(el)
|
|
2128
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2129
|
+
error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2130
|
+
return
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2094
2133
|
if (prevNode._if === true) {
|
|
2095
2134
|
removeNode(el)
|
|
2096
2135
|
} else if (prevNode._if === false) {
|
|
@@ -2110,6 +2149,7 @@ function postProcessIf (el) {
|
|
|
2110
2149
|
removeNode(el)
|
|
2111
2150
|
}
|
|
2112
2151
|
} else {
|
|
2152
|
+
el._if = null
|
|
2113
2153
|
attrs = [{
|
|
2114
2154
|
name: config[mode].directive.elseif,
|
|
2115
2155
|
value: el.elseif.raw
|
|
@@ -2117,7 +2157,17 @@ function postProcessIf (el) {
|
|
|
2117
2157
|
}
|
|
2118
2158
|
}
|
|
2119
2159
|
} else if (el.else) {
|
|
2160
|
+
if (el.for) {
|
|
2161
|
+
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`)
|
|
2162
|
+
return
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2120
2165
|
prevNode = findPrevNode(el)
|
|
2166
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2167
|
+
error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2168
|
+
return
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2121
2171
|
if (prevNode._if === true) {
|
|
2122
2172
|
removeNode(el)
|
|
2123
2173
|
} else if (prevNode._if === false) {
|
|
@@ -2141,23 +2191,100 @@ function addIfCondition (el, condition) {
|
|
|
2141
2191
|
el.ifConditions.push(condition)
|
|
2142
2192
|
}
|
|
2143
2193
|
|
|
2194
|
+
function getIfConditions (el) {
|
|
2195
|
+
return el?.ifConditions || []
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2144
2198
|
function postProcessIfReact (el) {
|
|
2145
|
-
let prevNode
|
|
2199
|
+
let prevNode, ifNode, result, ifConditions
|
|
2146
2200
|
if (el.if) {
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2201
|
+
// 取值
|
|
2202
|
+
// false -> 节点变为temp-node,并添加_if=false
|
|
2203
|
+
// true -> 添加_if=true,移除if
|
|
2204
|
+
// dynamic -> addIfCondition
|
|
2205
|
+
result = evalExp(el.if.exp)
|
|
2206
|
+
if (result.success) {
|
|
2207
|
+
if (result.result) {
|
|
2208
|
+
el._if = true
|
|
2209
|
+
delete el.if
|
|
2210
|
+
} else {
|
|
2211
|
+
replaceNode(el, getTempNode())._if = false
|
|
2212
|
+
}
|
|
2213
|
+
} else {
|
|
2214
|
+
el._if = null
|
|
2215
|
+
addIfCondition(el, {
|
|
2216
|
+
exp: el.if.exp,
|
|
2156
2217
|
block: el
|
|
2157
2218
|
})
|
|
2158
|
-
|
|
2219
|
+
}
|
|
2220
|
+
} else if (el.elseif) {
|
|
2221
|
+
if (el.for) {
|
|
2222
|
+
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`)
|
|
2223
|
+
return
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
ifNode = findPrevNode(el)
|
|
2227
|
+
ifConditions = getIfConditions(ifNode)
|
|
2228
|
+
prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
|
|
2229
|
+
|
|
2230
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2231
|
+
error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2232
|
+
return
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
if (prevNode._if === true) {
|
|
2236
|
+
removeNode(el)
|
|
2237
|
+
} else if (prevNode._if === false) {
|
|
2238
|
+
el.if = el.elseif
|
|
2239
|
+
delete el.elseif
|
|
2240
|
+
postProcessIfReact(el)
|
|
2241
|
+
} else {
|
|
2242
|
+
result = evalExp(el.elseif.exp)
|
|
2243
|
+
if (result.success) {
|
|
2244
|
+
if (result.result) {
|
|
2245
|
+
delete el.elseif
|
|
2246
|
+
el._if = true
|
|
2247
|
+
addIfCondition(ifNode, {
|
|
2248
|
+
exp: el.elseif.exp,
|
|
2249
|
+
block: el
|
|
2250
|
+
})
|
|
2251
|
+
removeNode(el, true)
|
|
2252
|
+
} else {
|
|
2253
|
+
removeNode(el)
|
|
2254
|
+
}
|
|
2255
|
+
} else {
|
|
2256
|
+
el._if = null
|
|
2257
|
+
addIfCondition(ifNode, {
|
|
2258
|
+
exp: el.elseif.exp,
|
|
2259
|
+
block: el
|
|
2260
|
+
})
|
|
2261
|
+
removeNode(el, true)
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
} else if (el.else) {
|
|
2265
|
+
if (el.for) {
|
|
2266
|
+
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`)
|
|
2267
|
+
return
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
ifNode = findPrevNode(el)
|
|
2271
|
+
ifConditions = getIfConditions(ifNode)
|
|
2272
|
+
prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
|
|
2273
|
+
|
|
2274
|
+
if (!prevNode || prevNode._if === undefined) {
|
|
2275
|
+
error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
|
|
2276
|
+
return
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
if (prevNode._if === true) {
|
|
2280
|
+
removeNode(el)
|
|
2281
|
+
} else if (prevNode._if === false) {
|
|
2282
|
+
delete el.else
|
|
2159
2283
|
} else {
|
|
2160
|
-
|
|
2284
|
+
addIfCondition(ifNode, {
|
|
2285
|
+
block: el
|
|
2286
|
+
})
|
|
2287
|
+
removeNode(el, true)
|
|
2161
2288
|
}
|
|
2162
2289
|
}
|
|
2163
2290
|
}
|
|
@@ -2524,6 +2651,16 @@ function getVirtualHostRoot (options, meta) {
|
|
|
2524
2651
|
if (isWeb(mode) && ctorType === 'page') {
|
|
2525
2652
|
return createASTElement('page')
|
|
2526
2653
|
}
|
|
2654
|
+
if (isReact(mode) && ctorType === 'page') {
|
|
2655
|
+
const rootView = createASTElement('view', [
|
|
2656
|
+
{
|
|
2657
|
+
name: 'class',
|
|
2658
|
+
value: MPX_TAG_PAGE_SELECTOR
|
|
2659
|
+
}
|
|
2660
|
+
])
|
|
2661
|
+
processElement(rootView, rootView, options, meta)
|
|
2662
|
+
return rootView
|
|
2663
|
+
}
|
|
2527
2664
|
}
|
|
2528
2665
|
return getTempNode()
|
|
2529
2666
|
}
|
|
@@ -2581,7 +2718,7 @@ function postProcessTemplate (el) {
|
|
|
2581
2718
|
}
|
|
2582
2719
|
}
|
|
2583
2720
|
|
|
2584
|
-
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,noMode')
|
|
2721
|
+
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,ks,noMode')
|
|
2585
2722
|
|
|
2586
2723
|
function isValidModeP (i) {
|
|
2587
2724
|
return isValidMode(i[0] === '_' ? i.slice(1) : i)
|
|
@@ -2717,6 +2854,78 @@ function processNoTransAttrs (el) {
|
|
|
2717
2854
|
}
|
|
2718
2855
|
}
|
|
2719
2856
|
|
|
2857
|
+
function initCrossPlatformConfig () {
|
|
2858
|
+
// 定义平台与前缀的双向映射关系
|
|
2859
|
+
const platformPrefixMap = {
|
|
2860
|
+
wx: 'wx:',
|
|
2861
|
+
ali: 'a:',
|
|
2862
|
+
swan: 's-',
|
|
2863
|
+
qq: 'qq:',
|
|
2864
|
+
tt: 'tt:',
|
|
2865
|
+
dd: 'dd:',
|
|
2866
|
+
jd: 'jd:',
|
|
2867
|
+
qa: 'qa:',
|
|
2868
|
+
web: 'v-'
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
if (isNoMode(mode)) {
|
|
2872
|
+
return null
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
return {
|
|
2876
|
+
currentPrefix: platformPrefixMap[mode] || 'wx:',
|
|
2877
|
+
platformPrefixMap
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
// 检测跨平台语法使用情况并给出警告
|
|
2882
|
+
function processCrossPlatformSyntaxWarning (el) {
|
|
2883
|
+
// 使用转换后的属性列表进行检查
|
|
2884
|
+
if (!el.attrsList || el.attrsList.length === 0) {
|
|
2885
|
+
return
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
// 如果配置为空,说明不需要检测
|
|
2889
|
+
if (!crossPlatformConfig) {
|
|
2890
|
+
return
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
const { currentPrefix, platformPrefixMap } = crossPlatformConfig
|
|
2894
|
+
|
|
2895
|
+
// 检查转换后的属性列表
|
|
2896
|
+
el.attrsList.forEach(attr => {
|
|
2897
|
+
const attrName = attr.name
|
|
2898
|
+
|
|
2899
|
+
// 检查是否使用了平台前缀
|
|
2900
|
+
for (const [platformName, prefix] of Object.entries(platformPrefixMap)) {
|
|
2901
|
+
if (attrName.startsWith(prefix)) {
|
|
2902
|
+
if (isReact(mode)) {
|
|
2903
|
+
// React Native 平台:只允许使用 wx: 前缀,其他前缀报错
|
|
2904
|
+
if (prefix !== 'wx:') {
|
|
2905
|
+
error$1(
|
|
2906
|
+
`React Native mode "${mode}" does not support "${prefix}" prefix. ` +
|
|
2907
|
+
`Use "wx:" prefix instead. Found: "${attrName}"`
|
|
2908
|
+
)
|
|
2909
|
+
}
|
|
2910
|
+
} else {
|
|
2911
|
+
// 小程序平台:检测跨平台语法使用
|
|
2912
|
+
if (platformName !== mode) {
|
|
2913
|
+
// 构建建议的正确属性名
|
|
2914
|
+
const suffixPart = attrName.substring(prefix.length)
|
|
2915
|
+
const suggestedAttr = currentPrefix + suffixPart
|
|
2916
|
+
|
|
2917
|
+
warn$1(
|
|
2918
|
+
`Your target mode is "${mode}", but used "${attrName}". ` +
|
|
2919
|
+
`Did you mean "${suggestedAttr}"?`
|
|
2920
|
+
)
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
break
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
})
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2720
2929
|
function processMpxTagName (el) {
|
|
2721
2930
|
const mpxTagName = getAndRemoveAttr(el, 'mpxTagName').val
|
|
2722
2931
|
if (mpxTagName) {
|
|
@@ -2746,6 +2955,9 @@ function processElement (el, root, options, meta) {
|
|
|
2746
2955
|
|
|
2747
2956
|
processDuplicateAttrsList(el)
|
|
2748
2957
|
|
|
2958
|
+
// 检测跨平台语法使用情况并给出警告
|
|
2959
|
+
processCrossPlatformSyntaxWarning(el)
|
|
2960
|
+
|
|
2749
2961
|
processInjectWxs(el, meta, options)
|
|
2750
2962
|
|
|
2751
2963
|
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
@@ -2890,7 +3102,7 @@ function cloneAttrsList (attrsList) {
|
|
|
2890
3102
|
}
|
|
2891
3103
|
|
|
2892
3104
|
function postProcessComponentIs (el, postProcessChild) {
|
|
2893
|
-
if (el.is && el.
|
|
3105
|
+
if (el.is && el.componentMap && el.componentMap.size > 0) {
|
|
2894
3106
|
let tempNode
|
|
2895
3107
|
if (el.for || el.if || el.elseif || el.else) {
|
|
2896
3108
|
tempNode = createASTElement('block')
|
|
@@ -2900,11 +3112,12 @@ function postProcessComponentIs (el, postProcessChild) {
|
|
|
2900
3112
|
replaceNode(el, tempNode, true)
|
|
2901
3113
|
postMoveBaseDirective(tempNode, el)
|
|
2902
3114
|
|
|
2903
|
-
|
|
2904
|
-
|
|
3115
|
+
// Map<CurrentName, SourceName>
|
|
3116
|
+
el.componentMap.forEach((source, name) => {
|
|
3117
|
+
const newChild = createASTElement(name, cloneAttrsList(el.attrsList), tempNode)
|
|
2905
3118
|
newChild.if = {
|
|
2906
|
-
raw: `{{${el.is} === ${stringify(
|
|
2907
|
-
exp: `${el.is} === ${stringify(
|
|
3119
|
+
raw: `{{${el.is} === ${stringify(source)}}}`,
|
|
3120
|
+
exp: `${el.is} === ${stringify(source)}`
|
|
2908
3121
|
}
|
|
2909
3122
|
el.children.forEach((child) => {
|
|
2910
3123
|
addChild(newChild, cloneNode(child))
|
|
@@ -3029,30 +3242,12 @@ function genIf (node) {
|
|
|
3029
3242
|
|
|
3030
3243
|
function genElseif (node) {
|
|
3031
3244
|
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
|
-
}
|
|
3245
|
+
return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
|
|
3042
3246
|
}
|
|
3043
3247
|
|
|
3044
3248
|
function genElse (node) {
|
|
3045
3249
|
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
|
-
}
|
|
3250
|
+
return `else{\n${genNode(node)}}\n`
|
|
3056
3251
|
}
|
|
3057
3252
|
|
|
3058
3253
|
function genExps (node) {
|
|
@@ -3065,7 +3260,7 @@ function genFor (node) {
|
|
|
3065
3260
|
node.forProcessed = true
|
|
3066
3261
|
const index = node.for.index || 'index'
|
|
3067
3262
|
const item = node.for.item || 'item'
|
|
3068
|
-
return `
|
|
3263
|
+
return `mpx_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
|
|
3069
3264
|
}
|
|
3070
3265
|
|
|
3071
3266
|
function genNode (node) {
|
|
@@ -3263,5 +3458,6 @@ module.exports = {
|
|
|
3263
3458
|
findPrevNode,
|
|
3264
3459
|
removeNode,
|
|
3265
3460
|
replaceNode,
|
|
3266
|
-
createASTElement
|
|
3461
|
+
createASTElement,
|
|
3462
|
+
evalExp
|
|
3267
3463
|
}
|
|
@@ -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,
|
|
@@ -110,10 +112,10 @@ module.exports = function (raw) {
|
|
|
110
112
|
if (rawCode) {
|
|
111
113
|
try {
|
|
112
114
|
const ignoreMap = Object.assign({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
mpx_i: true,
|
|
116
|
+
mpx_c: true,
|
|
117
|
+
mpx_sc: true,
|
|
118
|
+
mpx_r: true
|
|
117
119
|
}, meta.wxsModuleMap)
|
|
118
120
|
const bindResult = optimizeRenderLevel === 2
|
|
119
121
|
? bindThis.transformSimple(rawCode, {
|
|
@@ -124,9 +126,9 @@ module.exports = function (raw) {
|
|
|
124
126
|
renderReduce: optimizeRenderLevel === 1,
|
|
125
127
|
ignoreMap
|
|
126
128
|
})
|
|
127
|
-
resultSource += `global.currentInject.render = function (
|
|
129
|
+
resultSource += `global.currentInject.render = function (mpx_i, mpx_c, mpx_r, mpx_sc) {
|
|
128
130
|
${bindResult.code}
|
|
129
|
-
|
|
131
|
+
mpx_r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
130
132
|
};\n`
|
|
131
133
|
if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
|
|
132
134
|
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
package/lib/utils/const.js
CHANGED