UNPKG

2.3 kBJavaScriptView Raw
1/**
2* vue v3.5.13
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__ */ Object.create(null);
28function compileToFunction(template, options) {
29 if (!shared.isString(template)) {
30 if (template.nodeType) {
31 template = template.innerHTML;
32 } else {
33 runtimeDom.warn(`invalid template option: `, template);
34 return shared.NOOP;
35 }
36 }
37 const key = shared.genCacheKey(template, options);
38 const cached = compileCache[key];
39 if (cached) {
40 return cached;
41 }
42 if (template[0] === "#") {
43 const el = document.querySelector(template);
44 if (!el) {
45 runtimeDom.warn(`Template element not found or is empty: ${template}`);
46 }
47 template = el ? el.innerHTML : ``;
48 }
49 const opts = shared.extend(
50 {
51 hoistStatic: true,
52 onError: onError ,
53 onWarn: (e) => onError(e, true)
54 },
55 options
56 );
57 if (!opts.isCustomElement && typeof customElements !== "undefined") {
58 opts.isCustomElement = (tag) => !!customElements.get(tag);
59 }
60 const { code } = compilerDom.compile(template, opts);
61 function onError(err, asWarning = false) {
62 const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
63 const codeFrame = err.loc && shared.generateCodeFrame(
64 template,
65 err.loc.start.offset,
66 err.loc.end.offset
67 );
68 runtimeDom.warn(codeFrame ? `${message}
69${codeFrame}` : message);
70 }
71 const render = new Function("Vue", code)(runtimeDom__namespace);
72 render._rc = true;
73 return compileCache[key] = render;
74}
75runtimeDom.registerRuntimeCompiler(compileToFunction);
76
77exports.compile = compileToFunction;
78Object.keys(runtimeDom).forEach(function (k) {
79 if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
80});