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 | return shared.NOOP;
|
42 | }
|
43 | }
|
44 | const key = template;
|
45 | const cache = getCache(options);
|
46 | const cached = cache[key];
|
47 | if (cached) {
|
48 | return cached;
|
49 | }
|
50 | if (template[0] === "#") {
|
51 | const el = document.querySelector(template);
|
52 | template = el ? el.innerHTML : ``;
|
53 | }
|
54 | const opts = shared.extend(
|
55 | {
|
56 | hoistStatic: true,
|
57 | onError: void 0,
|
58 | onWarn: shared.NOOP
|
59 | },
|
60 | options
|
61 | );
|
62 | if (!opts.isCustomElement && typeof customElements !== "undefined") {
|
63 | opts.isCustomElement = (tag) => !!customElements.get(tag);
|
64 | }
|
65 | const { code } = compilerDom.compile(template, opts);
|
66 | const render = new Function("Vue", code)(runtimeDom__namespace);
|
67 | render._rc = true;
|
68 | return cache[key] = render;
|
69 | }
|
70 | runtimeDom.registerRuntimeCompiler(compileToFunction);
|
71 |
|
72 | exports.compile = compileToFunction;
|
73 | Object.keys(runtimeDom).forEach(function (k) {
|
74 | if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
|
75 | });
|