|
1 | | -import config from 'core/config' |
2 | | -import { warn, cached } from 'core/util/index' |
3 | | -import { mark, measure } from 'core/util/perf' |
| 1 | +import Vue from './runtime-with-compiler' |
| 2 | +import * as vca from 'vca/index' |
| 3 | +import { extend } from 'shared/util' |
4 | 4 |
|
5 | | -import Vue from './runtime/index' |
6 | | -import { query } from './util/index' |
7 | | -import { compileToFunctions } from './compiler/index' |
8 | | -import { |
9 | | - shouldDecodeNewlines, |
10 | | - shouldDecodeNewlinesForHref |
11 | | -} from './util/compat' |
12 | | -import type { Component } from 'typescript/component' |
13 | | -import type { GlobalAPI } from 'typescript/global-api' |
| 5 | +extend(Vue, vca) |
14 | 6 |
|
15 | | -const idToTemplate = cached(id => { |
16 | | - const el = query(id) |
17 | | - return el && el.innerHTML |
18 | | -}) |
19 | | - |
20 | | -const mount = Vue.prototype.$mount |
21 | | -Vue.prototype.$mount = function ( |
22 | | - el?: string | Element, |
23 | | - hydrating?: boolean |
24 | | -): Component { |
25 | | - el = el && query(el) |
26 | | - |
27 | | - /* istanbul ignore if */ |
28 | | - if (el === document.body || el === document.documentElement) { |
29 | | - __DEV__ && |
30 | | - warn( |
31 | | - `Do not mount Vue to <html> or <body> - mount to normal elements instead.` |
32 | | - ) |
33 | | - return this |
34 | | - } |
35 | | - |
36 | | - const options = this.$options |
37 | | - // resolve template/el and convert to render function |
38 | | - if (!options.render) { |
39 | | - let template = options.template |
40 | | - if (template) { |
41 | | - if (typeof template === 'string') { |
42 | | - if (template.charAt(0) === '#') { |
43 | | - template = idToTemplate(template) |
44 | | - /* istanbul ignore if */ |
45 | | - if (__DEV__ && !template) { |
46 | | - warn( |
47 | | - `Template element not found or is empty: ${options.template}`, |
48 | | - this |
49 | | - ) |
50 | | - } |
51 | | - } |
52 | | - } else if (template.nodeType) { |
53 | | - template = template.innerHTML |
54 | | - } else { |
55 | | - if (__DEV__) { |
56 | | - warn('invalid template option:' + template, this) |
57 | | - } |
58 | | - return this |
59 | | - } |
60 | | - } else if (el) { |
61 | | - // @ts-expect-error |
62 | | - template = getOuterHTML(el) |
63 | | - } |
64 | | - if (template) { |
65 | | - /* istanbul ignore if */ |
66 | | - if (__DEV__ && config.performance && mark) { |
67 | | - mark('compile') |
68 | | - } |
69 | | - |
70 | | - const { render, staticRenderFns } = compileToFunctions( |
71 | | - template, |
72 | | - { |
73 | | - outputSourceRange: __DEV__, |
74 | | - shouldDecodeNewlines, |
75 | | - shouldDecodeNewlinesForHref, |
76 | | - delimiters: options.delimiters, |
77 | | - comments: options.comments |
78 | | - }, |
79 | | - this |
80 | | - ) |
81 | | - options.render = render |
82 | | - options.staticRenderFns = staticRenderFns |
83 | | - |
84 | | - /* istanbul ignore if */ |
85 | | - if (__DEV__ && config.performance && mark) { |
86 | | - mark('compile end') |
87 | | - measure(`vue ${this._name} compile`, 'compile', 'compile end') |
88 | | - } |
89 | | - } |
90 | | - } |
91 | | - return mount.call(this, el, hydrating) |
92 | | -} |
93 | | - |
94 | | -/** |
95 | | - * Get outerHTML of elements, taking care |
96 | | - * of SVG elements in IE as well. |
97 | | - */ |
98 | | -function getOuterHTML(el: Element): string { |
99 | | - if (el.outerHTML) { |
100 | | - return el.outerHTML |
101 | | - } else { |
102 | | - const container = document.createElement('div') |
103 | | - container.appendChild(el.cloneNode(true)) |
104 | | - return container.innerHTML |
105 | | - } |
106 | | -} |
107 | | - |
108 | | -Vue.compile = compileToFunctions |
109 | | - |
110 | | -export default Vue as GlobalAPI |
| 7 | +export default Vue |
0 commit comments