@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115
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/README.md +1 -1
- package/lib/built-in-loader.js +49 -0
- package/lib/config.js +0 -14
- package/lib/content-loader.js +13 -0
- package/lib/dependency/ChildCompileDependency.js +24 -0
- package/lib/dependency/InjectDependency.js +26 -0
- package/lib/dependency/RemovedModuleDependency.js +23 -0
- package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
- package/lib/dependency/ResolveDependency.js +49 -0
- package/lib/extractor.js +178 -82
- package/lib/file-loader.js +19 -7
- package/lib/helpers.js +334 -39
- package/lib/index.js +525 -889
- package/lib/json-compiler/index.js +451 -245
- package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
- package/lib/loader.js +241 -178
- package/lib/native-loader.js +133 -71
- package/lib/parser.js +2 -1
- package/lib/path-loader.js +3 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +3 -2
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +3 -149
- package/lib/plugin-loader.js +287 -0
- package/lib/resolver/AddEnvPlugin.js +3 -4
- package/lib/resolver/AddModePlugin.js +3 -4
- package/lib/resolver/PackageEntryPlugin.js +36 -23
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/getInnerListeners.js +3 -1
- package/lib/runtime/components/web/mpx-image.vue +5 -20
- package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
- package/lib/runtime/components/web/mpx-swiper.vue +3 -18
- package/lib/runtime/i18n.wxs +11 -31
- package/lib/runtime/optionProcessor.js +3 -48
- package/lib/selector.js +10 -29
- package/lib/staticConfig.js +4 -0
- package/lib/style-compiler/index.js +24 -16
- package/lib/style-compiler/load-postcss-config.js +1 -3
- package/lib/style-compiler/plugins/conditional-strip.js +65 -68
- package/lib/style-compiler/plugins/rpx.js +37 -43
- package/lib/style-compiler/plugins/scope-id.js +72 -79
- package/lib/style-compiler/plugins/trans-special.js +18 -25
- package/lib/style-compiler/plugins/trim.js +7 -13
- package/lib/style-compiler/plugins/vw.js +16 -22
- package/lib/template-compiler/compiler.js +199 -106
- package/lib/template-compiler/index.js +139 -52
- package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
- package/lib/url-loader.js +29 -11
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/get-main-compilation.js +6 -0
- package/lib/utils/is-url-request.js +1 -10
- package/lib/utils/match-condition.js +1 -4
- package/lib/utils/normalize.js +15 -4
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/read-json-for-src.js +34 -0
- package/lib/utils/stringify-query.js +0 -4
- package/lib/utils/try-require.js +16 -0
- package/lib/web/processJSON.js +144 -113
- package/lib/web/processScript.js +34 -47
- package/lib/web/processTemplate.js +40 -57
- package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +8 -4
- package/lib/wxs/WxsTemplatePlugin.js +92 -46
- package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
- package/lib/wxs/wxs-loader.js +117 -0
- package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
- package/lib/wxss/getImportPrefix.js +30 -0
- package/lib/wxss/loader.js +43 -31
- package/lib/wxss/localsLoader.js +5 -1
- package/lib/wxss/processCss.js +103 -107
- package/package.json +18 -21
- package/LICENSE +0 -433
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/dependencies/AppEntryDependency.js +0 -58
- package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
- package/lib/dependencies/CommonJsVariableDependency.js +0 -81
- package/lib/dependencies/DynamicEntryDependency.js +0 -171
- package/lib/dependencies/FlagPluginDependency.js +0 -24
- package/lib/dependencies/InjectDependency.js +0 -43
- package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
- package/lib/dependencies/RecordIndependentDependency.js +0 -44
- package/lib/dependencies/RecordResourceMapDependency.js +0 -62
- package/lib/dependencies/RemoveEntryDependency.js +0 -40
- package/lib/dependencies/ResolveDependency.js +0 -88
- package/lib/independent-loader.js +0 -52
- package/lib/json-compiler/helper.js +0 -156
- package/lib/json-compiler/plugin.js +0 -150
- package/lib/partial-compile/index.js +0 -35
- package/lib/record-loader.js +0 -11
- package/lib/resolve-loader.js +0 -6
- package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
- package/lib/runtime/components/tenon/tenon-button.vue +0 -305
- package/lib/runtime/components/tenon/tenon-image.vue +0 -61
- package/lib/runtime/components/tenon/tenon-input.vue +0 -99
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
- package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
- package/lib/runtime/components/tenon/tenon-text.vue +0 -64
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/tenon/util.js +0 -44
- package/lib/runtime/optionProcessor.tenon.js +0 -386
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -105
- package/lib/tenon/processJSON.js +0 -360
- package/lib/tenon/processScript.js +0 -260
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -133
- package/lib/utils/const.js +0 -10
- package/lib/utils/emit-file.js +0 -10
- package/lib/utils/eval-json-js.js +0 -31
- package/lib/utils/get-entry-name.js +0 -13
- package/lib/utils/get-json-content.js +0 -42
- package/lib/utils/get-relative-path.js +0 -24
- package/lib/utils/resolve.js +0 -13
- package/lib/utils/set.js +0 -47
- package/lib/utils/stringify-loaders-resource.js +0 -25
- package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
- package/lib/wxs/loader.js +0 -142
|
@@ -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('../
|
|
4
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../staticConfig')
|
|
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')
|
|
8
9
|
const getRulesRunner = require('../platform/index')
|
|
9
10
|
const addQuery = require('../utils/add-query')
|
|
10
11
|
const transDynamicClassExpr = require('./trans-dynamic-class-expr')
|
|
11
12
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
12
13
|
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,6 +130,107 @@ 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
|
+
|
|
133
234
|
// Browser environment sniffing
|
|
134
235
|
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
|
|
135
236
|
const isIE = UA && /msie|trident/.test(UA)
|
|
@@ -153,9 +254,6 @@ let forScopesMap = {}
|
|
|
153
254
|
let hasI18n = false
|
|
154
255
|
let i18nInjectableComputed = []
|
|
155
256
|
let env
|
|
156
|
-
let platformGetTagNamespace
|
|
157
|
-
let filePath
|
|
158
|
-
let refId
|
|
159
257
|
|
|
160
258
|
function updateForScopesMap () {
|
|
161
259
|
forScopes.forEach((scope) => {
|
|
@@ -182,6 +280,9 @@ const deleteErrorInResultMap = (node) => {
|
|
|
182
280
|
rulesResultMap.delete(node)
|
|
183
281
|
Array.isArray(node.children) && node.children.forEach(item => deleteErrorInResultMap(item))
|
|
184
282
|
}
|
|
283
|
+
let platformGetTagNamespace
|
|
284
|
+
let basename
|
|
285
|
+
let refId
|
|
185
286
|
|
|
186
287
|
function baseWarn (msg) {
|
|
187
288
|
console.warn(('[template compiler]: ' + msg))
|
|
@@ -210,7 +311,7 @@ function decode (value) {
|
|
|
210
311
|
|
|
211
312
|
const i18nFuncNames = ['\\$(t)', '\\$(tc)', '\\$(te)', '\\$(d)', '\\$(n)']
|
|
212
313
|
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
213
|
-
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
314
|
+
const i18nWxsLoaderPath = normalize.lib('wxs/wxs-i18n-loader.js')
|
|
214
315
|
// 添加~前缀避免wxs绝对路径在存在projectRoot时被拼接为错误路径
|
|
215
316
|
const i18nWxsRequest = '~' + i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
216
317
|
const i18nModuleName = '__i18n__'
|
|
@@ -497,8 +598,8 @@ function parseHTML (html, options) {
|
|
|
497
598
|
|
|
498
599
|
function parseComponent (content, options) {
|
|
499
600
|
mode = options.mode || 'wx'
|
|
601
|
+
defs = options.defs || {}
|
|
500
602
|
env = options.env
|
|
501
|
-
filePath = options.filePath
|
|
502
603
|
|
|
503
604
|
let sfc = {
|
|
504
605
|
template: null,
|
|
@@ -548,9 +649,6 @@ function parseComponent (content, options) {
|
|
|
548
649
|
if (/^application\/json/.test(currentBlock.type) || currentBlock.name === 'json') {
|
|
549
650
|
tag = 'json'
|
|
550
651
|
}
|
|
551
|
-
if (currentBlock.name === 'json') {
|
|
552
|
-
currentBlock.useJSONJS = true
|
|
553
|
-
}
|
|
554
652
|
}
|
|
555
653
|
if (currentBlock.mode && currentBlock.env) {
|
|
556
654
|
if (currentBlock.mode === mode && currentBlock.env === env) {
|
|
@@ -594,6 +692,9 @@ function parseComponent (content, options) {
|
|
|
594
692
|
if (attr.name === 'scoped') {
|
|
595
693
|
block.scoped = true
|
|
596
694
|
}
|
|
695
|
+
if (attr.name === 'module') {
|
|
696
|
+
block.module = attr.value || true
|
|
697
|
+
}
|
|
597
698
|
if (attr.name === 'src') {
|
|
598
699
|
block.src = attr.value
|
|
599
700
|
}
|
|
@@ -609,15 +710,20 @@ function parseComponent (content, options) {
|
|
|
609
710
|
}
|
|
610
711
|
}
|
|
611
712
|
|
|
612
|
-
function end (tag, start) {
|
|
713
|
+
function end (tag, start, end) {
|
|
613
714
|
if (depth === 1 && currentBlock) {
|
|
614
715
|
currentBlock.end = start
|
|
615
716
|
let text = content.slice(currentBlock.start, currentBlock.end)
|
|
616
717
|
// pad content so that linters and pre-processors can output correct
|
|
617
718
|
// line numbers in errors and warnings
|
|
618
|
-
if (options.pad) {
|
|
719
|
+
if (currentBlock.tag !== 'template' && options.pad) {
|
|
619
720
|
text = padContent(currentBlock, options.pad) + text
|
|
620
721
|
}
|
|
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
|
+
}
|
|
621
727
|
currentBlock.content = text
|
|
622
728
|
currentBlock = null
|
|
623
729
|
}
|
|
@@ -668,7 +774,7 @@ function parse (template, options) {
|
|
|
668
774
|
defs = options.defs || {}
|
|
669
775
|
srcMode = options.srcMode || mode
|
|
670
776
|
isNative = options.isNative
|
|
671
|
-
|
|
777
|
+
basename = options.basename
|
|
672
778
|
i18n = options.i18n
|
|
673
779
|
refId = 0
|
|
674
780
|
|
|
@@ -719,6 +825,16 @@ function parse (template, options) {
|
|
|
719
825
|
attrs = guardIESVGBug(attrs)
|
|
720
826
|
}
|
|
721
827
|
|
|
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
|
+
|
|
722
838
|
let element = createASTElement(tag, attrs, currentParent)
|
|
723
839
|
if (ns) {
|
|
724
840
|
element.ns = ns
|
|
@@ -733,11 +849,27 @@ function parse (template, options) {
|
|
|
733
849
|
)
|
|
734
850
|
}
|
|
735
851
|
|
|
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
|
+
|
|
736
867
|
// multi root
|
|
737
868
|
if (!currentParent) genTempRoot()
|
|
738
869
|
|
|
739
870
|
currentParent.children.push(element)
|
|
740
871
|
element.parent = currentParent
|
|
872
|
+
|
|
741
873
|
processElement(element, root, options, meta)
|
|
742
874
|
tagNames.add(element.tag)
|
|
743
875
|
|
|
@@ -800,7 +932,10 @@ function parse (template, options) {
|
|
|
800
932
|
},
|
|
801
933
|
comment: function comment (text) {
|
|
802
934
|
if (!currentParent) genTempRoot()
|
|
803
|
-
|
|
935
|
+
// special comments should not be output
|
|
936
|
+
if (isMpxCommentAttrs(text)) {
|
|
937
|
+
produceMpxCommentAttrs(text)
|
|
938
|
+
} else if (options.hasComment) {
|
|
804
939
|
currentParent.children.push({
|
|
805
940
|
type: 3,
|
|
806
941
|
text: text,
|
|
@@ -811,6 +946,8 @@ function parse (template, options) {
|
|
|
811
946
|
}
|
|
812
947
|
})
|
|
813
948
|
|
|
949
|
+
assertMpxCommentAttrsEnd()
|
|
950
|
+
|
|
814
951
|
if (multiRootError) {
|
|
815
952
|
error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
|
|
816
953
|
}
|
|
@@ -904,19 +1041,6 @@ function modifyAttr (el, name, val) {
|
|
|
904
1041
|
}
|
|
905
1042
|
}
|
|
906
1043
|
|
|
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
|
-
|
|
920
1044
|
function stringify (str) {
|
|
921
1045
|
return JSON.stringify(str)
|
|
922
1046
|
}
|
|
@@ -1013,6 +1137,15 @@ function processComponentIs (el, options) {
|
|
|
1013
1137
|
}
|
|
1014
1138
|
}
|
|
1015
1139
|
|
|
1140
|
+
// function processComponentDepth (el, options) {
|
|
1141
|
+
// if (isComponentNode(el,options)) {
|
|
1142
|
+
// addAttrs(el, [{
|
|
1143
|
+
// name: 'mpxDepth',
|
|
1144
|
+
// value: '{{mpxDepth + 1}}'
|
|
1145
|
+
// }])
|
|
1146
|
+
// }
|
|
1147
|
+
// }
|
|
1148
|
+
|
|
1016
1149
|
const eventIdentifier = '__mpx_event__'
|
|
1017
1150
|
|
|
1018
1151
|
function parseFuncStr2 (str) {
|
|
@@ -1420,13 +1553,9 @@ function postProcessWxs (el, meta) {
|
|
|
1420
1553
|
content = el.children.filter((child) => {
|
|
1421
1554
|
return child.type === 3 && !child.isComment
|
|
1422
1555
|
}).map(child => child.text).join('\n')
|
|
1423
|
-
|
|
1424
|
-
const fakeRequest = filePath + config[mode].wxs.ext
|
|
1425
|
-
|
|
1426
|
-
src = addQuery(`~${fakeRequest}!=!${filePath}`, {
|
|
1556
|
+
src = addQuery('./' + basename, {
|
|
1427
1557
|
wxsModule: module
|
|
1428
1558
|
})
|
|
1429
|
-
|
|
1430
1559
|
addAttrs(el, [{
|
|
1431
1560
|
name: config[mode].wxs.src,
|
|
1432
1561
|
value: src
|
|
@@ -1507,9 +1636,9 @@ function postProcessFor (el) {
|
|
|
1507
1636
|
}
|
|
1508
1637
|
|
|
1509
1638
|
function evalExp (exp) {
|
|
1639
|
+
// eslint-disable-next-line no-new-func
|
|
1510
1640
|
let result = { success: false }
|
|
1511
1641
|
try {
|
|
1512
|
-
// eslint-disable-next-line no-new-func
|
|
1513
1642
|
const fn = new Function(`return ${exp};`)
|
|
1514
1643
|
result = {
|
|
1515
1644
|
success: true,
|
|
@@ -1813,57 +1942,36 @@ function processBuiltInComponents (el, meta) {
|
|
|
1813
1942
|
}
|
|
1814
1943
|
}
|
|
1815
1944
|
|
|
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
|
-
|
|
1850
1945
|
function processAliStyleClassHack (el, options, root) {
|
|
1946
|
+
let processor
|
|
1947
|
+
// 处理组件标签
|
|
1948
|
+
if (isComponentNode(el, options)) processor = ({ value, typeName }) => [typeName, value]
|
|
1851
1949
|
// 处理组件根节点
|
|
1852
1950
|
if (options.isComponent && el === root && isRealNode(el)) {
|
|
1853
|
-
|
|
1854
|
-
let
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
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
|
|
1865
1967
|
})
|
|
1866
|
-
|
|
1968
|
+
if (newValue !== undefined) {
|
|
1969
|
+
addAttrs(el, [{
|
|
1970
|
+
name: newName,
|
|
1971
|
+
value: newValue
|
|
1972
|
+
}])
|
|
1973
|
+
}
|
|
1974
|
+
})
|
|
1867
1975
|
}
|
|
1868
1976
|
|
|
1869
1977
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
@@ -2072,22 +2180,10 @@ function processElement (el, root, options, meta) {
|
|
|
2072
2180
|
processComponentGenericsForWeb(el, options, meta)
|
|
2073
2181
|
return
|
|
2074
2182
|
}
|
|
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
|
-
}
|
|
2084
2183
|
|
|
2085
2184
|
const pass = isNative || processTemplate(el) || processingTemplate
|
|
2086
2185
|
|
|
2087
|
-
|
|
2088
|
-
if (mode === 'ali') {
|
|
2089
|
-
processScoped(el, options)
|
|
2090
|
-
}
|
|
2186
|
+
processScoped(el, options)
|
|
2091
2187
|
|
|
2092
2188
|
if (transAli) {
|
|
2093
2189
|
processAliExternalClassesHack(el, options)
|
|
@@ -2103,9 +2199,9 @@ function processElement (el, root, options, meta) {
|
|
|
2103
2199
|
processShow(el, options, root)
|
|
2104
2200
|
}
|
|
2105
2201
|
|
|
2106
|
-
|
|
2202
|
+
// 当mode为ali不管是不是跨平台都需要进行此处理,以保障ali当中的refs相关增强能力正常运行
|
|
2203
|
+
if (mode === 'ali') {
|
|
2107
2204
|
processAliStyleClassHack(el, options, root)
|
|
2108
|
-
processAliEventHack(el, options, root)
|
|
2109
2205
|
}
|
|
2110
2206
|
|
|
2111
2207
|
if (!pass) {
|
|
@@ -2118,7 +2214,7 @@ function processElement (el, root, options, meta) {
|
|
|
2118
2214
|
|
|
2119
2215
|
function closeElement (el, meta) {
|
|
2120
2216
|
postProcessAtMode(el)
|
|
2121
|
-
if (mode === 'web'
|
|
2217
|
+
if (mode === 'web') {
|
|
2122
2218
|
postProcessWxs(el, meta)
|
|
2123
2219
|
// 处理代码维度条件编译移除死分支
|
|
2124
2220
|
postProcessIf(el)
|
|
@@ -2166,16 +2262,14 @@ function postProcessComponentIs (el) {
|
|
|
2166
2262
|
let tempNode
|
|
2167
2263
|
if (el.for || el.if || el.elseif || el.else) {
|
|
2168
2264
|
tempNode = createASTElement('block', [])
|
|
2169
|
-
|
|
2265
|
+
tempNode.for = el.for
|
|
2266
|
+
tempNode.if = el.if
|
|
2267
|
+
tempNode.elseif = el.elseif
|
|
2268
|
+
tempNode.else = el.else
|
|
2170
2269
|
} else {
|
|
2171
2270
|
tempNode = getTempNode()
|
|
2172
2271
|
}
|
|
2173
|
-
let range = []
|
|
2174
|
-
if (el.attrsMap.range) {
|
|
2175
|
-
range = getAndRemoveAttr(el, 'range').val.split(',')
|
|
2176
|
-
}
|
|
2177
2272
|
el.components.forEach(function (component) {
|
|
2178
|
-
if (range.length > 0 && !range.includes(component)) return
|
|
2179
2273
|
let newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
|
|
2180
2274
|
newChild.if = {
|
|
2181
2275
|
raw: `{{${el.is} === ${stringify(component)}}}`,
|
|
@@ -2192,7 +2286,7 @@ function postProcessComponentIs (el) {
|
|
|
2192
2286
|
if (!el.parent) {
|
|
2193
2287
|
error$1('Dynamic component can not be the template root, considering wrapping it with <view> or <text> tag!')
|
|
2194
2288
|
} else {
|
|
2195
|
-
el = replaceNode(el, tempNode
|
|
2289
|
+
el = replaceNode(el, tempNode) || el
|
|
2196
2290
|
}
|
|
2197
2291
|
}
|
|
2198
2292
|
return el
|
|
@@ -2227,7 +2321,7 @@ function serialize (root) {
|
|
|
2227
2321
|
result += node.text
|
|
2228
2322
|
}
|
|
2229
2323
|
}
|
|
2230
|
-
if (node.tag === 'wxs' &&
|
|
2324
|
+
if (node.tag === 'wxs' && mode === 'web') {
|
|
2231
2325
|
return result
|
|
2232
2326
|
}
|
|
2233
2327
|
if (node.type === 1) {
|
|
@@ -2392,6 +2486,5 @@ module.exports = {
|
|
|
2392
2486
|
makeAttrsMap,
|
|
2393
2487
|
stringifyAttr,
|
|
2394
2488
|
parseMustache,
|
|
2395
|
-
stringifyWithResolveComputed
|
|
2396
|
-
addAttrs
|
|
2489
|
+
stringifyWithResolveComputed
|
|
2397
2490
|
}
|