Compare commits
5 Commits
6493da5bfa
...
88be3a2749
Author | SHA1 | Date | |
---|---|---|---|
88be3a2749 | |||
05b8cc7469 | |||
|
f79c423621 | ||
|
c1375da45f | ||
|
6aaf8efeff |
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,3 +1,15 @@
|
||||
## [3.2.39](https://github.com/vuejs/core/compare/v3.2.38...v3.2.39) (2022-09-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **runtime-core:** avoid double firing when mounting inside a watcher callback ([6aaf8ef](https://github.com/vuejs/core/commit/6aaf8efefffdb0d4b93f178b2bb36cd3c6bc31b8)), closes [#6614](https://github.com/vuejs/core/issues/6614)
|
||||
* **runtime-core:** support extends template for runtime compiler ([#6250](https://github.com/vuejs/core/issues/6250)) ([9875ecd](https://github.com/vuejs/core/commit/9875ecd762155732008e397d450edb0f8c01b05c)), closes [#6249](https://github.com/vuejs/core/issues/6249)
|
||||
* **ssr:** reset current instance ([#6184](https://github.com/vuejs/core/issues/6184)) ([6493da5](https://github.com/vuejs/core/commit/6493da5bfa4624267248deb3d31dca2a4fb22aee)), closes [#6110](https://github.com/vuejs/core/issues/6110)
|
||||
* **types:** support TypeScript 4.8 ([5381abc](https://github.com/vuejs/core/commit/5381abc0571e58a9be6cf482dc50c8db8300f86c)), closes [#6554](https://github.com/vuejs/core/issues/6554)
|
||||
|
||||
|
||||
|
||||
## [3.2.38](https://github.com/vuejs/core/compare/v3.2.37...v3.2.38) (2022-08-30)
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"packageManager": "pnpm@7.1.0",
|
||||
"scripts": {
|
||||
"dev": "node scripts/dev.js",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/compiler-core",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/compiler-core",
|
||||
"main": "index.js",
|
||||
"module": "dist/compiler-core.esm-bundler.js",
|
||||
@ -32,7 +32,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/shared": "3.2.39",
|
||||
"@babel/parser": "^7.16.4",
|
||||
"estree-walker": "^2.0.2",
|
||||
"source-map": "^0.6.1"
|
||||
|
@ -65,6 +65,7 @@ export function baseCompile(
|
||||
const onError = options.onError || defaultOnError
|
||||
const isModuleMode = options.mode === 'module'
|
||||
/* istanbul ignore if */
|
||||
// 只要不是 dev onError 就是空函数
|
||||
if (__BROWSER__) {
|
||||
if (options.prefixIdentifiers === true) {
|
||||
onError(createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED))
|
||||
@ -81,7 +82,7 @@ export function baseCompile(
|
||||
if (options.scopeId && !isModuleMode) {
|
||||
onError(createCompilerError(ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED))
|
||||
}
|
||||
|
||||
// 给options 赋初始值 如果不是字符串 直接返回 template
|
||||
const ast = isString(template) ? baseParse(template, options) : template
|
||||
const [nodeTransforms, directiveTransforms] =
|
||||
getBaseTransformPreset(prefixIdentifiers)
|
||||
|
@ -67,17 +67,17 @@ const decodeMap: Record<string, string> = {
|
||||
}
|
||||
|
||||
export const defaultParserOptions: MergedParserOptions = {
|
||||
delimiters: [`{{`, `}}`],
|
||||
getNamespace: () => Namespaces.HTML,
|
||||
getTextMode: () => TextModes.DATA,
|
||||
isVoidTag: NO,
|
||||
isPreTag: NO,
|
||||
isCustomElement: NO,
|
||||
delimiters: [`{{`, `}}`], // 模板分割付
|
||||
getNamespace: () => Namespaces.HTML, // HTML
|
||||
getTextMode: () => TextModes.DATA, //DATA
|
||||
isVoidTag: NO, // 无效标签
|
||||
isPreTag: NO, // 是不是pre标签
|
||||
isCustomElement: NO, // 是不是自定义标签
|
||||
decodeEntities: (rawText: string): string =>
|
||||
rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
|
||||
rawText.replace(decodeRE, (_, p1) => decodeMap[p1]), // 讲实体字符转换成字符串
|
||||
onError: defaultOnError,
|
||||
onWarn: defaultOnWarn,
|
||||
comments: __DEV__
|
||||
comments: __DEV__ // ???
|
||||
}
|
||||
|
||||
export const enum TextModes {
|
||||
@ -105,8 +105,11 @@ export function baseParse(
|
||||
content: string,
|
||||
options: ParserOptions = {}
|
||||
): RootNode {
|
||||
// 给options 覆初始值 没有的属性都赋值进去
|
||||
const context = createParserContext(content, options)
|
||||
// 貌似获取的是固定的
|
||||
const start = getCursor(context)
|
||||
// create root
|
||||
return createRoot(
|
||||
parseChildren(context, TextModes.DATA, []),
|
||||
getSelection(context, start)
|
||||
@ -117,15 +120,12 @@ function createParserContext(
|
||||
content: string,
|
||||
rawOptions: ParserOptions
|
||||
): ParserContext {
|
||||
const options = extend({}, defaultParserOptions)
|
||||
|
||||
const options = extend({}, defaultParserOptions) // 这一行将所有defaultParserOptions属性复制给options
|
||||
// 如果对象属性没有 讲使用默认的 defaultParserOptions
|
||||
let key: keyof ParserOptions
|
||||
for (key in rawOptions) {
|
||||
// @ts-ignore
|
||||
options[key] =
|
||||
rawOptions[key] === undefined
|
||||
? defaultParserOptions[key]
|
||||
: rawOptions[key]
|
||||
options[key] = rawOptions[key] === undefined ? defaultParserOptions[key] : rawOptions[key] // 当rawOptions key值是undefined的时候 给defaultParserOptionsde的值 不是unidentified 给 rawOptions的值
|
||||
}
|
||||
return {
|
||||
options,
|
||||
@ -139,24 +139,27 @@ function createParserContext(
|
||||
onWarn: options.onWarn
|
||||
}
|
||||
}
|
||||
|
||||
// 解析标签
|
||||
// ancestors 默认是空数组
|
||||
function parseChildren(
|
||||
context: ParserContext,
|
||||
mode: TextModes,
|
||||
ancestors: ElementNode[]
|
||||
): TemplateChildNode[] {
|
||||
// ancestors 获取最后一个元素 默认undefined
|
||||
// mode DATA
|
||||
const parent = last(ancestors)
|
||||
const ns = parent ? parent.ns : Namespaces.HTML
|
||||
const nodes: TemplateChildNode[] = []
|
||||
|
||||
const ns = parent ? parent.ns : Namespaces.HTML // 如果有 就取ns 没有 HTML ?
|
||||
const nodes: TemplateChildNode[] = [] // ??创建列表
|
||||
// 判断是不是结束标签
|
||||
while (!isEnd(context, mode, ancestors)) {
|
||||
__TEST__ && assert(context.source.length > 0)
|
||||
const s = context.source
|
||||
const s = context.source // html 代码
|
||||
let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined
|
||||
|
||||
if (mode === TextModes.DATA || mode === TextModes.RCDATA) {
|
||||
if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
|
||||
// '{{'
|
||||
// 判断是不是'{{' 开头
|
||||
node = parseInterpolation(context, mode)
|
||||
} else if (mode === TextModes.DATA && s[0] === '<') {
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
|
||||
@ -964,11 +967,12 @@ function parseInterpolation(
|
||||
context: ParserContext,
|
||||
mode: TextModes
|
||||
): InterpolationNode | undefined {
|
||||
const [open, close] = context.options.delimiters
|
||||
__TEST__ && assert(startsWith(context.source, open))
|
||||
const [open, close] = context.options.delimiters // open {{ close }}
|
||||
__TEST__ && assert(startsWith(context.source, open)) // 是否为test
|
||||
|
||||
const closeIndex = context.source.indexOf(close, open.length)
|
||||
if (closeIndex === -1) {
|
||||
const closeIndex = context.source.indexOf(close, open.length)// 获取结束位置
|
||||
if (closeIndex === -1) {
|
||||
// 找不到结束
|
||||
emitError(context, ErrorCodes.X_MISSING_INTERPOLATION_END)
|
||||
return undefined
|
||||
}
|
||||
@ -1057,6 +1061,7 @@ function parseTextData(
|
||||
}
|
||||
|
||||
function getCursor(context: ParserContext): Position {
|
||||
console.log(context)
|
||||
const { column, line, offset } = context
|
||||
return { column, line, offset }
|
||||
}
|
||||
@ -1067,6 +1072,7 @@ function getSelection(
|
||||
end?: Position
|
||||
): SourceLocation {
|
||||
end = end || getCursor(context)
|
||||
console.log(start,end)
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
@ -1132,7 +1138,7 @@ function isEnd(
|
||||
mode: TextModes,
|
||||
ancestors: ElementNode[]
|
||||
): boolean {
|
||||
const s = context.source
|
||||
const s = context.source // 原始html
|
||||
|
||||
switch (mode) {
|
||||
case TextModes.DATA:
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/compiler-dom",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/compiler-dom",
|
||||
"main": "index.js",
|
||||
"module": "dist/compiler-dom.esm-bundler.js",
|
||||
@ -37,7 +37,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-core": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/compiler-core": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,14 @@ export const DOMDirectiveTransforms: Record<string, DirectiveTransform> = {
|
||||
show: transformShow
|
||||
}
|
||||
|
||||
// 生成语法树
|
||||
export function compile(
|
||||
template: string,
|
||||
options: CompilerOptions = {}
|
||||
): CodegenResult {
|
||||
// template 模板
|
||||
// options 不知道干啥的参数
|
||||
// console.log(options)
|
||||
return baseCompile(
|
||||
template,
|
||||
extend({}, parserOptions, options, {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/compiler-sfc",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/compiler-sfc",
|
||||
"main": "dist/compiler-sfc.cjs.js",
|
||||
"module": "dist/compiler-sfc.esm-browser.js",
|
||||
@ -33,11 +33,11 @@
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.16.4",
|
||||
"@vue/compiler-core": "3.2.38",
|
||||
"@vue/compiler-dom": "3.2.38",
|
||||
"@vue/compiler-ssr": "3.2.38",
|
||||
"@vue/reactivity-transform": "3.2.38",
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-core": "3.2.39",
|
||||
"@vue/compiler-dom": "3.2.39",
|
||||
"@vue/compiler-ssr": "3.2.39",
|
||||
"@vue/reactivity-transform": "3.2.39",
|
||||
"@vue/shared": "3.2.39",
|
||||
"estree-walker": "^2.0.2",
|
||||
"magic-string": "^0.25.7",
|
||||
"source-map": "^0.6.1",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/compiler-ssr",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/compiler-ssr",
|
||||
"main": "dist/compiler-ssr.cjs.js",
|
||||
"types": "dist/compiler-ssr.d.ts",
|
||||
@ -28,7 +28,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-dom": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/compiler-dom": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/reactivity-transform",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/reactivity-transform",
|
||||
"main": "dist/reactivity-transform.cjs.js",
|
||||
"files": [
|
||||
@ -29,8 +29,8 @@
|
||||
"homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.16.4",
|
||||
"@vue/compiler-core": "3.2.38",
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-core": "3.2.39",
|
||||
"@vue/shared": "3.2.39",
|
||||
"estree-walker": "^2.0.2",
|
||||
"magic-string": "^0.25.7"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/reactivity",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/reactivity",
|
||||
"main": "index.js",
|
||||
"module": "dist/reactivity.esm-bundler.js",
|
||||
@ -36,6 +36,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/reactivity#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38"
|
||||
"@vue/shared": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -534,4 +534,16 @@ describe('scheduler', () => {
|
||||
// should not be called
|
||||
expect(spy).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it('flushPreFlushCbs inside a pre job', async () => {
|
||||
const spy = jest.fn()
|
||||
const job = () => {
|
||||
spy()
|
||||
flushPreFlushCbs()
|
||||
}
|
||||
job.pre = true
|
||||
queueJob(job)
|
||||
await nextTick()
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/runtime-core",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/runtime-core",
|
||||
"main": "index.js",
|
||||
"module": "dist/runtime-core.esm-bundler.js",
|
||||
@ -32,7 +32,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-core#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/reactivity": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/reactivity": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -756,6 +756,7 @@ let installWithProxy: (i: ComponentInternalInstance) => void
|
||||
* For runtime-dom to register the compiler.
|
||||
* Note the exported method uses any to avoid d.ts relying on the compiler types.
|
||||
*/
|
||||
// ???
|
||||
export function registerRuntimeCompiler(_compile: any) {
|
||||
compile = _compile
|
||||
installWithProxy = i => {
|
||||
|
@ -133,7 +133,11 @@ export function queuePostFlushCb(cb: SchedulerJobs) {
|
||||
queueFlush()
|
||||
}
|
||||
|
||||
export function flushPreFlushCbs(seen?: CountMap, i = flushIndex) {
|
||||
export function flushPreFlushCbs(
|
||||
seen?: CountMap,
|
||||
// if currently flushing, skip the current job itself
|
||||
i = isFlushing ? flushIndex + 1 : 0
|
||||
) {
|
||||
if (__DEV__) {
|
||||
seen = seen || new Map()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/runtime-dom",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/runtime-dom",
|
||||
"main": "index.js",
|
||||
"module": "dist/runtime-dom.esm-bundler.js",
|
||||
@ -35,8 +35,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/runtime-core": "3.2.38",
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/runtime-core": "3.2.39",
|
||||
"csstype": "^2.6.8"
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ export const vShow: ObjectDirective<VShowElement> = {
|
||||
setDisplay(el, value)
|
||||
}
|
||||
},
|
||||
// 监听器 属性复制
|
||||
mounted(el, { value }, { transition }) {
|
||||
if (transition && value) {
|
||||
transition.enter(el)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/runtime-test",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/runtime-test",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
@ -25,7 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-test#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/runtime-core": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/runtime-core": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/server-renderer",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "@vue/server-renderer",
|
||||
"main": "index.js",
|
||||
"module": "dist/server-renderer.esm-bundler.js",
|
||||
@ -32,10 +32,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/server-renderer#readme",
|
||||
"peerDependencies": {
|
||||
"vue": "3.2.38"
|
||||
"vue": "3.2.39"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-ssr": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/compiler-ssr": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/sfc-playground",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@ -8,11 +8,11 @@
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^1.10.2",
|
||||
"vite": "^2.9.8"
|
||||
"@vitejs/plugin-vue": "^3.0.0",
|
||||
"vite": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "3.2.38",
|
||||
"vue": "3.2.39",
|
||||
"@vue/repl": "^1.3.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"jszip": "^3.6.0"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/shared",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "internal utils shared across @vue packages",
|
||||
"main": "index.js",
|
||||
"module": "dist/shared.esm-bundler.js",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/size-check",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "vite build"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/template-explorer",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"private": true,
|
||||
"buildOptions": {
|
||||
"formats": [
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue/compat",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "Vue 3 compatibility build for Vue 2",
|
||||
"main": "index.js",
|
||||
"module": "dist/vue.runtime.esm-bundler.js",
|
||||
@ -38,6 +38,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme",
|
||||
"peerDependencies": {
|
||||
"vue": "3.2.38"
|
||||
"vue": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -21,24 +21,31 @@ import * as runtimeDom from '@vue/runtime-dom'
|
||||
|
||||
function wrappedCreateApp(...args: any[]) {
|
||||
// @ts-ignore
|
||||
// 兼容new Vue
|
||||
const app = createApp(...args)
|
||||
// todo: 是不是看内部组件是否兼容??
|
||||
if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) {
|
||||
// register built-in components so that they can be resolved via strings
|
||||
// in the legacy h() call. The __compat__ prefix is to ensure that v3 h()
|
||||
// doesn't get affected.
|
||||
// 。注册内部组件
|
||||
app.component('__compat__transition', Transition)
|
||||
app.component('__compat__transition-group', TransitionGroup)
|
||||
app.component('__compat__keep-alive', KeepAlive)
|
||||
// built-in directives. No need for prefix since there's no render fn API
|
||||
// for resolving directives via string in v3.
|
||||
// v-show 实现
|
||||
app._context.directives.show = vShow
|
||||
// v-model 实现
|
||||
app._context.directives.model = vModelDynamic
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
export function createCompatVue() {
|
||||
// 旧得全局构造函数????
|
||||
const Vue = compatUtils.createCompatVue(createApp, wrappedCreateApp)
|
||||
// 把所有runtimeDom里面的属性方法放到Vue里面
|
||||
extend(Vue, runtimeDom)
|
||||
return Vue
|
||||
}
|
||||
|
@ -17,23 +17,31 @@ function compileToFunction(
|
||||
template: string | HTMLElement,
|
||||
options?: CompilerOptions
|
||||
): RenderFunction {
|
||||
// 不是string
|
||||
if (!isString(template)) {
|
||||
// 判断节点类型 没有就不是节点
|
||||
if (template.nodeType) {
|
||||
// 取内部的html代码
|
||||
template = template.innerHTML
|
||||
} else {
|
||||
// 报错 返回一个空函数
|
||||
__DEV__ && warn(`invalid template option: `, template)
|
||||
return NOOP
|
||||
}
|
||||
}
|
||||
|
||||
const key = template
|
||||
// 获取值
|
||||
const cached = compileCache[key]
|
||||
// 如果有值 直接返回缓存之前的
|
||||
if (cached) {
|
||||
return cached
|
||||
}
|
||||
|
||||
// 判断第一个字符串是不是#
|
||||
if (template[0] === '#') {
|
||||
// 那么通过id 去选择元素
|
||||
const el = document.querySelector(template)
|
||||
// 如果获取不到
|
||||
if (__DEV__ && !el) {
|
||||
warn(`Template element not found or is empty: ${template}`)
|
||||
}
|
||||
@ -41,13 +49,14 @@ function compileToFunction(
|
||||
// Reason: potential execution of JS expressions in in-DOM template.
|
||||
// The user must make sure the in-DOM template is trusted. If it's rendered
|
||||
// by the server, the template should not contain any user data.
|
||||
// 获取的到 取内部的html
|
||||
template = el ? el.innerHTML : ``
|
||||
}
|
||||
|
||||
// 如果是 dev 不是test 不包含 options.whitespace 发出警告 压缩空白
|
||||
if (__DEV__ && !__TEST__ && (!options || !options.whitespace)) {
|
||||
warnDeprecation(DeprecationTypes.CONFIG_WHITESPACE, null)
|
||||
}
|
||||
|
||||
// template html 模板
|
||||
const { code } = compile(
|
||||
template,
|
||||
extend(
|
||||
@ -89,9 +98,11 @@ function compileToFunction(
|
||||
return (compileCache[key] = render)
|
||||
}
|
||||
|
||||
// 为runtime-dom 注册编译器
|
||||
registerRuntimeCompiler(compileToFunction)
|
||||
|
||||
// 创建vue 初始化属性 自带组件
|
||||
const Vue = createCompatVue()
|
||||
// 编译?函数
|
||||
Vue.compile = compileToFunction
|
||||
|
||||
export default Vue
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue",
|
||||
"version": "3.2.38",
|
||||
"version": "3.2.39",
|
||||
"description": "The progressive JavaScript framework for building modern web UI.",
|
||||
"main": "index.js",
|
||||
"module": "dist/vue.runtime.esm-bundler.js",
|
||||
@ -68,10 +68,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.2.38",
|
||||
"@vue/compiler-dom": "3.2.38",
|
||||
"@vue/runtime-dom": "3.2.38",
|
||||
"@vue/compiler-sfc": "3.2.38",
|
||||
"@vue/server-renderer": "3.2.38"
|
||||
"@vue/shared": "3.2.39",
|
||||
"@vue/compiler-dom": "3.2.39",
|
||||
"@vue/runtime-dom": "3.2.39",
|
||||
"@vue/compiler-sfc": "3.2.39",
|
||||
"@vue/server-renderer": "3.2.39"
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
|
||||
import * as runtimeDom from '@vue/runtime-dom'
|
||||
import { isString, NOOP, generateCodeFrame, extend } from '@vue/shared'
|
||||
import { InternalRenderFunction } from 'packages/runtime-core/src/component'
|
||||
|
||||
// 判断是不是调试模式
|
||||
if (__DEV__) {
|
||||
initDev()
|
||||
}
|
||||
@ -17,21 +17,27 @@ function compileToFunction(
|
||||
template: string | HTMLElement,
|
||||
options?: CompilerOptions
|
||||
): RenderFunction {
|
||||
// 判断是不是字符串
|
||||
if (!isString(template)) {
|
||||
// 不是字符串判断下有没有nodeType属性
|
||||
if (template.nodeType) {
|
||||
// 获取内部的html代码
|
||||
template = template.innerHTML
|
||||
} else {
|
||||
// 报错 返回空函数
|
||||
__DEV__ && warn(`invalid template option: `, template)
|
||||
return NOOP
|
||||
}
|
||||
}
|
||||
|
||||
// key 等于传入末班
|
||||
const key = template
|
||||
// 获取缓存 ??
|
||||
const cached = compileCache[key]
|
||||
// 有直接返回缓存
|
||||
if (cached) {
|
||||
return cached
|
||||
}
|
||||
|
||||
// 判断是不是id
|
||||
if (template[0] === '#') {
|
||||
const el = document.querySelector(template)
|
||||
if (__DEV__ && !el) {
|
||||
@ -43,7 +49,10 @@ function compileToFunction(
|
||||
// by the server, the template should not contain any user data.
|
||||
template = el ? el.innerHTML : ``
|
||||
}
|
||||
|
||||
// 合并传入的选项
|
||||
// 添加 hoistStatic
|
||||
// onError
|
||||
// onWarn
|
||||
const opts = extend(
|
||||
{
|
||||
hoistStatic: true,
|
||||
@ -52,7 +61,9 @@ function compileToFunction(
|
||||
} as CompilerOptions,
|
||||
options
|
||||
)
|
||||
|
||||
// ?? 不知道这个是干啥的
|
||||
// 根不执行
|
||||
console.log(opts.isCustomElement,customElements)
|
||||
if (!opts.isCustomElement && typeof customElements !== 'undefined') {
|
||||
opts.isCustomElement = tag => !!customElements.get(tag)
|
||||
}
|
||||
|
117
pnpm-lock.yaml
generated
117
pnpm-lock.yaml
generated
@ -106,7 +106,7 @@ importers:
|
||||
specifiers:
|
||||
'@babel/parser': ^7.16.4
|
||||
'@babel/types': ^7.16.0
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/shared': 3.2.39
|
||||
estree-walker: ^2.0.2
|
||||
source-map: ^0.6.1
|
||||
dependencies:
|
||||
@ -119,8 +119,8 @@ importers:
|
||||
|
||||
packages/compiler-dom:
|
||||
specifiers:
|
||||
'@vue/compiler-core': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/compiler-core': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/compiler-core': link:../compiler-core
|
||||
'@vue/shared': link:../shared
|
||||
@ -131,12 +131,12 @@ importers:
|
||||
'@babel/types': ^7.16.0
|
||||
'@types/estree': ^0.0.48
|
||||
'@types/lru-cache': ^5.1.0
|
||||
'@vue/compiler-core': 3.2.38
|
||||
'@vue/compiler-dom': 3.2.38
|
||||
'@vue/compiler-ssr': 3.2.38
|
||||
'@vue/compiler-core': 3.2.39
|
||||
'@vue/compiler-dom': 3.2.39
|
||||
'@vue/compiler-ssr': 3.2.39
|
||||
'@vue/consolidate': ^0.17.3
|
||||
'@vue/reactivity-transform': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/reactivity-transform': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
estree-walker: ^2.0.2
|
||||
hash-sum: ^2.0.0
|
||||
lru-cache: ^5.1.1
|
||||
@ -174,15 +174,15 @@ importers:
|
||||
|
||||
packages/compiler-ssr:
|
||||
specifiers:
|
||||
'@vue/compiler-dom': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/compiler-dom': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/compiler-dom': link:../compiler-dom
|
||||
'@vue/shared': link:../shared
|
||||
|
||||
packages/reactivity:
|
||||
specifiers:
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/shared': link:../shared
|
||||
|
||||
@ -191,8 +191,8 @@ importers:
|
||||
'@babel/core': ^7.16.0
|
||||
'@babel/parser': ^7.16.4
|
||||
'@babel/types': ^7.16.0
|
||||
'@vue/compiler-core': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/compiler-core': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
estree-walker: ^2.0.2
|
||||
magic-string: ^0.25.7
|
||||
dependencies:
|
||||
@ -207,16 +207,16 @@ importers:
|
||||
|
||||
packages/runtime-core:
|
||||
specifiers:
|
||||
'@vue/reactivity': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/reactivity': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/reactivity': link:../reactivity
|
||||
'@vue/shared': link:../shared
|
||||
|
||||
packages/runtime-dom:
|
||||
specifiers:
|
||||
'@vue/runtime-core': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/runtime-core': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
csstype: ^2.6.8
|
||||
dependencies:
|
||||
'@vue/runtime-core': link:../runtime-core
|
||||
@ -225,36 +225,36 @@ importers:
|
||||
|
||||
packages/runtime-test:
|
||||
specifiers:
|
||||
'@vue/runtime-core': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/runtime-core': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/runtime-core': link:../runtime-core
|
||||
'@vue/shared': link:../shared
|
||||
|
||||
packages/server-renderer:
|
||||
specifiers:
|
||||
'@vue/compiler-ssr': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/compiler-ssr': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/compiler-ssr': link:../compiler-ssr
|
||||
'@vue/shared': link:../shared
|
||||
|
||||
packages/sfc-playground:
|
||||
specifiers:
|
||||
'@vitejs/plugin-vue': ^1.10.2
|
||||
'@vitejs/plugin-vue': ^3.0.0
|
||||
'@vue/repl': ^1.3.0
|
||||
file-saver: ^2.0.5
|
||||
jszip: ^3.6.0
|
||||
vite: ^2.9.8
|
||||
vue: 3.2.38
|
||||
vite: ^3.0.0
|
||||
vue: 3.2.39
|
||||
dependencies:
|
||||
'@vue/repl': 1.3.0_vue@packages+vue
|
||||
file-saver: 2.0.5
|
||||
jszip: 3.7.1
|
||||
vue: link:../vue
|
||||
devDependencies:
|
||||
'@vitejs/plugin-vue': 1.10.2_vite@2.9.8
|
||||
vite: 2.9.8
|
||||
'@vitejs/plugin-vue': 3.1.0_yvvbnwjsosvjg6n7dkt3ewqphy
|
||||
vite: 3.0.9
|
||||
|
||||
packages/shared:
|
||||
specifiers: {}
|
||||
@ -272,11 +272,11 @@ importers:
|
||||
|
||||
packages/vue:
|
||||
specifiers:
|
||||
'@vue/compiler-dom': 3.2.38
|
||||
'@vue/compiler-sfc': 3.2.38
|
||||
'@vue/runtime-dom': 3.2.38
|
||||
'@vue/server-renderer': 3.2.38
|
||||
'@vue/shared': 3.2.38
|
||||
'@vue/compiler-dom': 3.2.39
|
||||
'@vue/compiler-sfc': 3.2.39
|
||||
'@vue/runtime-dom': 3.2.39
|
||||
'@vue/server-renderer': 3.2.39
|
||||
'@vue/shared': 3.2.39
|
||||
dependencies:
|
||||
'@vue/compiler-dom': link:../compiler-dom
|
||||
'@vue/compiler-sfc': link:../compiler-sfc
|
||||
@ -1344,13 +1344,15 @@ packages:
|
||||
eslint-visitor-keys: 3.3.0
|
||||
dev: true
|
||||
|
||||
/@vitejs/plugin-vue/1.10.2_vite@2.9.8:
|
||||
resolution: {integrity: sha512-/QJ0Z9qfhAFtKRY+r57ziY4BSbGUTGsPRMpB/Ron3QPwBZM4OZAZHdTa4a8PafCwU5DTatXG8TMDoP8z+oDqJw==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
/@vitejs/plugin-vue/3.1.0_yvvbnwjsosvjg6n7dkt3ewqphy:
|
||||
resolution: {integrity: sha512-fmxtHPjSOEIRg6vHYDaem+97iwCUg/uSIaTzp98lhELt2ISOQuDo2hbkBdXod0g15IhfPMQmAxh4heUks2zvDA==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
peerDependencies:
|
||||
vite: ^2.5.10
|
||||
vite: ^3.0.0
|
||||
vue: ^3.2.25
|
||||
dependencies:
|
||||
vite: 2.9.8
|
||||
vite: 3.0.9
|
||||
vue: link:packages/vue
|
||||
dev: true
|
||||
|
||||
/@vue/consolidate/0.17.3:
|
||||
@ -5805,15 +5807,6 @@ packages:
|
||||
resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==}
|
||||
dev: true
|
||||
|
||||
/postcss/8.4.13:
|
||||
resolution: {integrity: sha512-jtL6eTBrza5MPzy8oJLFuUscHDXTV5KcLlqAWHl5q5WYRfnNRGSmOZmOZ1T6Gy7A99mOZfqungmZMpMmCVJ8ZA==}
|
||||
engines: {node: ^10 || ^12 || >=14}
|
||||
dependencies:
|
||||
nanoid: 3.3.4
|
||||
picocolors: 1.0.0
|
||||
source-map-js: 1.0.2
|
||||
dev: true
|
||||
|
||||
/postcss/8.4.16:
|
||||
resolution: {integrity: sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==}
|
||||
engines: {node: ^10 || ^12 || >=14}
|
||||
@ -6259,7 +6252,7 @@ packages:
|
||||
resolution: {integrity: sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
is-core-module: 2.8.1
|
||||
is-core-module: 2.10.0
|
||||
path-parse: 1.0.7
|
||||
supports-preserve-symlinks-flag: 1.0.0
|
||||
dev: true
|
||||
@ -6389,14 +6382,6 @@ packages:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/rollup/2.61.1:
|
||||
resolution: {integrity: sha512-BbTXlEvB8d+XFbK/7E5doIcRtxWPRiqr0eb5vQ0+2paMM04Ye4PZY5nHOQef2ix24l/L0SpLd5hwcH15QHPdvA==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
hasBin: true
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/rollup/2.77.3:
|
||||
resolution: {integrity: sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
@ -7222,30 +7207,6 @@ packages:
|
||||
engines: {node: '>= 0.8'}
|
||||
dev: true
|
||||
|
||||
/vite/2.9.8:
|
||||
resolution: {integrity: sha512-zsBGwn5UT3YS0NLSJ7hnR54+vUKfgzMUh/Z9CxF1YKEBVIe213+63jrFLmZphgGI5zXwQCSmqIdbPuE8NJywPw==}
|
||||
engines: {node: '>=12.2.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
less: '*'
|
||||
sass: '*'
|
||||
stylus: '*'
|
||||
peerDependenciesMeta:
|
||||
less:
|
||||
optional: true
|
||||
sass:
|
||||
optional: true
|
||||
stylus:
|
||||
optional: true
|
||||
dependencies:
|
||||
esbuild: 0.14.35
|
||||
postcss: 8.4.13
|
||||
resolve: 1.22.0
|
||||
rollup: 2.61.1
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/vite/3.0.9:
|
||||
resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
|
Loading…
x
Reference in New Issue
Block a user