1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | Object.defineProperty(exports, '__esModule', { value: true });
|
9 |
|
10 | var compilerDom = require('@vue/compiler-dom');
|
11 | var runtimeDom = require('@vue/runtime-dom');
|
12 | var shared = require('@vue/shared');
|
13 |
|
14 | function _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 |
|
25 | var runtimeDom__namespace = _interopNamespaceDefault(runtimeDom);
|
26 |
|
27 | const compileCache = new WeakMap();
|
28 | function getCache(options) {
|
29 | let c = compileCache.get(options != null ? options : shared.EMPTY_OBJ);
|
30 | if (!c) {
|
31 | c = Object.create(null);
|
32 | compileCache.set(options != null ? options : shared.EMPTY_OBJ, c);
|
33 | }
|
34 | return c;
|
35 | }
|
36 | function 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 | }
|
84 | runtimeDom.registerRuntimeCompiler(compileToFunction);
|
85 |
|
86 | exports.compile = compileToFunction;
|
87 | Object.keys(runtimeDom).forEach(function (k) {
|
88 | if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
|
89 | });
|