2019-09-16 15:06:45 -04:00
|
|
|
// This package is the "full-build" that includes both the runtime
|
2019-09-20 00:24:16 -04:00
|
|
|
// and the compiler, and supports on-the-fly compilation of the template option.
|
2019-09-20 12:16:19 -04:00
|
|
|
import { compile, CompilerOptions } from '@vue/compiler-dom'
|
2019-12-01 23:09:34 -05:00
|
|
|
import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
|
2019-10-11 11:16:20 -04:00
|
|
|
import * as runtimeDom from '@vue/runtime-dom'
|
2019-12-01 23:09:34 -05:00
|
|
|
import { isString, NOOP } from '@vue/shared'
|
|
|
|
|
|
|
|
const idToTemplateCache = Object.create(null)
|
2019-09-20 00:12:37 -04:00
|
|
|
|
2019-09-20 12:16:19 -04:00
|
|
|
function compileToFunction(
|
2019-12-01 23:09:34 -05:00
|
|
|
template: string | HTMLElement,
|
2019-09-20 12:16:19 -04:00
|
|
|
options?: CompilerOptions
|
|
|
|
): RenderFunction {
|
2019-12-01 23:09:34 -05:00
|
|
|
if (isString(template)) {
|
|
|
|
if (template[0] === '#') {
|
|
|
|
if (template in idToTemplateCache) {
|
|
|
|
template = idToTemplateCache[template]
|
|
|
|
} else {
|
|
|
|
const el = document.querySelector(template)
|
|
|
|
if (__DEV__ && !el) {
|
|
|
|
warn(`Template element not found or is empty: ${template}`)
|
|
|
|
}
|
|
|
|
template = idToTemplateCache[template] = el ? el.innerHTML : ``
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (template.nodeType) {
|
|
|
|
template = template.innerHTML
|
|
|
|
} else {
|
|
|
|
__DEV__ && warn(`invalid template option: `, template)
|
|
|
|
return NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
const { code } = compile(template as string, {
|
2019-10-04 09:03:00 -04:00
|
|
|
hoistStatic: true,
|
2019-12-01 23:09:34 -05:00
|
|
|
cacheHandlers: true,
|
2019-10-03 23:30:25 -04:00
|
|
|
...options
|
|
|
|
})
|
2019-10-11 11:16:20 -04:00
|
|
|
|
2019-12-10 11:14:29 -05:00
|
|
|
const render = new Function('Vue', code)(runtimeDom) as RenderFunction
|
|
|
|
render.isRuntimeCompiled = true
|
|
|
|
return render
|
2019-09-20 00:12:37 -04:00
|
|
|
}
|
|
|
|
|
2019-09-20 12:16:19 -04:00
|
|
|
registerRuntimeCompiler(compileToFunction)
|
2019-09-20 00:24:16 -04:00
|
|
|
|
2019-09-20 12:16:19 -04:00
|
|
|
export { compileToFunction as compile }
|
2018-10-26 15:44:50 -04:00
|
|
|
export * from '@vue/runtime-dom'
|
2019-09-03 20:51:42 -04:00
|
|
|
|
2019-09-17 11:57:25 -04:00
|
|
|
if (__BROWSER__ && __DEV__) {
|
2019-09-03 20:51:42 -04:00
|
|
|
console[console.info ? 'info' : 'log'](
|
|
|
|
`You are running a development build of Vue.\n` +
|
|
|
|
`Make sure to use the production build (*.prod.js) when deploying for production.`
|
|
|
|
)
|
|
|
|
}
|