index.js
1.17 KB
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
/* @flow */
import { genStaticKeys } from 'shared/util'
import { createCompiler } from 'compiler/index'
import modules from './modules/index'
import directives from './directives/index'
import {
isUnaryTag,
mustUseProp,
isReservedTag,
canBeLeftOpenTag,
getTagNamespace
} from '../util/element'
export const baseOptions: WeexCompilerOptions = {
modules,
directives,
isUnaryTag,
mustUseProp,
canBeLeftOpenTag,
isReservedTag,
getTagNamespace,
preserveWhitespace: false,
recyclable: false,
staticKeys: genStaticKeys(modules)
}
const compiler = createCompiler(baseOptions)
export function compile (
template: string,
options?: WeexCompilerOptions
): WeexCompiledResult {
let generateAltRender = false
if (options && options.recyclable === true) {
generateAltRender = true
options.recyclable = false
}
const result = compiler.compile(template, options)
// generate @render function for <recycle-list>
if (options && generateAltRender) {
options.recyclable = true
// disable static optimizations
options.optimize = false
const { render } = compiler.compile(template, options)
result['@render'] = render
}
return result
}