vue 2.6.13 → 2.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -295
- package/compiler-sfc/index.d.ts +1 -0
- package/compiler-sfc/index.js +1 -0
- package/compiler-sfc/index.mjs +1 -0
- package/compiler-sfc/package.json +5 -0
- package/dist/vue.common.dev.js +11481 -11946
- package/dist/vue.common.prod.js +8 -3
- package/dist/vue.esm.browser.js +11321 -12011
- package/dist/vue.esm.browser.min.js +8 -3
- package/dist/vue.esm.js +11476 -11984
- package/dist/vue.js +11484 -11949
- package/dist/vue.min.js +8 -3
- package/dist/vue.runtime.common.dev.js +8427 -8421
- package/dist/vue.runtime.common.prod.js +8 -3
- package/dist/vue.runtime.esm.js +8436 -8454
- package/dist/vue.runtime.js +8430 -8424
- package/dist/vue.runtime.min.js +8 -3
- package/package.json +88 -111
- package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/package.json +30 -0
- package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
- package/src/compiler/codegen/{events.js → events.ts} +21 -41
- package/src/compiler/codegen/{index.js → index.ts} +146 -136
- package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/{index.js → index.ts} +0 -2
- package/src/compiler/directives/{model.js → model.ts} +15 -18
- package/src/compiler/directives/{on.js → on.ts} +3 -4
- package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
- package/src/compiler/{helpers.js → helpers.ts} +73 -61
- package/src/compiler/{index.js → index.ts} +2 -3
- package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
- package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
- package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
- package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
- package/src/compiler/parser/{index.js → index.ts} +190 -172
- package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
- package/src/compiler/{to-function.js → to-function.ts} +27 -22
- package/src/core/components/{index.js → index.ts} +0 -0
- package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
- package/src/core/{config.js → config.ts} +28 -30
- package/src/core/global-api/{assets.js → assets.ts} +8 -7
- package/src/core/global-api/{extend.js → extend.ts} +10 -13
- package/src/core/global-api/{index.js → index.ts} +4 -5
- package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
- package/src/core/global-api/use.ts +23 -0
- package/src/core/{index.js → index.ts} +1 -1
- package/src/core/instance/{events.js → events.ts} +41 -24
- package/src/core/instance/{index.js → index.ts} +9 -5
- package/src/core/instance/{init.js → init.ts} +26 -15
- package/src/core/instance/inject.ts +72 -0
- package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
- package/src/core/instance/{proxy.js → proxy.ts} +29 -24
- package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
- package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
- package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
- package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
- package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
- package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
- package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
- package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
- package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
- package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
- package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
- package/src/core/instance/{render.js → render.ts} +66 -29
- package/src/core/instance/{state.js → state.ts} +100 -83
- package/src/core/observer/{array.js → array.ts} +11 -2
- package/src/core/observer/{dep.js → dep.ts} +37 -15
- package/src/core/observer/{index.js → index.ts} +137 -71
- package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
- package/src/core/observer/{traverse.js → traverse.ts} +10 -7
- package/src/core/observer/{watcher.js → watcher.ts} +88 -60
- package/src/core/util/{debug.js → debug.ts} +38 -34
- package/src/core/util/{env.js → env.ts} +27 -30
- package/src/core/util/{error.js → error.ts} +12 -14
- package/src/core/util/{index.js → index.ts} +0 -2
- package/src/core/util/{lang.js → lang.ts} +6 -7
- package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
- package/src/core/util/{options.js → options.ts} +119 -114
- package/src/core/util/{perf.js → perf.ts} +5 -1
- package/src/core/util/{props.js → props.ts} +54 -50
- package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
- package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
- package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
- package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
- package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
- package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
- package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
- package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
- package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +96 -0
- package/src/core/vdom/{patch.js → patch.ts} +239 -138
- package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
- package/src/global.d.ts +15 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
- package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
- package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
- package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
- package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
- package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
- package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
- package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
- package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
- package/src/platforms/web/entry-compiler-sfc.ts +1 -0
- package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
- package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
- package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
- package/src/platforms/web/entry-runtime.ts +7 -0
- package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
- package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
- package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
- package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
- package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
- package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
- package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
- package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
- package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
- package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
- package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
- package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
- package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
- package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
- package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
- package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
- package/src/platforms/web/util/{class.js → class.ts} +23 -21
- package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
- package/src/platforms/web/util/{element.js → element.ts} +21 -22
- package/src/platforms/web/util/{index.js → index.ts} +2 -6
- package/src/platforms/web/util/{style.js → style.ts} +12 -12
- package/src/sfc/{parser.js → parser.ts} +18 -15
- package/src/shared/{constants.js → constants.ts} +2 -6
- package/src/shared/{util.js → util.ts} +78 -55
- package/src/types/compiler.ts +224 -0
- package/src/types/component.ts +209 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +120 -0
- package/src/types/ssr.ts +27 -0
- package/src/types/utils.ts +3 -0
- package/src/types/vnode.ts +127 -0
- package/src/v3/apiInject.ts +66 -0
- package/src/v3/apiLifecycle.ts +53 -0
- package/src/v3/apiSetup.ts +161 -0
- package/src/v3/apiWatch.ts +355 -0
- package/src/v3/currentInstance.ts +23 -0
- package/src/v3/debug.ts +21 -0
- package/src/v3/h.ts +18 -0
- package/src/v3/index.ts +77 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +134 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +123 -0
- package/src/v3/reactivity/readonly.ts +121 -0
- package/src/v3/reactivity/ref.ts +249 -0
- package/types/index.d.ts +10 -13
- package/types/options.d.ts +265 -132
- package/types/plugin.d.ts +4 -4
- package/types/umd.d.ts +47 -27
- package/types/v3-generated.d.ts +389 -0
- package/types/v3.d.ts +16 -0
- package/types/vnode.d.ts +70 -57
- package/types/vue.d.ts +292 -88
- package/dist/README.md +0 -122
- package/src/compiler/directives/bind.js +0 -11
- package/src/core/global-api/use.js +0 -23
- package/src/core/instance/inject.js +0 -73
- package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
- package/src/core/vdom/helpers/update-listeners.js +0 -95
- package/src/core/vdom/modules/index.js +0 -7
- package/src/core/vdom/modules/ref.js +0 -45
- package/src/platforms/web/compiler/directives/html.js +0 -9
- package/src/platforms/web/entry-server-basic-renderer.js +0 -13
- package/src/platforms/web/entry-server-renderer.js +0 -27
- package/src/platforms/web/runtime/node-ops.js +0 -59
- package/src/platforms/web/server/compiler.js +0 -11
- package/src/platforms/web/server/directives/index.js +0 -7
- package/src/platforms/web/server/directives/model.js +0 -44
- package/src/platforms/web/server/directives/show.js +0 -12
- package/src/platforms/web/server/modules/attrs.js +0 -67
- package/src/platforms/web/server/modules/class.js +0 -11
- package/src/platforms/web/server/modules/dom-props.js +0 -50
- package/src/platforms/web/server/modules/index.js +0 -11
- package/src/platforms/web/server/modules/style.js +0 -41
- package/src/platforms/web/server/util.js +0 -101
- package/src/platforms/weex/compiler/directives/index.js +0 -5
- package/src/platforms/weex/compiler/directives/model.js +0 -33
- package/src/platforms/weex/compiler/index.js +0 -52
- package/src/platforms/weex/compiler/modules/append.js +0 -27
- package/src/platforms/weex/compiler/modules/class.js +0 -74
- package/src/platforms/weex/compiler/modules/index.js +0 -13
- package/src/platforms/weex/compiler/modules/props.js +0 -37
- package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
- package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
- package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
- package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
- package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
- package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
- package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
- package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
- package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
- package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
- package/src/platforms/weex/compiler/modules/style.js +0 -87
- package/src/platforms/weex/entry-compiler.js +0 -2
- package/src/platforms/weex/entry-framework.js +0 -187
- package/src/platforms/weex/entry-runtime-factory.js +0 -6
- package/src/platforms/weex/runtime/components/index.js +0 -9
- package/src/platforms/weex/runtime/components/richtext.js +0 -82
- package/src/platforms/weex/runtime/components/transition-group.js +0 -148
- package/src/platforms/weex/runtime/components/transition.js +0 -9
- package/src/platforms/weex/runtime/directives/index.js +0 -2
- package/src/platforms/weex/runtime/index.js +0 -42
- package/src/platforms/weex/runtime/modules/attrs.js +0 -44
- package/src/platforms/weex/runtime/modules/class.js +0 -76
- package/src/platforms/weex/runtime/modules/events.js +0 -54
- package/src/platforms/weex/runtime/modules/index.js +0 -13
- package/src/platforms/weex/runtime/modules/style.js +0 -84
- package/src/platforms/weex/runtime/modules/transition.js +0 -270
- package/src/platforms/weex/runtime/node-ops.js +0 -91
- package/src/platforms/weex/runtime/patch.js +0 -16
- package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
- package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
- package/src/platforms/weex/runtime/text-node.js +0 -9
- package/src/platforms/weex/util/element.js +0 -52
- package/src/platforms/weex/util/index.js +0 -40
- package/src/platforms/weex/util/parser.js +0 -60
- package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
- package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
- package/src/server/bundle-renderer/source-map-support.js +0 -45
- package/src/server/create-basic-renderer.js +0 -37
- package/src/server/create-renderer.js +0 -152
- package/src/server/optimizing-compiler/codegen.js +0 -264
- package/src/server/optimizing-compiler/index.js +0 -20
- package/src/server/optimizing-compiler/modules.js +0 -124
- package/src/server/optimizing-compiler/optimizer.js +0 -141
- package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
- package/src/server/render-context.js +0 -130
- package/src/server/render-stream.js +0 -95
- package/src/server/render.js +0 -437
- package/src/server/template-renderer/create-async-file-mapper.js +0 -57
- package/src/server/template-renderer/index.js +0 -277
- package/src/server/template-renderer/parse-template.js +0 -42
- package/src/server/template-renderer/template-stream.js +0 -82
- package/src/server/util.js +0 -18
- package/src/server/webpack-plugin/client.js +0 -65
- package/src/server/webpack-plugin/server.js +0 -66
- package/src/server/webpack-plugin/util.js +0 -34
- package/src/server/write.js +0 -50
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { cached } from 'shared/util'
|
|
4
2
|
import { parseFilters } from './filter-parser'
|
|
5
3
|
|
|
@@ -13,27 +11,28 @@ const buildRegex = cached(delimiters => {
|
|
|
13
11
|
})
|
|
14
12
|
|
|
15
13
|
type TextParseResult = {
|
|
16
|
-
expression: string
|
|
14
|
+
expression: string
|
|
17
15
|
tokens: Array<string | { '@binding': string }>
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
export function parseText
|
|
18
|
+
export function parseText(
|
|
21
19
|
text: string,
|
|
22
20
|
delimiters?: [string, string]
|
|
23
21
|
): TextParseResult | void {
|
|
22
|
+
//@ts-expect-error
|
|
24
23
|
const tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE
|
|
25
24
|
if (!tagRE.test(text)) {
|
|
26
25
|
return
|
|
27
26
|
}
|
|
28
|
-
const tokens = []
|
|
29
|
-
const rawTokens = []
|
|
30
|
-
let lastIndex = tagRE.lastIndex = 0
|
|
27
|
+
const tokens: string[] = []
|
|
28
|
+
const rawTokens: any[] = []
|
|
29
|
+
let lastIndex = (tagRE.lastIndex = 0)
|
|
31
30
|
let match, index, tokenValue
|
|
32
31
|
while ((match = tagRE.exec(text))) {
|
|
33
32
|
index = match.index
|
|
34
33
|
// push text token
|
|
35
34
|
if (index > lastIndex) {
|
|
36
|
-
rawTokens.push(tokenValue = text.slice(lastIndex, index))
|
|
35
|
+
rawTokens.push((tokenValue = text.slice(lastIndex, index)))
|
|
37
36
|
tokens.push(JSON.stringify(tokenValue))
|
|
38
37
|
}
|
|
39
38
|
// tag token
|
|
@@ -43,7 +42,7 @@ export function parseText (
|
|
|
43
42
|
lastIndex = index + match[0].length
|
|
44
43
|
}
|
|
45
44
|
if (lastIndex < text.length) {
|
|
46
|
-
rawTokens.push(tokenValue = text.slice(lastIndex))
|
|
45
|
+
rawTokens.push((tokenValue = text.slice(lastIndex)))
|
|
47
46
|
tokens.push(JSON.stringify(tokenValue))
|
|
48
47
|
}
|
|
49
48
|
return {
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { noop, extend } from 'shared/util'
|
|
4
2
|
import { warn as baseWarn, tip } from 'core/util/debug'
|
|
5
3
|
import { generateCodeFrame } from './codeframe'
|
|
4
|
+
import type { Component } from 'types/component'
|
|
5
|
+
import { CompilerOptions } from 'types/compiler'
|
|
6
6
|
|
|
7
7
|
type CompiledFunctionResult = {
|
|
8
|
-
render: Function
|
|
9
|
-
staticRenderFns: Array<Function
|
|
10
|
-
}
|
|
8
|
+
render: Function
|
|
9
|
+
staticRenderFns: Array<Function>
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
function createFunction
|
|
12
|
+
function createFunction(code, errors) {
|
|
13
13
|
try {
|
|
14
14
|
return new Function(code)
|
|
15
|
-
} catch (err) {
|
|
15
|
+
} catch (err: any) {
|
|
16
16
|
errors.push({ err, code })
|
|
17
17
|
return noop
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function createCompileToFunctionFn
|
|
21
|
+
export function createCompileToFunctionFn(compile: Function): Function {
|
|
22
22
|
const cache = Object.create(null)
|
|
23
23
|
|
|
24
|
-
return function compileToFunctions
|
|
24
|
+
return function compileToFunctions(
|
|
25
25
|
template: string,
|
|
26
26
|
options?: CompilerOptions,
|
|
27
27
|
vm?: Component
|
|
@@ -31,18 +31,18 @@ export function createCompileToFunctionFn (compile: Function): Function {
|
|
|
31
31
|
delete options.warn
|
|
32
32
|
|
|
33
33
|
/* istanbul ignore if */
|
|
34
|
-
if (
|
|
34
|
+
if (__DEV__) {
|
|
35
35
|
// detect possible CSP restriction
|
|
36
36
|
try {
|
|
37
37
|
new Function('return 1')
|
|
38
|
-
} catch (e) {
|
|
38
|
+
} catch (e: any) {
|
|
39
39
|
if (e.toString().match(/unsafe-eval|CSP/)) {
|
|
40
40
|
warn(
|
|
41
41
|
'It seems you are using the standalone build of Vue.js in an ' +
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
'environment with Content Security Policy that prohibits unsafe-eval. ' +
|
|
43
|
+
'The template compiler cannot work in this environment. Consider ' +
|
|
44
|
+
'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
|
|
45
|
+
'templates into render functions.'
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -60,20 +60,21 @@ export function createCompileToFunctionFn (compile: Function): Function {
|
|
|
60
60
|
const compiled = compile(template, options)
|
|
61
61
|
|
|
62
62
|
// check compilation errors/tips
|
|
63
|
-
if (
|
|
63
|
+
if (__DEV__) {
|
|
64
64
|
if (compiled.errors && compiled.errors.length) {
|
|
65
65
|
if (options.outputSourceRange) {
|
|
66
66
|
compiled.errors.forEach(e => {
|
|
67
67
|
warn(
|
|
68
68
|
`Error compiling template:\n\n${e.msg}\n\n` +
|
|
69
|
-
|
|
69
|
+
generateCodeFrame(template, e.start, e.end),
|
|
70
70
|
vm
|
|
71
71
|
)
|
|
72
72
|
})
|
|
73
73
|
} else {
|
|
74
74
|
warn(
|
|
75
75
|
`Error compiling template:\n\n${template}\n\n` +
|
|
76
|
-
|
|
76
|
+
compiled.errors.map(e => `- ${e}`).join('\n') +
|
|
77
|
+
'\n',
|
|
77
78
|
vm
|
|
78
79
|
)
|
|
79
80
|
}
|
|
@@ -88,8 +89,8 @@ export function createCompileToFunctionFn (compile: Function): Function {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
// turn code into functions
|
|
91
|
-
const res = {}
|
|
92
|
-
const fnGenErrors = []
|
|
92
|
+
const res: any = {}
|
|
93
|
+
const fnGenErrors: any[] = []
|
|
93
94
|
res.render = createFunction(compiled.render, fnGenErrors)
|
|
94
95
|
res.staticRenderFns = compiled.staticRenderFns.map(code => {
|
|
95
96
|
return createFunction(code, fnGenErrors)
|
|
@@ -99,11 +100,15 @@ export function createCompileToFunctionFn (compile: Function): Function {
|
|
|
99
100
|
// this should only happen if there is a bug in the compiler itself.
|
|
100
101
|
// mostly for codegen development use
|
|
101
102
|
/* istanbul ignore if */
|
|
102
|
-
if (
|
|
103
|
+
if (__DEV__) {
|
|
103
104
|
if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
|
|
104
105
|
warn(
|
|
105
106
|
`Failed to generate render function:\n\n` +
|
|
106
|
-
|
|
107
|
+
fnGenErrors
|
|
108
|
+
.map(
|
|
109
|
+
({ err, code }) => `${(err as any).toString()} in\n\n${code}\n`
|
|
110
|
+
)
|
|
111
|
+
.join('\n'),
|
|
107
112
|
vm
|
|
108
113
|
)
|
|
109
114
|
}
|
|
File without changes
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { isRegExp, remove } from 'shared/util'
|
|
1
|
+
import { isRegExp, isArray, remove } from 'shared/util'
|
|
4
2
|
import { getFirstComponentChild } from 'core/vdom/helpers/index'
|
|
3
|
+
import type VNode from 'core/vdom/vnode'
|
|
4
|
+
import type { VNodeComponentOptions } from 'types/vnode'
|
|
5
|
+
import type { Component } from 'types/component'
|
|
5
6
|
|
|
6
7
|
type CacheEntry = {
|
|
7
|
-
name
|
|
8
|
-
tag
|
|
9
|
-
componentInstance
|
|
10
|
-
}
|
|
8
|
+
name?: string
|
|
9
|
+
tag?: string
|
|
10
|
+
componentInstance?: Component
|
|
11
|
+
}
|
|
11
12
|
|
|
12
|
-
type CacheEntryMap =
|
|
13
|
+
type CacheEntryMap = Record<string, CacheEntry | null>
|
|
13
14
|
|
|
14
|
-
function getComponentName
|
|
15
|
+
function getComponentName(opts?: VNodeComponentOptions): string | null {
|
|
15
16
|
return opts && (opts.Ctor.options.name || opts.tag)
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function matches
|
|
19
|
-
|
|
19
|
+
function matches(
|
|
20
|
+
pattern: string | RegExp | Array<string>,
|
|
21
|
+
name: string
|
|
22
|
+
): boolean {
|
|
23
|
+
if (isArray(pattern)) {
|
|
20
24
|
return pattern.indexOf(name) > -1
|
|
21
25
|
} else if (typeof pattern === 'string') {
|
|
22
26
|
return pattern.split(',').indexOf(name) > -1
|
|
@@ -27,12 +31,15 @@ function matches (pattern: string | RegExp | Array<string>, name: string): boole
|
|
|
27
31
|
return false
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
function pruneCache
|
|
34
|
+
function pruneCache(
|
|
35
|
+
keepAliveInstance: { cache: CacheEntryMap; keys: string[]; _vnode: VNode },
|
|
36
|
+
filter: Function
|
|
37
|
+
) {
|
|
31
38
|
const { cache, keys, _vnode } = keepAliveInstance
|
|
32
39
|
for (const key in cache) {
|
|
33
|
-
const entry
|
|
40
|
+
const entry = cache[key]
|
|
34
41
|
if (entry) {
|
|
35
|
-
const name
|
|
42
|
+
const name = entry.name
|
|
36
43
|
if (name && !filter(name)) {
|
|
37
44
|
pruneCacheEntry(cache, key, keys, _vnode)
|
|
38
45
|
}
|
|
@@ -40,14 +47,15 @@ function pruneCache (keepAliveInstance: any, filter: Function) {
|
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
function pruneCacheEntry
|
|
50
|
+
function pruneCacheEntry(
|
|
44
51
|
cache: CacheEntryMap,
|
|
45
52
|
key: string,
|
|
46
53
|
keys: Array<string>,
|
|
47
54
|
current?: VNode
|
|
48
55
|
) {
|
|
49
|
-
const entry
|
|
56
|
+
const entry = cache[key]
|
|
50
57
|
if (entry && (!current || entry.tag !== current.tag)) {
|
|
58
|
+
// @ts-expect-error can be undefined
|
|
51
59
|
entry.componentInstance.$destroy()
|
|
52
60
|
}
|
|
53
61
|
cache[key] = null
|
|
@@ -56,6 +64,7 @@ function pruneCacheEntry (
|
|
|
56
64
|
|
|
57
65
|
const patternTypes: Array<Function> = [String, RegExp, Array]
|
|
58
66
|
|
|
67
|
+
// TODO defineComponent
|
|
59
68
|
export default {
|
|
60
69
|
name: 'keep-alive',
|
|
61
70
|
abstract: true,
|
|
@@ -74,7 +83,7 @@ export default {
|
|
|
74
83
|
cache[keyToCache] = {
|
|
75
84
|
name: getComponentName(componentOptions),
|
|
76
85
|
tag,
|
|
77
|
-
componentInstance
|
|
86
|
+
componentInstance
|
|
78
87
|
}
|
|
79
88
|
keys.push(keyToCache)
|
|
80
89
|
// prune oldest entry
|
|
@@ -86,18 +95,18 @@ export default {
|
|
|
86
95
|
}
|
|
87
96
|
},
|
|
88
97
|
|
|
89
|
-
created
|
|
98
|
+
created() {
|
|
90
99
|
this.cache = Object.create(null)
|
|
91
100
|
this.keys = []
|
|
92
101
|
},
|
|
93
102
|
|
|
94
|
-
destroyed
|
|
103
|
+
destroyed() {
|
|
95
104
|
for (const key in this.cache) {
|
|
96
105
|
pruneCacheEntry(this.cache, key, this.keys)
|
|
97
106
|
}
|
|
98
107
|
},
|
|
99
108
|
|
|
100
|
-
mounted
|
|
109
|
+
mounted() {
|
|
101
110
|
this.cacheVNode()
|
|
102
111
|
this.$watch('include', val => {
|
|
103
112
|
pruneCache(this, name => matches(val, name))
|
|
@@ -107,17 +116,17 @@ export default {
|
|
|
107
116
|
})
|
|
108
117
|
},
|
|
109
118
|
|
|
110
|
-
updated
|
|
119
|
+
updated() {
|
|
111
120
|
this.cacheVNode()
|
|
112
121
|
},
|
|
113
122
|
|
|
114
|
-
render
|
|
123
|
+
render() {
|
|
115
124
|
const slot = this.$slots.default
|
|
116
|
-
const vnode
|
|
117
|
-
const componentOptions
|
|
125
|
+
const vnode = getFirstComponentChild(slot)
|
|
126
|
+
const componentOptions = vnode && vnode.componentOptions
|
|
118
127
|
if (componentOptions) {
|
|
119
128
|
// check pattern
|
|
120
|
-
const name
|
|
129
|
+
const name = getComponentName(componentOptions)
|
|
121
130
|
const { include, exclude } = this
|
|
122
131
|
if (
|
|
123
132
|
// not included
|
|
@@ -129,11 +138,13 @@ export default {
|
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
const { cache, keys } = this
|
|
132
|
-
const key
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
const key =
|
|
142
|
+
vnode.key == null
|
|
143
|
+
? // same constructor may get registered as different local components
|
|
144
|
+
// so cid alone is not enough (#3269)
|
|
145
|
+
componentOptions.Ctor.cid +
|
|
146
|
+
(componentOptions.tag ? `::${componentOptions.tag}` : '')
|
|
147
|
+
: vnode.key
|
|
137
148
|
if (cache[key]) {
|
|
138
149
|
vnode.componentInstance = cache[key].componentInstance
|
|
139
150
|
// make current key freshest
|
|
@@ -145,6 +156,7 @@ export default {
|
|
|
145
156
|
this.keyToCache = key
|
|
146
157
|
}
|
|
147
158
|
|
|
159
|
+
// @ts-expect-error can vnode.data can be undefined
|
|
148
160
|
vnode.data.keepAlive = true
|
|
149
161
|
}
|
|
150
162
|
return vnode || (slot && slot[0])
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
no,
|
|
5
|
-
noop,
|
|
6
|
-
identity
|
|
7
|
-
} from 'shared/util'
|
|
1
|
+
import { no, noop, identity } from 'shared/util'
|
|
8
2
|
|
|
9
3
|
import { LIFECYCLE_HOOKS } from 'shared/constants'
|
|
4
|
+
import type { Component } from 'types/component'
|
|
10
5
|
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface Config {
|
|
12
10
|
// user
|
|
13
|
-
optionMergeStrategies: { [key: string]: Function }
|
|
14
|
-
silent: boolean
|
|
15
|
-
productionTip: boolean
|
|
16
|
-
performance: boolean
|
|
17
|
-
devtools: boolean
|
|
18
|
-
errorHandler
|
|
19
|
-
warnHandler
|
|
20
|
-
ignoredElements: Array<string | RegExp
|
|
21
|
-
keyCodes: { [key: string]: number | Array<number> }
|
|
11
|
+
optionMergeStrategies: { [key: string]: Function }
|
|
12
|
+
silent: boolean
|
|
13
|
+
productionTip: boolean
|
|
14
|
+
performance: boolean
|
|
15
|
+
devtools: boolean
|
|
16
|
+
errorHandler?: (err: Error, vm: Component, info: string) => void
|
|
17
|
+
warnHandler?: (msg: string, vm: Component, trace: string) => void
|
|
18
|
+
ignoredElements: Array<string | RegExp>
|
|
19
|
+
keyCodes: { [key: string]: number | Array<number> }
|
|
22
20
|
|
|
23
21
|
// platform
|
|
24
|
-
isReservedTag: (x
|
|
25
|
-
isReservedAttr: (x
|
|
26
|
-
parsePlatformTagName: (x: string) => string
|
|
27
|
-
isUnknownElement: (x
|
|
28
|
-
getTagNamespace: (x
|
|
29
|
-
mustUseProp: (tag: string, type
|
|
22
|
+
isReservedTag: (x: string) => boolean | undefined
|
|
23
|
+
isReservedAttr: (x: string) => true | undefined
|
|
24
|
+
parsePlatformTagName: (x: string) => string
|
|
25
|
+
isUnknownElement: (x: string) => boolean
|
|
26
|
+
getTagNamespace: (x: string) => string | undefined
|
|
27
|
+
mustUseProp: (tag: string, type?: string | null, name?: string) => boolean
|
|
30
28
|
|
|
31
29
|
// private
|
|
32
|
-
async: boolean
|
|
30
|
+
async: boolean
|
|
33
31
|
|
|
34
32
|
// legacy
|
|
35
|
-
_lifecycleHooks: Array<string
|
|
36
|
-
}
|
|
33
|
+
_lifecycleHooks: Array<string>
|
|
34
|
+
}
|
|
37
35
|
|
|
38
|
-
export default
|
|
36
|
+
export default {
|
|
39
37
|
/**
|
|
40
38
|
* Option merge strategies (used in core/util/options)
|
|
41
39
|
*/
|
|
@@ -50,12 +48,12 @@ export default ({
|
|
|
50
48
|
/**
|
|
51
49
|
* Show production mode tip message on boot?
|
|
52
50
|
*/
|
|
53
|
-
productionTip:
|
|
51
|
+
productionTip: __DEV__,
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
54
|
* Whether to enable devtools
|
|
57
55
|
*/
|
|
58
|
-
devtools:
|
|
56
|
+
devtools: __DEV__,
|
|
59
57
|
|
|
60
58
|
/**
|
|
61
59
|
* Whether to record perf
|
|
@@ -127,4 +125,4 @@ export default ({
|
|
|
127
125
|
* Exposed for legacy reasons
|
|
128
126
|
*/
|
|
129
127
|
_lifecycleHooks: LIFECYCLE_HOOKS
|
|
130
|
-
}
|
|
128
|
+
} as unknown as Config
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { ASSET_TYPES } from 'shared/constants'
|
|
4
|
-
import {
|
|
2
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
3
|
+
import { isFunction, isPlainObject, validateComponentName } from '../util/index'
|
|
5
4
|
|
|
6
|
-
export function initAssetRegisters
|
|
5
|
+
export function initAssetRegisters(Vue: GlobalAPI) {
|
|
7
6
|
/**
|
|
8
7
|
* Create asset registration methods.
|
|
9
8
|
*/
|
|
10
9
|
ASSET_TYPES.forEach(type => {
|
|
10
|
+
// @ts-expect-error function is not exact same type
|
|
11
11
|
Vue[type] = function (
|
|
12
12
|
id: string,
|
|
13
|
-
definition
|
|
13
|
+
definition?: Function | Object
|
|
14
14
|
): Function | Object | void {
|
|
15
15
|
if (!definition) {
|
|
16
16
|
return this.options[type + 's'][id]
|
|
17
17
|
} else {
|
|
18
18
|
/* istanbul ignore if */
|
|
19
|
-
if (
|
|
19
|
+
if (__DEV__ && type === 'component') {
|
|
20
20
|
validateComponentName(id)
|
|
21
21
|
}
|
|
22
22
|
if (type === 'component' && isPlainObject(definition)) {
|
|
23
|
+
// @ts-expect-error
|
|
23
24
|
definition.name = definition.name || id
|
|
24
25
|
definition = this.options._base.extend(definition)
|
|
25
26
|
}
|
|
26
|
-
if (type === 'directive' &&
|
|
27
|
+
if (type === 'directive' && isFunction(definition)) {
|
|
27
28
|
definition = { bind: definition, update: definition }
|
|
28
29
|
}
|
|
29
30
|
this.options[type + 's'][id] = definition
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { ASSET_TYPES } from 'shared/constants'
|
|
2
|
+
import type { Component } from 'types/component'
|
|
3
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
4
4
|
import { defineComputed, proxy } from '../instance/state'
|
|
5
5
|
import { extend, mergeOptions, validateComponentName } from '../util/index'
|
|
6
6
|
|
|
7
|
-
export function initExtend
|
|
7
|
+
export function initExtend(Vue: GlobalAPI) {
|
|
8
8
|
/**
|
|
9
9
|
* Each instance constructor, including Vue, has a unique
|
|
10
10
|
* cid. This enables us to create wrapped "child
|
|
@@ -16,7 +16,7 @@ export function initExtend (Vue: GlobalAPI) {
|
|
|
16
16
|
/**
|
|
17
17
|
* Class inheritance
|
|
18
18
|
*/
|
|
19
|
-
Vue.extend = function (extendOptions:
|
|
19
|
+
Vue.extend = function (extendOptions: any): typeof Component {
|
|
20
20
|
extendOptions = extendOptions || {}
|
|
21
21
|
const Super = this
|
|
22
22
|
const SuperId = Super.cid
|
|
@@ -26,20 +26,17 @@ export function initExtend (Vue: GlobalAPI) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const name = extendOptions.name || Super.options.name
|
|
29
|
-
if (
|
|
29
|
+
if (__DEV__ && name) {
|
|
30
30
|
validateComponentName(name)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const Sub = function VueComponent
|
|
33
|
+
const Sub = function VueComponent(this: any, options: any) {
|
|
34
34
|
this._init(options)
|
|
35
|
-
}
|
|
35
|
+
} as unknown as typeof Component
|
|
36
36
|
Sub.prototype = Object.create(Super.prototype)
|
|
37
37
|
Sub.prototype.constructor = Sub
|
|
38
38
|
Sub.cid = cid++
|
|
39
|
-
Sub.options = mergeOptions(
|
|
40
|
-
Super.options,
|
|
41
|
-
extendOptions
|
|
42
|
-
)
|
|
39
|
+
Sub.options = mergeOptions(Super.options, extendOptions)
|
|
43
40
|
Sub['super'] = Super
|
|
44
41
|
|
|
45
42
|
// For props and computed properties, we define the proxy getters on
|
|
@@ -80,14 +77,14 @@ export function initExtend (Vue: GlobalAPI) {
|
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
function initProps
|
|
80
|
+
function initProps(Comp: typeof Component) {
|
|
84
81
|
const props = Comp.options.props
|
|
85
82
|
for (const key in props) {
|
|
86
83
|
proxy(Comp.prototype, `_props`, key)
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
function initComputed
|
|
87
|
+
function initComputed(Comp: typeof Component) {
|
|
91
88
|
const computed = Comp.options.computed
|
|
92
89
|
for (const key in computed) {
|
|
93
90
|
defineComputed(Comp.prototype, key, computed[key])
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import config from '../config'
|
|
4
2
|
import { initUse } from './use'
|
|
5
3
|
import { initMixin } from './mixin'
|
|
@@ -17,12 +15,13 @@ import {
|
|
|
17
15
|
mergeOptions,
|
|
18
16
|
defineReactive
|
|
19
17
|
} from '../util/index'
|
|
18
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
20
19
|
|
|
21
|
-
export function initGlobalAPI
|
|
20
|
+
export function initGlobalAPI(Vue: GlobalAPI) {
|
|
22
21
|
// config
|
|
23
|
-
const configDef = {}
|
|
22
|
+
const configDef: Record<string, any> = {}
|
|
24
23
|
configDef.get = () => config
|
|
25
|
-
if (
|
|
24
|
+
if (__DEV__) {
|
|
26
25
|
configDef.set = () => {
|
|
27
26
|
warn(
|
|
28
27
|
'Do not replace the Vue.config object, set individual fields instead.'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
3
2
|
import { mergeOptions } from '../util/index'
|
|
4
3
|
|
|
5
|
-
export function initMixin
|
|
4
|
+
export function initMixin(Vue: GlobalAPI) {
|
|
6
5
|
Vue.mixin = function (mixin: Object) {
|
|
7
6
|
this.options = mergeOptions(this.options, mixin)
|
|
8
7
|
return this
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
2
|
+
import { toArray, isFunction } from '../util/index'
|
|
3
|
+
|
|
4
|
+
export function initUse(Vue: GlobalAPI) {
|
|
5
|
+
Vue.use = function (plugin: Function | any) {
|
|
6
|
+
const installedPlugins =
|
|
7
|
+
this._installedPlugins || (this._installedPlugins = [])
|
|
8
|
+
if (installedPlugins.indexOf(plugin) > -1) {
|
|
9
|
+
return this
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// additional parameters
|
|
13
|
+
const args = toArray(arguments, 1)
|
|
14
|
+
args.unshift(this)
|
|
15
|
+
if (isFunction(plugin.install)) {
|
|
16
|
+
plugin.install.apply(plugin, args)
|
|
17
|
+
} else if (isFunction(plugin)) {
|
|
18
|
+
plugin.apply(null, args)
|
|
19
|
+
}
|
|
20
|
+
installedPlugins.push(plugin)
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
}
|