@mpxjs/webpack-plugin 2.6.113 → 2.6.114-alpha.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/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependency/AddEntryDependency.js +24 -0
- package/lib/dependency/ResolveDependency.js +4 -0
- package/lib/index.js +44 -3
- package/lib/json-compiler/index.js +3 -0
- package/lib/loader.js +43 -2
- package/lib/path-loader.js +4 -1
- package/lib/platform/template/wx/component-config/button.js +14 -2
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +4 -0
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +117 -1
- package/lib/runtime/components/tenon/getInnerListeners.js +308 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/template-compiler/compiler.js +11 -2
- package/lib/template-compiler/trans-dynamic-class-expr.js +1 -1
- package/lib/tenon/index.js +108 -0
- package/lib/tenon/processJSON.js +361 -0
- package/lib/tenon/processScript.js +260 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/utils/get-relative-path.js +24 -0
- package/package.json +7 -3
package/README.md
CHANGED
package/lib/config.js
CHANGED
|
@@ -356,6 +356,20 @@ module.exports = {
|
|
|
356
356
|
templatePrefix: 'module.exports = \n'
|
|
357
357
|
}
|
|
358
358
|
},
|
|
359
|
+
tenon: {
|
|
360
|
+
directive: {
|
|
361
|
+
if: 'v-if',
|
|
362
|
+
elseif: 'v-else-if',
|
|
363
|
+
else: 'v-else'
|
|
364
|
+
},
|
|
365
|
+
wxs: {
|
|
366
|
+
tag: 'wxs',
|
|
367
|
+
module: 'module',
|
|
368
|
+
src: 'src',
|
|
369
|
+
ext: '.wxs',
|
|
370
|
+
templatePrefix: 'module.exports = \n'
|
|
371
|
+
}
|
|
372
|
+
},
|
|
359
373
|
qa: {
|
|
360
374
|
typeExtMap: {
|
|
361
375
|
json: '.json',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
|
|
3
|
+
class AddEntryDependency extends NullDependency {
|
|
4
|
+
constructor ({ context, dep, name }) {
|
|
5
|
+
super()
|
|
6
|
+
this.__addEntryParams = [ context, dep, name ]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get type () {
|
|
10
|
+
return 'mpx add entry'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// updateHash (hash) {
|
|
14
|
+
// super.updateHash(hash)
|
|
15
|
+
// hash.update(this.childCompileEntryModule.identifier())
|
|
16
|
+
// }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
AddEntryDependency.Template = class AddEntryDependencyTemplate {
|
|
20
|
+
apply () {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = AddEntryDependency
|
|
@@ -42,6 +42,10 @@ ResolveDependency.Template = class ResolveDependencyTemplate {
|
|
|
42
42
|
if (!resolved) {
|
|
43
43
|
dep.compilation.errors.push(new Error(`Path ${dep.resource} is not a page/component/static resource, which is resolved from ${dep.issuerResource}!`))
|
|
44
44
|
}
|
|
45
|
+
// for tenon
|
|
46
|
+
if (dep.compilation.__mpx__.mode === 'tenon') {
|
|
47
|
+
return `getRelativePath(currentURL, ${JSON.stringify(resolved)}) + '.js'`
|
|
48
|
+
}
|
|
45
49
|
return JSON.stringify(dep.publicPath + resolved)
|
|
46
50
|
}
|
|
47
51
|
}
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const ResolveDependency = require('./dependency/ResolveDependency')
|
|
|
7
7
|
const InjectDependency = require('./dependency/InjectDependency')
|
|
8
8
|
const ReplaceDependency = require('./dependency/ReplaceDependency')
|
|
9
9
|
const ChildCompileDependency = require('./dependency/ChildCompileDependency')
|
|
10
|
+
const AddEntryDependency = require('./dependency/AddEntryDependency')
|
|
10
11
|
const NullFactory = require('webpack/lib/NullFactory')
|
|
11
12
|
const normalize = require('./utils/normalize')
|
|
12
13
|
const toPosix = require('./utils/to-posix')
|
|
@@ -228,7 +229,7 @@ class MpxWebpackPlugin {
|
|
|
228
229
|
let splitChunksPlugin
|
|
229
230
|
let splitChunksOptions
|
|
230
231
|
|
|
231
|
-
if (this.options.mode !== 'web') {
|
|
232
|
+
if (this.options.mode !== 'web' && this.options.mode !== 'tenon') {
|
|
232
233
|
compiler.options.optimization.runtimeChunk = {
|
|
233
234
|
name: (entrypoint) => {
|
|
234
235
|
for (let packageName in mpx.independentSubpackagesMap) {
|
|
@@ -296,6 +297,9 @@ class MpxWebpackPlugin {
|
|
|
296
297
|
compilation.dependencyFactories.set(ChildCompileDependency, new NullFactory())
|
|
297
298
|
compilation.dependencyTemplates.set(ChildCompileDependency, new ChildCompileDependency.Template())
|
|
298
299
|
|
|
300
|
+
compilation.dependencyFactories.set(AddEntryDependency, new NullFactory())
|
|
301
|
+
compilation.dependencyTemplates.set(AddEntryDependency, new AddEntryDependency.Template())
|
|
302
|
+
|
|
299
303
|
compilation.dependencyFactories.set(RemovedModuleDependency, normalModuleFactory)
|
|
300
304
|
compilation.dependencyTemplates.set(RemovedModuleDependency, new RemovedModuleDependency.Template())
|
|
301
305
|
|
|
@@ -590,6 +594,23 @@ class MpxWebpackPlugin {
|
|
|
590
594
|
const rawProcessModuleDependencies = compilation.processModuleDependencies
|
|
591
595
|
compilation.processModuleDependencies = (module, callback) => {
|
|
592
596
|
let proxyedCallback = callback
|
|
597
|
+
if (module.__has_tenon_entry) {
|
|
598
|
+
let tasks = []
|
|
599
|
+
module.dependencies.forEach(dep => {
|
|
600
|
+
if (dep instanceof AddEntryDependency) {
|
|
601
|
+
tasks.push(new Promise(resolve => {
|
|
602
|
+
compilation.addEntry(...dep.__addEntryParams, (err) => {
|
|
603
|
+
resolve(err)
|
|
604
|
+
})
|
|
605
|
+
}))
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
proxyedCallback = (error) => {
|
|
609
|
+
Promise.all(tasks).then(errs => {
|
|
610
|
+
callback(errs.filter(e => !!e)[0] || error)
|
|
611
|
+
})
|
|
612
|
+
}
|
|
613
|
+
}
|
|
593
614
|
if (module.rawRequest === mpx.appScriptRawRequest) {
|
|
594
615
|
// 避免模块request重名,只对第一次匹配到的模块进行代理
|
|
595
616
|
mpx.appScriptRawRequest = ''
|
|
@@ -816,6 +837,27 @@ class MpxWebpackPlugin {
|
|
|
816
837
|
}
|
|
817
838
|
})
|
|
818
839
|
|
|
840
|
+
// processing for tenon-store
|
|
841
|
+
if (mpx.mode === 'tenon') {
|
|
842
|
+
let TENON_STORE_ID = 0
|
|
843
|
+
parser.hooks.call.for('imported var').tap('MpxWebpackPlugin', (expr) => {
|
|
844
|
+
if (['createStore', 'createStoreWithThis'].includes(expr.callee.name)) {
|
|
845
|
+
const current = parser.state.current
|
|
846
|
+
const storeOptions = expr.arguments.length && expr.arguments[0]
|
|
847
|
+
if (storeOptions) {
|
|
848
|
+
current.addDependency(new InjectDependency({
|
|
849
|
+
content: 'Object.assign(',
|
|
850
|
+
index: storeOptions.range[0]
|
|
851
|
+
}))
|
|
852
|
+
current.addDependency(new InjectDependency({
|
|
853
|
+
content: `, { __store_id: ${TENON_STORE_ID++} })`,
|
|
854
|
+
index: storeOptions.range[1]
|
|
855
|
+
}))
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
})
|
|
859
|
+
}
|
|
860
|
+
|
|
819
861
|
if (mpx.srcMode !== mpx.mode) {
|
|
820
862
|
// 全量替换未声明的wx identifier
|
|
821
863
|
parser.hooks.expression.for('wx').tap('MpxWebpackPlugin', transHandler)
|
|
@@ -864,7 +906,6 @@ class MpxWebpackPlugin {
|
|
|
864
906
|
'set',
|
|
865
907
|
'remove',
|
|
866
908
|
'delete: del',
|
|
867
|
-
'setConvertRule',
|
|
868
909
|
'getMixin',
|
|
869
910
|
'getComputed',
|
|
870
911
|
'implement'
|
|
@@ -905,7 +946,7 @@ class MpxWebpackPlugin {
|
|
|
905
946
|
|
|
906
947
|
// 为了正确生成sourceMap,将该步骤由原来的compile.hooks.emit迁移到compilation.hooks.optimizeChunkAssets中来
|
|
907
948
|
compilation.hooks.optimizeChunkAssets.tapAsync('MpxWebpackPlugin', (chunks, callback) => {
|
|
908
|
-
if (mpx.mode === 'web') return callback()
|
|
949
|
+
if (mpx.mode === 'web' || mpx.mode === 'tenon') return callback()
|
|
909
950
|
const jsonpFunction = compilation.outputOptions.jsonpFunction
|
|
910
951
|
|
|
911
952
|
function getTargetFile (file) {
|
|
@@ -176,6 +176,9 @@ module.exports = function (raw = '{}') {
|
|
|
176
176
|
if (!json.usingComponents) {
|
|
177
177
|
json.usingComponents = {}
|
|
178
178
|
}
|
|
179
|
+
if (!json.component && mode === 'swan') {
|
|
180
|
+
json.component = true
|
|
181
|
+
}
|
|
179
182
|
}
|
|
180
183
|
} else if (componentsMap[resourcePath]) {
|
|
181
184
|
// component
|
package/lib/loader.js
CHANGED
|
@@ -12,6 +12,7 @@ const processJSON = require('./web/processJSON')
|
|
|
12
12
|
const processScript = require('./web/processScript')
|
|
13
13
|
const processStyles = require('./web/processStyles')
|
|
14
14
|
const processTemplate = require('./web/processTemplate')
|
|
15
|
+
const processForTenon = require('./tenon/index')
|
|
15
16
|
const readJsonForSrc = require('./utils/read-json-for-src')
|
|
16
17
|
const normalize = require('./utils/normalize')
|
|
17
18
|
const getMainCompilation = require('./utils/get-main-compilation')
|
|
@@ -163,6 +164,47 @@ module.exports = function (content) {
|
|
|
163
164
|
projectRoot
|
|
164
165
|
})
|
|
165
166
|
|
|
167
|
+
if (mode === 'tenon') {
|
|
168
|
+
if (ctorType === 'app' && !queryObj.app) {
|
|
169
|
+
const request = addQuery(this.resource, { app: true })
|
|
170
|
+
output += `
|
|
171
|
+
import App from ${stringifyRequest(request)}
|
|
172
|
+
import * as Tenon from '@hummer/tenon-vue'
|
|
173
|
+
|
|
174
|
+
Tenon.render(App)\n`
|
|
175
|
+
// 直接结束loader进入parse
|
|
176
|
+
this.loaderIndex = -1
|
|
177
|
+
return callback(null, output)
|
|
178
|
+
}
|
|
179
|
+
if (ctorType === 'page' && queryObj.tenon) {
|
|
180
|
+
console.log(resourcePath)
|
|
181
|
+
const request = addQuery(resourcePath, { page: true })
|
|
182
|
+
output += `
|
|
183
|
+
import page from ${stringifyRequest(request)}
|
|
184
|
+
import * as Tenon from '@hummer/tenon-vue'
|
|
185
|
+
|
|
186
|
+
Tenon.render(page)\n`
|
|
187
|
+
this.loaderIndex = -1
|
|
188
|
+
return callback(null, output)
|
|
189
|
+
}
|
|
190
|
+
return processForTenon({
|
|
191
|
+
mpx,
|
|
192
|
+
loaderContext,
|
|
193
|
+
isProduction,
|
|
194
|
+
queryObj,
|
|
195
|
+
filePath,
|
|
196
|
+
parts,
|
|
197
|
+
ctorType,
|
|
198
|
+
autoScope,
|
|
199
|
+
componentsMap,
|
|
200
|
+
projectRoot,
|
|
201
|
+
getRequireForSrc,
|
|
202
|
+
vueContentCache,
|
|
203
|
+
moduleId,
|
|
204
|
+
callback
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
166
208
|
// 处理mode为web时输出vue格式文件
|
|
167
209
|
if (mode === 'web') {
|
|
168
210
|
if (ctorType === 'app' && !queryObj.app) {
|
|
@@ -300,8 +342,7 @@ module.exports = function (content) {
|
|
|
300
342
|
// 注入构造函数
|
|
301
343
|
let ctor = 'App'
|
|
302
344
|
if (ctorType === 'page') {
|
|
303
|
-
|
|
304
|
-
if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan') {
|
|
345
|
+
if (mpx.forceUsePageCtor || mode === 'ali') {
|
|
305
346
|
ctor = 'Page'
|
|
306
347
|
} else {
|
|
307
348
|
ctor = 'Component'
|
package/lib/path-loader.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
module.exports = function () {
|
|
2
|
-
return `
|
|
2
|
+
return `
|
|
3
|
+
var currentURL = global.currentPagePath
|
|
4
|
+
var getRelativePath = require('@mpxjs/webpack-plugin/lib/utils/get-relative-path').getRelativePath
|
|
5
|
+
module.exports = __mpx_resolve_path__(${JSON.stringify(this.resource)})`
|
|
3
6
|
}
|
|
@@ -28,6 +28,8 @@ module.exports = function ({ print }) {
|
|
|
28
28
|
const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })
|
|
29
29
|
const webPropLog = print({ platform: 'web', tag: TAG_NAME, isError: false })
|
|
30
30
|
const webEventLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'event' })
|
|
31
|
+
const tenonPropLog = print({ platform: 'tenon', tag: TAG_NAME, isError: false })
|
|
32
|
+
const tenonEventLog = print({ platform: 'tenon', tag: TAG_NAME, isError: false, type: 'event' })
|
|
31
33
|
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
|
|
32
34
|
const wxPropValueLog = print({ platform: 'wx', tag: TAG_NAME, isError: false, type: 'value' })
|
|
33
35
|
|
|
@@ -37,6 +39,10 @@ module.exports = function ({ print }) {
|
|
|
37
39
|
el.isBuiltIn = true
|
|
38
40
|
return 'mpx-button'
|
|
39
41
|
},
|
|
42
|
+
tenon (tag, { el }) {
|
|
43
|
+
el.isBuiltIn = true
|
|
44
|
+
return 'tenon-button'
|
|
45
|
+
},
|
|
40
46
|
props: [
|
|
41
47
|
{
|
|
42
48
|
test: 'open-type',
|
|
@@ -131,13 +137,18 @@ module.exports = function ({ print }) {
|
|
|
131
137
|
},
|
|
132
138
|
{
|
|
133
139
|
test: /^(open-type|lang|session-from|send-message-title|send-message-path|send-message-img|show-message-card|app-parameter)$/,
|
|
134
|
-
web: webPropLog
|
|
140
|
+
web: webPropLog,
|
|
141
|
+
tenon: tenonPropLog
|
|
135
142
|
},
|
|
136
143
|
{
|
|
137
144
|
test: /^(size|type|plain|loading|form-type|hover-class|hover-stop-propagation|hover-start-time|hover-stay-time|use-built-in)$/,
|
|
138
145
|
web (prop, { el }) {
|
|
139
146
|
// todo 这部分能力基于内部封装实现
|
|
140
147
|
el.isBuiltIn = true
|
|
148
|
+
},
|
|
149
|
+
tenon (prop, { el }) {
|
|
150
|
+
// todo 这部分能力基于内部封装实现
|
|
151
|
+
el.isBuiltIn = true
|
|
141
152
|
}
|
|
142
153
|
},
|
|
143
154
|
{
|
|
@@ -174,7 +185,8 @@ module.exports = function ({ print }) {
|
|
|
174
185
|
},
|
|
175
186
|
{
|
|
176
187
|
test: /^(getuserinfo|contact|error|launchapp|opensetting|getphonenumber)$/,
|
|
177
|
-
web: webEventLog
|
|
188
|
+
web: webEventLog,
|
|
189
|
+
tenon: tenonEventLog
|
|
178
190
|
}
|
|
179
191
|
]
|
|
180
192
|
}
|
|
@@ -20,6 +20,10 @@ module.exports = function ({ print }) {
|
|
|
20
20
|
el.isBuiltIn = true
|
|
21
21
|
return 'mpx-input'
|
|
22
22
|
},
|
|
23
|
+
tenon (tag, { el }) {
|
|
24
|
+
el.isBuiltIn = true
|
|
25
|
+
return 'tenon-input'
|
|
26
|
+
},
|
|
23
27
|
props: [
|
|
24
28
|
{
|
|
25
29
|
test: /^(cursor-spacing|auto-focus|adjust-position|hold-keyboard)$/,
|
|
@@ -19,6 +19,10 @@ module.exports = function ({ print }) {
|
|
|
19
19
|
el.isBuiltIn = true
|
|
20
20
|
return 'mpx-scroll-view'
|
|
21
21
|
},
|
|
22
|
+
tenon (tag, { el }) {
|
|
23
|
+
el.isBuiltIn = true
|
|
24
|
+
return 'tenon-scroll-view'
|
|
25
|
+
},
|
|
22
26
|
props: [
|
|
23
27
|
{
|
|
24
28
|
test: /^(enable-flex|scroll-anchorin|refresher-enabled|refresher-threshold|refresher-default-style|refresher-background|refresher-triggered|enhanced|bounces|show-scrollbar|paging-enabled|fast-deceleratio)$/,
|
|
@@ -22,6 +22,11 @@ module.exports = function ({ print }) {
|
|
|
22
22
|
el.isBuiltIn = true
|
|
23
23
|
return 'mpx-textarea'
|
|
24
24
|
},
|
|
25
|
+
tenon (tag, { el }) {
|
|
26
|
+
// form全量使用内建组件
|
|
27
|
+
el.isBuiltIn = true
|
|
28
|
+
return 'tenon-textarea'
|
|
29
|
+
},
|
|
25
30
|
props: [
|
|
26
31
|
{
|
|
27
32
|
test: /^(auto-focus|fixed|cursor-spacing|cursor|show-confirm-bar|selection-start|selection-end|adjust-position|hold-keyboard|disable-default-padding|confirm-type)$/,
|
|
@@ -10,7 +10,7 @@ const normalize = require('../../../utils/normalize')
|
|
|
10
10
|
|
|
11
11
|
module.exports = function getSpec ({ warn, error }) {
|
|
12
12
|
const spec = {
|
|
13
|
-
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd'],
|
|
13
|
+
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'tenon'],
|
|
14
14
|
// props预处理
|
|
15
15
|
preProps: [],
|
|
16
16
|
// props后处理
|
|
@@ -24,6 +24,15 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
24
24
|
value: parsed.result
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
},
|
|
28
|
+
tenon ({ name, value }) {
|
|
29
|
+
const parsed = parseMustache(value)
|
|
30
|
+
if (parsed.hasBinding) {
|
|
31
|
+
return {
|
|
32
|
+
name: name === 'animation' ? 'v-' + name : ':' + name,
|
|
33
|
+
value: parsed.result
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
38
|
],
|
|
@@ -86,6 +95,16 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
86
95
|
name: 'v-for',
|
|
87
96
|
value: `(${itemName}, ${indexName}) in ${parsed.result}`
|
|
88
97
|
}
|
|
98
|
+
},
|
|
99
|
+
tenon ({ value }, { el }) {
|
|
100
|
+
const parsed = parseMustache(value)
|
|
101
|
+
const attrsMap = el.attrsMap
|
|
102
|
+
const itemName = attrsMap['wx:for-item'] || 'item'
|
|
103
|
+
const indexName = attrsMap['wx:for-index'] || 'index'
|
|
104
|
+
return {
|
|
105
|
+
name: 'v-for',
|
|
106
|
+
value: `(${itemName}, ${indexName}) in ${parsed.result}`
|
|
107
|
+
}
|
|
89
108
|
}
|
|
90
109
|
},
|
|
91
110
|
{
|
|
@@ -111,6 +130,25 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
111
130
|
name: ':key',
|
|
112
131
|
value
|
|
113
132
|
}
|
|
133
|
+
},
|
|
134
|
+
tenon ({ value }, { el }) {
|
|
135
|
+
// vue的template中不能包含key,对应于小程序中的block
|
|
136
|
+
if (el.tag === 'block') return false
|
|
137
|
+
const itemName = el.attrsMap['wx:for-item'] || 'item'
|
|
138
|
+
const keyName = value
|
|
139
|
+
if (value === '*this') {
|
|
140
|
+
value = itemName
|
|
141
|
+
} else {
|
|
142
|
+
if (isValidIdentifierStr(keyName)) {
|
|
143
|
+
value = `${itemName}.${keyName}`
|
|
144
|
+
} else {
|
|
145
|
+
value = `${itemName}['${keyName}']`
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
name: ':key',
|
|
150
|
+
value
|
|
151
|
+
}
|
|
114
152
|
}
|
|
115
153
|
},
|
|
116
154
|
{
|
|
@@ -121,6 +159,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
121
159
|
},
|
|
122
160
|
web () {
|
|
123
161
|
return false
|
|
162
|
+
},
|
|
163
|
+
tenon () {
|
|
164
|
+
return false
|
|
124
165
|
}
|
|
125
166
|
},
|
|
126
167
|
{
|
|
@@ -163,6 +204,45 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
163
204
|
}
|
|
164
205
|
]
|
|
165
206
|
}
|
|
207
|
+
},
|
|
208
|
+
tenon ({ value }, { el }) {
|
|
209
|
+
el.hasEvent = true
|
|
210
|
+
const attrsMap = el.attrsMap
|
|
211
|
+
const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
|
|
212
|
+
const stringify = JSON.stringify
|
|
213
|
+
const match = tagRE.exec(value)
|
|
214
|
+
if (match) {
|
|
215
|
+
const modelProp = attrsMap['wx:model-prop'] || 'value'
|
|
216
|
+
const modelEvent = attrsMap['wx:model-event'] || 'input'
|
|
217
|
+
const modelValuePathRaw = attrsMap['wx:model-value-path']
|
|
218
|
+
const modelValuePath = modelValuePathRaw === undefined ? 'value' : modelValuePathRaw
|
|
219
|
+
const modelFilter = attrsMap['wx:model-filter']
|
|
220
|
+
let modelValuePathArr
|
|
221
|
+
try {
|
|
222
|
+
modelValuePathArr = JSON5.parse(modelValuePath)
|
|
223
|
+
} catch (e) {
|
|
224
|
+
if (modelValuePath === '') {
|
|
225
|
+
modelValuePathArr = []
|
|
226
|
+
} else {
|
|
227
|
+
modelValuePathArr = modelValuePath.split('.')
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
let modelValue = match[1].trim()
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
name: ':' + modelProp,
|
|
234
|
+
value: modelValue
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'mpxModelEvent',
|
|
238
|
+
value: modelEvent
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: '@mpxModel',
|
|
242
|
+
value: `__model(${stringifyWithResolveComputed(modelValue)}, $event, ${stringify(modelValuePathArr)}, ${stringify(modelFilter)})`
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
166
246
|
}
|
|
167
247
|
},
|
|
168
248
|
{
|
|
@@ -191,6 +271,14 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
191
271
|
name: ':' + dir,
|
|
192
272
|
value: parsed.result
|
|
193
273
|
}
|
|
274
|
+
},
|
|
275
|
+
tenon ({ name, value }) {
|
|
276
|
+
const dir = this.test.exec(name)[1]
|
|
277
|
+
const parsed = parseMustache(value)
|
|
278
|
+
return {
|
|
279
|
+
name: ':' + dir,
|
|
280
|
+
value: parsed.result
|
|
281
|
+
}
|
|
194
282
|
}
|
|
195
283
|
},
|
|
196
284
|
// 通用指令
|
|
@@ -248,6 +336,17 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
248
336
|
name: 'v-' + dir,
|
|
249
337
|
value: parsed.result
|
|
250
338
|
}
|
|
339
|
+
},
|
|
340
|
+
tenon ({ name, value }) {
|
|
341
|
+
let dir = this.test.exec(name)[1]
|
|
342
|
+
const parsed = parseMustache(value)
|
|
343
|
+
if (dir === 'elif') {
|
|
344
|
+
dir = 'else-if'
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
name: 'v-' + dir,
|
|
348
|
+
value: parsed.result
|
|
349
|
+
}
|
|
251
350
|
}
|
|
252
351
|
},
|
|
253
352
|
// 事件
|
|
@@ -288,6 +387,23 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
288
387
|
name: rPrefix + rEventName + meta.modifierStr,
|
|
289
388
|
value
|
|
290
389
|
}
|
|
390
|
+
},
|
|
391
|
+
tenon ({ name, value }, { eventRules, el }) {
|
|
392
|
+
const match = this.test.exec(name)
|
|
393
|
+
const prefix = match[1]
|
|
394
|
+
const eventName = match[2]
|
|
395
|
+
const modifierStr = match[3] || ''
|
|
396
|
+
const meta = {
|
|
397
|
+
modifierStr
|
|
398
|
+
}
|
|
399
|
+
// 记录event监听信息用于后续判断是否需要使用内置基础组件
|
|
400
|
+
el.hasEvent = true
|
|
401
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'web', meta })
|
|
402
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'web' })
|
|
403
|
+
return {
|
|
404
|
+
name: rPrefix + rEventName + meta.modifierStr,
|
|
405
|
+
value
|
|
406
|
+
}
|
|
291
407
|
}
|
|
292
408
|
},
|
|
293
409
|
// 无障碍
|