1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| const {
| hyphenate,
| getPlatformCompiler
| } = require('@dcloudio/uni-cli-shared')
|
| const SRC_REGEX = /src="([^"]+)"/g
| module.exports = function compile (source, options) {
| const {
| compileToWxml,
| compileToTemplate
| } = getPlatformCompiler()
| if (typeof compileToWxml === 'function') {
| const components = {
| 'slots': {
| src: '/common/slots.wxml',
| name: 'slots'
| }
| }
|
| Object.keys(options.imports).forEach(name => {
| if (name !== '_slots_') {
| components[hyphenate(name)] = options.imports[name]
| }
| })
|
| const compiled = options.compiled
|
| const {
| code,
| // compiled,
| slots: mpvueSlots,
| importCode
| } = compileToWxml(compiled, {
| name: options.name,
| components,
| moduleId: options.scopeId || ('M' + options.name)
| })
|
| const deps = []
| if (importCode) {
| let match
| /* eslint-disable no-cond-assign */
| while (match = SRC_REGEX.exec(importCode)) {
| deps.push(match[1])
| }
| }
|
| const slots = Object.keys(mpvueSlots).map(slotName => {
| const slot = mpvueSlots[slotName]
| return {
| name: slot.name,
| slotName,
| body: slot.code,
| dependencies: deps
| }
| })
|
| return {
| body: code,
| slots,
| deps,
| mpvue: true
| }
| }
|
| return compileToTemplate(source, Object.assign(options, {
| htmlParse: {
| templateName: 'octoParse'
| }
| }))
| }
|
|