@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,999 @@
1
+ import he from 'he'
2
+ import { parseHTML } from './html-parser'
3
+ import { parseText } from './text-parser'
4
+ import { parseFilters } from './filter-parser'
5
+ import { genAssignmentCode } from '../directives/model'
6
+ import { extend, cached, no, camelize, hyphenate } from 'shared/util'
7
+ import { isIE, isEdge, isServerRendering } from 'core/util/env'
8
+
9
+ import {
10
+ addProp,
11
+ addAttr,
12
+ baseWarn,
13
+ addHandler,
14
+ addDirective,
15
+ getBindingAttr,
16
+ getAndRemoveAttr,
17
+ getRawBindingAttr,
18
+ pluckModuleFunction,
19
+ getAndRemoveAttrByRegex
20
+ } from '../helpers'
21
+
22
+ import {
23
+ ASTAttr,
24
+ ASTElement,
25
+ ASTIfCondition,
26
+ ASTNode,
27
+ ASTText,
28
+ CompilerOptions
29
+ } from 'types/compiler'
30
+
31
+ export const onRE = /^@|^v-on:/
32
+ export const dirRE = process.env.VBIND_PROP_SHORTHAND
33
+ ? /^v-|^@|^:|^\.|^#/
34
+ : /^v-|^@|^:|^#/
35
+ export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
36
+ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
37
+ const stripParensRE = /^\(|\)$/g
38
+ const dynamicArgRE = /^\[.*\]$/
39
+
40
+ const argRE = /:(.*)$/
41
+ export const bindRE = /^:|^\.|^v-bind:/
42
+ const propBindRE = /^\./
43
+ const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g
44
+
45
+ export const slotRE = /^v-slot(:|$)|^#/
46
+
47
+ const lineBreakRE = /[\r\n]/
48
+ const whitespaceRE = /[ \f\t\r\n]+/g
49
+
50
+ const invalidAttributeRE = /[\s"'<>\/=]/
51
+
52
+ const decodeHTMLCached = cached(he.decode)
53
+
54
+ export const emptySlotScopeToken = `_empty_`
55
+
56
+ // configurable state
57
+ export let warn: any
58
+ let delimiters
59
+ let transforms
60
+ let preTransforms
61
+ let postTransforms
62
+ let platformIsPreTag
63
+ let platformMustUseProp
64
+ let platformGetTagNamespace
65
+ let maybeComponent
66
+
67
+ export function createASTElement(
68
+ tag: string,
69
+ attrs: Array<ASTAttr>,
70
+ parent: ASTElement | void
71
+ ): ASTElement {
72
+ return {
73
+ type: 1,
74
+ tag,
75
+ attrsList: attrs,
76
+ attrsMap: makeAttrsMap(attrs),
77
+ rawAttrsMap: {},
78
+ parent,
79
+ children: []
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Convert HTML string to AST.
85
+ */
86
+ export function parse(template: string, options: CompilerOptions): ASTElement {
87
+ warn = options.warn || baseWarn
88
+
89
+ platformIsPreTag = options.isPreTag || no
90
+ platformMustUseProp = options.mustUseProp || no
91
+ platformGetTagNamespace = options.getTagNamespace || no
92
+ const isReservedTag = options.isReservedTag || no
93
+ maybeComponent = (el: ASTElement) =>
94
+ !!(
95
+ el.component ||
96
+ el.attrsMap[':is'] ||
97
+ el.attrsMap['v-bind:is'] ||
98
+ !(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag))
99
+ )
100
+ transforms = pluckModuleFunction(options.modules, 'transformNode')
101
+ preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
102
+ postTransforms = pluckModuleFunction(options.modules, 'postTransformNode')
103
+
104
+ delimiters = options.delimiters
105
+
106
+ const stack: any[] = []
107
+ const preserveWhitespace = options.preserveWhitespace !== false
108
+ const whitespaceOption = options.whitespace
109
+ let root
110
+ let currentParent
111
+ let inVPre = false
112
+ let inPre = false
113
+ let warned = false
114
+
115
+ function warnOnce(msg, range) {
116
+ if (!warned) {
117
+ warned = true
118
+ warn(msg, range)
119
+ }
120
+ }
121
+
122
+ function closeElement(element) {
123
+ trimEndingWhitespace(element)
124
+ if (!inVPre && !element.processed) {
125
+ element = processElement(element, options)
126
+ }
127
+ // tree management
128
+ if (!stack.length && element !== root) {
129
+ // allow root elements with v-if, v-else-if and v-else
130
+ if (root.if && (element.elseif || element.else)) {
131
+ if (__DEV__) {
132
+ checkRootConstraints(element)
133
+ }
134
+ addIfCondition(root, {
135
+ exp: element.elseif,
136
+ block: element
137
+ })
138
+ } else if (__DEV__) {
139
+ warnOnce(
140
+ `Component template should contain exactly one root element. ` +
141
+ `If you are using v-if on multiple elements, ` +
142
+ `use v-else-if to chain them instead.`,
143
+ { start: element.start }
144
+ )
145
+ }
146
+ }
147
+ if (currentParent && !element.forbidden) {
148
+ if (element.elseif || element.else) {
149
+ processIfConditions(element, currentParent)
150
+ } else {
151
+ if (element.slotScope) {
152
+ // scoped slot
153
+ // keep it in the children list so that v-else(-if) conditions can
154
+ // find it as the prev node.
155
+ const name = element.slotTarget || '"default"'
156
+ ;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[
157
+ name
158
+ ] = element
159
+ }
160
+ currentParent.children.push(element)
161
+ element.parent = currentParent
162
+ }
163
+ }
164
+
165
+ // final children cleanup
166
+ // filter out scoped slots
167
+ element.children = element.children.filter(c => !c.slotScope)
168
+ // remove trailing whitespace node again
169
+ trimEndingWhitespace(element)
170
+
171
+ // check pre state
172
+ if (element.pre) {
173
+ inVPre = false
174
+ }
175
+ if (platformIsPreTag(element.tag)) {
176
+ inPre = false
177
+ }
178
+ // apply post-transforms
179
+ for (let i = 0; i < postTransforms.length; i++) {
180
+ postTransforms[i](element, options)
181
+ }
182
+ }
183
+
184
+ function trimEndingWhitespace(el) {
185
+ // remove trailing whitespace node
186
+ if (!inPre) {
187
+ let lastNode
188
+ while (
189
+ (lastNode = el.children[el.children.length - 1]) &&
190
+ lastNode.type === 3 &&
191
+ lastNode.text === ' '
192
+ ) {
193
+ el.children.pop()
194
+ }
195
+ }
196
+ }
197
+
198
+ function checkRootConstraints(el) {
199
+ if (el.tag === 'slot' || el.tag === 'template') {
200
+ warnOnce(
201
+ `Cannot use <${el.tag}> as component root element because it may ` +
202
+ 'contain multiple nodes.',
203
+ { start: el.start }
204
+ )
205
+ }
206
+ if (el.attrsMap.hasOwnProperty('v-for')) {
207
+ warnOnce(
208
+ 'Cannot use v-for on stateful component root element because ' +
209
+ 'it renders multiple elements.',
210
+ el.rawAttrsMap['v-for']
211
+ )
212
+ }
213
+ }
214
+
215
+ parseHTML(template, {
216
+ warn,
217
+ expectHTML: options.expectHTML,
218
+ isUnaryTag: options.isUnaryTag,
219
+ canBeLeftOpenTag: options.canBeLeftOpenTag,
220
+ shouldDecodeNewlines: options.shouldDecodeNewlines,
221
+ shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
222
+ shouldKeepComment: options.comments,
223
+ outputSourceRange: options.outputSourceRange,
224
+ start(tag, attrs, unary, start, end) {
225
+ // check namespace.
226
+ // inherit parent ns if there is one
227
+ const ns =
228
+ (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
229
+
230
+ // handle IE svg bug
231
+ /* istanbul ignore if */
232
+ if (isIE && ns === 'svg') {
233
+ attrs = guardIESVGBug(attrs)
234
+ }
235
+
236
+ let element: ASTElement = createASTElement(tag, attrs, currentParent)
237
+ if (ns) {
238
+ element.ns = ns
239
+ }
240
+
241
+ if (__DEV__) {
242
+ if (options.outputSourceRange) {
243
+ element.start = start
244
+ element.end = end
245
+ element.rawAttrsMap = element.attrsList.reduce((cumulated, attr) => {
246
+ cumulated[attr.name] = attr
247
+ return cumulated
248
+ }, {})
249
+ }
250
+ attrs.forEach(attr => {
251
+ if (invalidAttributeRE.test(attr.name)) {
252
+ warn(
253
+ `Invalid dynamic argument expression: attribute names cannot contain ` +
254
+ `spaces, quotes, <, >, / or =.`,
255
+ options.outputSourceRange
256
+ ? {
257
+ start: attr.start! + attr.name.indexOf(`[`),
258
+ end: attr.start! + attr.name.length
259
+ }
260
+ : undefined
261
+ )
262
+ }
263
+ })
264
+ }
265
+
266
+ if (isForbiddenTag(element) && !isServerRendering()) {
267
+ element.forbidden = true
268
+ __DEV__ &&
269
+ warn(
270
+ 'Templates should only be responsible for mapping the state to the ' +
271
+ 'UI. Avoid placing tags with side-effects in your templates, such as ' +
272
+ `<${tag}>` +
273
+ ', as they will not be parsed.',
274
+ { start: element.start }
275
+ )
276
+ }
277
+
278
+ // apply pre-transforms
279
+ for (let i = 0; i < preTransforms.length; i++) {
280
+ element = preTransforms[i](element, options) || element
281
+ }
282
+
283
+ if (!inVPre) {
284
+ processPre(element)
285
+ if (element.pre) {
286
+ inVPre = true
287
+ }
288
+ }
289
+ if (platformIsPreTag(element.tag)) {
290
+ inPre = true
291
+ }
292
+ if (inVPre) {
293
+ processRawAttrs(element)
294
+ } else if (!element.processed) {
295
+ // structural directives
296
+ processFor(element)
297
+ processIf(element)
298
+ processOnce(element)
299
+ }
300
+
301
+ if (!root) {
302
+ root = element
303
+ if (__DEV__) {
304
+ checkRootConstraints(root)
305
+ }
306
+ }
307
+
308
+ if (!unary) {
309
+ currentParent = element
310
+ stack.push(element)
311
+ } else {
312
+ closeElement(element)
313
+ }
314
+ },
315
+
316
+ end(tag, start, end) {
317
+ const element = stack[stack.length - 1]
318
+ // pop stack
319
+ stack.length -= 1
320
+ currentParent = stack[stack.length - 1]
321
+ if (__DEV__ && options.outputSourceRange) {
322
+ element.end = end
323
+ }
324
+ closeElement(element)
325
+ },
326
+
327
+ chars(text: string, start?: number, end?: number) {
328
+ if (!currentParent) {
329
+ if (__DEV__) {
330
+ if (text === template) {
331
+ warnOnce(
332
+ 'Component template requires a root element, rather than just text.',
333
+ { start }
334
+ )
335
+ } else if ((text = text.trim())) {
336
+ warnOnce(`text "${text}" outside root element will be ignored.`, {
337
+ start
338
+ })
339
+ }
340
+ }
341
+ return
342
+ }
343
+ // IE textarea placeholder bug
344
+ /* istanbul ignore if */
345
+ if (
346
+ isIE &&
347
+ currentParent.tag === 'textarea' &&
348
+ currentParent.attrsMap.placeholder === text
349
+ ) {
350
+ return
351
+ }
352
+ const children = currentParent.children
353
+ if (inPre || text.trim()) {
354
+ text = isTextTag(currentParent)
355
+ ? text
356
+ : (decodeHTMLCached(text) as string)
357
+ } else if (!children.length) {
358
+ // remove the whitespace-only node right after an opening tag
359
+ text = ''
360
+ } else if (whitespaceOption) {
361
+ if (whitespaceOption === 'condense') {
362
+ // in condense mode, remove the whitespace node if it contains
363
+ // line break, otherwise condense to a single space
364
+ text = lineBreakRE.test(text) ? '' : ' '
365
+ } else {
366
+ text = ' '
367
+ }
368
+ } else {
369
+ text = preserveWhitespace ? ' ' : ''
370
+ }
371
+ if (text) {
372
+ if (!inPre && whitespaceOption === 'condense') {
373
+ // condense consecutive whitespaces into single space
374
+ text = text.replace(whitespaceRE, ' ')
375
+ }
376
+ let res
377
+ let child: ASTNode | undefined
378
+ if (!inVPre && text !== ' ' && (res = parseText(text, delimiters))) {
379
+ child = {
380
+ type: 2,
381
+ expression: res.expression,
382
+ tokens: res.tokens,
383
+ text
384
+ }
385
+ } else if (
386
+ text !== ' ' ||
387
+ !children.length ||
388
+ children[children.length - 1].text !== ' '
389
+ ) {
390
+ child = {
391
+ type: 3,
392
+ text
393
+ }
394
+ }
395
+ if (child) {
396
+ if (__DEV__ && options.outputSourceRange) {
397
+ child.start = start
398
+ child.end = end
399
+ }
400
+ children.push(child)
401
+ }
402
+ }
403
+ },
404
+ comment(text: string, start, end) {
405
+ // adding anything as a sibling to the root node is forbidden
406
+ // comments should still be allowed, but ignored
407
+ if (currentParent) {
408
+ const child: ASTText = {
409
+ type: 3,
410
+ text,
411
+ isComment: true
412
+ }
413
+ if (__DEV__ && options.outputSourceRange) {
414
+ child.start = start
415
+ child.end = end
416
+ }
417
+ currentParent.children.push(child)
418
+ }
419
+ }
420
+ })
421
+ return root
422
+ }
423
+
424
+ function processPre(el) {
425
+ if (getAndRemoveAttr(el, 'v-pre') != null) {
426
+ el.pre = true
427
+ }
428
+ }
429
+
430
+ function processRawAttrs(el) {
431
+ const list = el.attrsList
432
+ const len = list.length
433
+ if (len) {
434
+ const attrs: Array<ASTAttr> = (el.attrs = new Array(len))
435
+ for (let i = 0; i < len; i++) {
436
+ attrs[i] = {
437
+ name: list[i].name,
438
+ value: JSON.stringify(list[i].value)
439
+ }
440
+ if (list[i].start != null) {
441
+ attrs[i].start = list[i].start
442
+ attrs[i].end = list[i].end
443
+ }
444
+ }
445
+ } else if (!el.pre) {
446
+ // non root node in pre blocks with no attributes
447
+ el.plain = true
448
+ }
449
+ }
450
+
451
+ export function processElement(element: ASTElement, options: CompilerOptions) {
452
+ processKey(element)
453
+
454
+ // determine whether this is a plain element after
455
+ // removing structural attributes
456
+ element.plain =
457
+ !element.key && !element.scopedSlots && !element.attrsList.length
458
+
459
+ processRef(element)
460
+ processSlotContent(element)
461
+ processSlotOutlet(element)
462
+ processComponent(element)
463
+ for (let i = 0; i < transforms.length; i++) {
464
+ element = transforms[i](element, options) || element
465
+ }
466
+ processAttrs(element)
467
+ return element
468
+ }
469
+
470
+ function processKey(el) {
471
+ const exp = getBindingAttr(el, 'key')
472
+ if (exp) {
473
+ if (__DEV__) {
474
+ if (el.tag === 'template') {
475
+ warn(
476
+ `<template> cannot be keyed. Place the key on real elements instead.`,
477
+ getRawBindingAttr(el, 'key')
478
+ )
479
+ }
480
+ if (el.for) {
481
+ const iterator = el.iterator2 || el.iterator1
482
+ const parent = el.parent
483
+ if (
484
+ iterator &&
485
+ iterator === exp &&
486
+ parent &&
487
+ parent.tag === 'transition-group'
488
+ ) {
489
+ warn(
490
+ `Do not use v-for index as key on <transition-group> children, ` +
491
+ `this is the same as not using keys.`,
492
+ getRawBindingAttr(el, 'key'),
493
+ true /* tip */
494
+ )
495
+ }
496
+ }
497
+ }
498
+ el.key = exp
499
+ }
500
+ }
501
+
502
+ function processRef(el) {
503
+ const ref = getBindingAttr(el, 'ref')
504
+ if (ref) {
505
+ el.ref = ref
506
+ el.refInFor = checkInFor(el)
507
+ }
508
+ }
509
+
510
+ export function processFor(el: ASTElement) {
511
+ let exp
512
+ if ((exp = getAndRemoveAttr(el, 'v-for'))) {
513
+ const res = parseFor(exp)
514
+ if (res) {
515
+ extend(el, res)
516
+ } else if (__DEV__) {
517
+ warn(`Invalid v-for expression: ${exp}`, el.rawAttrsMap['v-for'])
518
+ }
519
+ }
520
+ }
521
+
522
+ type ForParseResult = {
523
+ for: string
524
+ alias: string
525
+ iterator1?: string
526
+ iterator2?: string
527
+ }
528
+
529
+ export function parseFor(exp: string): ForParseResult | undefined {
530
+ const inMatch = exp.match(forAliasRE)
531
+ if (!inMatch) return
532
+ const res: any = {}
533
+ res.for = inMatch[2].trim()
534
+ const alias = inMatch[1].trim().replace(stripParensRE, '')
535
+ const iteratorMatch = alias.match(forIteratorRE)
536
+ if (iteratorMatch) {
537
+ res.alias = alias.replace(forIteratorRE, '').trim()
538
+ res.iterator1 = iteratorMatch[1].trim()
539
+ if (iteratorMatch[2]) {
540
+ res.iterator2 = iteratorMatch[2].trim()
541
+ }
542
+ } else {
543
+ res.alias = alias
544
+ }
545
+ return res
546
+ }
547
+
548
+ function processIf(el) {
549
+ const exp = getAndRemoveAttr(el, 'v-if')
550
+ if (exp) {
551
+ el.if = exp
552
+ addIfCondition(el, {
553
+ exp: exp,
554
+ block: el
555
+ })
556
+ } else {
557
+ if (getAndRemoveAttr(el, 'v-else') != null) {
558
+ el.else = true
559
+ }
560
+ const elseif = getAndRemoveAttr(el, 'v-else-if')
561
+ if (elseif) {
562
+ el.elseif = elseif
563
+ }
564
+ }
565
+ }
566
+
567
+ function processIfConditions(el, parent) {
568
+ const prev = findPrevElement(parent.children)
569
+ if (prev && prev.if) {
570
+ addIfCondition(prev, {
571
+ exp: el.elseif,
572
+ block: el
573
+ })
574
+ } else if (__DEV__) {
575
+ warn(
576
+ `v-${el.elseif ? 'else-if="' + el.elseif + '"' : 'else'} ` +
577
+ `used on element <${el.tag}> without corresponding v-if.`,
578
+ el.rawAttrsMap[el.elseif ? 'v-else-if' : 'v-else']
579
+ )
580
+ }
581
+ }
582
+
583
+ function findPrevElement(children: Array<any>): ASTElement | void {
584
+ let i = children.length
585
+ while (i--) {
586
+ if (children[i].type === 1) {
587
+ return children[i]
588
+ } else {
589
+ if (__DEV__ && children[i].text !== ' ') {
590
+ warn(
591
+ `text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
592
+ `will be ignored.`,
593
+ children[i]
594
+ )
595
+ }
596
+ children.pop()
597
+ }
598
+ }
599
+ }
600
+
601
+ export function addIfCondition(el: ASTElement, condition: ASTIfCondition) {
602
+ if (!el.ifConditions) {
603
+ el.ifConditions = []
604
+ }
605
+ el.ifConditions.push(condition)
606
+ }
607
+
608
+ function processOnce(el) {
609
+ const once = getAndRemoveAttr(el, 'v-once')
610
+ if (once != null) {
611
+ el.once = true
612
+ }
613
+ }
614
+
615
+ // handle content being passed to a component as slot,
616
+ // e.g. <template slot="xxx">, <div slot-scope="xxx">
617
+ function processSlotContent(el) {
618
+ let slotScope
619
+ if (el.tag === 'template') {
620
+ slotScope = getAndRemoveAttr(el, 'scope')
621
+ /* istanbul ignore if */
622
+ if (__DEV__ && slotScope) {
623
+ warn(
624
+ `the "scope" attribute for scoped slots have been deprecated and ` +
625
+ `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
626
+ `can also be used on plain elements in addition to <template> to ` +
627
+ `denote scoped slots.`,
628
+ el.rawAttrsMap['scope'],
629
+ true
630
+ )
631
+ }
632
+ el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope')
633
+ } else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
634
+ /* istanbul ignore if */
635
+ if (__DEV__ && el.attrsMap['v-for']) {
636
+ warn(
637
+ `Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
638
+ `(v-for takes higher priority). Use a wrapper <template> for the ` +
639
+ `scoped slot to make it clearer.`,
640
+ el.rawAttrsMap['slot-scope'],
641
+ true
642
+ )
643
+ }
644
+ el.slotScope = slotScope
645
+ }
646
+
647
+ // slot="xxx"
648
+ const slotTarget = getBindingAttr(el, 'slot')
649
+ if (slotTarget) {
650
+ el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
651
+ el.slotTargetDynamic = !!(
652
+ el.attrsMap[':slot'] || el.attrsMap['v-bind:slot']
653
+ )
654
+ // preserve slot as an attribute for native shadow DOM compat
655
+ // only for non-scoped slots.
656
+ if (el.tag !== 'template' && !el.slotScope) {
657
+ addAttr(el, 'slot', slotTarget, getRawBindingAttr(el, 'slot'))
658
+ }
659
+ }
660
+
661
+ // 2.6 v-slot syntax
662
+ if (process.env.NEW_SLOT_SYNTAX) {
663
+ if (el.tag === 'template') {
664
+ // v-slot on <template>
665
+ const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
666
+ if (slotBinding) {
667
+ if (__DEV__) {
668
+ if (el.slotTarget || el.slotScope) {
669
+ warn(`Unexpected mixed usage of different slot syntaxes.`, el)
670
+ }
671
+ if (el.parent && !maybeComponent(el.parent)) {
672
+ warn(
673
+ `<template v-slot> can only appear at the root level inside ` +
674
+ `the receiving component`,
675
+ el
676
+ )
677
+ }
678
+ }
679
+ const { name, dynamic } = getSlotName(slotBinding)
680
+ el.slotTarget = name
681
+ el.slotTargetDynamic = dynamic
682
+ el.slotScope = slotBinding.value || emptySlotScopeToken // force it into a scoped slot for perf
683
+ }
684
+ } else {
685
+ // v-slot on component, denotes default slot
686
+ const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
687
+ if (slotBinding) {
688
+ if (__DEV__) {
689
+ if (!maybeComponent(el)) {
690
+ warn(
691
+ `v-slot can only be used on components or <template>.`,
692
+ slotBinding
693
+ )
694
+ }
695
+ if (el.slotScope || el.slotTarget) {
696
+ warn(`Unexpected mixed usage of different slot syntaxes.`, el)
697
+ }
698
+ if (el.scopedSlots) {
699
+ warn(
700
+ `To avoid scope ambiguity, the default slot should also use ` +
701
+ `<template> syntax when there are other named slots.`,
702
+ slotBinding
703
+ )
704
+ }
705
+ }
706
+ // add the component's children to its default slot
707
+ const slots = el.scopedSlots || (el.scopedSlots = {})
708
+ const { name, dynamic } = getSlotName(slotBinding)
709
+ const slotContainer = (slots[name] = createASTElement(
710
+ 'template',
711
+ [],
712
+ el
713
+ ))
714
+ slotContainer.slotTarget = name
715
+ slotContainer.slotTargetDynamic = dynamic
716
+ slotContainer.children = el.children.filter((c: any) => {
717
+ if (!c.slotScope) {
718
+ c.parent = slotContainer
719
+ return true
720
+ }
721
+ })
722
+ slotContainer.slotScope = slotBinding.value || emptySlotScopeToken
723
+ // remove children as they are returned from scopedSlots now
724
+ el.children = []
725
+ // mark el non-plain so data gets generated
726
+ el.plain = false
727
+ }
728
+ }
729
+ }
730
+ }
731
+
732
+ function getSlotName(binding) {
733
+ let name = binding.name.replace(slotRE, '')
734
+ if (!name) {
735
+ if (binding.name[0] !== '#') {
736
+ name = 'default'
737
+ } else if (__DEV__) {
738
+ warn(`v-slot shorthand syntax requires a slot name.`, binding)
739
+ }
740
+ }
741
+ return dynamicArgRE.test(name)
742
+ ? // dynamic [name]
743
+ { name: name.slice(1, -1), dynamic: true }
744
+ : // static name
745
+ { name: `"${name}"`, dynamic: false }
746
+ }
747
+
748
+ // handle <slot/> outlets
749
+ function processSlotOutlet(el) {
750
+ if (el.tag === 'slot') {
751
+ el.slotName = getBindingAttr(el, 'name')
752
+ if (__DEV__ && el.key) {
753
+ warn(
754
+ `\`key\` does not work on <slot> because slots are abstract outlets ` +
755
+ `and can possibly expand into multiple elements. ` +
756
+ `Use the key on a wrapping element instead.`,
757
+ getRawBindingAttr(el, 'key')
758
+ )
759
+ }
760
+ }
761
+ }
762
+
763
+ function processComponent(el) {
764
+ let binding
765
+ if ((binding = getBindingAttr(el, 'is'))) {
766
+ el.component = binding
767
+ }
768
+ if (getAndRemoveAttr(el, 'inline-template') != null) {
769
+ el.inlineTemplate = true
770
+ }
771
+ }
772
+
773
+ function processAttrs(el) {
774
+ const list = el.attrsList
775
+ let i, l, name, rawName, value, modifiers, syncGen, isDynamic
776
+ for (i = 0, l = list.length; i < l; i++) {
777
+ name = rawName = list[i].name
778
+ value = list[i].value
779
+ if (dirRE.test(name)) {
780
+ // mark element as dynamic
781
+ el.hasBindings = true
782
+ // modifiers
783
+ modifiers = parseModifiers(name.replace(dirRE, ''))
784
+ // support .foo shorthand syntax for the .prop modifier
785
+ if (process.env.VBIND_PROP_SHORTHAND && propBindRE.test(name)) {
786
+ ;(modifiers || (modifiers = {})).prop = true
787
+ name = `.` + name.slice(1).replace(modifierRE, '')
788
+ } else if (modifiers) {
789
+ name = name.replace(modifierRE, '')
790
+ }
791
+ if (bindRE.test(name)) {
792
+ // v-bind
793
+ name = name.replace(bindRE, '')
794
+ value = parseFilters(value)
795
+ isDynamic = dynamicArgRE.test(name)
796
+ if (isDynamic) {
797
+ name = name.slice(1, -1)
798
+ }
799
+ if (__DEV__ && value.trim().length === 0) {
800
+ warn(
801
+ `The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
802
+ )
803
+ }
804
+ if (modifiers) {
805
+ if (modifiers.prop && !isDynamic) {
806
+ name = camelize(name)
807
+ if (name === 'innerHtml') name = 'innerHTML'
808
+ }
809
+ if (modifiers.camel && !isDynamic) {
810
+ name = camelize(name)
811
+ }
812
+ if (modifiers.sync) {
813
+ syncGen = genAssignmentCode(value, `$event`)
814
+ if (!isDynamic) {
815
+ addHandler(
816
+ el,
817
+ `update:${camelize(name)}`,
818
+ syncGen,
819
+ null,
820
+ false,
821
+ warn,
822
+ list[i]
823
+ )
824
+ if (hyphenate(name) !== camelize(name)) {
825
+ addHandler(
826
+ el,
827
+ `update:${hyphenate(name)}`,
828
+ syncGen,
829
+ null,
830
+ false,
831
+ warn,
832
+ list[i]
833
+ )
834
+ }
835
+ } else {
836
+ // handler w/ dynamic event name
837
+ addHandler(
838
+ el,
839
+ `"update:"+(${name})`,
840
+ syncGen,
841
+ null,
842
+ false,
843
+ warn,
844
+ list[i],
845
+ true // dynamic
846
+ )
847
+ }
848
+ }
849
+ }
850
+ if (
851
+ (modifiers && modifiers.prop) ||
852
+ (!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name))
853
+ ) {
854
+ addProp(el, name, value, list[i], isDynamic)
855
+ } else {
856
+ addAttr(el, name, value, list[i], isDynamic)
857
+ }
858
+ } else if (onRE.test(name)) {
859
+ // v-on
860
+ name = name.replace(onRE, '')
861
+ isDynamic = dynamicArgRE.test(name)
862
+ if (isDynamic) {
863
+ name = name.slice(1, -1)
864
+ }
865
+ addHandler(el, name, value, modifiers, false, warn, list[i], isDynamic)
866
+ } else {
867
+ // normal directives
868
+ name = name.replace(dirRE, '')
869
+ // parse arg
870
+ const argMatch = name.match(argRE)
871
+ let arg = argMatch && argMatch[1]
872
+ isDynamic = false
873
+ if (arg) {
874
+ name = name.slice(0, -(arg.length + 1))
875
+ if (dynamicArgRE.test(arg)) {
876
+ arg = arg.slice(1, -1)
877
+ isDynamic = true
878
+ }
879
+ }
880
+ addDirective(
881
+ el,
882
+ name,
883
+ rawName,
884
+ value,
885
+ arg,
886
+ isDynamic,
887
+ modifiers,
888
+ list[i]
889
+ )
890
+ if (__DEV__ && name === 'model') {
891
+ checkForAliasModel(el, value)
892
+ }
893
+ }
894
+ } else {
895
+ // literal attribute
896
+ if (__DEV__) {
897
+ const res = parseText(value, delimiters)
898
+ if (res) {
899
+ warn(
900
+ `${name}="${value}": ` +
901
+ 'Interpolation inside attributes has been removed. ' +
902
+ 'Use v-bind or the colon shorthand instead. For example, ' +
903
+ 'instead of <div id="{{ val }}">, use <div :id="val">.',
904
+ list[i]
905
+ )
906
+ }
907
+ }
908
+ addAttr(el, name, JSON.stringify(value), list[i])
909
+ // #6887 firefox doesn't update muted state if set via attribute
910
+ // even immediately after element creation
911
+ if (
912
+ !el.component &&
913
+ name === 'muted' &&
914
+ platformMustUseProp(el.tag, el.attrsMap.type, name)
915
+ ) {
916
+ addProp(el, name, 'true', list[i])
917
+ }
918
+ }
919
+ }
920
+ }
921
+
922
+ function checkInFor(el: ASTElement): boolean {
923
+ let parent: ASTElement | void = el
924
+ while (parent) {
925
+ if (parent.for !== undefined) {
926
+ return true
927
+ }
928
+ parent = parent.parent
929
+ }
930
+ return false
931
+ }
932
+
933
+ function parseModifiers(name: string): Object | void {
934
+ const match = name.match(modifierRE)
935
+ if (match) {
936
+ const ret = {}
937
+ match.forEach(m => {
938
+ ret[m.slice(1)] = true
939
+ })
940
+ return ret
941
+ }
942
+ }
943
+
944
+ function makeAttrsMap(attrs: Array<Record<string, any>>): Record<string, any> {
945
+ const map = {}
946
+ for (let i = 0, l = attrs.length; i < l; i++) {
947
+ if (__DEV__ && map[attrs[i].name] && !isIE && !isEdge) {
948
+ warn('duplicate attribute: ' + attrs[i].name, attrs[i])
949
+ }
950
+ map[attrs[i].name] = attrs[i].value
951
+ }
952
+ return map
953
+ }
954
+
955
+ // for script (e.g. type="x/template") or style, do not decode content
956
+ function isTextTag(el): boolean {
957
+ return el.tag === 'script' || el.tag === 'style'
958
+ }
959
+
960
+ function isForbiddenTag(el): boolean {
961
+ return (
962
+ el.tag === 'style' ||
963
+ (el.tag === 'script' &&
964
+ (!el.attrsMap.type || el.attrsMap.type === 'text/javascript'))
965
+ )
966
+ }
967
+
968
+ const ieNSBug = /^xmlns:NS\d+/
969
+ const ieNSPrefix = /^NS\d+:/
970
+
971
+ /* istanbul ignore next */
972
+ function guardIESVGBug(attrs) {
973
+ const res: any[] = []
974
+ for (let i = 0; i < attrs.length; i++) {
975
+ const attr = attrs[i]
976
+ if (!ieNSBug.test(attr.name)) {
977
+ attr.name = attr.name.replace(ieNSPrefix, '')
978
+ res.push(attr)
979
+ }
980
+ }
981
+ return res
982
+ }
983
+
984
+ function checkForAliasModel(el, value) {
985
+ let _el = el
986
+ while (_el) {
987
+ if (_el.for && _el.alias === value) {
988
+ warn(
989
+ `<${el.tag} v-model="${value}">: ` +
990
+ `You are binding v-model directly to a v-for iteration alias. ` +
991
+ `This will not be able to modify the v-for source array because ` +
992
+ `writing to the alias is like modifying a function local variable. ` +
993
+ `Consider using an array of objects and use v-model on an object property instead.`,
994
+ el.rawAttrsMap['v-model']
995
+ )
996
+ }
997
+ _el = _el.parent
998
+ }
999
+ }