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 _interopNamespaceDefault(e) {
|
10 | var n = Object.create(null);
|
11 | if (e) {
|
12 | for (var k in e) {
|
13 | n[k] = e[k];
|
14 | }
|
15 | }
|
16 | n.default = e;
|
17 | return Object.freeze(n);
|
18 | }
|
19 |
|
20 | var runtimeDom__namespace = _interopNamespaceDefault(runtimeDom);
|
21 |
|
22 |
|
23 | const compileCache = Object.create(null);
|
24 | function compileToFunction(template, options) {
|
25 | if (!shared.isString(template)) {
|
26 | if (template.nodeType) {
|
27 | template = template.innerHTML;
|
28 | }
|
29 | else {
|
30 | runtimeDom.warn(`invalid template option: `, template);
|
31 | return shared.NOOP;
|
32 | }
|
33 | }
|
34 | const key = template;
|
35 | const cached = compileCache[key];
|
36 | if (cached) {
|
37 | return cached;
|
38 | }
|
39 | if (template[0] === '#') {
|
40 | const el = document.querySelector(template);
|
41 | if (!el) {
|
42 | runtimeDom.warn(`Template element not found or is empty: ${template}`);
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | template = el ? el.innerHTML : ``;
|
49 | }
|
50 | const opts = shared.extend({
|
51 | hoistStatic: true,
|
52 | onError: onError ,
|
53 | onWarn: e => onError(e, true)
|
54 | }, options);
|
55 | if (!opts.isCustomElement && typeof customElements !== 'undefined') {
|
56 | opts.isCustomElement = tag => !!customElements.get(tag);
|
57 | }
|
58 | const { code } = compilerDom.compile(template, opts);
|
59 | function onError(err, asWarning = false) {
|
60 | const message = asWarning
|
61 | ? err.message
|
62 | : `Template compilation error: ${err.message}`;
|
63 | const codeFrame = err.loc &&
|
64 | shared.generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
|
65 | runtimeDom.warn(codeFrame ? `${message}\n${codeFrame}` : message);
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | const render = (new Function('Vue', code)(runtimeDom__namespace));
|
72 | render._rc = true;
|
73 | return (compileCache[key] = render);
|
74 | }
|
75 | runtimeDom.registerRuntimeCompiler(compileToFunction);
|
76 |
|
77 | exports.compile = compileToFunction;
|
78 | Object.keys(runtimeDom).forEach(function(k) {
|
79 | if (k !== 'default') exports[k] = runtimeDom[k];
|
80 | });
|