Skip to content

Commit e1e5a75

Browse files
committed
wip: fix entry with compiler
1 parent f50a1b8 commit e1e5a75

File tree

3 files changed

+116
-109
lines changed

3 files changed

+116
-109
lines changed

src/platforms/web/entry-runtime-with-compiler-esm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from './entry-runtime-with-compiler'
1+
import Vue from './runtime-with-compiler'
22

33
export default Vue
44

Lines changed: 5 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,7 @@
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'
44

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)
146

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
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import config from 'core/config'
2+
import { warn, cached } from 'core/util/index'
3+
import { mark, measure } from 'core/util/perf'
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'
14+
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

0 commit comments

Comments
 (0)