UNPKG

2.01 kBJavaScriptView Raw
1/**
2* vue v3.4.25
3* (c) 2018-present Yuxi (Evan) You and Vue contributors
4* @license MIT
5**/
6'use strict';
7
8Object.defineProperty(exports, '__esModule', { value: true });
9
10var compilerDom = require('@vue/compiler-dom');
11var runtimeDom = require('@vue/runtime-dom');
12var shared = require('@vue/shared');
13
14function _interopNamespaceDefault(e) {
15 var n = Object.create(null);
16 if (e) {
17 for (var k in e) {
18 n[k] = e[k];
19 }
20 }
21 n.default = e;
22 return Object.freeze(n);
23}
24
25var runtimeDom__namespace = /*#__PURE__*/_interopNamespaceDefault(runtimeDom);
26
27const compileCache = /* @__PURE__ */ new WeakMap();
28function getCache(options) {
29 let c = compileCache.get(options != null ? options : shared.EMPTY_OBJ);
30 if (!c) {
31 c = /* @__PURE__ */ Object.create(null);
32 compileCache.set(options != null ? options : shared.EMPTY_OBJ, c);
33 }
34 return c;
35}
36function compileToFunction(template, options) {
37 if (!shared.isString(template)) {
38 if (template.nodeType) {
39 template = template.innerHTML;
40 } else {
41 return shared.NOOP;
42 }
43 }
44 const key = template;
45 const cache = getCache(options);
46 const cached = cache[key];
47 if (cached) {
48 return cached;
49 }
50 if (template[0] === "#") {
51 const el = document.querySelector(template);
52 template = el ? el.innerHTML : ``;
53 }
54 const opts = shared.extend(
55 {
56 hoistStatic: true,
57 onError: void 0,
58 onWarn: shared.NOOP
59 },
60 options
61 );
62 if (!opts.isCustomElement && typeof customElements !== "undefined") {
63 opts.isCustomElement = (tag) => !!customElements.get(tag);
64 }
65 const { code } = compilerDom.compile(template, opts);
66 const render = new Function("Vue", code)(runtimeDom__namespace);
67 render._rc = true;
68 return cache[key] = render;
69}
70runtimeDom.registerRuntimeCompiler(compileToFunction);
71
72exports.compile = compileToFunction;
73Object.keys(runtimeDom).forEach(function (k) {
74 if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
75});