@mpxjs/webpack-plugin 2.10.19 → 2.10.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dependencies/ResolveDependency.js +2 -2
- package/lib/index.js +25 -6
- package/lib/json-compiler/helper.js +11 -10
- package/lib/json-compiler/index.js +7 -4
- package/lib/json-compiler/plugin.js +4 -4
- package/lib/loader.js +4 -4
- package/lib/native-loader.js +4 -4
- package/lib/platform/create-diagnostic.js +168 -0
- package/lib/platform/index.js +16 -3
- package/lib/platform/json/wx/index.js +66 -17
- package/lib/platform/run-rules.js +9 -5
- package/lib/platform/style/wx/index.js +4 -3
- package/lib/platform/template/normalize-component-rules.js +7 -9
- package/lib/platform/template/wx/component-config/custom-built-in-component.js +34 -0
- package/lib/platform/template/wx/component-config/index.js +18 -3
- package/lib/platform/template/wx/component-config/input.js +1 -7
- package/lib/platform/template/wx/component-config/movable-view.js +1 -7
- package/lib/platform/template/wx/component-config/text.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -25
- package/lib/platform/template/wx/index.js +48 -34
- package/lib/react/processJSON.js +7 -4
- package/lib/react/processStyles.js +22 -8
- package/lib/react/processTemplate.js +85 -41
- package/lib/react/style-helper.js +120 -85
- package/lib/react/template-loader.js +148 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +1 -2
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +3 -2
- package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
- package/lib/runtime/components/react/mpx-image.tsx +1 -3
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/utils.tsx +3 -2
- package/lib/runtime/components/wx/default-component.mpx +9 -0
- package/lib/runtime/components/wx/default-page.mpx +3 -11
- package/lib/runtime/optionProcessor.d.ts +2 -0
- package/lib/runtime/optionProcessor.js +77 -1
- package/lib/style-compiler/index.js +2 -0
- package/lib/style-compiler/plugins/remove-strip-conditional-comments.js +14 -0
- package/lib/style-compiler/strip-conditional.js +40 -26
- package/lib/template-compiler/compiler.js +274 -116
- package/lib/template-compiler/gen-node-react.js +35 -7
- package/lib/template-compiler/index.js +9 -7
- package/lib/utils/const.js +4 -1
- package/lib/utils/partial-compile-rules.js +27 -0
- package/lib/utils/pre-process-json.js +3 -0
- package/lib/utils/source-location.js +96 -0
- package/lib/web/compile-wx-template-fragment.js +68 -0
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +7 -4
- package/lib/web/processScript.js +41 -3
- package/lib/web/processTemplate.js +61 -19
- package/lib/web/template-loader.js +123 -0
- package/lib/web/template-shared.js +48 -0
- package/lib/wxml/loader.js +3 -2
- package/lib/wxss/loader.js +1 -1
- package/lib/wxss/utils.js +6 -4
- package/package.json +11 -4
- package/lib/platform/template/wx/component-config/component.js +0 -41
|
@@ -15,19 +15,23 @@ function defaultNormalizeTest (rawTest, context) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
module.exports = function runRules (rules = [], input, options = {}) {
|
|
18
|
-
const { mode, testKey, normalizeTest, data = {}, meta = {}, waterfall } = options
|
|
18
|
+
const { mode, testKey, normalizeTest, data = {}, meta = {}, waterfall, diagnostic } = options
|
|
19
19
|
rules = rules.rules || rules
|
|
20
20
|
for (let i = 0; i < rules.length; i++) {
|
|
21
21
|
const rule = rules[i]
|
|
22
22
|
const tester = (normalizeTest || defaultNormalizeTest)(rule.test, rule)
|
|
23
23
|
const testInput = testKey ? input[testKey] : input
|
|
24
24
|
const processor = rule[mode]
|
|
25
|
-
// mode传入data中供processor
|
|
25
|
+
// mode 和 diagnostic 传入 data 中供 processor 内部使用
|
|
26
26
|
Object.assign(data, {
|
|
27
|
-
mode
|
|
27
|
+
mode,
|
|
28
|
+
diagnostic
|
|
28
29
|
})
|
|
29
|
-
if (tester(testInput, meta) && processor) {
|
|
30
|
-
const
|
|
30
|
+
if (tester(testInput, meta, data) && processor) {
|
|
31
|
+
const runProcessor = () => processor.call(rule, input, data, meta)
|
|
32
|
+
const result = diagnostic && diagnostic.withContext
|
|
33
|
+
? diagnostic.withContext({ mode, rule, input, data, meta, testKey, testInput }, runProcessor)
|
|
34
|
+
: runProcessor()
|
|
31
35
|
meta.processed = true
|
|
32
36
|
if (result !== undefined) {
|
|
33
37
|
input = result
|
|
@@ -3,7 +3,7 @@ const { parseValues } = require('../../../utils/string')
|
|
|
3
3
|
|
|
4
4
|
module.exports = function getSpec({ warn, error }) {
|
|
5
5
|
// React Native 双端都不支持的 CSS property
|
|
6
|
-
const unsupportedPropExp = /^(white-space|text-overflow|animation|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|
|
|
6
|
+
const unsupportedPropExp = /^(white-space|text-overflow|animation|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|caret-color|float|clear)$/
|
|
7
7
|
const unsupportedPropMode = {
|
|
8
8
|
// React Native ios 不支持的 CSS property
|
|
9
9
|
ios: /^(vertical-align)$/,
|
|
@@ -50,7 +50,7 @@ module.exports = function getSpec({ warn, error }) {
|
|
|
50
50
|
'flex-direction': ['row', 'row-reverse', 'column', 'column-reverse'],
|
|
51
51
|
'flex-wrap': ['wrap', 'nowrap', 'wrap-reverse'],
|
|
52
52
|
'pointer-events': ['auto', 'box-none', 'box-only', 'none'],
|
|
53
|
-
'vertical-align': ['auto', 'top', 'bottom', '
|
|
53
|
+
'vertical-align': ['auto', 'top', 'bottom', 'middle'],
|
|
54
54
|
position: ['relative', 'absolute', 'fixed'],
|
|
55
55
|
'font-variant': ['small-caps', 'oldstyle-nums', 'lining-nums', 'tabular-nums', 'proportional-nums'],
|
|
56
56
|
'text-align': ['left', 'right', 'center', 'justify'],
|
|
@@ -421,8 +421,9 @@ module.exports = function getSpec({ warn, error }) {
|
|
|
421
421
|
// css var & 数组直接返回
|
|
422
422
|
if (Array.isArray(value) || cssVariableExp.test(value)) return { prop, value }
|
|
423
423
|
const values = parseValues(value)
|
|
424
|
+
// Todo 2 RN下顺序不一致转换结果不一致,故这里不处理,动画前后transform排序不一致的问题,由业务调整写法
|
|
424
425
|
// Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
|
|
425
|
-
values.sort()
|
|
426
|
+
// values.sort()
|
|
426
427
|
const transform = []
|
|
427
428
|
values.forEach(item => {
|
|
428
429
|
const match = item.match(/([/\w]+)\((.+)\)/)
|
|
@@ -20,17 +20,15 @@ module.exports = function normalizeComponentRules (cfgs, spec) {
|
|
|
20
20
|
data = Object.assign({}, data, { el, eventRules })
|
|
21
21
|
const testKey = 'name'
|
|
22
22
|
let rAttrsList = []
|
|
23
|
-
const options = {
|
|
24
|
-
mode,
|
|
25
|
-
testKey,
|
|
26
|
-
data
|
|
27
|
-
}
|
|
28
23
|
el.attrsList.forEach((attr) => {
|
|
29
24
|
const meta = {}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const options = {
|
|
26
|
+
mode,
|
|
27
|
+
testKey,
|
|
28
|
+
diagnostic: data.diagnostic,
|
|
29
|
+
data: Object.assign({}, data, { attr })
|
|
30
|
+
}
|
|
31
|
+
let rAttr = runRules(spec.directive, attr, Object.assign({}, options, { meta }))
|
|
34
32
|
// 指令未匹配到时说明为props,因为目前所有的指令都需要转换
|
|
35
33
|
if (!meta.processed) {
|
|
36
34
|
rAttr = runRules(spec.preProps, rAttr, options)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const CUSTOM_BUILTIN_MODES = ['web', 'ios', 'android', 'harmony']
|
|
2
|
+
|
|
3
|
+
function testCustomBuiltInTag (tag, meta, data) {
|
|
4
|
+
const map = data && data.customBuiltInComponents
|
|
5
|
+
return !!(map && map[tag])
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 命中后不再走后续常规 component-config(无 waterfall,run-rules 直接 break)。
|
|
10
|
+
* 从 runRules 的 data.customBuiltInComponents 读取配置;先写入 originalTag,再 mpx- 前缀。
|
|
11
|
+
*/
|
|
12
|
+
function applyCustomBuiltin (el, data) {
|
|
13
|
+
const map = data && data.customBuiltInComponents
|
|
14
|
+
if (!map || !map[el.tag]) return el
|
|
15
|
+
el.originalTag = el.tag
|
|
16
|
+
el.isBuiltIn = true
|
|
17
|
+
el.tag = 'mpx-' + el.originalTag
|
|
18
|
+
return el
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @returns {object}
|
|
23
|
+
*/
|
|
24
|
+
module.exports = function customBuiltInComponent () {
|
|
25
|
+
return {
|
|
26
|
+
skipNormalize: true,
|
|
27
|
+
supportedModes: CUSTOM_BUILTIN_MODES,
|
|
28
|
+
test: testCustomBuiltInTag,
|
|
29
|
+
web: applyCustomBuiltin,
|
|
30
|
+
ios: applyCustomBuiltin,
|
|
31
|
+
android: applyCustomBuiltin,
|
|
32
|
+
harmony: applyCustomBuiltin
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -39,12 +39,26 @@ const view = require('./view')
|
|
|
39
39
|
const webView = require('./web-view')
|
|
40
40
|
const label = require('./label')
|
|
41
41
|
const wxs = require('./wxs')
|
|
42
|
-
const component = require('./component')
|
|
43
42
|
const fixComponentName = require('./fix-component-name')
|
|
43
|
+
const customBuiltInComponent = require('./custom-built-in-component')
|
|
44
44
|
const rootPortal = require('./root-portal')
|
|
45
45
|
const stickyHeader = require('./sticky-header')
|
|
46
46
|
const stickySection = require('./sticky-section')
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* 未命中上方任一组件 test 的标签,仍须走 normalizeComponentRules 中的通用
|
|
50
|
+
* 指令 / 属性 / 事件链路(如 wx 源码输出 ali 时 bindtap → onTap)。
|
|
51
|
+
* 历史上在 template/wx/index.js 里通过 normalizeComponentRules(cfgs.concat({}), spec)
|
|
52
|
+
* 末尾塞入空对象,由 run-rules 对缺省 test 退化为恒 true;此处改为显式配置且必须排在最后。
|
|
53
|
+
*/
|
|
54
|
+
function defaultCatchAllComponentConfig () {
|
|
55
|
+
return {
|
|
56
|
+
test () {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
module.exports = function getComponentConfigs ({ warn, error }) {
|
|
49
63
|
/**
|
|
50
64
|
* universal print for detail component warn or error
|
|
@@ -85,6 +99,7 @@ module.exports = function getComponentConfigs ({ warn, error }) {
|
|
|
85
99
|
// 转换规则只需以微信为基准配置微信和支付宝的差异部分,比如微信和支付宝都支持但是写法不一致,或者微信支持而支付宝不支持的部分(抛出错误或警告)
|
|
86
100
|
return [
|
|
87
101
|
fixComponentName({ print }),
|
|
102
|
+
customBuiltInComponent(),
|
|
88
103
|
...unsupported({ print }),
|
|
89
104
|
ad({ print }),
|
|
90
105
|
view({ print }),
|
|
@@ -126,9 +141,9 @@ module.exports = function getComponentConfigs ({ warn, error }) {
|
|
|
126
141
|
livePusher({ print }),
|
|
127
142
|
hyphenTagName({ print }),
|
|
128
143
|
label({ print }),
|
|
129
|
-
component(),
|
|
130
144
|
rootPortal({ print }),
|
|
131
145
|
stickyHeader({ print }),
|
|
132
|
-
stickySection({ print })
|
|
146
|
+
stickySection({ print }),
|
|
147
|
+
defaultCatchAllComponentConfig()
|
|
133
148
|
]
|
|
134
149
|
}
|
|
@@ -92,12 +92,6 @@ module.exports = function ({ print }) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
|
-
{
|
|
96
|
-
test: /^(password|auto-focus|focus|cursor|selection-start|selection-end|use-built-in)$/,
|
|
97
|
-
web (prop, { el }) {
|
|
98
|
-
el.isBuiltIn = true
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
95
|
{
|
|
102
96
|
test: /^(placeholder-style|placeholder-class|cursor-spacing|confirm-type|confirm-hold|adjust-position|hold-keyboard)$/,
|
|
103
97
|
web: webPropLog
|
|
@@ -107,7 +101,7 @@ module.exports = function ({ print }) {
|
|
|
107
101
|
qa: qaPropLog
|
|
108
102
|
},
|
|
109
103
|
{
|
|
110
|
-
test: /^(always-embed|
|
|
104
|
+
test: /^(always-embed|safe-password-.+)$/,
|
|
111
105
|
ios: iosPropLog,
|
|
112
106
|
android: androidPropLog,
|
|
113
107
|
harmony: harmonyPropLog
|
|
@@ -33,10 +33,7 @@ module.exports = function ({ print }) {
|
|
|
33
33
|
props: [
|
|
34
34
|
{
|
|
35
35
|
test: /^(out-of-bounds)$/,
|
|
36
|
-
ali: qaPropLog
|
|
37
|
-
ios: iosPropLog,
|
|
38
|
-
android: androidPropLog,
|
|
39
|
-
harmony: harmonyPropLog
|
|
36
|
+
ali: qaPropLog
|
|
40
37
|
},
|
|
41
38
|
{
|
|
42
39
|
test: /^(inertia)$/,
|
|
@@ -44,9 +41,6 @@ module.exports = function ({ print }) {
|
|
|
44
41
|
},
|
|
45
42
|
{
|
|
46
43
|
test: /^(damping|friction)$/,
|
|
47
|
-
ios: iosPropLog,
|
|
48
|
-
android: androidPropLog,
|
|
49
|
-
harmony: harmonyPropLog,
|
|
50
44
|
ks: ksPropLog
|
|
51
45
|
},
|
|
52
46
|
{
|
|
@@ -14,13 +14,10 @@ module.exports = function ({ print }) {
|
|
|
14
14
|
const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' })
|
|
15
15
|
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
|
|
16
16
|
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
|
|
17
|
-
const iosValueLogError = print({ platform: 'ios', tag: TAG_NAME, isError: true, type: 'value' })
|
|
18
17
|
const iosPropLog = print({ platform: 'ios', tag: TAG_NAME, isError: false })
|
|
19
18
|
const iosEventLog = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'event' })
|
|
20
|
-
const androidValueLogError = print({ platform: 'android', tag: TAG_NAME, isError: true, type: 'value' })
|
|
21
19
|
const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
|
|
22
20
|
const androidEventLog = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'event' })
|
|
23
|
-
const harmonyValueLogError = print({ platform: 'harmony', tag: TAG_NAME, isError: true, type: 'value' })
|
|
24
21
|
const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
|
|
25
22
|
const harmonyEventLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'event' })
|
|
26
23
|
const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
|
|
@@ -72,28 +69,7 @@ module.exports = function ({ print }) {
|
|
|
72
69
|
qa: qaPropLog
|
|
73
70
|
},
|
|
74
71
|
{
|
|
75
|
-
test:
|
|
76
|
-
ios ({ name, value }) {
|
|
77
|
-
const notSupported = ['return']
|
|
78
|
-
if (notSupported.includes(value)) {
|
|
79
|
-
iosValueLogError({ name, value })
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
android ({ name, value }) {
|
|
83
|
-
const notSupported = ['return']
|
|
84
|
-
if (notSupported.includes(value)) {
|
|
85
|
-
androidValueLogError({ name, value })
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
harmony ({ name, value }) {
|
|
89
|
-
const notSupported = ['return']
|
|
90
|
-
if (notSupported.includes(value)) {
|
|
91
|
-
harmonyValueLogError({ name, value })
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
test: /^(always-embed|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
|
|
72
|
+
test: /^(always-embed|confirm-hold|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
|
|
97
73
|
ios: iosPropLog,
|
|
98
74
|
android: androidPropLog,
|
|
99
75
|
harmony: harmonyPropLog
|
|
@@ -9,7 +9,7 @@ const { dash2hump } = require('../../../utils/hump-dash')
|
|
|
9
9
|
|
|
10
10
|
module.exports = function getSpec ({ warn, error }) {
|
|
11
11
|
function getRnDirectiveEventHandle (mode) {
|
|
12
|
-
return function ({ name, value }, { eventRules, el }) {
|
|
12
|
+
return function ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
13
13
|
const match = this.test.exec(name)
|
|
14
14
|
const prefix = match[1]
|
|
15
15
|
const eventName = match[2]
|
|
@@ -17,8 +17,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
17
17
|
const meta = {
|
|
18
18
|
modifierStr
|
|
19
19
|
}
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const data = { el, attr }
|
|
21
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode, data, diagnostic })
|
|
22
|
+
const rEventName = runRules(eventRules, eventName, { mode, data, diagnostic })
|
|
22
23
|
return {
|
|
23
24
|
name: rPrefix + rEventName + meta.modifierStr,
|
|
24
25
|
value
|
|
@@ -68,7 +69,12 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
68
69
|
// props后处理
|
|
69
70
|
postProps: [
|
|
70
71
|
{
|
|
71
|
-
web (
|
|
72
|
+
web (prop, data) {
|
|
73
|
+
const { name, value } = prop
|
|
74
|
+
// `<template is>` / `data` 留给 compiler 与 RN 一致的 parseMustache 路径;勿在此处转成 :is / :data
|
|
75
|
+
if (data.el && data.el.tag === 'template' && (name === 'is' || name === 'data')) {
|
|
76
|
+
return prop
|
|
77
|
+
}
|
|
72
78
|
const parsed = parseMustacheWithContext(value)
|
|
73
79
|
if (name.startsWith('data-')) {
|
|
74
80
|
return {
|
|
@@ -119,14 +125,14 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
if (el) {
|
|
122
|
-
const
|
|
123
|
-
|
|
128
|
+
const injectWxsInfo = {
|
|
129
|
+
injectWxsRequest: '~' + normalize.lib('runtime/swanHelper.wxs'),
|
|
124
130
|
injectWxsModuleName: 'mpxSwanHelper'
|
|
125
131
|
}
|
|
126
|
-
if (el.
|
|
127
|
-
el.
|
|
132
|
+
if (el.injectWxsInfos && Array.isArray(el.injectWxsInfos)) {
|
|
133
|
+
el.injectWxsInfos.push(injectWxsInfo)
|
|
128
134
|
} else {
|
|
129
|
-
el.
|
|
135
|
+
el.injectWxsInfos = [injectWxsInfo]
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
return {
|
|
@@ -354,13 +360,14 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
354
360
|
// 事件
|
|
355
361
|
{
|
|
356
362
|
test: /^(bind|catch|capture-bind|capture-catch):?(.*?)(\..*)?$/,
|
|
357
|
-
ali ({ name, value }, { eventRules }) {
|
|
363
|
+
ali ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
358
364
|
const match = this.test.exec(name)
|
|
359
365
|
const prefix = match[1]
|
|
360
366
|
const eventName = match[2]
|
|
361
367
|
const modifierStr = match[3] || ''
|
|
362
|
-
const
|
|
363
|
-
const
|
|
368
|
+
const data = { el, attr }
|
|
369
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'ali', data, diagnostic })
|
|
370
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'ali', data, diagnostic })
|
|
364
371
|
return {
|
|
365
372
|
name: rPrefix + dash2hump(rEventName.replace(/^./, (matched) => {
|
|
366
373
|
return matched.toUpperCase()
|
|
@@ -368,85 +375,91 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
368
375
|
value
|
|
369
376
|
}
|
|
370
377
|
},
|
|
371
|
-
swan ({ name, value }, { eventRules }) {
|
|
378
|
+
swan ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
372
379
|
const match = this.test.exec(name)
|
|
373
380
|
const prefix = match[1]
|
|
374
381
|
const eventName = match[2]
|
|
375
382
|
const modifierStr = match[3] || ''
|
|
376
|
-
|
|
377
|
-
|
|
383
|
+
const data = { el, attr }
|
|
384
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'swan', data, diagnostic })
|
|
385
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'swan', data, diagnostic })
|
|
378
386
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
379
387
|
return {
|
|
380
388
|
name: rPrefix + rEventName + modifierStr,
|
|
381
389
|
value
|
|
382
390
|
}
|
|
383
391
|
},
|
|
384
|
-
qq ({ name, value }, { eventRules }) {
|
|
392
|
+
qq ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
385
393
|
const match = this.test.exec(name)
|
|
386
394
|
const prefix = match[1]
|
|
387
395
|
const eventName = match[2]
|
|
388
396
|
const modifierStr = match[3] || ''
|
|
389
|
-
|
|
390
|
-
|
|
397
|
+
const data = { el, attr }
|
|
398
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'qq', data, diagnostic })
|
|
399
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'qq', data, diagnostic })
|
|
391
400
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
392
401
|
return {
|
|
393
402
|
name: rPrefix + rEventName + modifierStr,
|
|
394
403
|
value
|
|
395
404
|
}
|
|
396
405
|
},
|
|
397
|
-
jd ({ name, value }, { eventRules }) {
|
|
406
|
+
jd ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
398
407
|
const match = this.test.exec(name)
|
|
399
408
|
const prefix = match[1]
|
|
400
409
|
const eventName = match[2]
|
|
401
410
|
const modifierStr = match[3] || ''
|
|
402
|
-
|
|
403
|
-
|
|
411
|
+
const data = { el, attr }
|
|
412
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'jd', data, diagnostic })
|
|
413
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'jd', data, diagnostic })
|
|
404
414
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
405
415
|
return {
|
|
406
416
|
name: rPrefix + rEventName + modifierStr,
|
|
407
417
|
value
|
|
408
418
|
}
|
|
409
419
|
},
|
|
410
|
-
tt ({ name, value }, { eventRules }) {
|
|
420
|
+
tt ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
411
421
|
const match = this.test.exec(name)
|
|
412
422
|
const prefix = match[1]
|
|
413
423
|
const eventName = match[2]
|
|
414
424
|
const modifierStr = match[3] || ''
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
const data = { el, attr }
|
|
426
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'tt', data, diagnostic })
|
|
427
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'tt', data, diagnostic })
|
|
417
428
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
418
429
|
return {
|
|
419
430
|
name: rPrefix + rEventName + modifierStr,
|
|
420
431
|
value
|
|
421
432
|
}
|
|
422
433
|
},
|
|
423
|
-
ks ({ name, value }, { eventRules }) {
|
|
434
|
+
ks ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
424
435
|
const match = this.test.exec(name)
|
|
425
436
|
const prefix = match[1]
|
|
426
437
|
const eventName = match[2]
|
|
427
438
|
const modifierStr = match[3] || ''
|
|
428
|
-
|
|
429
|
-
|
|
439
|
+
const data = { el, attr }
|
|
440
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'ks', data, diagnostic })
|
|
441
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'ks', data, diagnostic })
|
|
430
442
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
431
443
|
return {
|
|
432
444
|
name: rPrefix + rEventName + modifierStr,
|
|
433
445
|
value
|
|
434
446
|
}
|
|
435
447
|
},
|
|
436
|
-
dd ({ name, value }, { eventRules }) {
|
|
448
|
+
dd ({ name, value }, { eventRules, el, attr, diagnostic }) {
|
|
437
449
|
const match = this.test.exec(name)
|
|
438
450
|
const prefix = match[1]
|
|
439
451
|
const eventName = match[2]
|
|
440
452
|
const modifierStr = match[3] || ''
|
|
441
|
-
|
|
442
|
-
|
|
453
|
+
const data = { el, attr }
|
|
454
|
+
let rPrefix = runRules(spec.event.prefix, prefix, { mode: 'dd', data, diagnostic })
|
|
455
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'dd', data, diagnostic })
|
|
443
456
|
if (rEventName.includes('-')) rPrefix += ':'
|
|
444
457
|
return {
|
|
445
458
|
name: rPrefix + rEventName + modifierStr,
|
|
446
459
|
value
|
|
447
460
|
}
|
|
448
461
|
},
|
|
449
|
-
web ({ name, value }, { eventRules, el, usingComponents }) {
|
|
462
|
+
web ({ name, value }, { eventRules, el, attr, usingComponents, diagnostic }) {
|
|
450
463
|
const match = this.test.exec(name)
|
|
451
464
|
const prefix = match[1]
|
|
452
465
|
const eventName = match[2]
|
|
@@ -455,8 +468,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
455
468
|
modifierStr
|
|
456
469
|
}
|
|
457
470
|
const isComponent = usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
458
|
-
const
|
|
459
|
-
const
|
|
471
|
+
const data = { el, attr, isComponent }
|
|
472
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'web', data, meta, diagnostic })
|
|
473
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'web', data, diagnostic })
|
|
460
474
|
return {
|
|
461
475
|
name: rPrefix + rEventName + meta.modifierStr,
|
|
462
476
|
value
|
|
@@ -590,6 +604,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
590
604
|
]
|
|
591
605
|
}
|
|
592
606
|
}
|
|
593
|
-
spec.rules = normalizeComponentRules(getComponentConfigs({ warn, error })
|
|
607
|
+
spec.rules = normalizeComponentRules(getComponentConfigs({ warn, error }), spec)
|
|
594
608
|
return spec
|
|
595
609
|
}
|
package/lib/react/processJSON.js
CHANGED
|
@@ -37,15 +37,15 @@ module.exports = function (jsonContent, {
|
|
|
37
37
|
|
|
38
38
|
const context = loaderContext.context
|
|
39
39
|
|
|
40
|
-
const emitWarning = (msg) => {
|
|
40
|
+
const emitWarning = (msg, loc) => {
|
|
41
41
|
loaderContext.emitWarning(
|
|
42
|
-
new Error('[Mpx json warning][' + loaderContext.
|
|
42
|
+
new Error('[Mpx json warning][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
|
|
43
43
|
)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const emitError = (msg) => {
|
|
46
|
+
const emitError = (msg, loc) => {
|
|
47
47
|
loaderContext.emitError(
|
|
48
|
-
new Error('[Mpx json error][' + loaderContext.
|
|
48
|
+
new Error('[Mpx json error][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
|
|
49
49
|
)
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -109,6 +109,9 @@ module.exports = function (jsonContent, {
|
|
|
109
109
|
waterfall: true,
|
|
110
110
|
warn: emitWarning,
|
|
111
111
|
error: emitError,
|
|
112
|
+
diagnostic: {
|
|
113
|
+
file: loaderContext.resourcePath
|
|
114
|
+
},
|
|
112
115
|
data: {
|
|
113
116
|
// polyfill global usingComponents
|
|
114
117
|
globalComponents: mpx.globalComponents
|
|
@@ -12,16 +12,17 @@ module.exports = function (styles, {
|
|
|
12
12
|
}, callback) {
|
|
13
13
|
const { getRequestString } = createHelpers(loaderContext)
|
|
14
14
|
let content = ''
|
|
15
|
+
const styleResults = []
|
|
15
16
|
let output = '/* styles */\n'
|
|
16
17
|
if (styles.length) {
|
|
17
|
-
const warn = (msg) => {
|
|
18
|
+
const warn = (msg, loc) => {
|
|
18
19
|
loaderContext.emitWarning(
|
|
19
|
-
new Error('[Mpx style warning][' + loaderContext.
|
|
20
|
+
new Error('[Mpx style warning][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
|
|
20
21
|
)
|
|
21
22
|
}
|
|
22
|
-
const error = (msg) => {
|
|
23
|
+
const error = (msg, loc) => {
|
|
23
24
|
loaderContext.emitError(
|
|
24
|
-
new Error('[Mpx style error][' + loaderContext.
|
|
25
|
+
new Error('[Mpx style error][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
|
|
25
26
|
)
|
|
26
27
|
}
|
|
27
28
|
const { mode, srcMode } = loaderContext.getMpx()
|
|
@@ -35,11 +36,22 @@ module.exports = function (styles, {
|
|
|
35
36
|
// todo 建立新的request在内部导出classMap,便于样式模块复用
|
|
36
37
|
loaderContext.importModule(JSON.parse(getRequestString('styles', style, extraOptions, i))).then((result) => {
|
|
37
38
|
if (Array.isArray(result)) {
|
|
38
|
-
result
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
result.forEach((item) => {
|
|
40
|
+
const css = item[1]
|
|
41
|
+
styleResults.push({
|
|
42
|
+
content: css,
|
|
43
|
+
map: item[3],
|
|
44
|
+
filename: loaderContext.resourcePath
|
|
45
|
+
})
|
|
46
|
+
content += css.trim() + '\n'
|
|
47
|
+
})
|
|
48
|
+
} else {
|
|
49
|
+
styleResults.push({
|
|
50
|
+
content: result,
|
|
51
|
+
filename: loaderContext.resourcePath
|
|
52
|
+
})
|
|
53
|
+
content += result.trim() + '\n'
|
|
41
54
|
}
|
|
42
|
-
content += result.trim() + '\n'
|
|
43
55
|
callback()
|
|
44
56
|
}).catch((e) => {
|
|
45
57
|
callback(e)
|
|
@@ -55,7 +67,9 @@ module.exports = function (styles, {
|
|
|
55
67
|
const formatValueName = '_f'
|
|
56
68
|
const classMap = getClassMap({
|
|
57
69
|
content,
|
|
70
|
+
styles: styleResults,
|
|
58
71
|
filename: loaderContext.resourcePath,
|
|
72
|
+
inputFileSystem: loaderContext._compiler && loaderContext._compiler.inputFileSystem,
|
|
59
73
|
mode,
|
|
60
74
|
srcMode,
|
|
61
75
|
ctorType,
|