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,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { ASTElement, ASTModifiers } from 'types/compiler'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Cross-platform code generation for component v-model
|
|
5
5
|
*/
|
|
6
|
-
export function genComponentModel
|
|
6
|
+
export function genComponentModel(
|
|
7
7
|
el: ASTElement,
|
|
8
8
|
value: string,
|
|
9
|
-
modifiers:
|
|
10
|
-
):
|
|
9
|
+
modifiers: ASTModifiers | null
|
|
10
|
+
): void {
|
|
11
11
|
const { number, trim } = modifiers || {}
|
|
12
12
|
|
|
13
13
|
const baseValueExpression = '$$v'
|
|
@@ -33,10 +33,7 @@ export function genComponentModel (
|
|
|
33
33
|
/**
|
|
34
34
|
* Cross-platform codegen helper for generating v-model value assignment code.
|
|
35
35
|
*/
|
|
36
|
-
export function genAssignmentCode
|
|
37
|
-
value: string,
|
|
38
|
-
assignment: string
|
|
39
|
-
): string {
|
|
36
|
+
export function genAssignmentCode(value: string, assignment: string): string {
|
|
40
37
|
const res = parseModel(value)
|
|
41
38
|
if (res.key === null) {
|
|
42
39
|
return `${value}=${assignment}`
|
|
@@ -63,11 +60,11 @@ export function genAssignmentCode (
|
|
|
63
60
|
let len, str, chr, index, expressionPos, expressionEndPos
|
|
64
61
|
|
|
65
62
|
type ModelParseResult = {
|
|
66
|
-
exp: string
|
|
63
|
+
exp: string
|
|
67
64
|
key: string | null
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
export function parseModel
|
|
67
|
+
export function parseModel(val: string): ModelParseResult {
|
|
71
68
|
// Fix https://github.com/vuejs/vue/pull/7730
|
|
72
69
|
// allow v-model="obj.val " (trailing whitespace)
|
|
73
70
|
val = val.trim()
|
|
@@ -96,7 +93,7 @@ export function parseModel (val: string): ModelParseResult {
|
|
|
96
93
|
/* istanbul ignore if */
|
|
97
94
|
if (isStringStart(chr)) {
|
|
98
95
|
parseString(chr)
|
|
99
|
-
} else if (chr ===
|
|
96
|
+
} else if (chr === 0x5b) {
|
|
100
97
|
parseBracket(chr)
|
|
101
98
|
}
|
|
102
99
|
}
|
|
@@ -107,19 +104,19 @@ export function parseModel (val: string): ModelParseResult {
|
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
|
|
110
|
-
function next
|
|
107
|
+
function next(): number {
|
|
111
108
|
return str.charCodeAt(++index)
|
|
112
109
|
}
|
|
113
110
|
|
|
114
|
-
function eof
|
|
111
|
+
function eof(): boolean {
|
|
115
112
|
return index >= len
|
|
116
113
|
}
|
|
117
114
|
|
|
118
|
-
function isStringStart
|
|
115
|
+
function isStringStart(chr: number): boolean {
|
|
119
116
|
return chr === 0x22 || chr === 0x27
|
|
120
117
|
}
|
|
121
118
|
|
|
122
|
-
function parseBracket
|
|
119
|
+
function parseBracket(chr: number): void {
|
|
123
120
|
let inBracket = 1
|
|
124
121
|
expressionPos = index
|
|
125
122
|
while (!eof()) {
|
|
@@ -128,8 +125,8 @@ function parseBracket (chr: number): void {
|
|
|
128
125
|
parseString(chr)
|
|
129
126
|
continue
|
|
130
127
|
}
|
|
131
|
-
if (chr ===
|
|
132
|
-
if (chr ===
|
|
128
|
+
if (chr === 0x5b) inBracket++
|
|
129
|
+
if (chr === 0x5d) inBracket--
|
|
133
130
|
if (inBracket === 0) {
|
|
134
131
|
expressionEndPos = index
|
|
135
132
|
break
|
|
@@ -137,7 +134,7 @@ function parseBracket (chr: number): void {
|
|
|
137
134
|
}
|
|
138
135
|
}
|
|
139
136
|
|
|
140
|
-
function parseString
|
|
137
|
+
function parseString(chr: number): void {
|
|
141
138
|
const stringQuote = chr
|
|
142
139
|
while (!eof()) {
|
|
143
140
|
chr = next()
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { warn } from 'core/util/index'
|
|
2
|
+
import { ASTDirective, ASTElement } from 'types/compiler'
|
|
4
3
|
|
|
5
|
-
export default function on
|
|
6
|
-
if (
|
|
4
|
+
export default function on(el: ASTElement, dir: ASTDirective) {
|
|
5
|
+
if (__DEV__ && dir.modifiers) {
|
|
7
6
|
warn(`v-on without argument does not support modifiers.`)
|
|
8
7
|
}
|
|
9
8
|
el.wrapListeners = (code: string) => `_g(${code},${dir.value})`
|
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ASTElement, ASTNode } from 'types/compiler'
|
|
3
2
|
import { dirRE, onRE } from './parser/index'
|
|
4
3
|
|
|
5
|
-
type Range = { start?: number
|
|
4
|
+
type Range = { start?: number; end?: number }
|
|
6
5
|
|
|
7
6
|
// these keywords should not appear inside expressions, but operators like
|
|
8
7
|
// typeof, instanceof and in are allowed
|
|
9
|
-
const prohibitedKeywordRE = new RegExp(
|
|
10
|
-
'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const prohibitedKeywordRE = new RegExp(
|
|
9
|
+
'\\b' +
|
|
10
|
+
(
|
|
11
|
+
'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
|
|
12
|
+
'super,throw,while,yield,delete,export,import,return,switch,default,' +
|
|
13
|
+
'extends,finally,continue,debugger,function,arguments'
|
|
14
|
+
)
|
|
15
|
+
.split(',')
|
|
16
|
+
.join('\\b|\\b') +
|
|
17
|
+
'\\b'
|
|
18
|
+
)
|
|
14
19
|
|
|
15
20
|
// these unary operators should not be used as property/method names
|
|
16
|
-
const unaryOperatorsRE = new RegExp(
|
|
17
|
-
'
|
|
18
|
-
|
|
21
|
+
const unaryOperatorsRE = new RegExp(
|
|
22
|
+
'\\b' +
|
|
23
|
+
'delete,typeof,void'.split(',').join('\\s*\\([^\\)]*\\)|\\b') +
|
|
24
|
+
'\\s*\\([^\\)]*\\)'
|
|
25
|
+
)
|
|
19
26
|
|
|
20
27
|
// strip strings in expressions
|
|
21
|
-
const stripStringRE =
|
|
28
|
+
const stripStringRE =
|
|
29
|
+
/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
|
22
30
|
|
|
23
31
|
// detect problematic expressions in a template
|
|
24
|
-
export function detectErrors
|
|
32
|
+
export function detectErrors(ast: ASTNode | undefined, warn: Function) {
|
|
25
33
|
if (ast) {
|
|
26
34
|
checkNode(ast, warn)
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
function checkNode
|
|
38
|
+
function checkNode(node: ASTNode, warn: Function) {
|
|
31
39
|
if (node.type === 1) {
|
|
32
40
|
for (const name in node.attrsMap) {
|
|
33
41
|
if (dirRE.test(name)) {
|
|
@@ -37,7 +45,12 @@ function checkNode (node: ASTNode, warn: Function) {
|
|
|
37
45
|
if (name === 'v-for') {
|
|
38
46
|
checkFor(node, `v-for="${value}"`, warn, range)
|
|
39
47
|
} else if (name === 'v-slot' || name[0] === '#') {
|
|
40
|
-
checkFunctionParameterExpression(
|
|
48
|
+
checkFunctionParameterExpression(
|
|
49
|
+
value,
|
|
50
|
+
`${name}="${value}"`,
|
|
51
|
+
warn,
|
|
52
|
+
range
|
|
53
|
+
)
|
|
41
54
|
} else if (onRE.test(name)) {
|
|
42
55
|
checkEvent(value, `${name}="${value}"`, warn, range)
|
|
43
56
|
} else {
|
|
@@ -56,28 +69,33 @@ function checkNode (node: ASTNode, warn: Function) {
|
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
|
|
59
|
-
function checkEvent
|
|
72
|
+
function checkEvent(exp: string, text: string, warn: Function, range?: Range) {
|
|
60
73
|
const stripped = exp.replace(stripStringRE, '')
|
|
61
74
|
const keywordMatch: any = stripped.match(unaryOperatorsRE)
|
|
62
75
|
if (keywordMatch && stripped.charAt(keywordMatch.index - 1) !== '$') {
|
|
63
76
|
warn(
|
|
64
77
|
`avoid using JavaScript unary operator as property name: ` +
|
|
65
|
-
|
|
78
|
+
`"${keywordMatch[0]}" in expression ${text.trim()}`,
|
|
66
79
|
range
|
|
67
80
|
)
|
|
68
81
|
}
|
|
69
82
|
checkExpression(exp, text, warn, range)
|
|
70
83
|
}
|
|
71
84
|
|
|
72
|
-
function checkFor
|
|
85
|
+
function checkFor(
|
|
86
|
+
node: ASTElement,
|
|
87
|
+
text: string,
|
|
88
|
+
warn: Function,
|
|
89
|
+
range?: Range
|
|
90
|
+
) {
|
|
73
91
|
checkExpression(node.for || '', text, warn, range)
|
|
74
92
|
checkIdentifier(node.alias, 'v-for alias', text, warn, range)
|
|
75
93
|
checkIdentifier(node.iterator1, 'v-for iterator', text, warn, range)
|
|
76
94
|
checkIdentifier(node.iterator2, 'v-for iterator', text, warn, range)
|
|
77
95
|
}
|
|
78
96
|
|
|
79
|
-
function checkIdentifier
|
|
80
|
-
ident:
|
|
97
|
+
function checkIdentifier(
|
|
98
|
+
ident: string | null | undefined,
|
|
81
99
|
type: string,
|
|
82
100
|
text: string,
|
|
83
101
|
warn: Function,
|
|
@@ -86,42 +104,54 @@ function checkIdentifier (
|
|
|
86
104
|
if (typeof ident === 'string') {
|
|
87
105
|
try {
|
|
88
106
|
new Function(`var ${ident}=_`)
|
|
89
|
-
} catch (e) {
|
|
107
|
+
} catch (e: any) {
|
|
90
108
|
warn(`invalid ${type} "${ident}" in expression: ${text.trim()}`, range)
|
|
91
109
|
}
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
function checkExpression
|
|
113
|
+
function checkExpression(
|
|
114
|
+
exp: string,
|
|
115
|
+
text: string,
|
|
116
|
+
warn: Function,
|
|
117
|
+
range?: Range
|
|
118
|
+
) {
|
|
96
119
|
try {
|
|
97
120
|
new Function(`return ${exp}`)
|
|
98
|
-
} catch (e) {
|
|
99
|
-
const keywordMatch = exp
|
|
121
|
+
} catch (e: any) {
|
|
122
|
+
const keywordMatch = exp
|
|
123
|
+
.replace(stripStringRE, '')
|
|
124
|
+
.match(prohibitedKeywordRE)
|
|
100
125
|
if (keywordMatch) {
|
|
101
126
|
warn(
|
|
102
127
|
`avoid using JavaScript keyword as property name: ` +
|
|
103
|
-
|
|
128
|
+
`"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`,
|
|
104
129
|
range
|
|
105
130
|
)
|
|
106
131
|
} else {
|
|
107
132
|
warn(
|
|
108
133
|
`invalid expression: ${e.message} in\n\n` +
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
` ${exp}\n\n` +
|
|
135
|
+
` Raw expression: ${text.trim()}\n`,
|
|
111
136
|
range
|
|
112
137
|
)
|
|
113
138
|
}
|
|
114
139
|
}
|
|
115
140
|
}
|
|
116
141
|
|
|
117
|
-
function checkFunctionParameterExpression
|
|
142
|
+
function checkFunctionParameterExpression(
|
|
143
|
+
exp: string,
|
|
144
|
+
text: string,
|
|
145
|
+
warn: Function,
|
|
146
|
+
range?: Range
|
|
147
|
+
) {
|
|
118
148
|
try {
|
|
119
149
|
new Function(exp, '')
|
|
120
|
-
} catch (e) {
|
|
150
|
+
} catch (e: any) {
|
|
121
151
|
warn(
|
|
122
152
|
`invalid function parameter expression: ${e.message} in\n\n` +
|
|
123
|
-
|
|
124
|
-
|
|
153
|
+
` ${exp}\n\n` +
|
|
154
|
+
` Raw expression: ${text.trim()}\n`,
|
|
125
155
|
range
|
|
126
156
|
)
|
|
127
157
|
}
|
|
@@ -1,91 +1,111 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { emptyObject } from 'shared/util'
|
|
2
|
+
import { ASTElement, ASTModifiers } from 'types/compiler'
|
|
4
3
|
import { parseFilters } from './parser/filter-parser'
|
|
5
4
|
|
|
6
|
-
type Range = { start?: number
|
|
5
|
+
type Range = { start?: number; end?: number }
|
|
7
6
|
|
|
8
7
|
/* eslint-disable no-unused-vars */
|
|
9
|
-
export function baseWarn
|
|
8
|
+
export function baseWarn(msg: string, range?: Range) {
|
|
10
9
|
console.error(`[Vue compiler]: ${msg}`)
|
|
11
10
|
}
|
|
12
11
|
/* eslint-enable no-unused-vars */
|
|
13
12
|
|
|
14
|
-
export function pluckModuleFunction<
|
|
15
|
-
modules:
|
|
16
|
-
key:
|
|
17
|
-
): Array<
|
|
18
|
-
return modules
|
|
19
|
-
? modules.map(m => m[key]).filter(_ => _)
|
|
20
|
-
: []
|
|
13
|
+
export function pluckModuleFunction<T, K extends keyof T>(
|
|
14
|
+
modules: Array<T> | undefined,
|
|
15
|
+
key: K
|
|
16
|
+
): Array<T[K]> {
|
|
17
|
+
return modules ? modules.map(m => m[key]).filter(_ => _) : []
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
export function addProp
|
|
24
|
-
|
|
20
|
+
export function addProp(
|
|
21
|
+
el: ASTElement,
|
|
22
|
+
name: string,
|
|
23
|
+
value: string,
|
|
24
|
+
range?: Range,
|
|
25
|
+
dynamic?: boolean
|
|
26
|
+
) {
|
|
27
|
+
;(el.props || (el.props = [])).push(
|
|
28
|
+
rangeSetItem({ name, value, dynamic }, range)
|
|
29
|
+
)
|
|
25
30
|
el.plain = false
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
export function addAttr
|
|
33
|
+
export function addAttr(
|
|
34
|
+
el: ASTElement,
|
|
35
|
+
name: string,
|
|
36
|
+
value: any,
|
|
37
|
+
range?: Range,
|
|
38
|
+
dynamic?: boolean
|
|
39
|
+
) {
|
|
29
40
|
const attrs = dynamic
|
|
30
|
-
?
|
|
31
|
-
:
|
|
41
|
+
? el.dynamicAttrs || (el.dynamicAttrs = [])
|
|
42
|
+
: el.attrs || (el.attrs = [])
|
|
32
43
|
attrs.push(rangeSetItem({ name, value, dynamic }, range))
|
|
33
44
|
el.plain = false
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
// add a raw attr (use this in preTransforms)
|
|
37
|
-
export function addRawAttr
|
|
48
|
+
export function addRawAttr(
|
|
49
|
+
el: ASTElement,
|
|
50
|
+
name: string,
|
|
51
|
+
value: any,
|
|
52
|
+
range?: Range
|
|
53
|
+
) {
|
|
38
54
|
el.attrsMap[name] = value
|
|
39
55
|
el.attrsList.push(rangeSetItem({ name, value }, range))
|
|
40
56
|
}
|
|
41
57
|
|
|
42
|
-
export function addDirective
|
|
58
|
+
export function addDirective(
|
|
43
59
|
el: ASTElement,
|
|
44
60
|
name: string,
|
|
45
61
|
rawName: string,
|
|
46
62
|
value: string,
|
|
47
|
-
arg
|
|
48
|
-
isDynamicArg
|
|
49
|
-
modifiers
|
|
63
|
+
arg?: string,
|
|
64
|
+
isDynamicArg?: boolean,
|
|
65
|
+
modifiers?: ASTModifiers,
|
|
50
66
|
range?: Range
|
|
51
67
|
) {
|
|
52
|
-
(el.directives || (el.directives = [])).push(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
;(el.directives || (el.directives = [])).push(
|
|
69
|
+
rangeSetItem(
|
|
70
|
+
{
|
|
71
|
+
name,
|
|
72
|
+
rawName,
|
|
73
|
+
value,
|
|
74
|
+
arg,
|
|
75
|
+
isDynamicArg,
|
|
76
|
+
modifiers
|
|
77
|
+
},
|
|
78
|
+
range
|
|
79
|
+
)
|
|
80
|
+
)
|
|
60
81
|
el.plain = false
|
|
61
82
|
}
|
|
62
83
|
|
|
63
|
-
function prependModifierMarker
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
function prependModifierMarker(
|
|
85
|
+
symbol: string,
|
|
86
|
+
name: string,
|
|
87
|
+
dynamic?: boolean
|
|
88
|
+
): string {
|
|
89
|
+
return dynamic ? `_p(${name},"${symbol}")` : symbol + name // mark the event as captured
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
export function addHandler
|
|
92
|
+
export function addHandler(
|
|
70
93
|
el: ASTElement,
|
|
71
94
|
name: string,
|
|
72
95
|
value: string,
|
|
73
|
-
modifiers
|
|
96
|
+
modifiers?: ASTModifiers | null,
|
|
74
97
|
important?: boolean,
|
|
75
|
-
warn?:
|
|
98
|
+
warn?: Function,
|
|
76
99
|
range?: Range,
|
|
77
100
|
dynamic?: boolean
|
|
78
101
|
) {
|
|
79
102
|
modifiers = modifiers || emptyObject
|
|
80
103
|
// warn prevent and passive modifier
|
|
81
104
|
/* istanbul ignore if */
|
|
82
|
-
if (
|
|
83
|
-
process.env.NODE_ENV !== 'production' && warn &&
|
|
84
|
-
modifiers.prevent && modifiers.passive
|
|
85
|
-
) {
|
|
105
|
+
if (__DEV__ && warn && modifiers.prevent && modifiers.passive) {
|
|
86
106
|
warn(
|
|
87
|
-
|
|
88
|
-
|
|
107
|
+
"passive and prevent can't be used together. " +
|
|
108
|
+
"Passive handler can't prevent default event.",
|
|
89
109
|
range
|
|
90
110
|
)
|
|
91
111
|
}
|
|
@@ -149,23 +169,21 @@ export function addHandler (
|
|
|
149
169
|
el.plain = false
|
|
150
170
|
}
|
|
151
171
|
|
|
152
|
-
export function getRawBindingAttr
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
) {
|
|
156
|
-
return el.rawAttrsMap[':' + name] ||
|
|
172
|
+
export function getRawBindingAttr(el: ASTElement, name: string) {
|
|
173
|
+
return (
|
|
174
|
+
el.rawAttrsMap[':' + name] ||
|
|
157
175
|
el.rawAttrsMap['v-bind:' + name] ||
|
|
158
176
|
el.rawAttrsMap[name]
|
|
177
|
+
)
|
|
159
178
|
}
|
|
160
179
|
|
|
161
|
-
export function getBindingAttr
|
|
180
|
+
export function getBindingAttr(
|
|
162
181
|
el: ASTElement,
|
|
163
182
|
name: string,
|
|
164
183
|
getStatic?: boolean
|
|
165
|
-
):
|
|
184
|
+
): string | undefined {
|
|
166
185
|
const dynamicValue =
|
|
167
|
-
getAndRemoveAttr(el, ':' + name) ||
|
|
168
|
-
getAndRemoveAttr(el, 'v-bind:' + name)
|
|
186
|
+
getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name)
|
|
169
187
|
if (dynamicValue != null) {
|
|
170
188
|
return parseFilters(dynamicValue)
|
|
171
189
|
} else if (getStatic !== false) {
|
|
@@ -180,11 +198,11 @@ export function getBindingAttr (
|
|
|
180
198
|
// doesn't get processed by processAttrs.
|
|
181
199
|
// By default it does NOT remove it from the map (attrsMap) because the map is
|
|
182
200
|
// needed during codegen.
|
|
183
|
-
export function getAndRemoveAttr
|
|
201
|
+
export function getAndRemoveAttr(
|
|
184
202
|
el: ASTElement,
|
|
185
203
|
name: string,
|
|
186
204
|
removeFromMap?: boolean
|
|
187
|
-
):
|
|
205
|
+
): string | undefined {
|
|
188
206
|
let val
|
|
189
207
|
if ((val = el.attrsMap[name]) != null) {
|
|
190
208
|
const list = el.attrsList
|
|
@@ -201,10 +219,7 @@ export function getAndRemoveAttr (
|
|
|
201
219
|
return val
|
|
202
220
|
}
|
|
203
221
|
|
|
204
|
-
export function getAndRemoveAttrByRegex
|
|
205
|
-
el: ASTElement,
|
|
206
|
-
name: RegExp
|
|
207
|
-
) {
|
|
222
|
+
export function getAndRemoveAttrByRegex(el: ASTElement, name: RegExp) {
|
|
208
223
|
const list = el.attrsList
|
|
209
224
|
for (let i = 0, l = list.length; i < l; i++) {
|
|
210
225
|
const attr = list[i]
|
|
@@ -215,10 +230,7 @@ export function getAndRemoveAttrByRegex (
|
|
|
215
230
|
}
|
|
216
231
|
}
|
|
217
232
|
|
|
218
|
-
function rangeSetItem
|
|
219
|
-
item: any,
|
|
220
|
-
range?: { start?: number, end?: number }
|
|
221
|
-
) {
|
|
233
|
+
function rangeSetItem(item: any, range?: { start?: number; end?: number }) {
|
|
222
234
|
if (range) {
|
|
223
235
|
if (range.start != null) {
|
|
224
236
|
item.start = range.start
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { parse } from './parser/index'
|
|
4
2
|
import { optimize } from './optimizer'
|
|
5
3
|
import { generate } from './codegen/index'
|
|
6
4
|
import { createCompilerCreator } from './create-compiler'
|
|
5
|
+
import { CompilerOptions, CompiledResult } from 'types/compiler'
|
|
7
6
|
|
|
8
7
|
// `createCompilerCreator` allows creating compilers that use alternative
|
|
9
8
|
// parser/optimizer/codegen, e.g the SSR optimizing compiler.
|
|
10
9
|
// Here we just export a default compiler using the default parts.
|
|
11
|
-
export const createCompiler = createCompilerCreator(function baseCompile
|
|
10
|
+
export const createCompiler = createCompilerCreator(function baseCompile(
|
|
12
11
|
template: string,
|
|
13
12
|
options: CompilerOptions
|
|
14
13
|
): CompiledResult {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { makeMap, isBuiltInTag, cached, no } from 'shared/util'
|
|
2
|
+
import { ASTElement, CompilerOptions, ASTNode } from 'types/compiler'
|
|
4
3
|
|
|
5
4
|
let isStaticKey
|
|
6
5
|
let isPlatformReservedTag
|
|
@@ -18,7 +17,10 @@ const genStaticKeysCached = cached(genStaticKeys)
|
|
|
18
17
|
* create fresh nodes for them on each re-render;
|
|
19
18
|
* 2. Completely skip them in the patching process.
|
|
20
19
|
*/
|
|
21
|
-
export function optimize
|
|
20
|
+
export function optimize(
|
|
21
|
+
root: ASTElement | null | undefined,
|
|
22
|
+
options: CompilerOptions
|
|
23
|
+
) {
|
|
22
24
|
if (!root) return
|
|
23
25
|
isStaticKey = genStaticKeysCached(options.staticKeys || '')
|
|
24
26
|
isPlatformReservedTag = options.isReservedTag || no
|
|
@@ -28,14 +30,14 @@ export function optimize (root: ?ASTElement, options: CompilerOptions) {
|
|
|
28
30
|
markStaticRoots(root, false)
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function genStaticKeys
|
|
33
|
+
function genStaticKeys(keys: string): Function {
|
|
32
34
|
return makeMap(
|
|
33
35
|
'type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap' +
|
|
34
|
-
|
|
36
|
+
(keys ? ',' + keys : '')
|
|
35
37
|
)
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function markStatic
|
|
40
|
+
function markStatic(node: ASTNode) {
|
|
39
41
|
node.static = isStatic(node)
|
|
40
42
|
if (node.type === 1) {
|
|
41
43
|
// do not make component slot content static. this avoids
|
|
@@ -67,7 +69,7 @@ function markStatic (node: ASTNode) {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
function markStaticRoots
|
|
72
|
+
function markStaticRoots(node: ASTNode, isInFor: boolean) {
|
|
71
73
|
if (node.type === 1) {
|
|
72
74
|
if (node.static || node.once) {
|
|
73
75
|
node.staticInFor = isInFor
|
|
@@ -75,10 +77,11 @@ function markStaticRoots (node: ASTNode, isInFor: boolean) {
|
|
|
75
77
|
// For a node to qualify as a static root, it should have children that
|
|
76
78
|
// are not just static text. Otherwise the cost of hoisting out will
|
|
77
79
|
// outweigh the benefits and it's better off to just always render it fresh.
|
|
78
|
-
if (
|
|
79
|
-
node.
|
|
80
|
-
node.children
|
|
81
|
-
|
|
80
|
+
if (
|
|
81
|
+
node.static &&
|
|
82
|
+
node.children.length &&
|
|
83
|
+
!(node.children.length === 1 && node.children[0].type === 3)
|
|
84
|
+
) {
|
|
82
85
|
node.staticRoot = true
|
|
83
86
|
return
|
|
84
87
|
} else {
|
|
@@ -97,24 +100,28 @@ function markStaticRoots (node: ASTNode, isInFor: boolean) {
|
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
function isStatic
|
|
101
|
-
if (node.type === 2) {
|
|
103
|
+
function isStatic(node: ASTNode): boolean {
|
|
104
|
+
if (node.type === 2) {
|
|
105
|
+
// expression
|
|
102
106
|
return false
|
|
103
107
|
}
|
|
104
|
-
if (node.type === 3) {
|
|
108
|
+
if (node.type === 3) {
|
|
109
|
+
// text
|
|
105
110
|
return true
|
|
106
111
|
}
|
|
107
|
-
return !!(
|
|
108
|
-
|
|
109
|
-
!node.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
return !!(
|
|
113
|
+
node.pre ||
|
|
114
|
+
(!node.hasBindings && // no dynamic bindings
|
|
115
|
+
!node.if &&
|
|
116
|
+
!node.for && // not v-if or v-for or v-else
|
|
117
|
+
!isBuiltInTag(node.tag) && // not a built-in
|
|
118
|
+
isPlatformReservedTag(node.tag) && // not a component
|
|
119
|
+
!isDirectChildOfTemplateFor(node) &&
|
|
120
|
+
Object.keys(node).every(isStaticKey))
|
|
121
|
+
)
|
|
115
122
|
}
|
|
116
123
|
|
|
117
|
-
function isDirectChildOfTemplateFor
|
|
124
|
+
function isDirectChildOfTemplateFor(node: ASTElement): boolean {
|
|
118
125
|
while (node.parent) {
|
|
119
126
|
node = node.parent
|
|
120
127
|
if (node.tag !== 'template') {
|