@nest-vue/vue-security-patched 2.7.16-patch.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.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/compiler-sfc/index.d.ts +1 -0
  4. package/compiler-sfc/index.js +1 -0
  5. package/compiler-sfc/index.mjs +1 -0
  6. package/compiler-sfc/package.json +5 -0
  7. package/dist/vue.common.js +5 -0
  8. package/dist/vue.runtime.common.js +5 -0
  9. package/dist/vue.runtime.mjs +76 -0
  10. package/package.json +136 -0
  11. package/packages/compiler-sfc/api-extractor.json +64 -0
  12. package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
  13. package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
  14. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  15. package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
  16. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  17. package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
  18. package/packages/compiler-sfc/package.json +37 -0
  19. package/packages/compiler-sfc/src/babelUtils.ts +423 -0
  20. package/packages/compiler-sfc/src/compileScript.ts +1916 -0
  21. package/packages/compiler-sfc/src/compileStyle.ts +147 -0
  22. package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
  23. package/packages/compiler-sfc/src/cssVars.ts +179 -0
  24. package/packages/compiler-sfc/src/index.ts +31 -0
  25. package/packages/compiler-sfc/src/parse.ts +129 -0
  26. package/packages/compiler-sfc/src/parseComponent.ts +220 -0
  27. package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
  28. package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
  29. package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
  30. package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
  31. package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
  32. package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
  33. package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
  34. package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
  35. package/packages/compiler-sfc/src/types.ts +69 -0
  36. package/packages/compiler-sfc/src/warn.ts +16 -0
  37. package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
  38. package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
  39. package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
  40. package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
  41. package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
  42. package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
  43. package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
  44. package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
  45. package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
  46. package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
  47. package/packages/compiler-sfc/test/tsconfig.json +7 -0
  48. package/packages/compiler-sfc/test/util.ts +35 -0
  49. package/src/compiler/codeframe.ts +52 -0
  50. package/src/compiler/codegen/events.ts +170 -0
  51. package/src/compiler/codegen/index.ts +668 -0
  52. package/src/compiler/create-compiler.ts +83 -0
  53. package/src/compiler/directives/bind.ts +9 -0
  54. package/src/compiler/directives/index.ts +9 -0
  55. package/src/compiler/directives/model.ts +145 -0
  56. package/src/compiler/directives/on.ts +9 -0
  57. package/src/compiler/error-detector.ts +158 -0
  58. package/src/compiler/helpers.ts +243 -0
  59. package/src/compiler/index.ts +24 -0
  60. package/src/compiler/optimizer.ts +135 -0
  61. package/src/compiler/parser/entity-decoder.ts +9 -0
  62. package/src/compiler/parser/filter-parser.ts +116 -0
  63. package/src/compiler/parser/html-parser.ts +345 -0
  64. package/src/compiler/parser/index.ts +999 -0
  65. package/src/compiler/parser/text-parser.ts +52 -0
  66. package/src/compiler/to-function.ts +119 -0
  67. package/src/core/components/index.ts +5 -0
  68. package/src/core/components/keep-alive.ts +171 -0
  69. package/src/core/config.ts +128 -0
  70. package/src/core/global-api/assets.ts +35 -0
  71. package/src/core/global-api/extend.ts +94 -0
  72. package/src/core/global-api/index.ts +68 -0
  73. package/src/core/global-api/mixin.ts +9 -0
  74. package/src/core/global-api/use.ts +23 -0
  75. package/src/core/index.ts +27 -0
  76. package/src/core/instance/events.ts +160 -0
  77. package/src/core/instance/index.ts +27 -0
  78. package/src/core/instance/init.ts +143 -0
  79. package/src/core/instance/inject.ts +80 -0
  80. package/src/core/instance/lifecycle.ts +421 -0
  81. package/src/core/instance/proxy.ts +97 -0
  82. package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
  83. package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
  84. package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
  85. package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
  86. package/src/core/instance/render-helpers/index.ts +31 -0
  87. package/src/core/instance/render-helpers/render-list.ts +49 -0
  88. package/src/core/instance/render-helpers/render-slot.ts +39 -0
  89. package/src/core/instance/render-helpers/render-static.ts +57 -0
  90. package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
  91. package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
  92. package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
  93. package/src/core/instance/render.ts +172 -0
  94. package/src/core/instance/state.ts +393 -0
  95. package/src/core/observer/array.ts +54 -0
  96. package/src/core/observer/dep.ts +108 -0
  97. package/src/core/observer/index.ts +339 -0
  98. package/src/core/observer/scheduler.ts +199 -0
  99. package/src/core/observer/traverse.ts +47 -0
  100. package/src/core/observer/watcher.ts +278 -0
  101. package/src/core/util/debug.ts +105 -0
  102. package/src/core/util/env.ts +93 -0
  103. package/src/core/util/error.ts +81 -0
  104. package/src/core/util/index.ts +9 -0
  105. package/src/core/util/lang.ts +45 -0
  106. package/src/core/util/next-tick.ts +117 -0
  107. package/src/core/util/options.ts +489 -0
  108. package/src/core/util/perf.ts +28 -0
  109. package/src/core/util/props.ts +254 -0
  110. package/src/core/vdom/create-component.ts +275 -0
  111. package/src/core/vdom/create-element.ts +172 -0
  112. package/src/core/vdom/create-functional-component.ts +180 -0
  113. package/src/core/vdom/helpers/extract-props.ts +75 -0
  114. package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
  115. package/src/core/vdom/helpers/index.ts +7 -0
  116. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  117. package/src/core/vdom/helpers/merge-hook.ts +40 -0
  118. package/src/core/vdom/helpers/normalize-children.ts +99 -0
  119. package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
  120. package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
  121. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  122. package/src/core/vdom/modules/directives.ts +137 -0
  123. package/src/core/vdom/modules/index.ts +4 -0
  124. package/src/core/vdom/modules/template-ref.ts +94 -0
  125. package/src/core/vdom/patch.ts +907 -0
  126. package/src/core/vdom/vnode.ts +119 -0
  127. package/src/global.d.ts +17 -0
  128. package/src/platforms/web/compiler/directives/html.ts +8 -0
  129. package/src/platforms/web/compiler/directives/index.ts +9 -0
  130. package/src/platforms/web/compiler/directives/model.ts +181 -0
  131. package/src/platforms/web/compiler/directives/text.ts +8 -0
  132. package/src/platforms/web/compiler/index.ts +6 -0
  133. package/src/platforms/web/compiler/modules/class.ts +44 -0
  134. package/src/platforms/web/compiler/modules/index.ts +5 -0
  135. package/src/platforms/web/compiler/modules/model.ts +89 -0
  136. package/src/platforms/web/compiler/modules/style.ts +47 -0
  137. package/src/platforms/web/compiler/options.ts +25 -0
  138. package/src/platforms/web/compiler/util.ts +22 -0
  139. package/src/platforms/web/entry-compiler.ts +4 -0
  140. package/src/platforms/web/entry-runtime-esm.ts +5 -0
  141. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  142. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  143. package/src/platforms/web/entry-runtime.ts +7 -0
  144. package/src/platforms/web/runtime/class-util.ts +61 -0
  145. package/src/platforms/web/runtime/components/index.ts +7 -0
  146. package/src/platforms/web/runtime/components/transition-group.ts +204 -0
  147. package/src/platforms/web/runtime/components/transition.ts +205 -0
  148. package/src/platforms/web/runtime/directives/index.ts +7 -0
  149. package/src/platforms/web/runtime/directives/model.ts +148 -0
  150. package/src/platforms/web/runtime/directives/show.ts +61 -0
  151. package/src/platforms/web/runtime/index.ts +75 -0
  152. package/src/platforms/web/runtime/modules/attrs.ts +115 -0
  153. package/src/platforms/web/runtime/modules/class.ts +37 -0
  154. package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
  155. package/src/platforms/web/runtime/modules/events.ts +127 -0
  156. package/src/platforms/web/runtime/modules/index.ts +8 -0
  157. package/src/platforms/web/runtime/modules/style.ts +102 -0
  158. package/src/platforms/web/runtime/modules/transition.ts +341 -0
  159. package/src/platforms/web/runtime/node-ops.ts +66 -0
  160. package/src/platforms/web/runtime/patch.ts +10 -0
  161. package/src/platforms/web/runtime/transition-util.ts +215 -0
  162. package/src/platforms/web/runtime-with-compiler.ts +110 -0
  163. package/src/platforms/web/util/attrs.ts +58 -0
  164. package/src/platforms/web/util/class.ts +87 -0
  165. package/src/platforms/web/util/compat.ts +16 -0
  166. package/src/platforms/web/util/element.ts +76 -0
  167. package/src/platforms/web/util/index.ts +21 -0
  168. package/src/platforms/web/util/style.ts +71 -0
  169. package/src/shared/constants.ts +20 -0
  170. package/src/shared/util.ts +378 -0
  171. package/src/types/compiler.ts +207 -0
  172. package/src/types/component.ts +212 -0
  173. package/src/types/global-api.ts +37 -0
  174. package/src/types/modules.d.ts +15 -0
  175. package/src/types/options.ts +114 -0
  176. package/src/types/ssr.ts +27 -0
  177. package/src/types/utils.ts +3 -0
  178. package/src/types/vnode.ts +127 -0
  179. package/src/v3/apiAsyncComponent.ts +117 -0
  180. package/src/v3/apiInject.ts +71 -0
  181. package/src/v3/apiLifecycle.ts +68 -0
  182. package/src/v3/apiSetup.ts +246 -0
  183. package/src/v3/apiWatch.ts +353 -0
  184. package/src/v3/currentInstance.ts +23 -0
  185. package/src/v3/debug.ts +21 -0
  186. package/src/v3/h.ts +18 -0
  187. package/src/v3/index.ts +96 -0
  188. package/src/v3/reactivity/computed.ts +100 -0
  189. package/src/v3/reactivity/effect.ts +20 -0
  190. package/src/v3/reactivity/effectScope.ts +137 -0
  191. package/src/v3/reactivity/operations.ts +14 -0
  192. package/src/v3/reactivity/reactive.ts +137 -0
  193. package/src/v3/reactivity/readonly.ts +127 -0
  194. package/src/v3/reactivity/ref.ts +293 -0
  195. package/src/v3/sfc-helpers/useCssModule.ts +24 -0
  196. package/src/v3/sfc-helpers/useCssVars.ts +34 -0
  197. package/types/built-in-components.d.ts +63 -0
  198. package/types/common.d.ts +21 -0
  199. package/types/index.d.ts +81 -0
  200. package/types/jsx.d.ts +1353 -0
  201. package/types/options.d.ts +349 -0
  202. package/types/plugin.d.ts +8 -0
  203. package/types/umd.d.ts +68 -0
  204. package/types/v3-component-options.d.ts +252 -0
  205. package/types/v3-component-props.d.ts +99 -0
  206. package/types/v3-component-public-instance.d.ts +232 -0
  207. package/types/v3-define-async-component.d.ts +26 -0
  208. package/types/v3-define-component.d.ts +201 -0
  209. package/types/v3-directive.d.ts +29 -0
  210. package/types/v3-manual-apis.d.ts +10 -0
  211. package/types/v3-setup-context.d.ts +41 -0
  212. package/types/v3-setup-helpers.d.ts +154 -0
  213. package/types/vnode.d.ts +117 -0
  214. package/types/vue.d.ts +446 -0
@@ -0,0 +1,668 @@
1
+ import { genHandlers } from './events'
2
+ import baseDirectives from '../directives/index'
3
+ import { camelize, no, extend, capitalize } from 'shared/util'
4
+ import { baseWarn, pluckModuleFunction } from '../helpers'
5
+ import { emptySlotScopeToken } from '../parser/index'
6
+ import {
7
+ ASTAttr,
8
+ ASTDirective,
9
+ ASTElement,
10
+ ASTExpression,
11
+ ASTIfConditions,
12
+ ASTNode,
13
+ ASTText,
14
+ CompilerOptions
15
+ } from 'types/compiler'
16
+ import { BindingMetadata, BindingTypes } from 'sfc/types'
17
+
18
+ type TransformFunction = (el: ASTElement, code: string) => string
19
+ type DataGenFunction = (el: ASTElement) => string
20
+ type DirectiveFunction = (
21
+ el: ASTElement,
22
+ dir: ASTDirective,
23
+ warn: Function
24
+ ) => boolean
25
+
26
+ export class CodegenState {
27
+ options: CompilerOptions
28
+ warn: Function
29
+ transforms: Array<TransformFunction>
30
+ dataGenFns: Array<DataGenFunction>
31
+ directives: { [key: string]: DirectiveFunction }
32
+ maybeComponent: (el: ASTElement) => boolean
33
+ onceId: number
34
+ staticRenderFns: Array<string>
35
+ pre: boolean
36
+
37
+ constructor(options: CompilerOptions) {
38
+ this.options = options
39
+ this.warn = options.warn || baseWarn
40
+ this.transforms = pluckModuleFunction(options.modules, 'transformCode')
41
+ this.dataGenFns = pluckModuleFunction(options.modules, 'genData')
42
+ this.directives = extend(extend({}, baseDirectives), options.directives)
43
+ const isReservedTag = options.isReservedTag || no
44
+ this.maybeComponent = (el: ASTElement) =>
45
+ !!el.component || !isReservedTag(el.tag)
46
+ this.onceId = 0
47
+ this.staticRenderFns = []
48
+ this.pre = false
49
+ }
50
+ }
51
+
52
+ export type CodegenResult = {
53
+ render: string
54
+ staticRenderFns: Array<string>
55
+ }
56
+
57
+ export function generate(
58
+ ast: ASTElement | void,
59
+ options: CompilerOptions
60
+ ): CodegenResult {
61
+ const state = new CodegenState(options)
62
+ // fix #11483, Root level <script> tags should not be rendered.
63
+ const code = ast
64
+ ? ast.tag === 'script'
65
+ ? 'null'
66
+ : genElement(ast, state)
67
+ : '_c("div")'
68
+ return {
69
+ render: `with(this){return ${code}}`,
70
+ staticRenderFns: state.staticRenderFns
71
+ }
72
+ }
73
+
74
+ export function genElement(el: ASTElement, state: CodegenState): string {
75
+ if (el.parent) {
76
+ el.pre = el.pre || el.parent.pre
77
+ }
78
+
79
+ if (el.staticRoot && !el.staticProcessed) {
80
+ return genStatic(el, state)
81
+ } else if (el.once && !el.onceProcessed) {
82
+ return genOnce(el, state)
83
+ } else if (el.for && !el.forProcessed) {
84
+ return genFor(el, state)
85
+ } else if (el.if && !el.ifProcessed) {
86
+ return genIf(el, state)
87
+ } else if (el.tag === 'template' && !el.slotTarget && !state.pre) {
88
+ return genChildren(el, state) || 'void 0'
89
+ } else if (el.tag === 'slot') {
90
+ return genSlot(el, state)
91
+ } else {
92
+ // component or element
93
+ let code
94
+ if (el.component) {
95
+ code = genComponent(el.component, el, state)
96
+ } else {
97
+ let data
98
+ const maybeComponent = state.maybeComponent(el)
99
+ if (!el.plain || (el.pre && maybeComponent)) {
100
+ data = genData(el, state)
101
+ }
102
+
103
+ let tag: string | undefined
104
+ // check if this is a component in <script setup>
105
+ const bindings = state.options.bindings
106
+ if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
107
+ tag = checkBindingType(bindings, el.tag)
108
+ }
109
+ if (!tag) tag = `'${el.tag}'`
110
+
111
+ const children = el.inlineTemplate ? null : genChildren(el, state, true)
112
+ code = `_c(${tag}${
113
+ data ? `,${data}` : '' // data
114
+ }${
115
+ children ? `,${children}` : '' // children
116
+ })`
117
+ }
118
+ // module transforms
119
+ for (let i = 0; i < state.transforms.length; i++) {
120
+ code = state.transforms[i](el, code)
121
+ }
122
+ return code
123
+ }
124
+ }
125
+
126
+ function checkBindingType(bindings: BindingMetadata, key: string) {
127
+ const camelName = camelize(key)
128
+ const PascalName = capitalize(camelName)
129
+ const checkType = (type) => {
130
+ if (bindings[key] === type) {
131
+ return key
132
+ }
133
+ if (bindings[camelName] === type) {
134
+ return camelName
135
+ }
136
+ if (bindings[PascalName] === type) {
137
+ return PascalName
138
+ }
139
+ }
140
+ const fromConst =
141
+ checkType(BindingTypes.SETUP_CONST) ||
142
+ checkType(BindingTypes.SETUP_REACTIVE_CONST)
143
+ if (fromConst) {
144
+ return fromConst
145
+ }
146
+
147
+ const fromMaybeRef =
148
+ checkType(BindingTypes.SETUP_LET) ||
149
+ checkType(BindingTypes.SETUP_REF) ||
150
+ checkType(BindingTypes.SETUP_MAYBE_REF)
151
+ if (fromMaybeRef) {
152
+ return fromMaybeRef
153
+ }
154
+ }
155
+
156
+ // hoist static sub-trees out
157
+ function genStatic(el: ASTElement, state: CodegenState): string {
158
+ el.staticProcessed = true
159
+ // Some elements (templates) need to behave differently inside of a v-pre
160
+ // node. All pre nodes are static roots, so we can use this as a location to
161
+ // wrap a state change and reset it upon exiting the pre node.
162
+ const originalPreState = state.pre
163
+ if (el.pre) {
164
+ state.pre = el.pre
165
+ }
166
+ state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
167
+ state.pre = originalPreState
168
+ return `_m(${state.staticRenderFns.length - 1}${
169
+ el.staticInFor ? ',true' : ''
170
+ })`
171
+ }
172
+
173
+ // v-once
174
+ function genOnce(el: ASTElement, state: CodegenState): string {
175
+ el.onceProcessed = true
176
+ if (el.if && !el.ifProcessed) {
177
+ return genIf(el, state)
178
+ } else if (el.staticInFor) {
179
+ let key = ''
180
+ let parent = el.parent
181
+ while (parent) {
182
+ if (parent.for) {
183
+ key = parent.key!
184
+ break
185
+ }
186
+ parent = parent.parent
187
+ }
188
+ if (!key) {
189
+ __DEV__ &&
190
+ state.warn(
191
+ `v-once can only be used inside v-for that is keyed. `,
192
+ el.rawAttrsMap['v-once']
193
+ )
194
+ return genElement(el, state)
195
+ }
196
+ return `_o(${genElement(el, state)},${state.onceId++},${key})`
197
+ } else {
198
+ return genStatic(el, state)
199
+ }
200
+ }
201
+
202
+ export function genIf(
203
+ el: any,
204
+ state: CodegenState,
205
+ altGen?: Function,
206
+ altEmpty?: string
207
+ ): string {
208
+ el.ifProcessed = true // avoid recursion
209
+ return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
210
+ }
211
+
212
+ function genIfConditions(
213
+ conditions: ASTIfConditions,
214
+ state: CodegenState,
215
+ altGen?: Function,
216
+ altEmpty?: string
217
+ ): string {
218
+ if (!conditions.length) {
219
+ return altEmpty || '_e()'
220
+ }
221
+
222
+ const condition = conditions.shift()!
223
+ if (condition.exp) {
224
+ return `(${condition.exp})?${genTernaryExp(
225
+ condition.block
226
+ )}:${genIfConditions(conditions, state, altGen, altEmpty)}`
227
+ } else {
228
+ return `${genTernaryExp(condition.block)}`
229
+ }
230
+
231
+ // v-if with v-once should generate code like (a)?_m(0):_m(1)
232
+ function genTernaryExp(el) {
233
+ return altGen
234
+ ? altGen(el, state)
235
+ : el.once
236
+ ? genOnce(el, state)
237
+ : genElement(el, state)
238
+ }
239
+ }
240
+
241
+ export function genFor(
242
+ el: any,
243
+ state: CodegenState,
244
+ altGen?: Function,
245
+ altHelper?: string
246
+ ): string {
247
+ const exp = el.for
248
+ const alias = el.alias
249
+ const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
250
+ const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
251
+
252
+ if (
253
+ __DEV__ &&
254
+ state.maybeComponent(el) &&
255
+ el.tag !== 'slot' &&
256
+ el.tag !== 'template' &&
257
+ !el.key
258
+ ) {
259
+ state.warn(
260
+ `<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
261
+ `v-for should have explicit keys. ` +
262
+ `See https://v2.vuejs.org/v2/guide/list.html#key for more info.`,
263
+ el.rawAttrsMap['v-for'],
264
+ true /* tip */
265
+ )
266
+ }
267
+
268
+ el.forProcessed = true // avoid recursion
269
+ return (
270
+ `${altHelper || '_l'}((${exp}),` +
271
+ `function(${alias}${iterator1}${iterator2}){` +
272
+ `return ${(altGen || genElement)(el, state)}` +
273
+ '})'
274
+ )
275
+ }
276
+
277
+ export function genData(el: ASTElement, state: CodegenState): string {
278
+ let data = '{'
279
+
280
+ // directives first.
281
+ // directives may mutate the el's other properties before they are generated.
282
+ const dirs = genDirectives(el, state)
283
+ if (dirs) data += dirs + ','
284
+
285
+ // key
286
+ if (el.key) {
287
+ data += `key:${el.key},`
288
+ }
289
+ // ref
290
+ if (el.ref) {
291
+ data += `ref:${el.ref},`
292
+ }
293
+ if (el.refInFor) {
294
+ data += `refInFor:true,`
295
+ }
296
+ // pre
297
+ if (el.pre) {
298
+ data += `pre:true,`
299
+ }
300
+ // record original tag name for components using "is" attribute
301
+ if (el.component) {
302
+ data += `tag:"${el.tag}",`
303
+ }
304
+ // module data generation functions
305
+ for (let i = 0; i < state.dataGenFns.length; i++) {
306
+ data += state.dataGenFns[i](el)
307
+ }
308
+ // attributes
309
+ if (el.attrs) {
310
+ data += `attrs:${genProps(el.attrs)},`
311
+ }
312
+ // DOM props
313
+ if (el.props) {
314
+ data += `domProps:${genProps(el.props)},`
315
+ }
316
+ // event handlers
317
+ if (el.events) {
318
+ data += `${genHandlers(el.events, false)},`
319
+ }
320
+ if (el.nativeEvents) {
321
+ data += `${genHandlers(el.nativeEvents, true)},`
322
+ }
323
+ // slot target
324
+ // only for non-scoped slots
325
+ if (el.slotTarget && !el.slotScope) {
326
+ data += `slot:${el.slotTarget},`
327
+ }
328
+ // scoped slots
329
+ if (el.scopedSlots) {
330
+ data += `${genScopedSlots(el, el.scopedSlots, state)},`
331
+ }
332
+ // component v-model
333
+ if (el.model) {
334
+ data += `model:{value:${el.model.value},callback:${el.model.callback},expression:${el.model.expression}},`
335
+ }
336
+ // inline-template
337
+ if (el.inlineTemplate) {
338
+ const inlineTemplate = genInlineTemplate(el, state)
339
+ if (inlineTemplate) {
340
+ data += `${inlineTemplate},`
341
+ }
342
+ }
343
+ data = data.replace(/,$/, '') + '}'
344
+ // v-bind dynamic argument wrap
345
+ // v-bind with dynamic arguments must be applied using the same v-bind object
346
+ // merge helper so that class/style/mustUseProp attrs are handled correctly.
347
+ if (el.dynamicAttrs) {
348
+ data = `_b(${data},"${el.tag}",${genProps(el.dynamicAttrs)})`
349
+ }
350
+ // v-bind data wrap
351
+ if (el.wrapData) {
352
+ data = el.wrapData(data)
353
+ }
354
+ // v-on data wrap
355
+ if (el.wrapListeners) {
356
+ data = el.wrapListeners(data)
357
+ }
358
+ return data
359
+ }
360
+
361
+ function genDirectives(el: ASTElement, state: CodegenState): string | void {
362
+ const dirs = el.directives
363
+ if (!dirs) return
364
+ let res = 'directives:['
365
+ let hasRuntime = false
366
+ let i, l, dir, needRuntime
367
+ for (i = 0, l = dirs.length; i < l; i++) {
368
+ dir = dirs[i]
369
+ needRuntime = true
370
+ const gen: DirectiveFunction = state.directives[dir.name]
371
+ if (gen) {
372
+ // compile-time directive that manipulates AST.
373
+ // returns true if it also needs a runtime counterpart.
374
+ needRuntime = !!gen(el, dir, state.warn)
375
+ }
376
+ if (needRuntime) {
377
+ hasRuntime = true
378
+ res += `{name:"${dir.name}",rawName:"${dir.rawName}"${
379
+ dir.value
380
+ ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}`
381
+ : ''
382
+ }${dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''}${
383
+ dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''
384
+ }},`
385
+ }
386
+ }
387
+ if (hasRuntime) {
388
+ return res.slice(0, -1) + ']'
389
+ }
390
+ }
391
+
392
+ function genInlineTemplate(
393
+ el: ASTElement,
394
+ state: CodegenState
395
+ ): string | undefined {
396
+ const ast = el.children[0]
397
+ if (__DEV__ && (el.children.length !== 1 || ast.type !== 1)) {
398
+ state.warn(
399
+ 'Inline-template components must have exactly one child element.',
400
+ { start: el.start }
401
+ )
402
+ }
403
+ if (ast && ast.type === 1) {
404
+ const inlineRenderFns = generate(ast, state.options)
405
+ return `inlineTemplate:{render:function(){${
406
+ inlineRenderFns.render
407
+ }},staticRenderFns:[${inlineRenderFns.staticRenderFns
408
+ .map(code => `function(){${code}}`)
409
+ .join(',')}]}`
410
+ }
411
+ }
412
+
413
+ function genScopedSlots(
414
+ el: ASTElement,
415
+ slots: { [key: string]: ASTElement },
416
+ state: CodegenState
417
+ ): string {
418
+ // by default scoped slots are considered "stable", this allows child
419
+ // components with only scoped slots to skip forced updates from parent.
420
+ // but in some cases we have to bail-out of this optimization
421
+ // for example if the slot contains dynamic names, has v-if or v-for on them...
422
+ let needsForceUpdate =
423
+ el.for ||
424
+ Object.keys(slots).some(key => {
425
+ const slot = slots[key]
426
+ return (
427
+ slot.slotTargetDynamic || slot.if || slot.for || containsSlotChild(slot) // is passing down slot from parent which may be dynamic
428
+ )
429
+ })
430
+
431
+ // #9534: if a component with scoped slots is inside a conditional branch,
432
+ // it's possible for the same component to be reused but with different
433
+ // compiled slot content. To avoid that, we generate a unique key based on
434
+ // the generated code of all the slot contents.
435
+ let needsKey = !!el.if
436
+
437
+ // OR when it is inside another scoped slot or v-for (the reactivity may be
438
+ // disconnected due to the intermediate scope variable)
439
+ // #9438, #9506
440
+ // TODO: this can be further optimized by properly analyzing in-scope bindings
441
+ // and skip force updating ones that do not actually use scope variables.
442
+ if (!needsForceUpdate) {
443
+ let parent = el.parent
444
+ while (parent) {
445
+ if (
446
+ (parent.slotScope && parent.slotScope !== emptySlotScopeToken) ||
447
+ parent.for
448
+ ) {
449
+ needsForceUpdate = true
450
+ break
451
+ }
452
+ if (parent.if) {
453
+ needsKey = true
454
+ }
455
+ parent = parent.parent
456
+ }
457
+ }
458
+
459
+ const generatedSlots = Object.keys(slots)
460
+ .map(key => genScopedSlot(slots[key], state))
461
+ .join(',')
462
+
463
+ return `scopedSlots:_u([${generatedSlots}]${
464
+ needsForceUpdate ? `,null,true` : ``
465
+ }${
466
+ !needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``
467
+ })`
468
+ }
469
+
470
+ function hash(str) {
471
+ let hash = 5381
472
+ let i = str.length
473
+ while (i) {
474
+ hash = (hash * 33) ^ str.charCodeAt(--i)
475
+ }
476
+ return hash >>> 0
477
+ }
478
+
479
+ function containsSlotChild(el: ASTNode): boolean {
480
+ if (el.type === 1) {
481
+ if (el.tag === 'slot') {
482
+ return true
483
+ }
484
+ return el.children.some(containsSlotChild)
485
+ }
486
+ return false
487
+ }
488
+
489
+ function genScopedSlot(el: ASTElement, state: CodegenState): string {
490
+ const isLegacySyntax = el.attrsMap['slot-scope']
491
+ if (el.if && !el.ifProcessed && !isLegacySyntax) {
492
+ return genIf(el, state, genScopedSlot, `null`)
493
+ }
494
+ if (el.for && !el.forProcessed) {
495
+ return genFor(el, state, genScopedSlot)
496
+ }
497
+ const slotScope =
498
+ el.slotScope === emptySlotScopeToken ? `` : String(el.slotScope)
499
+ const fn =
500
+ `function(${slotScope}){` +
501
+ `return ${
502
+ el.tag === 'template'
503
+ ? el.if && isLegacySyntax
504
+ ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
505
+ : genChildren(el, state) || 'undefined'
506
+ : genElement(el, state)
507
+ }}`
508
+ // reverse proxy v-slot without scope on this.$slots
509
+ const reverseProxy = slotScope ? `` : `,proxy:true`
510
+ return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`
511
+ }
512
+
513
+ export function genChildren(
514
+ el: ASTElement,
515
+ state: CodegenState,
516
+ checkSkip?: boolean,
517
+ altGenElement?: Function,
518
+ altGenNode?: Function
519
+ ): string | void {
520
+ const children = el.children
521
+ if (children.length) {
522
+ const el: any = children[0]
523
+ // optimize single v-for
524
+ if (
525
+ children.length === 1 &&
526
+ el.for &&
527
+ el.tag !== 'template' &&
528
+ el.tag !== 'slot'
529
+ ) {
530
+ const normalizationType = checkSkip
531
+ ? state.maybeComponent(el)
532
+ ? `,1`
533
+ : `,0`
534
+ : ``
535
+ return `${(altGenElement || genElement)(el, state)}${normalizationType}`
536
+ }
537
+ const normalizationType = checkSkip
538
+ ? getNormalizationType(children, state.maybeComponent)
539
+ : 0
540
+ const gen = altGenNode || genNode
541
+ return `[${children.map(c => gen(c, state)).join(',')}]${
542
+ normalizationType ? `,${normalizationType}` : ''
543
+ }`
544
+ }
545
+ }
546
+
547
+ // determine the normalization needed for the children array.
548
+ // 0: no normalization needed
549
+ // 1: simple normalization needed (possible 1-level deep nested array)
550
+ // 2: full normalization needed
551
+ function getNormalizationType(
552
+ children: Array<ASTNode>,
553
+ maybeComponent: (el: ASTElement) => boolean
554
+ ): number {
555
+ let res = 0
556
+ for (let i = 0; i < children.length; i++) {
557
+ const el: ASTNode = children[i]
558
+ if (el.type !== 1) {
559
+ continue
560
+ }
561
+ if (
562
+ needsNormalization(el) ||
563
+ (el.ifConditions &&
564
+ el.ifConditions.some(c => needsNormalization(c.block)))
565
+ ) {
566
+ res = 2
567
+ break
568
+ }
569
+ if (
570
+ maybeComponent(el) ||
571
+ (el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))
572
+ ) {
573
+ res = 1
574
+ }
575
+ }
576
+ return res
577
+ }
578
+
579
+ function needsNormalization(el: ASTElement): boolean {
580
+ return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
581
+ }
582
+
583
+ function genNode(node: ASTNode, state: CodegenState): string {
584
+ if (node.type === 1) {
585
+ return genElement(node, state)
586
+ } else if (node.type === 3 && node.isComment) {
587
+ return genComment(node)
588
+ } else {
589
+ return genText(node)
590
+ }
591
+ }
592
+
593
+ export function genText(text: ASTText | ASTExpression): string {
594
+ return `_v(${
595
+ text.type === 2
596
+ ? text.expression // no need for () because already wrapped in _s()
597
+ : transformSpecialNewlines(JSON.stringify(text.text))
598
+ })`
599
+ }
600
+
601
+ export function genComment(comment: ASTText): string {
602
+ return `_e(${JSON.stringify(comment.text)})`
603
+ }
604
+
605
+ function genSlot(el: ASTElement, state: CodegenState): string {
606
+ const slotName = el.slotName || '"default"'
607
+ const children = genChildren(el, state)
608
+ let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`
609
+ const attrs =
610
+ el.attrs || el.dynamicAttrs
611
+ ? genProps(
612
+ (el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
613
+ // slot props are camelized
614
+ name: camelize(attr.name),
615
+ value: attr.value,
616
+ dynamic: attr.dynamic
617
+ }))
618
+ )
619
+ : null
620
+ const bind = el.attrsMap['v-bind']
621
+ if ((attrs || bind) && !children) {
622
+ res += `,null`
623
+ }
624
+ if (attrs) {
625
+ res += `,${attrs}`
626
+ }
627
+ if (bind) {
628
+ res += `${attrs ? '' : ',null'},${bind}`
629
+ }
630
+ return res + ')'
631
+ }
632
+
633
+ // componentName is el.component, take it as argument to shun flow's pessimistic refinement
634
+ function genComponent(
635
+ componentName: string,
636
+ el: ASTElement,
637
+ state: CodegenState
638
+ ): string {
639
+ const children = el.inlineTemplate ? null : genChildren(el, state, true)
640
+ return `_c(${componentName},${genData(el, state)}${
641
+ children ? `,${children}` : ''
642
+ })`
643
+ }
644
+
645
+ function genProps(props: Array<ASTAttr>): string {
646
+ let staticProps = ``
647
+ let dynamicProps = ``
648
+ for (let i = 0; i < props.length; i++) {
649
+ const prop = props[i]
650
+ const value = transformSpecialNewlines(prop.value)
651
+ if (prop.dynamic) {
652
+ dynamicProps += `${prop.name},${value},`
653
+ } else {
654
+ staticProps += `"${prop.name}":${value},`
655
+ }
656
+ }
657
+ staticProps = `{${staticProps.slice(0, -1)}}`
658
+ if (dynamicProps) {
659
+ return `_d(${staticProps},[${dynamicProps.slice(0, -1)}])`
660
+ } else {
661
+ return staticProps
662
+ }
663
+ }
664
+
665
+ // #3895, #4268
666
+ function transformSpecialNewlines(text: string): string {
667
+ return text.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
668
+ }