UNPKG

2.53 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 runtimeDom.warn(`invalid template option: `, template);
42 return shared.NOOP;
43 }
44 }
45 const key = template;
46 const cache = getCache(options);
47 const cached = cache[key];
48 if (cached) {
49 return cached;
50 }
51 if (template[0] === "#") {
52 const el = document.querySelector(template);
53 if (!el) {
54 runtimeDom.warn(`Template element not found or is empty: ${template}`);
55 }
56 template = el ? el.innerHTML : ``;
57 }
58 const opts = shared.extend(
59 {
60 hoistStatic: true,
61 onError: onError ,
62 onWarn: (e) => onError(e, true)
63 },
64 options
65 );
66 if (!opts.isCustomElement && typeof customElements !== "undefined") {
67 opts.isCustomElement = (tag) => !!customElements.get(tag);
68 }
69 const { code } = compilerDom.compile(template, opts);
70 function onError(err, asWarning = false) {
71 const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
72 const codeFrame = err.loc && shared.generateCodeFrame(
73 template,
74 err.loc.start.offset,
75 err.loc.end.offset
76 );
77 runtimeDom.warn(codeFrame ? `${message}
78${codeFrame}` : message);
79 }
80 const render = new Function("Vue", code)(runtimeDom__namespace);
81 render._rc = true;
82 return cache[key] = render;
83}
84runtimeDom.registerRuntimeCompiler(compileToFunction);
85
86exports.compile = compileToFunction;
87Object.keys(runtimeDom).forEach(function (k) {
88 if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
89});