@mpxjs/webpack-plugin 2.7.52 → 2.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +24 -24
- package/lib/dependencies/CommonJsVariableDependency.js +1 -1
- package/lib/dependencies/DynamicEntryDependency.js +18 -11
- package/lib/extractor.js +1 -1
- package/lib/helpers.js +3 -1
- package/lib/index.js +24 -21
- package/lib/json-compiler/helper.js +1 -1
- package/lib/json-compiler/index.js +17 -17
- package/lib/json-compiler/plugin.js +3 -2
- package/lib/json-compiler/theme.js +1 -1
- package/lib/loader.js +3 -3
- package/lib/native-loader.js +1 -1
- package/lib/platform/json/normalize-test.js +3 -1
- package/lib/platform/run-rules.js +2 -2
- package/lib/platform/template/wx/component-config/camera.js +3 -3
- package/lib/platform/template/wx/component-config/canvas.js +5 -5
- package/lib/platform/template/wx/component-config/map.js +5 -5
- package/lib/platform/template/wx/component-config/navigator.js +7 -7
- package/lib/platform/template/wx/component-config/progress.js +4 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +3 -3
- package/lib/platform/template/wx/component-config/slider.js +6 -6
- package/lib/platform/template/wx/component-config/swiper.js +2 -2
- package/lib/platform/template/wx/component-config/video.js +4 -4
- package/lib/platform/template/wx/component-config/view.js +4 -4
- package/lib/platform/template/wx/index.js +45 -13
- package/lib/resolver/PackageEntryPlugin.js +1 -1
- package/lib/runtime/components/web/filterTag.js +6 -6
- package/lib/runtime/components/web/getInnerListeners.js +1 -1
- package/lib/runtime/components/web/mpx-button.vue +0 -1
- package/lib/runtime/components/web/mpx-icon.vue +1 -1
- package/lib/runtime/components/web/mpx-keep-alive.vue +2 -2
- package/lib/runtime/components/web/mpx-picker.vue +1 -1
- package/lib/runtime/components/web/mpx-progress.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
- package/lib/runtime/env.js +1 -0
- package/lib/runtime/i18n.wxs +44 -81
- package/lib/runtime/optionProcessor.d.ts +0 -4
- package/lib/runtime/optionProcessor.js +15 -13
- package/lib/runtime/stringify.wxs +3 -3
- package/lib/runtime/swanHelper.wxs +2 -2
- package/lib/runtime/{components/web/util.js → utils.js} +8 -5
- package/lib/script-setup-compiler/index.js +1163 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/rpx.js +1 -1
- package/lib/style-compiler/plugins/vw.js +6 -4
- package/lib/template-compiler/bind-this.js +5 -5
- package/lib/template-compiler/compiler.js +122 -179
- package/lib/template-compiler/index.js +3 -3
- package/lib/utils/add-query.js +2 -1
- package/lib/utils/gen-component-tag.js +1 -1
- package/lib/utils/has-own.js +5 -0
- package/lib/utils/is-empty-object.js +2 -1
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/{index.js → process-defs.js} +3 -10
- package/lib/utils/stringify-query.js +23 -21
- package/lib/web/processJSON.js +5 -5
- package/lib/web/processScript.js +16 -19
- package/lib/web/processTemplate.js +1 -1
- package/lib/wxml/loader.js +3 -3
- package/lib/wxs/i18n-loader.js +4 -11
- package/lib/wxs/pre-loader.js +51 -44
- package/lib/wxss/compile-exports.js +4 -4
- package/lib/wxss/createResolver.js +3 -3
- package/lib/wxss/css-base.js +13 -13
- package/lib/wxss/getLocalIdent.js +5 -4
- package/lib/wxss/loader.js +1 -1
- package/lib/wxss/localsLoader.js +14 -14
- package/lib/wxss/processCss.js +10 -7
- package/package.json +4 -3
- package/lib/utils/env.js +0 -4
- package/lib/utils/parse-asset.js +0 -195
|
@@ -65,11 +65,11 @@ module.exports = function ({ print }) {
|
|
|
65
65
|
test: /^(tap|markertap|callouttap|controltap|regionchange|)$/,
|
|
66
66
|
ali (eventName) {
|
|
67
67
|
const eventMap = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
tap: 'tap',
|
|
69
|
+
markertap: 'markerTap',
|
|
70
|
+
callouttap: 'calloutTap',
|
|
71
|
+
controltap: 'controlTap',
|
|
72
|
+
regionchange: 'regionChange'
|
|
73
73
|
}
|
|
74
74
|
return eventMap[eventName]
|
|
75
75
|
}
|
|
@@ -44,7 +44,7 @@ module.exports = function ({ print }) {
|
|
|
44
44
|
// 如果是个变量,报warning~
|
|
45
45
|
aliPropLog(attr)
|
|
46
46
|
} else {
|
|
47
|
-
|
|
47
|
+
const supportedList = ['navigate', 'redirect', 'switchTab', 'navigateBack', 'reLaunch', 'exit']
|
|
48
48
|
if (supportedList.indexOf(attr.value) === -1) {
|
|
49
49
|
aliValueLogError(attr)
|
|
50
50
|
}
|
|
@@ -58,14 +58,14 @@ module.exports = function ({ print }) {
|
|
|
58
58
|
// 如果是个变量,报warning~
|
|
59
59
|
ttPropLog(attr)
|
|
60
60
|
} else {
|
|
61
|
-
|
|
61
|
+
const supportedList = ['navigate', 'redirect', 'switchTab', 'navigateBack', 'reLaunch']
|
|
62
62
|
if (supportedList.indexOf(attr.value) === -1) {
|
|
63
63
|
ttValueLogError(attr)
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
web (attr) {
|
|
68
|
-
|
|
68
|
+
const supportedList = ['navigate', 'redirect', 'navigateBack', 'reLaunch']
|
|
69
69
|
if (supportedList.indexOf(attr.value) === -1) {
|
|
70
70
|
webValueLogError(attr)
|
|
71
71
|
}
|
|
@@ -77,7 +77,7 @@ module.exports = function ({ print }) {
|
|
|
77
77
|
if (isMustache(attr.value)) {
|
|
78
78
|
qaPropLog(attr)
|
|
79
79
|
} else {
|
|
80
|
-
|
|
80
|
+
const supportedList = ['navigate', 'redirect', 'switchTab', 'navigateBack', 'reLaunch']
|
|
81
81
|
if (supportedList.indexOf(attr.value) === -1) {
|
|
82
82
|
qaValueLogError(attr)
|
|
83
83
|
}
|
|
@@ -102,9 +102,9 @@ module.exports = function ({ print }) {
|
|
|
102
102
|
qa: qaEventLog,
|
|
103
103
|
jd (eventName) {
|
|
104
104
|
const eventMap = {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
success: 'success',
|
|
106
|
+
fail: 'error',
|
|
107
|
+
complete: 'complete'
|
|
108
108
|
}
|
|
109
109
|
return eventMap[eventName]
|
|
110
110
|
}
|
|
@@ -30,16 +30,16 @@ module.exports = function ({ print }) {
|
|
|
30
30
|
test: /^(activeColor|backgroundColor)$/,
|
|
31
31
|
ali (obj) {
|
|
32
32
|
const propsMap = {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
activeColor: 'active-color',
|
|
34
|
+
backgroundColor: 'background-color'
|
|
35
35
|
}
|
|
36
36
|
obj.name = propsMap[obj.name]
|
|
37
37
|
return obj
|
|
38
38
|
},
|
|
39
39
|
tt (obj) {
|
|
40
40
|
const propsMap = {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
activeColor: 'active-color',
|
|
42
|
+
backgroundColor: 'background-color'
|
|
43
43
|
}
|
|
44
44
|
obj.name = propsMap[obj.name]
|
|
45
45
|
return obj
|
|
@@ -46,9 +46,9 @@ module.exports = function ({ print }) {
|
|
|
46
46
|
test: /^(scrolltoupper|scrolltolower|scroll)$/,
|
|
47
47
|
ali (eventName) {
|
|
48
48
|
const eventMap = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
scrolltoupper: 'scrollToUpper',
|
|
50
|
+
scrolltolower: 'scrollToLower',
|
|
51
|
+
scroll: 'scroll'
|
|
52
52
|
}
|
|
53
53
|
return eventMap[eventName]
|
|
54
54
|
}
|
|
@@ -17,10 +17,10 @@ module.exports = function ({ print }) {
|
|
|
17
17
|
test: /^(color|selected-color|activeColor|backgroundColor|block-size|block-color)$/,
|
|
18
18
|
ali (obj) {
|
|
19
19
|
const propsMap = {
|
|
20
|
-
|
|
20
|
+
color: 'background-color',
|
|
21
21
|
'selected-color': 'active-color',
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
activeColor: 'active-color',
|
|
23
|
+
backgroundColor: 'background-color',
|
|
24
24
|
'block-size': 'handle-size',
|
|
25
25
|
'block-color': 'handle-color'
|
|
26
26
|
}
|
|
@@ -32,7 +32,7 @@ module.exports = function ({ print }) {
|
|
|
32
32
|
test: /^(color|selected-color)$/,
|
|
33
33
|
swan (obj) {
|
|
34
34
|
const propsMap = {
|
|
35
|
-
|
|
35
|
+
color: 'backgroundColor',
|
|
36
36
|
'selected-color': 'activeColor'
|
|
37
37
|
}
|
|
38
38
|
obj.name = propsMap[obj.name]
|
|
@@ -43,8 +43,8 @@ module.exports = function ({ print }) {
|
|
|
43
43
|
test: /^(activeColor|backgroundColor)$/,
|
|
44
44
|
tt (obj) {
|
|
45
45
|
const propsMap = {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
activeColor: 'active-color',
|
|
47
|
+
backgroundColor: 'background-color'
|
|
48
48
|
}
|
|
49
49
|
obj.name = propsMap[obj.name]
|
|
50
50
|
return obj
|
|
@@ -52,8 +52,8 @@ module.exports = function ({ print }) {
|
|
|
52
52
|
test: /^(change|animationfinish)$/,
|
|
53
53
|
ali (eventName) {
|
|
54
54
|
const eventMap = {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
change: 'change',
|
|
56
|
+
animationfinish: 'animationEnd'
|
|
57
57
|
}
|
|
58
58
|
return eventMap[eventName]
|
|
59
59
|
}
|
|
@@ -55,10 +55,10 @@ module.exports = function ({ print }) {
|
|
|
55
55
|
test: /^(timeupdate|fullscreenchange|waiting|loadedmetadata)$/,
|
|
56
56
|
ali (evtName) {
|
|
57
57
|
const eventMap = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
timeupdate: 'timeUpdate',
|
|
59
|
+
fullscreenchange: 'fullScreenChange',
|
|
60
|
+
waiting: 'loading',
|
|
61
|
+
loadedmetadata: 'renderStart'
|
|
62
62
|
}
|
|
63
63
|
return eventMap[evtName]
|
|
64
64
|
}
|
|
@@ -46,10 +46,10 @@ module.exports = function ({ print }) {
|
|
|
46
46
|
//
|
|
47
47
|
ali (eventName) {
|
|
48
48
|
const eventMap = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
transitionend: 'transitionEnd',
|
|
50
|
+
animationstart: 'animationStart',
|
|
51
|
+
animationiteration: 'animationIteration',
|
|
52
|
+
animationend: 'animationEnd'
|
|
53
53
|
}
|
|
54
54
|
return eventMap[eventName]
|
|
55
55
|
},
|
|
@@ -147,7 +147,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
147
147
|
modelValuePathArr = modelValuePath.split('.')
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
const modelValue = match[1].trim()
|
|
151
151
|
return [
|
|
152
152
|
{
|
|
153
153
|
name: ':' + modelProp,
|
|
@@ -188,9 +188,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
188
188
|
if (el.isStyleParsed) {
|
|
189
189
|
return false
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
const styleBinding = []
|
|
192
192
|
el.isStyleParsed = true
|
|
193
|
-
el.attrsList.
|
|
193
|
+
el.attrsList.forEach((item) => {
|
|
194
194
|
const parsed = parseMustache(item.value)
|
|
195
195
|
if (item.name === 'style') {
|
|
196
196
|
if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
|
|
@@ -293,11 +293,43 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
293
293
|
value
|
|
294
294
|
}
|
|
295
295
|
},
|
|
296
|
+
swan ({ name, value }, { eventRules }) {
|
|
297
|
+
const match = this.test.exec(name)
|
|
298
|
+
const eventName = match[2]
|
|
299
|
+
runRules(eventRules, eventName, { mode: 'swan' })
|
|
300
|
+
},
|
|
301
|
+
qq ({ name, value }, { eventRules }) {
|
|
302
|
+
const match = this.test.exec(name)
|
|
303
|
+
const eventName = match[2]
|
|
304
|
+
runRules(eventRules, eventName, { mode: 'qq' })
|
|
305
|
+
},
|
|
296
306
|
jd ({ name, value }, { eventRules }) {
|
|
297
307
|
const match = this.test.exec(name)
|
|
298
308
|
const eventName = match[2]
|
|
299
309
|
runRules(eventRules, eventName, { mode: 'jd' })
|
|
300
310
|
},
|
|
311
|
+
// tt ({ name, value }, { eventRules }) {
|
|
312
|
+
// const match = this.test.exec(name)
|
|
313
|
+
// const prefix = match[1]
|
|
314
|
+
// const eventName = match[2]
|
|
315
|
+
// const modifierStr = match[3] || ''
|
|
316
|
+
// const rEventName = runRules(eventRules, eventName, { mode: 'tt' })
|
|
317
|
+
// return {
|
|
318
|
+
// // 字节将所有事件转为小写
|
|
319
|
+
// name: prefix + rEventName.toLowerCase() + modifierStr,
|
|
320
|
+
// value
|
|
321
|
+
// }
|
|
322
|
+
// },
|
|
323
|
+
tt ({ name, value }, { eventRules }) {
|
|
324
|
+
const match = this.test.exec(name)
|
|
325
|
+
const eventName = match[2]
|
|
326
|
+
runRules(eventRules, eventName, { mode: 'tt' })
|
|
327
|
+
},
|
|
328
|
+
dd ({ name, value }, { eventRules }) {
|
|
329
|
+
const match = this.test.exec(name)
|
|
330
|
+
const eventName = match[2]
|
|
331
|
+
runRules(eventRules, eventName, { mode: 'dd' })
|
|
332
|
+
},
|
|
301
333
|
web ({ name, value }, { eventRules, el }) {
|
|
302
334
|
const match = this.test.exec(name)
|
|
303
335
|
const prefix = match[1]
|
|
@@ -320,7 +352,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
320
352
|
{
|
|
321
353
|
test: /^aria-(role|label)$/,
|
|
322
354
|
ali () {
|
|
323
|
-
warn(
|
|
355
|
+
warn('Ali environment does not support aria-role|label props!')
|
|
324
356
|
}
|
|
325
357
|
}
|
|
326
358
|
],
|
|
@@ -329,8 +361,8 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
329
361
|
{
|
|
330
362
|
ali (prefix) {
|
|
331
363
|
const prefixMap = {
|
|
332
|
-
|
|
333
|
-
|
|
364
|
+
bind: 'on',
|
|
365
|
+
catch: 'catch'
|
|
334
366
|
}
|
|
335
367
|
if (!prefixMap[prefix]) {
|
|
336
368
|
error(`Ali environment does not support [${prefix}] event handling!`)
|
|
@@ -373,13 +405,13 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
373
405
|
test: /^(touchstart|touchmove|touchcancel|touchend|tap|longpress|longtap|transitionend|animationstart|animationiteration|animationend|touchforcechange)$/,
|
|
374
406
|
ali (eventName) {
|
|
375
407
|
const eventMap = {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
408
|
+
touchstart: 'touchStart',
|
|
409
|
+
touchmove: 'touchMove',
|
|
410
|
+
touchend: 'touchEnd',
|
|
411
|
+
touchcancel: 'touchCancel',
|
|
412
|
+
tap: 'tap',
|
|
413
|
+
longtap: 'longTap',
|
|
414
|
+
longpress: 'longTap'
|
|
383
415
|
}
|
|
384
416
|
if (eventMap[eventName]) {
|
|
385
417
|
return eventMap[eventName]
|
|
@@ -18,7 +18,7 @@ module.exports = class PackageEntryPlugin {
|
|
|
18
18
|
const target = resolver.ensureHook(this.target)
|
|
19
19
|
resolver.getHook(this.source).tapAsync('PackageEntryPlugin', (request, resolveContext, callback) => {
|
|
20
20
|
if (request.miniprogram) return callback()
|
|
21
|
-
|
|
21
|
+
const { path: resourcePath, descriptionFileData, descriptionFileRoot } = request
|
|
22
22
|
if (request.miniprogram || !descriptionFileData) return callback()
|
|
23
23
|
|
|
24
24
|
let { name, miniprogram } = descriptionFileData
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line
|
|
2
2
|
const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/ // useless escape
|
|
3
|
-
const ncname =
|
|
3
|
+
const ncname = '[a-zA-Z_][\\w\\-\\.]*'
|
|
4
4
|
const qname = `((?:${ncname}\\:)?${ncname})`
|
|
5
5
|
const startTagOpen = new RegExp(`^<${qname}`)
|
|
6
6
|
const startTagClose = /^\s*(\/?)>/
|
|
@@ -208,7 +208,7 @@ function parseHTML (html, options) {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
export function parse (template) {
|
|
211
|
-
|
|
211
|
+
const nodes = []
|
|
212
212
|
const stack = []
|
|
213
213
|
let root
|
|
214
214
|
function pushChild (currentParent, child) {
|
|
@@ -220,7 +220,7 @@ export function parse (template) {
|
|
|
220
220
|
}
|
|
221
221
|
parseHTML(template, {
|
|
222
222
|
start (tag, attrs, unary) {
|
|
223
|
-
|
|
223
|
+
const element = createASTElement(tag, attrs, currentParent)
|
|
224
224
|
if (!unary && !stack.length) {
|
|
225
225
|
root = element
|
|
226
226
|
}
|
|
@@ -232,9 +232,9 @@ export function parse (template) {
|
|
|
232
232
|
}
|
|
233
233
|
attrs.forEach(attr => {
|
|
234
234
|
if (invalidAttributeRE.test(attr.name)) {
|
|
235
|
-
console.warn(
|
|
236
|
-
|
|
237
|
-
start: attr.start + attr.name.indexOf(
|
|
235
|
+
console.warn('Invalid dynamic argument expression: attribute names cannot contain ' +
|
|
236
|
+
'spaces, quotes, <, >, / or =.', {
|
|
237
|
+
start: attr.start + attr.name.indexOf('['),
|
|
238
238
|
end: attr.start + attr.name.length
|
|
239
239
|
})
|
|
240
240
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
2
|
+
import { isBrowser } from '../../env'
|
|
3
3
|
|
|
4
4
|
function isDef (v) {
|
|
5
5
|
return v !== undefined && v !== null
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
render: function render () {
|
|
42
42
|
const slot = this.$slots.default
|
|
43
43
|
const vnode = getFirstComponentChild(slot)
|
|
44
|
-
if (!
|
|
44
|
+
if (!isBrowser) {
|
|
45
45
|
return vnode || (slot && slot[0])
|
|
46
46
|
}
|
|
47
47
|
const vnodeKey = getVnodeKey(vnode)
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
<script type="text/ecmascript-6">
|
|
37
37
|
import BScroll from '@better-scroll/core'
|
|
38
38
|
import Wheel from '@better-scroll/wheel'
|
|
39
|
-
import { type } from '
|
|
39
|
+
import { type } from '../../utils'
|
|
40
40
|
import { getCustomEvent } from './getInnerListeners'
|
|
41
41
|
|
|
42
42
|
const startYear = 1970
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import getInnerListeners, { getCustomEvent } from './getInnerListeners'
|
|
3
|
-
import { processSize } from '
|
|
3
|
+
import { processSize } from '../../utils'
|
|
4
4
|
import BScroll from '@better-scroll/core'
|
|
5
5
|
import PullDown from '@better-scroll/pull-down'
|
|
6
6
|
import ObserveDom from '@better-scroll/observe-dom'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isBrowser = typeof window !== 'undefined'
|
package/lib/runtime/i18n.wxs
CHANGED
|
@@ -6,14 +6,18 @@ function genRegExp (str, flags) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function isArray (arr) {
|
|
10
10
|
if (!__mpx_wxs__) {
|
|
11
11
|
return Array.isArray(arr)
|
|
12
12
|
} else {
|
|
13
|
-
return arr && arr.constructor === 'Array'
|
|
13
|
+
return isDef(arr) && arr.constructor === 'Array'
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function isString (str) {
|
|
18
|
+
return typeof str === 'string'
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
function isObject (obj) {
|
|
18
22
|
return obj !== null && typeof obj === 'object'
|
|
19
23
|
}
|
|
@@ -83,7 +87,7 @@ function compile (tokens, values) {
|
|
|
83
87
|
var compiled = []
|
|
84
88
|
var index = 0
|
|
85
89
|
|
|
86
|
-
var mode =
|
|
90
|
+
var mode = isArray(values)
|
|
87
91
|
? 'list'
|
|
88
92
|
: isObject(values)
|
|
89
93
|
? 'named'
|
|
@@ -118,9 +122,7 @@ function compile (tokens, values) {
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
function interpolate (message, values) {
|
|
121
|
-
|
|
122
|
-
return [message]
|
|
123
|
-
}
|
|
125
|
+
values = values || {}
|
|
124
126
|
var tokens = _tokenCaches[message]
|
|
125
127
|
if (!tokens) {
|
|
126
128
|
tokens = parseMessage(message)
|
|
@@ -151,7 +153,7 @@ function outPutByPath (context, path) {
|
|
|
151
153
|
var key
|
|
152
154
|
var item = path[index]
|
|
153
155
|
if (result) {
|
|
154
|
-
if (
|
|
156
|
+
if (isArray(item)) {
|
|
155
157
|
// 获取子数组的输出结果作为当前key
|
|
156
158
|
key = outPutByPath(context, item)
|
|
157
159
|
} else if (genRegExp('^__mpx_str_').test(item)) {
|
|
@@ -245,50 +247,43 @@ function parsePath (pathStr) {
|
|
|
245
247
|
return curStack.value
|
|
246
248
|
}
|
|
247
249
|
|
|
248
|
-
function translate (messages, locale, key, values) {
|
|
249
|
-
var
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
if (isDef(message)) {
|
|
253
|
-
res = render(message, values)
|
|
254
|
-
}
|
|
250
|
+
function translate (messages, locale, fallbackLocale, key, values) {
|
|
251
|
+
var message = getMessage(messages, locale, fallbackLocale, key)
|
|
252
|
+
if (isString(message)) {
|
|
253
|
+
return render(message, values)
|
|
255
254
|
}
|
|
256
|
-
return
|
|
255
|
+
return key
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
function exist (messages, locale, key) {
|
|
260
|
-
|
|
261
|
-
if (messages && messages[locale] && key) {
|
|
262
|
-
var message = getPathValue(messages[locale], key)
|
|
263
|
-
if (isDef(message)) {
|
|
264
|
-
res = true
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return res
|
|
259
|
+
return isDef(resolve(messages, locale, key))
|
|
268
260
|
}
|
|
269
261
|
|
|
270
|
-
|
|
271
|
-
var
|
|
272
|
-
var
|
|
273
|
-
var
|
|
262
|
+
function getMessage (messages, locale, fallbackLocale, key) {
|
|
263
|
+
var locales = [locale, fallbackLocale]
|
|
264
|
+
for (var i = 0; i < locales.length; i++) {
|
|
265
|
+
var message = resolve(messages, locales[i], key)
|
|
266
|
+
if (isDef(message)) return message
|
|
267
|
+
}
|
|
268
|
+
}
|
|
274
269
|
|
|
275
|
-
function
|
|
276
|
-
|
|
270
|
+
function resolve (messages, locale, key) {
|
|
271
|
+
if (messages && messages[locale] && key) {
|
|
272
|
+
return getPathValue(messages[locale], key)
|
|
273
|
+
}
|
|
277
274
|
}
|
|
278
275
|
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
return __mpx_messages__ || messages
|
|
276
|
+
function getLocale () {
|
|
277
|
+
return __mpx_locale__ || 'zh-CN'
|
|
282
278
|
}
|
|
283
279
|
|
|
284
|
-
function
|
|
285
|
-
|
|
286
|
-
return __mpx_datetime_formats__ || dateTimeFormats
|
|
280
|
+
function getFallbackLocale () {
|
|
281
|
+
return __mpx_fallback_locale__ || 'zh-CN'
|
|
287
282
|
}
|
|
288
283
|
|
|
289
|
-
function
|
|
290
|
-
//
|
|
291
|
-
return
|
|
284
|
+
function getMessages (messages) {
|
|
285
|
+
// __mpx_messages__会在编译时通过lib/wxs/i18n-loader注入
|
|
286
|
+
return messages || __mpx_messages__ || {}
|
|
292
287
|
}
|
|
293
288
|
|
|
294
289
|
function fetchChoice (message, choice) {
|
|
@@ -307,46 +302,17 @@ function getChoiceIndex (choice, choicesLength) {
|
|
|
307
302
|
}
|
|
308
303
|
|
|
309
304
|
module.exports = {
|
|
310
|
-
t: function (locale, key, values) {
|
|
311
|
-
return translate(getMessages(), locale, key, values)
|
|
312
|
-
},
|
|
313
|
-
tc: function (locale, key, choice, values) {
|
|
314
|
-
return fetchChoice(translate(getMessages(), locale, key, values), choice)
|
|
305
|
+
t: function (messages, locale, fallbackLocale, key, values) {
|
|
306
|
+
return translate(getMessages(messages), locale, fallbackLocale, key, values)
|
|
315
307
|
},
|
|
316
|
-
|
|
317
|
-
return
|
|
308
|
+
tc: function (messages, locale, fallbackLocale, key, choice, values) {
|
|
309
|
+
return fetchChoice(translate(getMessages(messages), locale, fallbackLocale, key, values), choice)
|
|
318
310
|
},
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
console.log('Datetime localization is not supported!')
|
|
322
|
-
return value
|
|
323
|
-
// } else {
|
|
324
|
-
// if (!key) {
|
|
325
|
-
// return new Intl.DateTimeFormat(locale).format(value)
|
|
326
|
-
// }
|
|
327
|
-
// var formats = getDateTimeFormats()[locale]
|
|
328
|
-
// if (isDef(formats)) {
|
|
329
|
-
// var format = formats[key]
|
|
330
|
-
// return new Intl.DateTimeFormat(locale, format).format(value)
|
|
331
|
-
// }
|
|
332
|
-
// return value
|
|
333
|
-
// }
|
|
311
|
+
te: function (messages, locale, fallbackLocale, key) {
|
|
312
|
+
return exist(getMessages(messages), locale, key)
|
|
334
313
|
},
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
console.log('Number localization is not supported!')
|
|
338
|
-
return value
|
|
339
|
-
// } else {
|
|
340
|
-
// if (!key) {
|
|
341
|
-
// return new Intl.NumberFormat(locale, options).format(value)
|
|
342
|
-
// }
|
|
343
|
-
// var formats = getNumberFormats()[locale]
|
|
344
|
-
// if (isDef(formats)) {
|
|
345
|
-
// var format = formats[key]
|
|
346
|
-
// return new Intl.NumberFormat(locale, Object.assign({}, format, options)).format(value)
|
|
347
|
-
// }
|
|
348
|
-
// return value
|
|
349
|
-
// }
|
|
314
|
+
tm: function (messages, locale, fallbackLocale, key) {
|
|
315
|
+
return getMessage(getMessages(messages), locale, fallbackLocale, key)
|
|
350
316
|
}
|
|
351
317
|
}
|
|
352
318
|
|
|
@@ -354,12 +320,9 @@ if (!__mpx_wxs__) {
|
|
|
354
320
|
if (!global.i18n) {
|
|
355
321
|
global.i18n = {
|
|
356
322
|
locale: getLocale(),
|
|
357
|
-
|
|
323
|
+
fallbackLocale: getFallbackLocale(),
|
|
324
|
+
messages: getMessages(),
|
|
325
|
+
methods: module.exports
|
|
358
326
|
}
|
|
359
|
-
global.i18nMethods = Object.assign(module.exports, {
|
|
360
|
-
__getMessages: getMessages,
|
|
361
|
-
__getDateTimeFormats: getDateTimeFormats,
|
|
362
|
-
__getNumberFormats: getNumberFormats
|
|
363
|
-
})
|
|
364
327
|
}
|
|
365
328
|
}
|