1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var compilerDom = require('@vue/compiler-dom');
|
6 | var runtimeDom = require('@vue/runtime-dom');
|
7 | var shared = require('@vue/shared');
|
8 |
|
9 | function _interopNamespace(e) {
|
10 | if (e && e.__esModule) return e;
|
11 | var n = Object.create(null);
|
12 | if (e) {
|
13 | Object.keys(e).forEach(function (k) {
|
14 | n[k] = e[k];
|
15 | });
|
16 | }
|
17 | n['default'] = e;
|
18 | return Object.freeze(n);
|
19 | }
|
20 |
|
21 | var runtimeDom__namespace = _interopNamespace(runtimeDom);
|
22 |
|
23 |
|
24 | const compileCache = Object.create(null);
|
25 | function compileToFunction(template, options) {
|
26 | if (!shared.isString(template)) {
|
27 | if (template.nodeType) {
|
28 | template = template.innerHTML;
|
29 | }
|
30 | else {
|
31 | runtimeDom.warn(`invalid template option: `, template);
|
32 | return shared.NOOP;
|
33 | }
|
34 | }
|
35 | const key = template;
|
36 | const cached = compileCache[key];
|
37 | if (cached) {
|
38 | return cached;
|
39 | }
|
40 | if (template[0] === '#') {
|
41 | const el = document.querySelector(template);
|
42 | if (!el) {
|
43 | runtimeDom.warn(`Template element not found or is empty: ${template}`);
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | template = el ? el.innerHTML : ``;
|
50 | }
|
51 | const { code } = compilerDom.compile(template, shared.extend({
|
52 | hoistStatic: true,
|
53 | onError(err) {
|
54 | {
|
55 | const message = `Template compilation error: ${err.message}`;
|
56 | const codeFrame = err.loc &&
|
57 | shared.generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
|
58 | runtimeDom.warn(codeFrame ? `${message}\n${codeFrame}` : message);
|
59 | }
|
60 | }
|
61 | }, options));
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | const render = (new Function('Vue', code)(runtimeDom__namespace));
|
67 | render._rc = true;
|
68 | return (compileCache[key] = render);
|
69 | }
|
70 | runtimeDom.registerRuntimeCompiler(compileToFunction);
|
71 |
|
72 | Object.keys(runtimeDom).forEach(function (k) {
|
73 | if (k !== 'default') exports[k] = runtimeDom[k];
|
74 | });
|
75 | exports.compile = compileToFunction;
|