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,34 +1,48 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { genHandlers } from './events'
|
|
4
2
|
import baseDirectives from '../directives/index'
|
|
5
3
|
import { camelize, no, extend } from 'shared/util'
|
|
6
4
|
import { baseWarn, pluckModuleFunction } from '../helpers'
|
|
7
5
|
import { emptySlotScopeToken } from '../parser/index'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import {
|
|
7
|
+
ASTAttr,
|
|
8
|
+
ASTDirective,
|
|
9
|
+
ASTElement,
|
|
10
|
+
ASTExpression,
|
|
11
|
+
ASTIfConditions,
|
|
12
|
+
ASTNode,
|
|
13
|
+
ASTText,
|
|
14
|
+
CompilerOptions
|
|
15
|
+
} from 'types/compiler'
|
|
16
|
+
|
|
17
|
+
type TransformFunction = (el: ASTElement, code: string) => string
|
|
18
|
+
type DataGenFunction = (el: ASTElement) => string
|
|
19
|
+
type DirectiveFunction = (
|
|
20
|
+
el: ASTElement,
|
|
21
|
+
dir: ASTDirective,
|
|
22
|
+
warn: Function
|
|
23
|
+
) => boolean
|
|
12
24
|
|
|
13
25
|
export class CodegenState {
|
|
14
|
-
options: CompilerOptions
|
|
15
|
-
warn: Function
|
|
16
|
-
transforms: Array<TransformFunction
|
|
17
|
-
dataGenFns: Array<DataGenFunction
|
|
18
|
-
directives: { [key: string]: DirectiveFunction }
|
|
19
|
-
maybeComponent: (el: ASTElement) => boolean
|
|
20
|
-
onceId: number
|
|
21
|
-
staticRenderFns: Array<string
|
|
22
|
-
pre: boolean
|
|
23
|
-
|
|
24
|
-
constructor
|
|
26
|
+
options: CompilerOptions
|
|
27
|
+
warn: Function
|
|
28
|
+
transforms: Array<TransformFunction>
|
|
29
|
+
dataGenFns: Array<DataGenFunction>
|
|
30
|
+
directives: { [key: string]: DirectiveFunction }
|
|
31
|
+
maybeComponent: (el: ASTElement) => boolean
|
|
32
|
+
onceId: number
|
|
33
|
+
staticRenderFns: Array<string>
|
|
34
|
+
pre: boolean
|
|
35
|
+
|
|
36
|
+
constructor(options: CompilerOptions) {
|
|
25
37
|
this.options = options
|
|
26
38
|
this.warn = options.warn || baseWarn
|
|
39
|
+
//@ts-expect-error `this.transforms ` is a different type than `options.modules.transformCode`
|
|
27
40
|
this.transforms = pluckModuleFunction(options.modules, 'transformCode')
|
|
28
41
|
this.dataGenFns = pluckModuleFunction(options.modules, 'genData')
|
|
29
42
|
this.directives = extend(extend({}, baseDirectives), options.directives)
|
|
30
43
|
const isReservedTag = options.isReservedTag || no
|
|
31
|
-
this.maybeComponent = (el: ASTElement) =>
|
|
44
|
+
this.maybeComponent = (el: ASTElement) =>
|
|
45
|
+
!!el.component || !isReservedTag(el.tag)
|
|
32
46
|
this.onceId = 0
|
|
33
47
|
this.staticRenderFns = []
|
|
34
48
|
this.pre = false
|
|
@@ -36,24 +50,28 @@ export class CodegenState {
|
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
export type CodegenResult = {
|
|
39
|
-
render: string
|
|
53
|
+
render: string
|
|
40
54
|
staticRenderFns: Array<string>
|
|
41
|
-
}
|
|
55
|
+
}
|
|
42
56
|
|
|
43
|
-
export function generate
|
|
57
|
+
export function generate(
|
|
44
58
|
ast: ASTElement | void,
|
|
45
59
|
options: CompilerOptions
|
|
46
60
|
): CodegenResult {
|
|
47
61
|
const state = new CodegenState(options)
|
|
48
62
|
// fix #11483, Root level <script> tags should not be rendered.
|
|
49
|
-
const code = ast
|
|
63
|
+
const code = ast
|
|
64
|
+
? ast.tag === 'script'
|
|
65
|
+
? 'null'
|
|
66
|
+
: genElement(ast, state)
|
|
67
|
+
: '_c("div")'
|
|
50
68
|
return {
|
|
51
69
|
render: `with(this){return ${code}}`,
|
|
52
70
|
staticRenderFns: state.staticRenderFns
|
|
53
71
|
}
|
|
54
72
|
}
|
|
55
73
|
|
|
56
|
-
export function genElement
|
|
74
|
+
export function genElement(el: ASTElement, state: CodegenState): string {
|
|
57
75
|
if (el.parent) {
|
|
58
76
|
el.pre = el.pre || el.parent.pre
|
|
59
77
|
}
|
|
@@ -97,7 +115,7 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
|
|
97
115
|
}
|
|
98
116
|
|
|
99
117
|
// hoist static sub-trees out
|
|
100
|
-
function genStatic
|
|
118
|
+
function genStatic(el: ASTElement, state: CodegenState): string {
|
|
101
119
|
el.staticProcessed = true
|
|
102
120
|
// Some elements (templates) need to behave differently inside of a v-pre
|
|
103
121
|
// node. All pre nodes are static roots, so we can use this as a location to
|
|
@@ -108,15 +126,13 @@ function genStatic (el: ASTElement, state: CodegenState): string {
|
|
|
108
126
|
}
|
|
109
127
|
state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
|
|
110
128
|
state.pre = originalPreState
|
|
111
|
-
return `_m(${
|
|
112
|
-
state.staticRenderFns.length - 1
|
|
113
|
-
}${
|
|
129
|
+
return `_m(${state.staticRenderFns.length - 1}${
|
|
114
130
|
el.staticInFor ? ',true' : ''
|
|
115
131
|
})`
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
// v-once
|
|
119
|
-
function genOnce
|
|
135
|
+
function genOnce(el: ASTElement, state: CodegenState): string {
|
|
120
136
|
el.onceProcessed = true
|
|
121
137
|
if (el.if && !el.ifProcessed) {
|
|
122
138
|
return genIf(el, state)
|
|
@@ -125,16 +141,17 @@ function genOnce (el: ASTElement, state: CodegenState): string {
|
|
|
125
141
|
let parent = el.parent
|
|
126
142
|
while (parent) {
|
|
127
143
|
if (parent.for) {
|
|
128
|
-
key = parent.key
|
|
144
|
+
key = parent.key!
|
|
129
145
|
break
|
|
130
146
|
}
|
|
131
147
|
parent = parent.parent
|
|
132
148
|
}
|
|
133
149
|
if (!key) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
__DEV__ &&
|
|
151
|
+
state.warn(
|
|
152
|
+
`v-once can only be used inside v-for that is keyed. `,
|
|
153
|
+
el.rawAttrsMap['v-once']
|
|
154
|
+
)
|
|
138
155
|
return genElement(el, state)
|
|
139
156
|
}
|
|
140
157
|
return `_o(${genElement(el, state)},${state.onceId++},${key})`
|
|
@@ -143,7 +160,7 @@ function genOnce (el: ASTElement, state: CodegenState): string {
|
|
|
143
160
|
}
|
|
144
161
|
}
|
|
145
162
|
|
|
146
|
-
export function genIf
|
|
163
|
+
export function genIf(
|
|
147
164
|
el: any,
|
|
148
165
|
state: CodegenState,
|
|
149
166
|
altGen?: Function,
|
|
@@ -153,7 +170,7 @@ export function genIf (
|
|
|
153
170
|
return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
|
|
154
171
|
}
|
|
155
172
|
|
|
156
|
-
function genIfConditions
|
|
173
|
+
function genIfConditions(
|
|
157
174
|
conditions: ASTIfConditions,
|
|
158
175
|
state: CodegenState,
|
|
159
176
|
altGen?: Function,
|
|
@@ -163,28 +180,26 @@ function genIfConditions (
|
|
|
163
180
|
return altEmpty || '_e()'
|
|
164
181
|
}
|
|
165
182
|
|
|
166
|
-
const condition = conditions.shift()
|
|
183
|
+
const condition = conditions.shift()!
|
|
167
184
|
if (condition.exp) {
|
|
168
|
-
return `(${condition.exp})?${
|
|
169
|
-
|
|
170
|
-
}:${
|
|
171
|
-
genIfConditions(conditions, state, altGen, altEmpty)
|
|
172
|
-
}`
|
|
185
|
+
return `(${condition.exp})?${genTernaryExp(
|
|
186
|
+
condition.block
|
|
187
|
+
)}:${genIfConditions(conditions, state, altGen, altEmpty)}`
|
|
173
188
|
} else {
|
|
174
189
|
return `${genTernaryExp(condition.block)}`
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
// v-if with v-once should generate code like (a)?_m(0):_m(1)
|
|
178
|
-
function genTernaryExp
|
|
193
|
+
function genTernaryExp(el) {
|
|
179
194
|
return altGen
|
|
180
195
|
? altGen(el, state)
|
|
181
196
|
: el.once
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
? genOnce(el, state)
|
|
198
|
+
: genElement(el, state)
|
|
184
199
|
}
|
|
185
200
|
}
|
|
186
201
|
|
|
187
|
-
export function genFor
|
|
202
|
+
export function genFor(
|
|
188
203
|
el: any,
|
|
189
204
|
state: CodegenState,
|
|
190
205
|
altGen?: Function,
|
|
@@ -195,7 +210,8 @@ export function genFor (
|
|
|
195
210
|
const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
|
|
196
211
|
const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
|
|
197
212
|
|
|
198
|
-
if (
|
|
213
|
+
if (
|
|
214
|
+
__DEV__ &&
|
|
199
215
|
state.maybeComponent(el) &&
|
|
200
216
|
el.tag !== 'slot' &&
|
|
201
217
|
el.tag !== 'template' &&
|
|
@@ -203,21 +219,23 @@ export function genFor (
|
|
|
203
219
|
) {
|
|
204
220
|
state.warn(
|
|
205
221
|
`<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
|
|
206
|
-
|
|
207
|
-
|
|
222
|
+
`v-for should have explicit keys. ` +
|
|
223
|
+
`See https://vuejs.org/guide/list.html#key for more info.`,
|
|
208
224
|
el.rawAttrsMap['v-for'],
|
|
209
225
|
true /* tip */
|
|
210
226
|
)
|
|
211
227
|
}
|
|
212
228
|
|
|
213
229
|
el.forProcessed = true // avoid recursion
|
|
214
|
-
return
|
|
230
|
+
return (
|
|
231
|
+
`${altHelper || '_l'}((${exp}),` +
|
|
215
232
|
`function(${alias}${iterator1}${iterator2}){` +
|
|
216
|
-
|
|
233
|
+
`return ${(altGen || genElement)(el, state)}` +
|
|
217
234
|
'})'
|
|
235
|
+
)
|
|
218
236
|
}
|
|
219
237
|
|
|
220
|
-
export function genData
|
|
238
|
+
export function genData(el: ASTElement, state: CodegenState): string {
|
|
221
239
|
let data = '{'
|
|
222
240
|
|
|
223
241
|
// directives first.
|
|
@@ -274,13 +292,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
|
|
274
292
|
}
|
|
275
293
|
// component v-model
|
|
276
294
|
if (el.model) {
|
|
277
|
-
data += `model:{value:${
|
|
278
|
-
el.model.value
|
|
279
|
-
},callback:${
|
|
280
|
-
el.model.callback
|
|
281
|
-
},expression:${
|
|
282
|
-
el.model.expression
|
|
283
|
-
}},`
|
|
295
|
+
data += `model:{value:${el.model.value},callback:${el.model.callback},expression:${el.model.expression}},`
|
|
284
296
|
}
|
|
285
297
|
// inline-template
|
|
286
298
|
if (el.inlineTemplate) {
|
|
@@ -307,7 +319,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
|
|
307
319
|
return data
|
|
308
320
|
}
|
|
309
321
|
|
|
310
|
-
function genDirectives
|
|
322
|
+
function genDirectives(el: ASTElement, state: CodegenState): string | void {
|
|
311
323
|
const dirs = el.directives
|
|
312
324
|
if (!dirs) return
|
|
313
325
|
let res = 'directives:['
|
|
@@ -325,10 +337,10 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
|
|
|
325
337
|
if (needRuntime) {
|
|
326
338
|
hasRuntime = true
|
|
327
339
|
res += `{name:"${dir.name}",rawName:"${dir.rawName}"${
|
|
328
|
-
dir.value
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}${
|
|
340
|
+
dir.value
|
|
341
|
+
? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}`
|
|
342
|
+
: ''
|
|
343
|
+
}${dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''}${
|
|
332
344
|
dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''
|
|
333
345
|
}},`
|
|
334
346
|
}
|
|
@@ -338,11 +350,12 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
|
|
|
338
350
|
}
|
|
339
351
|
}
|
|
340
352
|
|
|
341
|
-
function genInlineTemplate
|
|
353
|
+
function genInlineTemplate(
|
|
354
|
+
el: ASTElement,
|
|
355
|
+
state: CodegenState
|
|
356
|
+
): string | undefined {
|
|
342
357
|
const ast = el.children[0]
|
|
343
|
-
if (
|
|
344
|
-
el.children.length !== 1 || ast.type !== 1
|
|
345
|
-
)) {
|
|
358
|
+
if (__DEV__ && (el.children.length !== 1 || ast.type !== 1)) {
|
|
346
359
|
state.warn(
|
|
347
360
|
'Inline-template components must have exactly one child element.',
|
|
348
361
|
{ start: el.start }
|
|
@@ -352,13 +365,13 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
|
|
|
352
365
|
const inlineRenderFns = generate(ast, state.options)
|
|
353
366
|
return `inlineTemplate:{render:function(){${
|
|
354
367
|
inlineRenderFns.render
|
|
355
|
-
}},staticRenderFns:[${
|
|
356
|
-
|
|
357
|
-
|
|
368
|
+
}},staticRenderFns:[${inlineRenderFns.staticRenderFns
|
|
369
|
+
.map(code => `function(){${code}}`)
|
|
370
|
+
.join(',')}]}`
|
|
358
371
|
}
|
|
359
372
|
}
|
|
360
373
|
|
|
361
|
-
function genScopedSlots
|
|
374
|
+
function genScopedSlots(
|
|
362
375
|
el: ASTElement,
|
|
363
376
|
slots: { [key: string]: ASTElement },
|
|
364
377
|
state: CodegenState
|
|
@@ -367,15 +380,14 @@ function genScopedSlots (
|
|
|
367
380
|
// components with only scoped slots to skip forced updates from parent.
|
|
368
381
|
// but in some cases we have to bail-out of this optimization
|
|
369
382
|
// for example if the slot contains dynamic names, has v-if or v-for on them...
|
|
370
|
-
let needsForceUpdate =
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
slot
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
)
|
|
378
|
-
})
|
|
383
|
+
let needsForceUpdate =
|
|
384
|
+
el.for ||
|
|
385
|
+
Object.keys(slots).some(key => {
|
|
386
|
+
const slot = slots[key]
|
|
387
|
+
return (
|
|
388
|
+
slot.slotTargetDynamic || slot.if || slot.for || containsSlotChild(slot) // is passing down slot from parent which may be dynamic
|
|
389
|
+
)
|
|
390
|
+
})
|
|
379
391
|
|
|
380
392
|
// #9534: if a component with scoped slots is inside a conditional branch,
|
|
381
393
|
// it's possible for the same component to be reused but with different
|
|
@@ -419,13 +431,13 @@ function genScopedSlots (
|
|
|
419
431
|
function hash(str) {
|
|
420
432
|
let hash = 5381
|
|
421
433
|
let i = str.length
|
|
422
|
-
while(i) {
|
|
434
|
+
while (i) {
|
|
423
435
|
hash = (hash * 33) ^ str.charCodeAt(--i)
|
|
424
436
|
}
|
|
425
437
|
return hash >>> 0
|
|
426
438
|
}
|
|
427
439
|
|
|
428
|
-
function containsSlotChild
|
|
440
|
+
function containsSlotChild(el: ASTNode): boolean {
|
|
429
441
|
if (el.type === 1) {
|
|
430
442
|
if (el.tag === 'slot') {
|
|
431
443
|
return true
|
|
@@ -435,10 +447,7 @@ function containsSlotChild (el: ASTNode): boolean {
|
|
|
435
447
|
return false
|
|
436
448
|
}
|
|
437
449
|
|
|
438
|
-
function genScopedSlot
|
|
439
|
-
el: ASTElement,
|
|
440
|
-
state: CodegenState
|
|
441
|
-
): string {
|
|
450
|
+
function genScopedSlot(el: ASTElement, state: CodegenState): string {
|
|
442
451
|
const isLegacySyntax = el.attrsMap['slot-scope']
|
|
443
452
|
if (el.if && !el.ifProcessed && !isLegacySyntax) {
|
|
444
453
|
return genIf(el, state, genScopedSlot, `null`)
|
|
@@ -446,22 +455,23 @@ function genScopedSlot (
|
|
|
446
455
|
if (el.for && !el.forProcessed) {
|
|
447
456
|
return genFor(el, state, genScopedSlot)
|
|
448
457
|
}
|
|
449
|
-
const slotScope =
|
|
450
|
-
? ``
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
`return ${
|
|
454
|
-
|
|
455
|
-
?
|
|
456
|
-
|
|
457
|
-
|
|
458
|
+
const slotScope =
|
|
459
|
+
el.slotScope === emptySlotScopeToken ? `` : String(el.slotScope)
|
|
460
|
+
const fn =
|
|
461
|
+
`function(${slotScope}){` +
|
|
462
|
+
`return ${
|
|
463
|
+
el.tag === 'template'
|
|
464
|
+
? el.if && isLegacySyntax
|
|
465
|
+
? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
|
|
466
|
+
: genChildren(el, state) || 'undefined'
|
|
467
|
+
: genElement(el, state)
|
|
458
468
|
}}`
|
|
459
469
|
// reverse proxy v-slot without scope on this.$slots
|
|
460
470
|
const reverseProxy = slotScope ? `` : `,proxy:true`
|
|
461
471
|
return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`
|
|
462
472
|
}
|
|
463
473
|
|
|
464
|
-
export function genChildren
|
|
474
|
+
export function genChildren(
|
|
465
475
|
el: ASTElement,
|
|
466
476
|
state: CodegenState,
|
|
467
477
|
checkSkip?: boolean,
|
|
@@ -472,13 +482,16 @@ export function genChildren (
|
|
|
472
482
|
if (children.length) {
|
|
473
483
|
const el: any = children[0]
|
|
474
484
|
// optimize single v-for
|
|
475
|
-
if (
|
|
485
|
+
if (
|
|
486
|
+
children.length === 1 &&
|
|
476
487
|
el.for &&
|
|
477
488
|
el.tag !== 'template' &&
|
|
478
489
|
el.tag !== 'slot'
|
|
479
490
|
) {
|
|
480
491
|
const normalizationType = checkSkip
|
|
481
|
-
? state.maybeComponent(el)
|
|
492
|
+
? state.maybeComponent(el)
|
|
493
|
+
? `,1`
|
|
494
|
+
: `,0`
|
|
482
495
|
: ``
|
|
483
496
|
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
|
|
484
497
|
}
|
|
@@ -496,7 +509,7 @@ export function genChildren (
|
|
|
496
509
|
// 0: no normalization needed
|
|
497
510
|
// 1: simple normalization needed (possible 1-level deep nested array)
|
|
498
511
|
// 2: full normalization needed
|
|
499
|
-
function getNormalizationType
|
|
512
|
+
function getNormalizationType(
|
|
500
513
|
children: Array<ASTNode>,
|
|
501
514
|
maybeComponent: (el: ASTElement) => boolean
|
|
502
515
|
): number {
|
|
@@ -506,24 +519,29 @@ function getNormalizationType (
|
|
|
506
519
|
if (el.type !== 1) {
|
|
507
520
|
continue
|
|
508
521
|
}
|
|
509
|
-
if (
|
|
510
|
-
|
|
522
|
+
if (
|
|
523
|
+
needsNormalization(el) ||
|
|
524
|
+
(el.ifConditions &&
|
|
525
|
+
el.ifConditions.some(c => needsNormalization(c.block)))
|
|
526
|
+
) {
|
|
511
527
|
res = 2
|
|
512
528
|
break
|
|
513
529
|
}
|
|
514
|
-
if (
|
|
515
|
-
|
|
530
|
+
if (
|
|
531
|
+
maybeComponent(el) ||
|
|
532
|
+
(el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))
|
|
533
|
+
) {
|
|
516
534
|
res = 1
|
|
517
535
|
}
|
|
518
536
|
}
|
|
519
537
|
return res
|
|
520
538
|
}
|
|
521
539
|
|
|
522
|
-
function needsNormalization
|
|
540
|
+
function needsNormalization(el: ASTElement): boolean {
|
|
523
541
|
return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
|
|
524
542
|
}
|
|
525
543
|
|
|
526
|
-
function genNode
|
|
544
|
+
function genNode(node: ASTNode, state: CodegenState): string {
|
|
527
545
|
if (node.type === 1) {
|
|
528
546
|
return genElement(node, state)
|
|
529
547
|
} else if (node.type === 3 && node.isComment) {
|
|
@@ -533,29 +551,33 @@ function genNode (node: ASTNode, state: CodegenState): string {
|
|
|
533
551
|
}
|
|
534
552
|
}
|
|
535
553
|
|
|
536
|
-
export function genText
|
|
537
|
-
return `_v(${
|
|
538
|
-
|
|
539
|
-
|
|
554
|
+
export function genText(text: ASTText | ASTExpression): string {
|
|
555
|
+
return `_v(${
|
|
556
|
+
text.type === 2
|
|
557
|
+
? text.expression // no need for () because already wrapped in _s()
|
|
558
|
+
: transformSpecialNewlines(JSON.stringify(text.text))
|
|
540
559
|
})`
|
|
541
560
|
}
|
|
542
561
|
|
|
543
|
-
export function genComment
|
|
562
|
+
export function genComment(comment: ASTText): string {
|
|
544
563
|
return `_e(${JSON.stringify(comment.text)})`
|
|
545
564
|
}
|
|
546
565
|
|
|
547
|
-
function genSlot
|
|
566
|
+
function genSlot(el: ASTElement, state: CodegenState): string {
|
|
548
567
|
const slotName = el.slotName || '"default"'
|
|
549
568
|
const children = genChildren(el, state)
|
|
550
569
|
let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`
|
|
551
|
-
const attrs =
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
570
|
+
const attrs =
|
|
571
|
+
el.attrs || el.dynamicAttrs
|
|
572
|
+
? genProps(
|
|
573
|
+
(el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
|
|
574
|
+
// slot props are camelized
|
|
575
|
+
name: camelize(attr.name),
|
|
576
|
+
value: attr.value,
|
|
577
|
+
dynamic: attr.dynamic
|
|
578
|
+
}))
|
|
579
|
+
)
|
|
580
|
+
: null
|
|
559
581
|
const bind = el.attrsMap['v-bind']
|
|
560
582
|
if ((attrs || bind) && !children) {
|
|
561
583
|
res += `,null`
|
|
@@ -570,7 +592,7 @@ function genSlot (el: ASTElement, state: CodegenState): string {
|
|
|
570
592
|
}
|
|
571
593
|
|
|
572
594
|
// componentName is el.component, take it as argument to shun flow's pessimistic refinement
|
|
573
|
-
function genComponent
|
|
595
|
+
function genComponent(
|
|
574
596
|
componentName: string,
|
|
575
597
|
el: ASTElement,
|
|
576
598
|
state: CodegenState
|
|
@@ -581,14 +603,12 @@ function genComponent (
|
|
|
581
603
|
})`
|
|
582
604
|
}
|
|
583
605
|
|
|
584
|
-
function genProps
|
|
606
|
+
function genProps(props: Array<ASTAttr>): string {
|
|
585
607
|
let staticProps = ``
|
|
586
608
|
let dynamicProps = ``
|
|
587
609
|
for (let i = 0; i < props.length; i++) {
|
|
588
610
|
const prop = props[i]
|
|
589
|
-
const value =
|
|
590
|
-
? generateValue(prop.value)
|
|
591
|
-
: transformSpecialNewlines(prop.value)
|
|
611
|
+
const value = transformSpecialNewlines(prop.value)
|
|
592
612
|
if (prop.dynamic) {
|
|
593
613
|
dynamicProps += `${prop.name},${value},`
|
|
594
614
|
} else {
|
|
@@ -603,17 +623,7 @@ function genProps (props: Array<ASTAttr>): string {
|
|
|
603
623
|
}
|
|
604
624
|
}
|
|
605
625
|
|
|
606
|
-
/* istanbul ignore next */
|
|
607
|
-
function generateValue (value) {
|
|
608
|
-
if (typeof value === 'string') {
|
|
609
|
-
return transformSpecialNewlines(value)
|
|
610
|
-
}
|
|
611
|
-
return JSON.stringify(value)
|
|
612
|
-
}
|
|
613
|
-
|
|
614
626
|
// #3895, #4268
|
|
615
|
-
function transformSpecialNewlines
|
|
616
|
-
return text
|
|
617
|
-
.replace(/\u2028/g, '\\u2028')
|
|
618
|
-
.replace(/\u2029/g, '\\u2029')
|
|
627
|
+
function transformSpecialNewlines(text: string): string {
|
|
628
|
+
return text.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
|
|
619
629
|
}
|
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import { extend } from 'shared/util'
|
|
2
|
+
import { CompilerOptions, CompiledResult, WarningMessage } from 'types/compiler'
|
|
4
3
|
import { detectErrors } from './error-detector'
|
|
5
4
|
import { createCompileToFunctionFn } from './to-function'
|
|
6
5
|
|
|
7
|
-
export function createCompilerCreator
|
|
8
|
-
return function createCompiler
|
|
9
|
-
function compile
|
|
6
|
+
export function createCompilerCreator(baseCompile: Function): Function {
|
|
7
|
+
return function createCompiler(baseOptions: CompilerOptions) {
|
|
8
|
+
function compile(
|
|
10
9
|
template: string,
|
|
11
10
|
options?: CompilerOptions
|
|
12
11
|
): CompiledResult {
|
|
13
12
|
const finalOptions = Object.create(baseOptions)
|
|
14
|
-
const errors = []
|
|
15
|
-
const tips = []
|
|
13
|
+
const errors: WarningMessage[] = []
|
|
14
|
+
const tips: WarningMessage[] = []
|
|
16
15
|
|
|
17
|
-
let warn = (
|
|
18
|
-
|
|
16
|
+
let warn = (
|
|
17
|
+
msg: WarningMessage,
|
|
18
|
+
range: { start: number; end: number },
|
|
19
|
+
tip: string
|
|
20
|
+
) => {
|
|
21
|
+
;(tip ? tips : errors).push(msg)
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
if (options) {
|
|
22
|
-
if (
|
|
25
|
+
if (__DEV__ && options.outputSourceRange) {
|
|
23
26
|
// $flow-disable-line
|
|
24
|
-
const leadingSpaceLength = template.match(/^\s*/)[0].length
|
|
27
|
+
const leadingSpaceLength = template.match(/^\s*/)![0].length
|
|
25
28
|
|
|
26
|
-
warn = (
|
|
27
|
-
|
|
29
|
+
warn = (
|
|
30
|
+
msg: WarningMessage | string,
|
|
31
|
+
range: { start: number; end: number },
|
|
32
|
+
tip: string
|
|
33
|
+
) => {
|
|
34
|
+
const data: WarningMessage = typeof msg === 'string' ? { msg } : msg
|
|
28
35
|
if (range) {
|
|
29
36
|
if (range.start != null) {
|
|
30
37
|
data.start = range.start + leadingSpaceLength
|
|
@@ -33,13 +40,14 @@ export function createCompilerCreator (baseCompile: Function): Function {
|
|
|
33
40
|
data.end = range.end + leadingSpaceLength
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
|
-
(tip ? tips : errors).push(data)
|
|
43
|
+
;(tip ? tips : errors).push(data)
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
46
|
// merge custom modules
|
|
40
47
|
if (options.modules) {
|
|
41
|
-
finalOptions.modules =
|
|
42
|
-
|
|
48
|
+
finalOptions.modules = (baseOptions.modules || []).concat(
|
|
49
|
+
options.modules
|
|
50
|
+
)
|
|
43
51
|
}
|
|
44
52
|
// merge custom directives
|
|
45
53
|
if (options.directives) {
|
|
@@ -51,7 +59,7 @@ export function createCompilerCreator (baseCompile: Function): Function {
|
|
|
51
59
|
// copy other options
|
|
52
60
|
for (const key in options) {
|
|
53
61
|
if (key !== 'modules' && key !== 'directives') {
|
|
54
|
-
finalOptions[key] = options[key]
|
|
62
|
+
finalOptions[key] = options[key as keyof CompilerOptions]
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
}
|
|
@@ -59,7 +67,7 @@ export function createCompilerCreator (baseCompile: Function): Function {
|
|
|
59
67
|
finalOptions.warn = warn
|
|
60
68
|
|
|
61
69
|
const compiled = baseCompile(template.trim(), finalOptions)
|
|
62
|
-
if (
|
|
70
|
+
if (__DEV__) {
|
|
63
71
|
detectErrors(compiled.ast, warn)
|
|
64
72
|
}
|
|
65
73
|
compiled.errors = errors
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTDirective, ASTElement } from 'types/compiler'
|
|
2
|
+
|
|
3
|
+
export default function bind(el: ASTElement, dir: ASTDirective) {
|
|
4
|
+
el.wrapData = (code: string) => {
|
|
5
|
+
return `_b(${code},'${el.tag}',${dir.value},${
|
|
6
|
+
dir.modifiers && dir.modifiers.prop ? 'true' : 'false'
|
|
7
|
+
}${dir.modifiers && dir.modifiers.sync ? ',true' : ''})`
|
|
8
|
+
}
|
|
9
|
+
}
|