UNPKG

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