UNPKG

2.15 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var compilerDom = require('@vue/compiler-dom');
6var runtimeDom = require('@vue/runtime-dom');
7var shared = require('@vue/shared');
8
9function _interopNamespace(e) {
10 if (e && e.__esModule) return e;
11 var n = Object.create(null);
12 if (e) {
13 Object.keys(e).forEach(function (k) {
14 n[k] = e[k];
15 });
16 }
17 n['default'] = e;
18 return Object.freeze(n);
19}
20
21var runtimeDom__namespace = /*#__PURE__*/_interopNamespace(runtimeDom);
22
23// This entry is the "full-build" that includes both the runtime
24const compileCache = Object.create(null);
25function compileToFunction(template, options) {
26 if (!shared.isString(template)) {
27 if (template.nodeType) {
28 template = template.innerHTML;
29 }
30 else {
31 return shared.NOOP;
32 }
33 }
34 const key = template;
35 const cached = compileCache[key];
36 if (cached) {
37 return cached;
38 }
39 if (template[0] === '#') {
40 const el = document.querySelector(template);
41 // __UNSAFE__
42 // Reason: potential execution of JS expressions in in-DOM template.
43 // The user must make sure the in-DOM template is trusted. If it's rendered
44 // by the server, the template should not contain any user data.
45 template = el ? el.innerHTML : ``;
46 }
47 const { code } = compilerDom.compile(template, shared.extend({
48 hoistStatic: true,
49 onError: undefined,
50 onWarn: shared.NOOP
51 }, options));
52 // The wildcard import results in a huge object with every export
53 // with keys that cannot be mangled, and can be quite heavy size-wise.
54 // In the global build we know `Vue` is available globally so we can avoid
55 // the wildcard object.
56 const render = (new Function('Vue', code)(runtimeDom__namespace));
57 render._rc = true;
58 return (compileCache[key] = render);
59}
60runtimeDom.registerRuntimeCompiler(compileToFunction);
61
62Object.keys(runtimeDom).forEach(function (k) {
63 if (k !== 'default') exports[k] = runtimeDom[k];
64});
65exports.compile = compileToFunction;