Compare commits

..

No commits in common. "88be3a27491245f203fd4801aea42af33e0a4378" and "6493da5bfa4624267248deb3d31dca2a4fb22aee" have entirely different histories.

29 changed files with 162 additions and 193 deletions

View File

@ -1,15 +1,3 @@
## [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) ## [3.2.38](https://github.com/vuejs/core/compare/v3.2.37...v3.2.38) (2022-08-30)

View File

@ -1,6 +1,6 @@
{ {
"private": true, "private": true,
"version": "3.2.39", "version": "3.2.38",
"packageManager": "pnpm@7.1.0", "packageManager": "pnpm@7.1.0",
"scripts": { "scripts": {
"dev": "node scripts/dev.js", "dev": "node scripts/dev.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/compiler-core", "name": "@vue/compiler-core",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/compiler-core", "description": "@vue/compiler-core",
"main": "index.js", "main": "index.js",
"module": "dist/compiler-core.esm-bundler.js", "module": "dist/compiler-core.esm-bundler.js",
@ -32,7 +32,7 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@babel/parser": "^7.16.4", "@babel/parser": "^7.16.4",
"estree-walker": "^2.0.2", "estree-walker": "^2.0.2",
"source-map": "^0.6.1" "source-map": "^0.6.1"

View File

@ -65,7 +65,6 @@ export function baseCompile(
const onError = options.onError || defaultOnError const onError = options.onError || defaultOnError
const isModuleMode = options.mode === 'module' const isModuleMode = options.mode === 'module'
/* istanbul ignore if */ /* istanbul ignore if */
// 只要不是 dev onError 就是空函数
if (__BROWSER__) { if (__BROWSER__) {
if (options.prefixIdentifiers === true) { if (options.prefixIdentifiers === true) {
onError(createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED)) onError(createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED))
@ -82,7 +81,7 @@ export function baseCompile(
if (options.scopeId && !isModuleMode) { if (options.scopeId && !isModuleMode) {
onError(createCompilerError(ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED)) onError(createCompilerError(ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED))
} }
// 给options 赋初始值 如果不是字符串 直接返回 template
const ast = isString(template) ? baseParse(template, options) : template const ast = isString(template) ? baseParse(template, options) : template
const [nodeTransforms, directiveTransforms] = const [nodeTransforms, directiveTransforms] =
getBaseTransformPreset(prefixIdentifiers) getBaseTransformPreset(prefixIdentifiers)

View File

@ -67,17 +67,17 @@ const decodeMap: Record<string, string> = {
} }
export const defaultParserOptions: MergedParserOptions = { export const defaultParserOptions: MergedParserOptions = {
delimiters: [`{{`, `}}`], // 模板分割付 delimiters: [`{{`, `}}`],
getNamespace: () => Namespaces.HTML, // HTML getNamespace: () => Namespaces.HTML,
getTextMode: () => TextModes.DATA, //DATA getTextMode: () => TextModes.DATA,
isVoidTag: NO, // 无效标签 isVoidTag: NO,
isPreTag: NO, // 是不是pre标签 isPreTag: NO,
isCustomElement: NO, // 是不是自定义标签 isCustomElement: NO,
decodeEntities: (rawText: string): string => decodeEntities: (rawText: string): string =>
rawText.replace(decodeRE, (_, p1) => decodeMap[p1]), // 讲实体字符转换成字符串 rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
onError: defaultOnError, onError: defaultOnError,
onWarn: defaultOnWarn, onWarn: defaultOnWarn,
comments: __DEV__ // ??? comments: __DEV__
} }
export const enum TextModes { export const enum TextModes {
@ -105,11 +105,8 @@ export function baseParse(
content: string, content: string,
options: ParserOptions = {} options: ParserOptions = {}
): RootNode { ): RootNode {
// 给options 覆初始值 没有的属性都赋值进去
const context = createParserContext(content, options) const context = createParserContext(content, options)
// 貌似获取的是固定的
const start = getCursor(context) const start = getCursor(context)
// create root
return createRoot( return createRoot(
parseChildren(context, TextModes.DATA, []), parseChildren(context, TextModes.DATA, []),
getSelection(context, start) getSelection(context, start)
@ -120,12 +117,15 @@ function createParserContext(
content: string, content: string,
rawOptions: ParserOptions rawOptions: ParserOptions
): ParserContext { ): ParserContext {
const options = extend({}, defaultParserOptions) // 这一行将所有defaultParserOptions属性复制给options const options = extend({}, defaultParserOptions)
// 如果对象属性没有 讲使用默认的 defaultParserOptions
let key: keyof ParserOptions let key: keyof ParserOptions
for (key in rawOptions) { for (key in rawOptions) {
// @ts-ignore // @ts-ignore
options[key] = rawOptions[key] === undefined ? defaultParserOptions[key] : rawOptions[key] // 当rawOptions key值是undefined的时候 给defaultParserOptionsde的值 不是unidentified 给 rawOptions的值 options[key] =
rawOptions[key] === undefined
? defaultParserOptions[key]
: rawOptions[key]
} }
return { return {
options, options,
@ -139,27 +139,24 @@ function createParserContext(
onWarn: options.onWarn onWarn: options.onWarn
} }
} }
// 解析标签
// ancestors 默认是空数组
function parseChildren( function parseChildren(
context: ParserContext, context: ParserContext,
mode: TextModes, mode: TextModes,
ancestors: ElementNode[] ancestors: ElementNode[]
): TemplateChildNode[] { ): TemplateChildNode[] {
// ancestors 获取最后一个元素 默认undefined
// mode DATA
const parent = last(ancestors) const parent = last(ancestors)
const ns = parent ? parent.ns : Namespaces.HTML // 如果有 就取ns 没有 HTML const ns = parent ? parent.ns : Namespaces.HTML
const nodes: TemplateChildNode[] = [] // ??创建列表 const nodes: TemplateChildNode[] = []
// 判断是不是结束标签
while (!isEnd(context, mode, ancestors)) { while (!isEnd(context, mode, ancestors)) {
__TEST__ && assert(context.source.length > 0) __TEST__ && assert(context.source.length > 0)
const s = context.source // html 代码 const s = context.source
let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined
if (mode === TextModes.DATA || mode === TextModes.RCDATA) { if (mode === TextModes.DATA || mode === TextModes.RCDATA) {
if (!context.inVPre && startsWith(s, context.options.delimiters[0])) { if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
// 判断是不是'{{' 开头 // '{{'
node = parseInterpolation(context, mode) node = parseInterpolation(context, mode)
} else if (mode === TextModes.DATA && s[0] === '<') { } else if (mode === TextModes.DATA && s[0] === '<') {
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
@ -967,12 +964,11 @@ function parseInterpolation(
context: ParserContext, context: ParserContext,
mode: TextModes mode: TextModes
): InterpolationNode | undefined { ): InterpolationNode | undefined {
const [open, close] = context.options.delimiters // open {{ close }} const [open, close] = context.options.delimiters
__TEST__ && assert(startsWith(context.source, open)) // 是否为test __TEST__ && assert(startsWith(context.source, open))
const closeIndex = context.source.indexOf(close, open.length)// 获取结束位置 const closeIndex = context.source.indexOf(close, open.length)
if (closeIndex === -1) { if (closeIndex === -1) {
// 找不到结束
emitError(context, ErrorCodes.X_MISSING_INTERPOLATION_END) emitError(context, ErrorCodes.X_MISSING_INTERPOLATION_END)
return undefined return undefined
} }
@ -1061,7 +1057,6 @@ function parseTextData(
} }
function getCursor(context: ParserContext): Position { function getCursor(context: ParserContext): Position {
console.log(context)
const { column, line, offset } = context const { column, line, offset } = context
return { column, line, offset } return { column, line, offset }
} }
@ -1072,7 +1067,6 @@ function getSelection(
end?: Position end?: Position
): SourceLocation { ): SourceLocation {
end = end || getCursor(context) end = end || getCursor(context)
console.log(start,end)
return { return {
start, start,
end, end,
@ -1138,7 +1132,7 @@ function isEnd(
mode: TextModes, mode: TextModes,
ancestors: ElementNode[] ancestors: ElementNode[]
): boolean { ): boolean {
const s = context.source // 原始html const s = context.source
switch (mode) { switch (mode) {
case TextModes.DATA: case TextModes.DATA:

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/compiler-dom", "name": "@vue/compiler-dom",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/compiler-dom", "description": "@vue/compiler-dom",
"main": "index.js", "main": "index.js",
"module": "dist/compiler-dom.esm-bundler.js", "module": "dist/compiler-dom.esm-bundler.js",
@ -37,7 +37,7 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/compiler-core": "3.2.39" "@vue/compiler-core": "3.2.38"
} }
} }

View File

@ -37,14 +37,10 @@ export const DOMDirectiveTransforms: Record<string, DirectiveTransform> = {
show: transformShow show: transformShow
} }
// 生成语法树
export function compile( export function compile(
template: string, template: string,
options: CompilerOptions = {} options: CompilerOptions = {}
): CodegenResult { ): CodegenResult {
// template 模板
// options 不知道干啥的参数
// console.log(options)
return baseCompile( return baseCompile(
template, template,
extend({}, parserOptions, options, { extend({}, parserOptions, options, {

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/compiler-sfc", "name": "@vue/compiler-sfc",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/compiler-sfc", "description": "@vue/compiler-sfc",
"main": "dist/compiler-sfc.cjs.js", "main": "dist/compiler-sfc.cjs.js",
"module": "dist/compiler-sfc.esm-browser.js", "module": "dist/compiler-sfc.esm-browser.js",
@ -33,11 +33,11 @@
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
"dependencies": { "dependencies": {
"@babel/parser": "^7.16.4", "@babel/parser": "^7.16.4",
"@vue/compiler-core": "3.2.39", "@vue/compiler-core": "3.2.38",
"@vue/compiler-dom": "3.2.39", "@vue/compiler-dom": "3.2.38",
"@vue/compiler-ssr": "3.2.39", "@vue/compiler-ssr": "3.2.38",
"@vue/reactivity-transform": "3.2.39", "@vue/reactivity-transform": "3.2.38",
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"estree-walker": "^2.0.2", "estree-walker": "^2.0.2",
"magic-string": "^0.25.7", "magic-string": "^0.25.7",
"source-map": "^0.6.1", "source-map": "^0.6.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/compiler-ssr", "name": "@vue/compiler-ssr",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/compiler-ssr", "description": "@vue/compiler-ssr",
"main": "dist/compiler-ssr.cjs.js", "main": "dist/compiler-ssr.cjs.js",
"types": "dist/compiler-ssr.d.ts", "types": "dist/compiler-ssr.d.ts",
@ -28,7 +28,7 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/compiler-dom": "3.2.39" "@vue/compiler-dom": "3.2.38"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/reactivity-transform", "name": "@vue/reactivity-transform",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/reactivity-transform", "description": "@vue/reactivity-transform",
"main": "dist/reactivity-transform.cjs.js", "main": "dist/reactivity-transform.cjs.js",
"files": [ "files": [
@ -29,8 +29,8 @@
"homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme", "homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme",
"dependencies": { "dependencies": {
"@babel/parser": "^7.16.4", "@babel/parser": "^7.16.4",
"@vue/compiler-core": "3.2.39", "@vue/compiler-core": "3.2.38",
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"estree-walker": "^2.0.2", "estree-walker": "^2.0.2",
"magic-string": "^0.25.7" "magic-string": "^0.25.7"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/reactivity", "name": "@vue/reactivity",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/reactivity", "description": "@vue/reactivity",
"main": "index.js", "main": "index.js",
"module": "dist/reactivity.esm-bundler.js", "module": "dist/reactivity.esm-bundler.js",
@ -36,6 +36,6 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/reactivity#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/reactivity#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39" "@vue/shared": "3.2.38"
} }
} }

View File

@ -534,16 +534,4 @@ describe('scheduler', () => {
// should not be called // should not be called
expect(spy).toHaveBeenCalledTimes(0) 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)
})
}) })

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/runtime-core", "name": "@vue/runtime-core",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/runtime-core", "description": "@vue/runtime-core",
"main": "index.js", "main": "index.js",
"module": "dist/runtime-core.esm-bundler.js", "module": "dist/runtime-core.esm-bundler.js",
@ -32,7 +32,7 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-core#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-core#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/reactivity": "3.2.39" "@vue/reactivity": "3.2.38"
} }
} }

View File

@ -756,7 +756,6 @@ let installWithProxy: (i: ComponentInternalInstance) => void
* For runtime-dom to register the compiler. * For runtime-dom to register the compiler.
* Note the exported method uses any to avoid d.ts relying on the compiler types. * Note the exported method uses any to avoid d.ts relying on the compiler types.
*/ */
//
export function registerRuntimeCompiler(_compile: any) { export function registerRuntimeCompiler(_compile: any) {
compile = _compile compile = _compile
installWithProxy = i => { installWithProxy = i => {

View File

@ -133,11 +133,7 @@ export function queuePostFlushCb(cb: SchedulerJobs) {
queueFlush() queueFlush()
} }
export function flushPreFlushCbs( export function flushPreFlushCbs(seen?: CountMap, i = flushIndex) {
seen?: CountMap,
// if currently flushing, skip the current job itself
i = isFlushing ? flushIndex + 1 : 0
) {
if (__DEV__) { if (__DEV__) {
seen = seen || new Map() seen = seen || new Map()
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/runtime-dom", "name": "@vue/runtime-dom",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/runtime-dom", "description": "@vue/runtime-dom",
"main": "index.js", "main": "index.js",
"module": "dist/runtime-dom.esm-bundler.js", "module": "dist/runtime-dom.esm-bundler.js",
@ -35,8 +35,8 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/runtime-core": "3.2.39", "@vue/runtime-core": "3.2.38",
"csstype": "^2.6.8" "csstype": "^2.6.8"
} }
} }

View File

@ -14,7 +14,6 @@ export const vShow: ObjectDirective<VShowElement> = {
setDisplay(el, value) setDisplay(el, value)
} }
}, },
// 监听器 属性复制
mounted(el, { value }, { transition }) { mounted(el, { value }, { transition }) {
if (transition && value) { if (transition && value) {
transition.enter(el) transition.enter(el)

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/runtime-test", "name": "@vue/runtime-test",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/runtime-test", "description": "@vue/runtime-test",
"private": true, "private": true,
"main": "index.js", "main": "index.js",
@ -25,7 +25,7 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-test#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-test#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/runtime-core": "3.2.39" "@vue/runtime-core": "3.2.38"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/server-renderer", "name": "@vue/server-renderer",
"version": "3.2.39", "version": "3.2.38",
"description": "@vue/server-renderer", "description": "@vue/server-renderer",
"main": "index.js", "main": "index.js",
"module": "dist/server-renderer.esm-bundler.js", "module": "dist/server-renderer.esm-bundler.js",
@ -32,10 +32,10 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/server-renderer#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/server-renderer#readme",
"peerDependencies": { "peerDependencies": {
"vue": "3.2.39" "vue": "3.2.38"
}, },
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/compiler-ssr": "3.2.39" "@vue/compiler-ssr": "3.2.38"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/sfc-playground", "name": "@vue/sfc-playground",
"version": "3.2.39", "version": "3.2.38",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
@ -8,11 +8,11 @@
"serve": "vite preview" "serve": "vite preview"
}, },
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "^3.0.0", "@vitejs/plugin-vue": "^1.10.2",
"vite": "^3.0.0" "vite": "^2.9.8"
}, },
"dependencies": { "dependencies": {
"vue": "3.2.39", "vue": "3.2.38",
"@vue/repl": "^1.3.0", "@vue/repl": "^1.3.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"jszip": "^3.6.0" "jszip": "^3.6.0"

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/shared", "name": "@vue/shared",
"version": "3.2.39", "version": "3.2.38",
"description": "internal utils shared across @vue packages", "description": "internal utils shared across @vue packages",
"main": "index.js", "main": "index.js",
"module": "dist/shared.esm-bundler.js", "module": "dist/shared.esm-bundler.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/size-check", "name": "@vue/size-check",
"version": "3.2.39", "version": "3.2.38",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "vite build" "build": "vite build"

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/template-explorer", "name": "@vue/template-explorer",
"version": "3.2.39", "version": "3.2.38",
"private": true, "private": true,
"buildOptions": { "buildOptions": {
"formats": [ "formats": [

View File

@ -1,6 +1,6 @@
{ {
"name": "@vue/compat", "name": "@vue/compat",
"version": "3.2.39", "version": "3.2.38",
"description": "Vue 3 compatibility build for Vue 2", "description": "Vue 3 compatibility build for Vue 2",
"main": "index.js", "main": "index.js",
"module": "dist/vue.runtime.esm-bundler.js", "module": "dist/vue.runtime.esm-bundler.js",
@ -38,6 +38,6 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme",
"peerDependencies": { "peerDependencies": {
"vue": "3.2.39" "vue": "3.2.38"
} }
} }

View File

@ -21,31 +21,24 @@ import * as runtimeDom from '@vue/runtime-dom'
function wrappedCreateApp(...args: any[]) { function wrappedCreateApp(...args: any[]) {
// @ts-ignore // @ts-ignore
// 兼容new Vue
const app = createApp(...args) const app = createApp(...args)
// todo: 是不是看内部组件是否兼容??
if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) { if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) {
// register built-in components so that they can be resolved via strings // 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() // in the legacy h() call. The __compat__ prefix is to ensure that v3 h()
// doesn't get affected. // doesn't get affected.
// 。注册内部组件
app.component('__compat__transition', Transition) app.component('__compat__transition', Transition)
app.component('__compat__transition-group', TransitionGroup) app.component('__compat__transition-group', TransitionGroup)
app.component('__compat__keep-alive', KeepAlive) app.component('__compat__keep-alive', KeepAlive)
// built-in directives. No need for prefix since there's no render fn API // built-in directives. No need for prefix since there's no render fn API
// for resolving directives via string in v3. // for resolving directives via string in v3.
// v-show 实现
app._context.directives.show = vShow app._context.directives.show = vShow
// v-model 实现
app._context.directives.model = vModelDynamic app._context.directives.model = vModelDynamic
} }
return app return app
} }
export function createCompatVue() { export function createCompatVue() {
// 旧得全局构造函数????
const Vue = compatUtils.createCompatVue(createApp, wrappedCreateApp) const Vue = compatUtils.createCompatVue(createApp, wrappedCreateApp)
// 把所有runtimeDom里面的属性方法放到Vue里面
extend(Vue, runtimeDom) extend(Vue, runtimeDom)
return Vue return Vue
} }

View File

@ -17,31 +17,23 @@ function compileToFunction(
template: string | HTMLElement, template: string | HTMLElement,
options?: CompilerOptions options?: CompilerOptions
): RenderFunction { ): RenderFunction {
// 不是string
if (!isString(template)) { if (!isString(template)) {
// 判断节点类型 没有就不是节点
if (template.nodeType) { if (template.nodeType) {
// 取内部的html代码
template = template.innerHTML template = template.innerHTML
} else { } else {
// 报错 返回一个空函数
__DEV__ && warn(`invalid template option: `, template) __DEV__ && warn(`invalid template option: `, template)
return NOOP return NOOP
} }
} }
const key = template const key = template
// 获取值
const cached = compileCache[key] const cached = compileCache[key]
// 如果有值 直接返回缓存之前的
if (cached) { if (cached) {
return cached return cached
} }
// 判断第一个字符串是不是#
if (template[0] === '#') { if (template[0] === '#') {
// 那么通过id 去选择元素
const el = document.querySelector(template) const el = document.querySelector(template)
// 如果获取不到
if (__DEV__ && !el) { if (__DEV__ && !el) {
warn(`Template element not found or is empty: ${template}`) warn(`Template element not found or is empty: ${template}`)
} }
@ -49,14 +41,13 @@ function compileToFunction(
// Reason: potential execution of JS expressions in in-DOM template. // 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 // 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. // by the server, the template should not contain any user data.
// 获取的到 取内部的html
template = el ? el.innerHTML : `` template = el ? el.innerHTML : ``
} }
// 如果是 dev 不是test 不包含 options.whitespace 发出警告 压缩空白
if (__DEV__ && !__TEST__ && (!options || !options.whitespace)) { if (__DEV__ && !__TEST__ && (!options || !options.whitespace)) {
warnDeprecation(DeprecationTypes.CONFIG_WHITESPACE, null) warnDeprecation(DeprecationTypes.CONFIG_WHITESPACE, null)
} }
// template html 模板
const { code } = compile( const { code } = compile(
template, template,
extend( extend(
@ -98,11 +89,9 @@ function compileToFunction(
return (compileCache[key] = render) return (compileCache[key] = render)
} }
// 为runtime-dom 注册编译器
registerRuntimeCompiler(compileToFunction) registerRuntimeCompiler(compileToFunction)
// 创建vue 初始化属性 自带组件
const Vue = createCompatVue() const Vue = createCompatVue()
// 编译?函数
Vue.compile = compileToFunction Vue.compile = compileToFunction
export default Vue export default Vue

View File

@ -1,6 +1,6 @@
{ {
"name": "vue", "name": "vue",
"version": "3.2.39", "version": "3.2.38",
"description": "The progressive JavaScript framework for building modern web UI.", "description": "The progressive JavaScript framework for building modern web UI.",
"main": "index.js", "main": "index.js",
"module": "dist/vue.runtime.esm-bundler.js", "module": "dist/vue.runtime.esm-bundler.js",
@ -68,10 +68,10 @@
}, },
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme", "homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme",
"dependencies": { "dependencies": {
"@vue/shared": "3.2.39", "@vue/shared": "3.2.38",
"@vue/compiler-dom": "3.2.39", "@vue/compiler-dom": "3.2.38",
"@vue/runtime-dom": "3.2.39", "@vue/runtime-dom": "3.2.38",
"@vue/compiler-sfc": "3.2.39", "@vue/compiler-sfc": "3.2.38",
"@vue/server-renderer": "3.2.39" "@vue/server-renderer": "3.2.38"
} }
} }

View File

@ -6,7 +6,7 @@ import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
import * as runtimeDom from '@vue/runtime-dom' import * as runtimeDom from '@vue/runtime-dom'
import { isString, NOOP, generateCodeFrame, extend } from '@vue/shared' import { isString, NOOP, generateCodeFrame, extend } from '@vue/shared'
import { InternalRenderFunction } from 'packages/runtime-core/src/component' import { InternalRenderFunction } from 'packages/runtime-core/src/component'
// 判断是不是调试模式
if (__DEV__) { if (__DEV__) {
initDev() initDev()
} }
@ -17,27 +17,21 @@ function compileToFunction(
template: string | HTMLElement, template: string | HTMLElement,
options?: CompilerOptions options?: CompilerOptions
): RenderFunction { ): RenderFunction {
// 判断是不是字符串
if (!isString(template)) { if (!isString(template)) {
// 不是字符串判断下有没有nodeType属性
if (template.nodeType) { if (template.nodeType) {
// 获取内部的html代码
template = template.innerHTML template = template.innerHTML
} else { } else {
// 报错 返回空函数
__DEV__ && warn(`invalid template option: `, template) __DEV__ && warn(`invalid template option: `, template)
return NOOP return NOOP
} }
} }
// key 等于传入末班
const key = template const key = template
// 获取缓存
const cached = compileCache[key] const cached = compileCache[key]
// 有直接返回缓存
if (cached) { if (cached) {
return cached return cached
} }
// 判断是不是id
if (template[0] === '#') { if (template[0] === '#') {
const el = document.querySelector(template) const el = document.querySelector(template)
if (__DEV__ && !el) { if (__DEV__ && !el) {
@ -49,10 +43,7 @@ function compileToFunction(
// by the server, the template should not contain any user data. // by the server, the template should not contain any user data.
template = el ? el.innerHTML : `` template = el ? el.innerHTML : ``
} }
// 合并传入的选项
// 添加 hoistStatic
// onError
// onWarn
const opts = extend( const opts = extend(
{ {
hoistStatic: true, hoistStatic: true,
@ -61,9 +52,7 @@ function compileToFunction(
} as CompilerOptions, } as CompilerOptions,
options options
) )
// ?? 不知道这个是干啥的
// 根不执行
console.log(opts.isCustomElement,customElements)
if (!opts.isCustomElement && typeof customElements !== 'undefined') { if (!opts.isCustomElement && typeof customElements !== 'undefined') {
opts.isCustomElement = tag => !!customElements.get(tag) opts.isCustomElement = tag => !!customElements.get(tag)
} }

117
pnpm-lock.yaml generated
View File

@ -106,7 +106,7 @@ importers:
specifiers: specifiers:
'@babel/parser': ^7.16.4 '@babel/parser': ^7.16.4
'@babel/types': ^7.16.0 '@babel/types': ^7.16.0
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
estree-walker: ^2.0.2 estree-walker: ^2.0.2
source-map: ^0.6.1 source-map: ^0.6.1
dependencies: dependencies:
@ -119,8 +119,8 @@ importers:
packages/compiler-dom: packages/compiler-dom:
specifiers: specifiers:
'@vue/compiler-core': 3.2.39 '@vue/compiler-core': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/compiler-core': link:../compiler-core '@vue/compiler-core': link:../compiler-core
'@vue/shared': link:../shared '@vue/shared': link:../shared
@ -131,12 +131,12 @@ importers:
'@babel/types': ^7.16.0 '@babel/types': ^7.16.0
'@types/estree': ^0.0.48 '@types/estree': ^0.0.48
'@types/lru-cache': ^5.1.0 '@types/lru-cache': ^5.1.0
'@vue/compiler-core': 3.2.39 '@vue/compiler-core': 3.2.38
'@vue/compiler-dom': 3.2.39 '@vue/compiler-dom': 3.2.38
'@vue/compiler-ssr': 3.2.39 '@vue/compiler-ssr': 3.2.38
'@vue/consolidate': ^0.17.3 '@vue/consolidate': ^0.17.3
'@vue/reactivity-transform': 3.2.39 '@vue/reactivity-transform': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
estree-walker: ^2.0.2 estree-walker: ^2.0.2
hash-sum: ^2.0.0 hash-sum: ^2.0.0
lru-cache: ^5.1.1 lru-cache: ^5.1.1
@ -174,15 +174,15 @@ importers:
packages/compiler-ssr: packages/compiler-ssr:
specifiers: specifiers:
'@vue/compiler-dom': 3.2.39 '@vue/compiler-dom': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/compiler-dom': link:../compiler-dom '@vue/compiler-dom': link:../compiler-dom
'@vue/shared': link:../shared '@vue/shared': link:../shared
packages/reactivity: packages/reactivity:
specifiers: specifiers:
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/shared': link:../shared '@vue/shared': link:../shared
@ -191,8 +191,8 @@ importers:
'@babel/core': ^7.16.0 '@babel/core': ^7.16.0
'@babel/parser': ^7.16.4 '@babel/parser': ^7.16.4
'@babel/types': ^7.16.0 '@babel/types': ^7.16.0
'@vue/compiler-core': 3.2.39 '@vue/compiler-core': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
estree-walker: ^2.0.2 estree-walker: ^2.0.2
magic-string: ^0.25.7 magic-string: ^0.25.7
dependencies: dependencies:
@ -207,16 +207,16 @@ importers:
packages/runtime-core: packages/runtime-core:
specifiers: specifiers:
'@vue/reactivity': 3.2.39 '@vue/reactivity': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/reactivity': link:../reactivity '@vue/reactivity': link:../reactivity
'@vue/shared': link:../shared '@vue/shared': link:../shared
packages/runtime-dom: packages/runtime-dom:
specifiers: specifiers:
'@vue/runtime-core': 3.2.39 '@vue/runtime-core': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
csstype: ^2.6.8 csstype: ^2.6.8
dependencies: dependencies:
'@vue/runtime-core': link:../runtime-core '@vue/runtime-core': link:../runtime-core
@ -225,36 +225,36 @@ importers:
packages/runtime-test: packages/runtime-test:
specifiers: specifiers:
'@vue/runtime-core': 3.2.39 '@vue/runtime-core': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/runtime-core': link:../runtime-core '@vue/runtime-core': link:../runtime-core
'@vue/shared': link:../shared '@vue/shared': link:../shared
packages/server-renderer: packages/server-renderer:
specifiers: specifiers:
'@vue/compiler-ssr': 3.2.39 '@vue/compiler-ssr': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/compiler-ssr': link:../compiler-ssr '@vue/compiler-ssr': link:../compiler-ssr
'@vue/shared': link:../shared '@vue/shared': link:../shared
packages/sfc-playground: packages/sfc-playground:
specifiers: specifiers:
'@vitejs/plugin-vue': ^3.0.0 '@vitejs/plugin-vue': ^1.10.2
'@vue/repl': ^1.3.0 '@vue/repl': ^1.3.0
file-saver: ^2.0.5 file-saver: ^2.0.5
jszip: ^3.6.0 jszip: ^3.6.0
vite: ^3.0.0 vite: ^2.9.8
vue: 3.2.39 vue: 3.2.38
dependencies: dependencies:
'@vue/repl': 1.3.0_vue@packages+vue '@vue/repl': 1.3.0_vue@packages+vue
file-saver: 2.0.5 file-saver: 2.0.5
jszip: 3.7.1 jszip: 3.7.1
vue: link:../vue vue: link:../vue
devDependencies: devDependencies:
'@vitejs/plugin-vue': 3.1.0_yvvbnwjsosvjg6n7dkt3ewqphy '@vitejs/plugin-vue': 1.10.2_vite@2.9.8
vite: 3.0.9 vite: 2.9.8
packages/shared: packages/shared:
specifiers: {} specifiers: {}
@ -272,11 +272,11 @@ importers:
packages/vue: packages/vue:
specifiers: specifiers:
'@vue/compiler-dom': 3.2.39 '@vue/compiler-dom': 3.2.38
'@vue/compiler-sfc': 3.2.39 '@vue/compiler-sfc': 3.2.38
'@vue/runtime-dom': 3.2.39 '@vue/runtime-dom': 3.2.38
'@vue/server-renderer': 3.2.39 '@vue/server-renderer': 3.2.38
'@vue/shared': 3.2.39 '@vue/shared': 3.2.38
dependencies: dependencies:
'@vue/compiler-dom': link:../compiler-dom '@vue/compiler-dom': link:../compiler-dom
'@vue/compiler-sfc': link:../compiler-sfc '@vue/compiler-sfc': link:../compiler-sfc
@ -1344,15 +1344,13 @@ packages:
eslint-visitor-keys: 3.3.0 eslint-visitor-keys: 3.3.0
dev: true dev: true
/@vitejs/plugin-vue/3.1.0_yvvbnwjsosvjg6n7dkt3ewqphy: /@vitejs/plugin-vue/1.10.2_vite@2.9.8:
resolution: {integrity: sha512-fmxtHPjSOEIRg6vHYDaem+97iwCUg/uSIaTzp98lhELt2ISOQuDo2hbkBdXod0g15IhfPMQmAxh4heUks2zvDA==} resolution: {integrity: sha512-/QJ0Z9qfhAFtKRY+r57ziY4BSbGUTGsPRMpB/Ron3QPwBZM4OZAZHdTa4a8PafCwU5DTatXG8TMDoP8z+oDqJw==}
engines: {node: ^14.18.0 || >=16.0.0} engines: {node: '>=12.0.0'}
peerDependencies: peerDependencies:
vite: ^3.0.0 vite: ^2.5.10
vue: ^3.2.25
dependencies: dependencies:
vite: 3.0.9 vite: 2.9.8
vue: link:packages/vue
dev: true dev: true
/@vue/consolidate/0.17.3: /@vue/consolidate/0.17.3:
@ -5807,6 +5805,15 @@ packages:
resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==} resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==}
dev: true 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: /postcss/8.4.16:
resolution: {integrity: sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==} resolution: {integrity: sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==}
engines: {node: ^10 || ^12 || >=14} engines: {node: ^10 || ^12 || >=14}
@ -6252,7 +6259,7 @@ packages:
resolution: {integrity: sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==} resolution: {integrity: sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==}
hasBin: true hasBin: true
dependencies: dependencies:
is-core-module: 2.10.0 is-core-module: 2.8.1
path-parse: 1.0.7 path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0 supports-preserve-symlinks-flag: 1.0.0
dev: true dev: true
@ -6382,6 +6389,14 @@ packages:
fsevents: 2.3.2 fsevents: 2.3.2
dev: true 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: /rollup/2.77.3:
resolution: {integrity: sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==} resolution: {integrity: sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==}
engines: {node: '>=10.0.0'} engines: {node: '>=10.0.0'}
@ -7207,6 +7222,30 @@ packages:
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
dev: true 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: /vite/3.0.9:
resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==} resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==}
engines: {node: ^14.18.0 || >=16.0.0} engines: {node: ^14.18.0 || >=16.0.0}