nav tabs on admin dashboard
This commit is contained in:
55
node_modules/vue/src/compiler/codegen/events.js
generated
vendored
55
node_modules/vue/src/compiler/codegen/events.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
/* @flow */
|
||||
|
||||
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/
|
||||
const fnInvokeRE = /\([^)]*?\);*$/
|
||||
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
|
||||
|
||||
// KeyboardEvent.keyCode aliases
|
||||
@@ -18,16 +19,19 @@ const keyCodes: { [key: string]: number | Array<number> } = {
|
||||
|
||||
// KeyboardEvent.key aliases
|
||||
const keyNames: { [key: string]: string | Array<string> } = {
|
||||
esc: 'Escape',
|
||||
// #7880: IE11 and Edge use `Esc` for Escape key name.
|
||||
esc: ['Esc', 'Escape'],
|
||||
tab: 'Tab',
|
||||
enter: 'Enter',
|
||||
space: ' ',
|
||||
// #9112: IE11 uses `Spacebar` for Space key name.
|
||||
space: [' ', 'Spacebar'],
|
||||
// #7806: IE11 uses key names without `Arrow` prefix for arrow keys.
|
||||
up: ['Up', 'ArrowUp'],
|
||||
left: ['Left', 'ArrowLeft'],
|
||||
right: ['Right', 'ArrowRight'],
|
||||
down: ['Down', 'ArrowDown'],
|
||||
'delete': ['Backspace', 'Delete']
|
||||
// #9112: IE11 uses `Del` for Delete key name.
|
||||
'delete': ['Backspace', 'Delete', 'Del']
|
||||
}
|
||||
|
||||
// #4868: modifiers that prevent the execution of the listener
|
||||
@@ -50,14 +54,25 @@ const modifierCode: { [key: string]: string } = {
|
||||
|
||||
export function genHandlers (
|
||||
events: ASTElementHandlers,
|
||||
isNative: boolean,
|
||||
warn: Function
|
||||
isNative: boolean
|
||||
): string {
|
||||
let res = isNative ? 'nativeOn:{' : 'on:{'
|
||||
const prefix = isNative ? 'nativeOn:' : 'on:'
|
||||
let staticHandlers = ``
|
||||
let dynamicHandlers = ``
|
||||
for (const name in events) {
|
||||
res += `"${name}":${genHandler(name, events[name])},`
|
||||
const handlerCode = genHandler(events[name])
|
||||
if (events[name] && events[name].dynamic) {
|
||||
dynamicHandlers += `${name},${handlerCode},`
|
||||
} else {
|
||||
staticHandlers += `"${name}":${handlerCode},`
|
||||
}
|
||||
}
|
||||
staticHandlers = `{${staticHandlers.slice(0, -1)}}`
|
||||
if (dynamicHandlers) {
|
||||
return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])`
|
||||
} else {
|
||||
return prefix + staticHandlers
|
||||
}
|
||||
return res.slice(0, -1) + '}'
|
||||
}
|
||||
|
||||
// Generate handler code with binding params on Weex
|
||||
@@ -78,20 +93,18 @@ function genWeexHandler (params: Array<any>, handlerCode: string) {
|
||||
'}'
|
||||
}
|
||||
|
||||
function genHandler (
|
||||
name: string,
|
||||
handler: ASTElementHandler | Array<ASTElementHandler>
|
||||
): string {
|
||||
function genHandler (handler: ASTElementHandler | Array<ASTElementHandler>): string {
|
||||
if (!handler) {
|
||||
return 'function(){}'
|
||||
}
|
||||
|
||||
if (Array.isArray(handler)) {
|
||||
return `[${handler.map(handler => genHandler(name, handler)).join(',')}]`
|
||||
return `[${handler.map(handler => genHandler(handler)).join(',')}]`
|
||||
}
|
||||
|
||||
const isMethodPath = simplePathRE.test(handler.value)
|
||||
const isFunctionExpression = fnExpRE.test(handler.value)
|
||||
const isFunctionInvocation = simplePathRE.test(handler.value.replace(fnInvokeRE, ''))
|
||||
|
||||
if (!handler.modifiers) {
|
||||
if (isMethodPath || isFunctionExpression) {
|
||||
@@ -101,7 +114,9 @@ function genHandler (
|
||||
if (__WEEX__ && handler.params) {
|
||||
return genWeexHandler(handler.params, handler.value)
|
||||
}
|
||||
return `function($event){${handler.value}}` // inline statement
|
||||
return `function($event){${
|
||||
isFunctionInvocation ? `return ${handler.value}` : handler.value
|
||||
}}` // inline statement
|
||||
} else {
|
||||
let code = ''
|
||||
let genModifierCode = ''
|
||||
@@ -136,7 +151,9 @@ function genHandler (
|
||||
? `return ${handler.value}($event)`
|
||||
: isFunctionExpression
|
||||
? `return (${handler.value})($event)`
|
||||
: handler.value
|
||||
: isFunctionInvocation
|
||||
? `return ${handler.value}`
|
||||
: handler.value
|
||||
/* istanbul ignore if */
|
||||
if (__WEEX__ && handler.params) {
|
||||
return genWeexHandler(handler.params, code + handlerCode)
|
||||
@@ -146,7 +163,13 @@ function genHandler (
|
||||
}
|
||||
|
||||
function genKeyFilter (keys: Array<string>): string {
|
||||
return `if(!('button' in $event)&&${keys.map(genFilterCode).join('&&')})return null;`
|
||||
return (
|
||||
// make sure the key filters only apply to KeyboardEvents
|
||||
// #9441: can't use 'keyCode' in $event because Chrome autofill fires fake
|
||||
// key events that do not have keyCode property...
|
||||
`if(!$event.type.indexOf('key')&&` +
|
||||
`${keys.map(genFilterCode).join('&&')})return null;`
|
||||
)
|
||||
}
|
||||
|
||||
function genFilterCode (key: string): string {
|
||||
|
||||
205
node_modules/vue/src/compiler/codegen/index.js
generated
vendored
205
node_modules/vue/src/compiler/codegen/index.js
generated
vendored
@@ -4,6 +4,7 @@ import { genHandlers } from './events'
|
||||
import baseDirectives from '../directives/index'
|
||||
import { camelize, no, extend } from 'shared/util'
|
||||
import { baseWarn, pluckModuleFunction } from '../helpers'
|
||||
import { emptySlotScopeToken } from '../parser/index'
|
||||
|
||||
type TransformFunction = (el: ASTElement, code: string) => string;
|
||||
type DataGenFunction = (el: ASTElement) => string;
|
||||
@@ -18,6 +19,7 @@ export class CodegenState {
|
||||
maybeComponent: (el: ASTElement) => boolean;
|
||||
onceId: number;
|
||||
staticRenderFns: Array<string>;
|
||||
pre: boolean;
|
||||
|
||||
constructor (options: CompilerOptions) {
|
||||
this.options = options
|
||||
@@ -26,9 +28,10 @@ export class CodegenState {
|
||||
this.dataGenFns = pluckModuleFunction(options.modules, 'genData')
|
||||
this.directives = extend(extend({}, baseDirectives), options.directives)
|
||||
const isReservedTag = options.isReservedTag || no
|
||||
this.maybeComponent = (el: ASTElement) => !isReservedTag(el.tag)
|
||||
this.maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)
|
||||
this.onceId = 0
|
||||
this.staticRenderFns = []
|
||||
this.pre = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +53,10 @@ export function generate (
|
||||
}
|
||||
|
||||
export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
if (el.parent) {
|
||||
el.pre = el.pre || el.parent.pre
|
||||
}
|
||||
|
||||
if (el.staticRoot && !el.staticProcessed) {
|
||||
return genStatic(el, state)
|
||||
} else if (el.once && !el.onceProcessed) {
|
||||
@@ -58,7 +65,7 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
return genFor(el, state)
|
||||
} else if (el.if && !el.ifProcessed) {
|
||||
return genIf(el, state)
|
||||
} else if (el.tag === 'template' && !el.slotTarget) {
|
||||
} else if (el.tag === 'template' && !el.slotTarget && !state.pre) {
|
||||
return genChildren(el, state) || 'void 0'
|
||||
} else if (el.tag === 'slot') {
|
||||
return genSlot(el, state)
|
||||
@@ -68,7 +75,10 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
if (el.component) {
|
||||
code = genComponent(el.component, el, state)
|
||||
} else {
|
||||
const data = el.plain ? undefined : genData(el, state)
|
||||
let data
|
||||
if (!el.plain || (el.pre && state.maybeComponent(el))) {
|
||||
data = genData(el, state)
|
||||
}
|
||||
|
||||
const children = el.inlineTemplate ? null : genChildren(el, state, true)
|
||||
code = `_c('${el.tag}'${
|
||||
@@ -88,7 +98,15 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
// hoist static sub-trees out
|
||||
function genStatic (el: ASTElement, state: CodegenState): string {
|
||||
el.staticProcessed = true
|
||||
// Some elements (templates) need to behave differently inside of a v-pre
|
||||
// node. All pre nodes are static roots, so we can use this as a location to
|
||||
// wrap a state change and reset it upon exiting the pre node.
|
||||
const originalPreState = state.pre
|
||||
if (el.pre) {
|
||||
state.pre = el.pre
|
||||
}
|
||||
state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
|
||||
state.pre = originalPreState
|
||||
return `_m(${
|
||||
state.staticRenderFns.length - 1
|
||||
}${
|
||||
@@ -113,7 +131,8 @@ function genOnce (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
if (!key) {
|
||||
process.env.NODE_ENV !== 'production' && state.warn(
|
||||
`v-once can only be used inside v-for that is keyed. `
|
||||
`v-once can only be used inside v-for that is keyed. `,
|
||||
el.rawAttrsMap['v-once']
|
||||
)
|
||||
return genElement(el, state)
|
||||
}
|
||||
@@ -185,6 +204,7 @@ export function genFor (
|
||||
`<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
|
||||
`v-for should have explicit keys. ` +
|
||||
`See https://vuejs.org/guide/list.html#key for more info.`,
|
||||
el.rawAttrsMap['v-for'],
|
||||
true /* tip */
|
||||
)
|
||||
}
|
||||
@@ -229,18 +249,18 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
// attributes
|
||||
if (el.attrs) {
|
||||
data += `attrs:{${genProps(el.attrs)}},`
|
||||
data += `attrs:${genProps(el.attrs)},`
|
||||
}
|
||||
// DOM props
|
||||
if (el.props) {
|
||||
data += `domProps:{${genProps(el.props)}},`
|
||||
data += `domProps:${genProps(el.props)},`
|
||||
}
|
||||
// event handlers
|
||||
if (el.events) {
|
||||
data += `${genHandlers(el.events, false, state.warn)},`
|
||||
data += `${genHandlers(el.events, false)},`
|
||||
}
|
||||
if (el.nativeEvents) {
|
||||
data += `${genHandlers(el.nativeEvents, true, state.warn)},`
|
||||
data += `${genHandlers(el.nativeEvents, true)},`
|
||||
}
|
||||
// slot target
|
||||
// only for non-scoped slots
|
||||
@@ -249,7 +269,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
// scoped slots
|
||||
if (el.scopedSlots) {
|
||||
data += `${genScopedSlots(el.scopedSlots, state)},`
|
||||
data += `${genScopedSlots(el, el.scopedSlots, state)},`
|
||||
}
|
||||
// component v-model
|
||||
if (el.model) {
|
||||
@@ -269,6 +289,12 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
}
|
||||
data = data.replace(/,$/, '') + '}'
|
||||
// v-bind dynamic argument wrap
|
||||
// v-bind with dynamic arguments must be applied using the same v-bind object
|
||||
// merge helper so that class/style/mustUseProp attrs are handled correctly.
|
||||
if (el.dynamicAttrs) {
|
||||
data = `_b(${data},"${el.tag}",${genProps(el.dynamicAttrs)})`
|
||||
}
|
||||
// v-bind data wrap
|
||||
if (el.wrapData) {
|
||||
data = el.wrapData(data)
|
||||
@@ -300,7 +326,7 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
|
||||
res += `{name:"${dir.name}",rawName:"${dir.rawName}"${
|
||||
dir.value ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}` : ''
|
||||
}${
|
||||
dir.arg ? `,arg:"${dir.arg}"` : ''
|
||||
dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''
|
||||
}${
|
||||
dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''
|
||||
}},`
|
||||
@@ -316,9 +342,12 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
|
||||
if (process.env.NODE_ENV !== 'production' && (
|
||||
el.children.length !== 1 || ast.type !== 1
|
||||
)) {
|
||||
state.warn('Inline-template components must have exactly one child element.')
|
||||
state.warn(
|
||||
'Inline-template components must have exactly one child element.',
|
||||
{ start: el.start }
|
||||
)
|
||||
}
|
||||
if (ast.type === 1) {
|
||||
if (ast && ast.type === 1) {
|
||||
const inlineRenderFns = generate(ast, state.options)
|
||||
return `inlineTemplate:{render:function(){${
|
||||
inlineRenderFns.render
|
||||
@@ -329,48 +358,106 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
|
||||
}
|
||||
|
||||
function genScopedSlots (
|
||||
el: ASTElement,
|
||||
slots: { [key: string]: ASTElement },
|
||||
state: CodegenState
|
||||
): string {
|
||||
return `scopedSlots:_u([${
|
||||
Object.keys(slots).map(key => {
|
||||
return genScopedSlot(key, slots[key], state)
|
||||
}).join(',')
|
||||
}])`
|
||||
// by default scoped slots are considered "stable", this allows child
|
||||
// components with only scoped slots to skip forced updates from parent.
|
||||
// but in some cases we have to bail-out of this optimization
|
||||
// for example if the slot contains dynamic names, has v-if or v-for on them...
|
||||
let needsForceUpdate = el.for || Object.keys(slots).some(key => {
|
||||
const slot = slots[key]
|
||||
return (
|
||||
slot.slotTargetDynamic ||
|
||||
slot.if ||
|
||||
slot.for ||
|
||||
containsSlotChild(slot) // is passing down slot from parent which may be dynamic
|
||||
)
|
||||
})
|
||||
|
||||
// #9534: if a component with scoped slots is inside a conditional branch,
|
||||
// it's possible for the same component to be reused but with different
|
||||
// compiled slot content. To avoid that, we generate a unique key based on
|
||||
// the generated code of all the slot contents.
|
||||
let needsKey = !!el.if
|
||||
|
||||
// OR when it is inside another scoped slot or v-for (the reactivity may be
|
||||
// disconnected due to the intermediate scope variable)
|
||||
// #9438, #9506
|
||||
// TODO: this can be further optimized by properly analyzing in-scope bindings
|
||||
// and skip force updating ones that do not actually use scope variables.
|
||||
if (!needsForceUpdate) {
|
||||
let parent = el.parent
|
||||
while (parent) {
|
||||
if (
|
||||
(parent.slotScope && parent.slotScope !== emptySlotScopeToken) ||
|
||||
parent.for
|
||||
) {
|
||||
needsForceUpdate = true
|
||||
break
|
||||
}
|
||||
if (parent.if) {
|
||||
needsKey = true
|
||||
}
|
||||
parent = parent.parent
|
||||
}
|
||||
}
|
||||
|
||||
const generatedSlots = Object.keys(slots)
|
||||
.map(key => genScopedSlot(slots[key], state))
|
||||
.join(',')
|
||||
|
||||
return `scopedSlots:_u([${generatedSlots}]${
|
||||
needsForceUpdate ? `,null,true` : ``
|
||||
}${
|
||||
!needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``
|
||||
})`
|
||||
}
|
||||
|
||||
function hash(str) {
|
||||
let hash = 5381
|
||||
let i = str.length
|
||||
while(i) {
|
||||
hash = (hash * 33) ^ str.charCodeAt(--i)
|
||||
}
|
||||
return hash >>> 0
|
||||
}
|
||||
|
||||
function containsSlotChild (el: ASTNode): boolean {
|
||||
if (el.type === 1) {
|
||||
if (el.tag === 'slot') {
|
||||
return true
|
||||
}
|
||||
return el.children.some(containsSlotChild)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function genScopedSlot (
|
||||
key: string,
|
||||
el: ASTElement,
|
||||
state: CodegenState
|
||||
): string {
|
||||
if (el.for && !el.forProcessed) {
|
||||
return genForScopedSlot(key, el, state)
|
||||
const isLegacySyntax = el.attrsMap['slot-scope']
|
||||
if (el.if && !el.ifProcessed && !isLegacySyntax) {
|
||||
return genIf(el, state, genScopedSlot, `null`)
|
||||
}
|
||||
const fn = `function(${String(el.slotScope)}){` +
|
||||
if (el.for && !el.forProcessed) {
|
||||
return genFor(el, state, genScopedSlot)
|
||||
}
|
||||
const slotScope = el.slotScope === emptySlotScopeToken
|
||||
? ``
|
||||
: String(el.slotScope)
|
||||
const fn = `function(${slotScope}){` +
|
||||
`return ${el.tag === 'template'
|
||||
? el.if
|
||||
? `${el.if}?${genChildren(el, state) || 'undefined'}:undefined`
|
||||
? el.if && isLegacySyntax
|
||||
? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
|
||||
: genChildren(el, state) || 'undefined'
|
||||
: genElement(el, state)
|
||||
}}`
|
||||
return `{key:${key},fn:${fn}}`
|
||||
}
|
||||
|
||||
function genForScopedSlot (
|
||||
key: string,
|
||||
el: any,
|
||||
state: CodegenState
|
||||
): string {
|
||||
const exp = el.for
|
||||
const alias = el.alias
|
||||
const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
|
||||
const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
|
||||
el.forProcessed = true // avoid recursion
|
||||
return `_l((${exp}),` +
|
||||
`function(${alias}${iterator1}${iterator2}){` +
|
||||
`return ${genScopedSlot(key, el, state)}` +
|
||||
'})'
|
||||
// reverse proxy v-slot without scope on this.$slots
|
||||
const reverseProxy = slotScope ? `` : `,proxy:true`
|
||||
return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`
|
||||
}
|
||||
|
||||
export function genChildren (
|
||||
@@ -389,7 +476,10 @@ export function genChildren (
|
||||
el.tag !== 'template' &&
|
||||
el.tag !== 'slot'
|
||||
) {
|
||||
return (altGenElement || genElement)(el, state)
|
||||
const normalizationType = checkSkip
|
||||
? state.maybeComponent(el) ? `,1` : `,0`
|
||||
: ``
|
||||
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
|
||||
}
|
||||
const normalizationType = checkSkip
|
||||
? getNormalizationType(children, state.maybeComponent)
|
||||
@@ -435,7 +525,7 @@ function needsNormalization (el: ASTElement): boolean {
|
||||
function genNode (node: ASTNode, state: CodegenState): string {
|
||||
if (node.type === 1) {
|
||||
return genElement(node, state)
|
||||
} if (node.type === 3 && node.isComment) {
|
||||
} else if (node.type === 3 && node.isComment) {
|
||||
return genComment(node)
|
||||
} else {
|
||||
return genText(node)
|
||||
@@ -457,7 +547,14 @@ function genSlot (el: ASTElement, state: CodegenState): string {
|
||||
const slotName = el.slotName || '"default"'
|
||||
const children = genChildren(el, state)
|
||||
let res = `_t(${slotName}${children ? `,${children}` : ''}`
|
||||
const attrs = el.attrs && `{${el.attrs.map(a => `${camelize(a.name)}:${a.value}`).join(',')}}`
|
||||
const attrs = el.attrs || el.dynamicAttrs
|
||||
? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
|
||||
// slot props are camelized
|
||||
name: camelize(attr.name),
|
||||
value: attr.value,
|
||||
dynamic: attr.dynamic
|
||||
})))
|
||||
: null
|
||||
const bind = el.attrsMap['v-bind']
|
||||
if ((attrs || bind) && !children) {
|
||||
res += `,null`
|
||||
@@ -483,18 +580,26 @@ function genComponent (
|
||||
})`
|
||||
}
|
||||
|
||||
function genProps (props: Array<{ name: string, value: any }>): string {
|
||||
let res = ''
|
||||
function genProps (props: Array<ASTAttr>): string {
|
||||
let staticProps = ``
|
||||
let dynamicProps = ``
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
const prop = props[i]
|
||||
/* istanbul ignore if */
|
||||
if (__WEEX__) {
|
||||
res += `"${prop.name}":${generateValue(prop.value)},`
|
||||
const value = __WEEX__
|
||||
? generateValue(prop.value)
|
||||
: transformSpecialNewlines(prop.value)
|
||||
if (prop.dynamic) {
|
||||
dynamicProps += `${prop.name},${value},`
|
||||
} else {
|
||||
res += `"${prop.name}":${transformSpecialNewlines(prop.value)},`
|
||||
staticProps += `"${prop.name}":${value},`
|
||||
}
|
||||
}
|
||||
return res.slice(0, -1)
|
||||
staticProps = `{${staticProps.slice(0, -1)}}`
|
||||
if (dynamicProps) {
|
||||
return `_d(${staticProps},[${dynamicProps.slice(0, -1)}])`
|
||||
} else {
|
||||
return staticProps
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
|
||||
26
node_modules/vue/src/compiler/create-compiler.js
generated
vendored
26
node_modules/vue/src/compiler/create-compiler.js
generated
vendored
@@ -13,11 +13,29 @@ export function createCompilerCreator (baseCompile: Function): Function {
|
||||
const finalOptions = Object.create(baseOptions)
|
||||
const errors = []
|
||||
const tips = []
|
||||
finalOptions.warn = (msg, tip) => {
|
||||
|
||||
let warn = (msg, range, tip) => {
|
||||
(tip ? tips : errors).push(msg)
|
||||
}
|
||||
|
||||
if (options) {
|
||||
if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
|
||||
// $flow-disable-line
|
||||
const leadingSpaceLength = template.match(/^\s*/)[0].length
|
||||
|
||||
warn = (msg, range, tip) => {
|
||||
const data: WarningMessage = { msg }
|
||||
if (range) {
|
||||
if (range.start != null) {
|
||||
data.start = range.start + leadingSpaceLength
|
||||
}
|
||||
if (range.end != null) {
|
||||
data.end = range.end + leadingSpaceLength
|
||||
}
|
||||
}
|
||||
(tip ? tips : errors).push(data)
|
||||
}
|
||||
}
|
||||
// merge custom modules
|
||||
if (options.modules) {
|
||||
finalOptions.modules =
|
||||
@@ -38,9 +56,11 @@ export function createCompilerCreator (baseCompile: Function): Function {
|
||||
}
|
||||
}
|
||||
|
||||
const compiled = baseCompile(template, finalOptions)
|
||||
finalOptions.warn = warn
|
||||
|
||||
const compiled = baseCompile(template.trim(), finalOptions)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
errors.push.apply(errors, detectErrors(compiled.ast))
|
||||
detectErrors(compiled.ast, warn)
|
||||
}
|
||||
compiled.errors = errors
|
||||
compiled.tips = tips
|
||||
|
||||
2
node_modules/vue/src/compiler/directives/model.js
generated
vendored
2
node_modules/vue/src/compiler/directives/model.js
generated
vendored
@@ -25,7 +25,7 @@ export function genComponentModel (
|
||||
|
||||
el.model = {
|
||||
value: `(${value})`,
|
||||
expression: `"${value}"`,
|
||||
expression: JSON.stringify(value),
|
||||
callback: `function (${baseValueExpression}) {${assignment}}`
|
||||
}
|
||||
}
|
||||
|
||||
57
node_modules/vue/src/compiler/error-detector.js
generated
vendored
57
node_modules/vue/src/compiler/error-detector.js
generated
vendored
@@ -2,6 +2,8 @@
|
||||
|
||||
import { dirRE, onRE } from './parser/index'
|
||||
|
||||
type Range = { start?: number, end?: number };
|
||||
|
||||
// these keywords should not appear inside expressions, but operators like
|
||||
// typeof, instanceof and in are allowed
|
||||
const prohibitedKeywordRE = new RegExp('\\b' + (
|
||||
@@ -19,89 +21,92 @@ const unaryOperatorsRE = new RegExp('\\b' + (
|
||||
const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
||||
|
||||
// detect problematic expressions in a template
|
||||
export function detectErrors (ast: ?ASTNode): Array<string> {
|
||||
const errors: Array<string> = []
|
||||
export function detectErrors (ast: ?ASTNode, warn: Function) {
|
||||
if (ast) {
|
||||
checkNode(ast, errors)
|
||||
checkNode(ast, warn)
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
function checkNode (node: ASTNode, errors: Array<string>) {
|
||||
function checkNode (node: ASTNode, warn: Function) {
|
||||
if (node.type === 1) {
|
||||
for (const name in node.attrsMap) {
|
||||
if (dirRE.test(name)) {
|
||||
const value = node.attrsMap[name]
|
||||
if (value) {
|
||||
const range = node.rawAttrsMap[name]
|
||||
if (name === 'v-for') {
|
||||
checkFor(node, `v-for="${value}"`, errors)
|
||||
checkFor(node, `v-for="${value}"`, warn, range)
|
||||
} else if (onRE.test(name)) {
|
||||
checkEvent(value, `${name}="${value}"`, errors)
|
||||
checkEvent(value, `${name}="${value}"`, warn, range)
|
||||
} else {
|
||||
checkExpression(value, `${name}="${value}"`, errors)
|
||||
checkExpression(value, `${name}="${value}"`, warn, range)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.children) {
|
||||
for (let i = 0; i < node.children.length; i++) {
|
||||
checkNode(node.children[i], errors)
|
||||
checkNode(node.children[i], warn)
|
||||
}
|
||||
}
|
||||
} else if (node.type === 2) {
|
||||
checkExpression(node.expression, node.text, errors)
|
||||
checkExpression(node.expression, node.text, warn, node)
|
||||
}
|
||||
}
|
||||
|
||||
function checkEvent (exp: string, text: string, errors: Array<string>) {
|
||||
function checkEvent (exp: string, text: string, warn: Function, range?: Range) {
|
||||
const stipped = exp.replace(stripStringRE, '')
|
||||
const keywordMatch: any = stipped.match(unaryOperatorsRE)
|
||||
if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
|
||||
errors.push(
|
||||
warn(
|
||||
`avoid using JavaScript unary operator as property name: ` +
|
||||
`"${keywordMatch[0]}" in expression ${text.trim()}`
|
||||
`"${keywordMatch[0]}" in expression ${text.trim()}`,
|
||||
range
|
||||
)
|
||||
}
|
||||
checkExpression(exp, text, errors)
|
||||
checkExpression(exp, text, warn, range)
|
||||
}
|
||||
|
||||
function checkFor (node: ASTElement, text: string, errors: Array<string>) {
|
||||
checkExpression(node.for || '', text, errors)
|
||||
checkIdentifier(node.alias, 'v-for alias', text, errors)
|
||||
checkIdentifier(node.iterator1, 'v-for iterator', text, errors)
|
||||
checkIdentifier(node.iterator2, 'v-for iterator', text, errors)
|
||||
function checkFor (node: ASTElement, text: string, warn: Function, range?: Range) {
|
||||
checkExpression(node.for || '', text, warn, range)
|
||||
checkIdentifier(node.alias, 'v-for alias', text, warn, range)
|
||||
checkIdentifier(node.iterator1, 'v-for iterator', text, warn, range)
|
||||
checkIdentifier(node.iterator2, 'v-for iterator', text, warn, range)
|
||||
}
|
||||
|
||||
function checkIdentifier (
|
||||
ident: ?string,
|
||||
type: string,
|
||||
text: string,
|
||||
errors: Array<string>
|
||||
warn: Function,
|
||||
range?: Range
|
||||
) {
|
||||
if (typeof ident === 'string') {
|
||||
try {
|
||||
new Function(`var ${ident}=_`)
|
||||
} catch (e) {
|
||||
errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`)
|
||||
warn(`invalid ${type} "${ident}" in expression: ${text.trim()}`, range)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkExpression (exp: string, text: string, errors: Array<string>) {
|
||||
function checkExpression (exp: string, text: string, warn: Function, range?: Range) {
|
||||
try {
|
||||
new Function(`return ${exp}`)
|
||||
} catch (e) {
|
||||
const keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE)
|
||||
if (keywordMatch) {
|
||||
errors.push(
|
||||
warn(
|
||||
`avoid using JavaScript keyword as property name: ` +
|
||||
`"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`
|
||||
`"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`,
|
||||
range
|
||||
)
|
||||
} else {
|
||||
errors.push(
|
||||
warn(
|
||||
`invalid expression: ${e.message} in\n\n` +
|
||||
` ${exp}\n\n` +
|
||||
` Raw expression: ${text.trim()}\n`
|
||||
` Raw expression: ${text.trim()}\n`,
|
||||
range
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
131
node_modules/vue/src/compiler/helpers.js
generated
vendored
131
node_modules/vue/src/compiler/helpers.js
generated
vendored
@@ -3,9 +3,13 @@
|
||||
import { emptyObject } from 'shared/util'
|
||||
import { parseFilters } from './parser/filter-parser'
|
||||
|
||||
export function baseWarn (msg: string) {
|
||||
type Range = { start?: number, end?: number };
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
export function baseWarn (msg: string, range?: Range) {
|
||||
console.error(`[Vue compiler]: ${msg}`)
|
||||
}
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
export function pluckModuleFunction<F: Function> (
|
||||
modules: ?Array<Object>,
|
||||
@@ -16,20 +20,23 @@ export function pluckModuleFunction<F: Function> (
|
||||
: []
|
||||
}
|
||||
|
||||
export function addProp (el: ASTElement, name: string, value: string) {
|
||||
(el.props || (el.props = [])).push({ name, value })
|
||||
export function addProp (el: ASTElement, name: string, value: string, range?: Range, dynamic?: boolean) {
|
||||
(el.props || (el.props = [])).push(rangeSetItem({ name, value, dynamic }, range))
|
||||
el.plain = false
|
||||
}
|
||||
|
||||
export function addAttr (el: ASTElement, name: string, value: any) {
|
||||
(el.attrs || (el.attrs = [])).push({ name, value })
|
||||
export function addAttr (el: ASTElement, name: string, value: any, range?: Range, dynamic?: boolean) {
|
||||
const attrs = dynamic
|
||||
? (el.dynamicAttrs || (el.dynamicAttrs = []))
|
||||
: (el.attrs || (el.attrs = []))
|
||||
attrs.push(rangeSetItem({ name, value, dynamic }, range))
|
||||
el.plain = false
|
||||
}
|
||||
|
||||
// add a raw attr (use this in preTransforms)
|
||||
export function addRawAttr (el: ASTElement, name: string, value: any) {
|
||||
export function addRawAttr (el: ASTElement, name: string, value: any, range?: Range) {
|
||||
el.attrsMap[name] = value
|
||||
el.attrsList.push({ name, value })
|
||||
el.attrsList.push(rangeSetItem({ name, value }, range))
|
||||
}
|
||||
|
||||
export function addDirective (
|
||||
@@ -38,19 +45,36 @@ export function addDirective (
|
||||
rawName: string,
|
||||
value: string,
|
||||
arg: ?string,
|
||||
modifiers: ?ASTModifiers
|
||||
isDynamicArg: boolean,
|
||||
modifiers: ?ASTModifiers,
|
||||
range?: Range
|
||||
) {
|
||||
(el.directives || (el.directives = [])).push({ name, rawName, value, arg, modifiers })
|
||||
(el.directives || (el.directives = [])).push(rangeSetItem({
|
||||
name,
|
||||
rawName,
|
||||
value,
|
||||
arg,
|
||||
isDynamicArg,
|
||||
modifiers
|
||||
}, range))
|
||||
el.plain = false
|
||||
}
|
||||
|
||||
function prependModifierMarker (symbol: string, name: string, dynamic?: boolean): string {
|
||||
return dynamic
|
||||
? `_p(${name},"${symbol}")`
|
||||
: symbol + name // mark the event as captured
|
||||
}
|
||||
|
||||
export function addHandler (
|
||||
el: ASTElement,
|
||||
name: string,
|
||||
value: string,
|
||||
modifiers: ?ASTModifiers,
|
||||
important?: boolean,
|
||||
warn?: Function
|
||||
warn?: ?Function,
|
||||
range?: Range,
|
||||
dynamic?: boolean
|
||||
) {
|
||||
modifiers = modifiers || emptyObject
|
||||
// warn prevent and passive modifier
|
||||
@@ -61,37 +85,44 @@ export function addHandler (
|
||||
) {
|
||||
warn(
|
||||
'passive and prevent can\'t be used together. ' +
|
||||
'Passive handler can\'t prevent default event.'
|
||||
'Passive handler can\'t prevent default event.',
|
||||
range
|
||||
)
|
||||
}
|
||||
|
||||
// check capture modifier
|
||||
if (modifiers.capture) {
|
||||
delete modifiers.capture
|
||||
name = '!' + name // mark the event as captured
|
||||
}
|
||||
if (modifiers.once) {
|
||||
delete modifiers.once
|
||||
name = '~' + name // mark the event as once
|
||||
}
|
||||
/* istanbul ignore if */
|
||||
if (modifiers.passive) {
|
||||
delete modifiers.passive
|
||||
name = '&' + name // mark the event as passive
|
||||
}
|
||||
|
||||
// normalize click.right and click.middle since they don't actually fire
|
||||
// this is technically browser-specific, but at least for now browsers are
|
||||
// the only target envs that have right/middle clicks.
|
||||
if (name === 'click') {
|
||||
if (modifiers.right) {
|
||||
if (modifiers.right) {
|
||||
if (dynamic) {
|
||||
name = `(${name})==='click'?'contextmenu':(${name})`
|
||||
} else if (name === 'click') {
|
||||
name = 'contextmenu'
|
||||
delete modifiers.right
|
||||
} else if (modifiers.middle) {
|
||||
}
|
||||
} else if (modifiers.middle) {
|
||||
if (dynamic) {
|
||||
name = `(${name})==='click'?'mouseup':(${name})`
|
||||
} else if (name === 'click') {
|
||||
name = 'mouseup'
|
||||
}
|
||||
}
|
||||
|
||||
// check capture modifier
|
||||
if (modifiers.capture) {
|
||||
delete modifiers.capture
|
||||
name = prependModifierMarker('!', name, dynamic)
|
||||
}
|
||||
if (modifiers.once) {
|
||||
delete modifiers.once
|
||||
name = prependModifierMarker('~', name, dynamic)
|
||||
}
|
||||
/* istanbul ignore if */
|
||||
if (modifiers.passive) {
|
||||
delete modifiers.passive
|
||||
name = prependModifierMarker('&', name, dynamic)
|
||||
}
|
||||
|
||||
let events
|
||||
if (modifiers.native) {
|
||||
delete modifiers.native
|
||||
@@ -100,9 +131,7 @@ export function addHandler (
|
||||
events = el.events || (el.events = {})
|
||||
}
|
||||
|
||||
const newHandler: any = {
|
||||
value: value.trim()
|
||||
}
|
||||
const newHandler: any = rangeSetItem({ value: value.trim(), dynamic }, range)
|
||||
if (modifiers !== emptyObject) {
|
||||
newHandler.modifiers = modifiers
|
||||
}
|
||||
@@ -120,6 +149,15 @@ export function addHandler (
|
||||
el.plain = false
|
||||
}
|
||||
|
||||
export function getRawBindingAttr (
|
||||
el: ASTElement,
|
||||
name: string
|
||||
) {
|
||||
return el.rawAttrsMap[':' + name] ||
|
||||
el.rawAttrsMap['v-bind:' + name] ||
|
||||
el.rawAttrsMap[name]
|
||||
}
|
||||
|
||||
export function getBindingAttr (
|
||||
el: ASTElement,
|
||||
name: string,
|
||||
@@ -162,3 +200,32 @@ export function getAndRemoveAttr (
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
export function getAndRemoveAttrByRegex (
|
||||
el: ASTElement,
|
||||
name: RegExp
|
||||
) {
|
||||
const list = el.attrsList
|
||||
for (let i = 0, l = list.length; i < l; i++) {
|
||||
const attr = list[i]
|
||||
if (name.test(attr.name)) {
|
||||
list.splice(i, 1)
|
||||
return attr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rangeSetItem (
|
||||
item: any,
|
||||
range?: { start?: number, end?: number }
|
||||
) {
|
||||
if (range) {
|
||||
if (range.start != null) {
|
||||
item.start = range.start
|
||||
}
|
||||
if (range.end != null) {
|
||||
item.end = range.end
|
||||
}
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
2
node_modules/vue/src/compiler/optimizer.js
generated
vendored
2
node_modules/vue/src/compiler/optimizer.js
generated
vendored
@@ -30,7 +30,7 @@ export function optimize (root: ?ASTElement, options: CompilerOptions) {
|
||||
|
||||
function genStaticKeys (keys: string): Function {
|
||||
return makeMap(
|
||||
'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +
|
||||
'type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap' +
|
||||
(keys ? ',' + keys : '')
|
||||
)
|
||||
}
|
||||
|
||||
56
node_modules/vue/src/compiler/parser/html-parser.js
generated
vendored
56
node_modules/vue/src/compiler/parser/html-parser.js
generated
vendored
@@ -11,12 +11,12 @@
|
||||
|
||||
import { makeMap, no } from 'shared/util'
|
||||
import { isNonPhrasingTag } from 'web/compiler/util'
|
||||
import { unicodeRegExp } from 'core/util/lang'
|
||||
|
||||
// Regular Expressions for parsing tags and attributes
|
||||
const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
|
||||
// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
|
||||
// but for Vue templates we can enforce a simple charset
|
||||
const ncname = '[a-zA-Z_][\\w\\-\\.]*'
|
||||
const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
|
||||
const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeRegExp.source}]*`
|
||||
const qnameCapture = `((?:${ncname}\\:)?${ncname})`
|
||||
const startTagOpen = new RegExp(`^<${qnameCapture}`)
|
||||
const startTagClose = /^\s*(\/?)>/
|
||||
@@ -26,11 +26,6 @@ const doctype = /^<!DOCTYPE [^>]+>/i
|
||||
const comment = /^<!\--/
|
||||
const conditionalComment = /^<!\[/
|
||||
|
||||
let IS_REGEX_CAPTURING_BROKEN = false
|
||||
'x'.replace(/x(.)?/g, function (m, g) {
|
||||
IS_REGEX_CAPTURING_BROKEN = g === ''
|
||||
})
|
||||
|
||||
// Special Elements (can contain anything)
|
||||
export const isPlainTextElement = makeMap('script,style,textarea', true)
|
||||
const reCache = {}
|
||||
@@ -41,10 +36,11 @@ const decodingMap = {
|
||||
'"': '"',
|
||||
'&': '&',
|
||||
' ': '\n',
|
||||
'	': '\t'
|
||||
'	': '\t',
|
||||
''': "'"
|
||||
}
|
||||
const encodedAttr = /&(?:lt|gt|quot|amp);/g
|
||||
const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10|#9);/g
|
||||
const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g
|
||||
const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g
|
||||
|
||||
// #5992
|
||||
const isIgnoreNewlineTag = makeMap('pre,textarea', true)
|
||||
@@ -74,7 +70,7 @@ export function parseHTML (html, options) {
|
||||
|
||||
if (commentEnd >= 0) {
|
||||
if (options.shouldKeepComment) {
|
||||
options.comment(html.substring(4, commentEnd))
|
||||
options.comment(html.substring(4, commentEnd), index, index + commentEnd + 3)
|
||||
}
|
||||
advance(commentEnd + 3)
|
||||
continue
|
||||
@@ -111,7 +107,7 @@ export function parseHTML (html, options) {
|
||||
const startTagMatch = parseStartTag()
|
||||
if (startTagMatch) {
|
||||
handleStartTag(startTagMatch)
|
||||
if (shouldIgnoreFirstNewline(lastTag, html)) {
|
||||
if (shouldIgnoreFirstNewline(startTagMatch.tagName, html)) {
|
||||
advance(1)
|
||||
}
|
||||
continue
|
||||
@@ -134,16 +130,18 @@ export function parseHTML (html, options) {
|
||||
rest = html.slice(textEnd)
|
||||
}
|
||||
text = html.substring(0, textEnd)
|
||||
advance(textEnd)
|
||||
}
|
||||
|
||||
if (textEnd < 0) {
|
||||
text = html
|
||||
html = ''
|
||||
}
|
||||
|
||||
if (text) {
|
||||
advance(text.length)
|
||||
}
|
||||
|
||||
if (options.chars && text) {
|
||||
options.chars(text)
|
||||
options.chars(text, index - text.length, index)
|
||||
}
|
||||
} else {
|
||||
let endTagLength = 0
|
||||
@@ -172,7 +170,7 @@ export function parseHTML (html, options) {
|
||||
if (html === last) {
|
||||
options.chars && options.chars(html)
|
||||
if (process.env.NODE_ENV !== 'production' && !stack.length && options.warn) {
|
||||
options.warn(`Mal-formatted tag at end of template: "${html}"`)
|
||||
options.warn(`Mal-formatted tag at end of template: "${html}"`, { start: index + html.length })
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -196,8 +194,10 @@ export function parseHTML (html, options) {
|
||||
}
|
||||
advance(start[0].length)
|
||||
let end, attr
|
||||
while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {
|
||||
while (!(end = html.match(startTagClose)) && (attr = html.match(dynamicArgAttribute) || html.match(attribute))) {
|
||||
attr.start = index
|
||||
advance(attr[0].length)
|
||||
attr.end = index
|
||||
match.attrs.push(attr)
|
||||
}
|
||||
if (end) {
|
||||
@@ -228,12 +228,6 @@ export function parseHTML (html, options) {
|
||||
const attrs = new Array(l)
|
||||
for (let i = 0; i < l; i++) {
|
||||
const args = match.attrs[i]
|
||||
// hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
|
||||
if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
|
||||
if (args[3] === '') { delete args[3] }
|
||||
if (args[4] === '') { delete args[4] }
|
||||
if (args[5] === '') { delete args[5] }
|
||||
}
|
||||
const value = args[3] || args[4] || args[5] || ''
|
||||
const shouldDecodeNewlines = tagName === 'a' && args[1] === 'href'
|
||||
? options.shouldDecodeNewlinesForHref
|
||||
@@ -242,10 +236,14 @@ export function parseHTML (html, options) {
|
||||
name: args[1],
|
||||
value: decodeAttr(value, shouldDecodeNewlines)
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
|
||||
attrs[i].start = args.start + args[0].match(/^\s*/).length
|
||||
attrs[i].end = args.end
|
||||
}
|
||||
}
|
||||
|
||||
if (!unary) {
|
||||
stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs })
|
||||
stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs, start: match.start, end: match.end })
|
||||
lastTag = tagName
|
||||
}
|
||||
|
||||
@@ -259,12 +257,9 @@ export function parseHTML (html, options) {
|
||||
if (start == null) start = index
|
||||
if (end == null) end = index
|
||||
|
||||
if (tagName) {
|
||||
lowerCasedTagName = tagName.toLowerCase()
|
||||
}
|
||||
|
||||
// Find the closest opened tag of the same type
|
||||
if (tagName) {
|
||||
lowerCasedTagName = tagName.toLowerCase()
|
||||
for (pos = stack.length - 1; pos >= 0; pos--) {
|
||||
if (stack[pos].lowerCasedTag === lowerCasedTagName) {
|
||||
break
|
||||
@@ -283,7 +278,8 @@ export function parseHTML (html, options) {
|
||||
options.warn
|
||||
) {
|
||||
options.warn(
|
||||
`tag <${stack[i].tag}> has no matching end tag.`
|
||||
`tag <${stack[i].tag}> has no matching end tag.`,
|
||||
{ start: stack[i].start, end: stack[i].end }
|
||||
)
|
||||
}
|
||||
if (options.end) {
|
||||
|
||||
618
node_modules/vue/src/compiler/parser/index.js
generated
vendored
618
node_modules/vue/src/compiler/parser/index.js
generated
vendored
@@ -5,7 +5,7 @@ import { parseHTML } from './html-parser'
|
||||
import { parseText } from './text-parser'
|
||||
import { parseFilters } from './filter-parser'
|
||||
import { genAssignmentCode } from '../directives/model'
|
||||
import { extend, cached, no, camelize } from 'shared/util'
|
||||
import { extend, cached, no, camelize, hyphenate } from 'shared/util'
|
||||
import { isIE, isEdge, isServerRendering } from 'core/util/env'
|
||||
|
||||
import {
|
||||
@@ -16,21 +16,36 @@ import {
|
||||
addDirective,
|
||||
getBindingAttr,
|
||||
getAndRemoveAttr,
|
||||
pluckModuleFunction
|
||||
getRawBindingAttr,
|
||||
pluckModuleFunction,
|
||||
getAndRemoveAttrByRegex
|
||||
} from '../helpers'
|
||||
|
||||
export const onRE = /^@|^v-on:/
|
||||
export const dirRE = /^v-|^@|^:/
|
||||
export const forAliasRE = /([^]*?)\s+(?:in|of)\s+([^]*)/
|
||||
export const dirRE = process.env.VBIND_PROP_SHORTHAND
|
||||
? /^v-|^@|^:|^\./
|
||||
: /^v-|^@|^:/
|
||||
export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
|
||||
export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
|
||||
const stripParensRE = /^\(|\)$/g
|
||||
const dynamicArgRE = /^\[.*\]$/
|
||||
|
||||
const argRE = /:(.*)$/
|
||||
export const bindRE = /^:|^v-bind:/
|
||||
const modifierRE = /\.[^.]+/g
|
||||
export const bindRE = /^:|^\.|^v-bind:/
|
||||
const propBindRE = /^\./
|
||||
const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g
|
||||
|
||||
const slotRE = /^v-slot(:|$)|^#/
|
||||
|
||||
const lineBreakRE = /[\r\n]/
|
||||
const whitespaceRE = /\s+/g
|
||||
|
||||
const invalidAttributeRE = /[\s"'<>\/=]/
|
||||
|
||||
const decodeHTMLCached = cached(he.decode)
|
||||
|
||||
export const emptySlotScopeToken = `_empty_`
|
||||
|
||||
// configurable state
|
||||
export let warn: any
|
||||
let delimiters
|
||||
@@ -40,12 +55,11 @@ let postTransforms
|
||||
let platformIsPreTag
|
||||
let platformMustUseProp
|
||||
let platformGetTagNamespace
|
||||
|
||||
type Attr = { name: string; value: string };
|
||||
let maybeComponent
|
||||
|
||||
export function createASTElement (
|
||||
tag: string,
|
||||
attrs: Array<Attr>,
|
||||
attrs: Array<ASTAttr>,
|
||||
parent: ASTElement | void
|
||||
): ASTElement {
|
||||
return {
|
||||
@@ -53,6 +67,7 @@ export function createASTElement (
|
||||
tag,
|
||||
attrsList: attrs,
|
||||
attrsMap: makeAttrsMap(attrs),
|
||||
rawAttrsMap: {},
|
||||
parent,
|
||||
children: []
|
||||
}
|
||||
@@ -70,6 +85,8 @@ export function parse (
|
||||
platformIsPreTag = options.isPreTag || no
|
||||
platformMustUseProp = options.mustUseProp || no
|
||||
platformGetTagNamespace = options.getTagNamespace || no
|
||||
const isReservedTag = options.isReservedTag || no
|
||||
maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)
|
||||
|
||||
transforms = pluckModuleFunction(options.modules, 'transformNode')
|
||||
preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
|
||||
@@ -79,20 +96,67 @@ export function parse (
|
||||
|
||||
const stack = []
|
||||
const preserveWhitespace = options.preserveWhitespace !== false
|
||||
const whitespaceOption = options.whitespace
|
||||
let root
|
||||
let currentParent
|
||||
let inVPre = false
|
||||
let inPre = false
|
||||
let warned = false
|
||||
|
||||
function warnOnce (msg) {
|
||||
function warnOnce (msg, range) {
|
||||
if (!warned) {
|
||||
warned = true
|
||||
warn(msg)
|
||||
warn(msg, range)
|
||||
}
|
||||
}
|
||||
|
||||
function closeElement (element) {
|
||||
trimEndingWhitespace(element)
|
||||
if (!inVPre && !element.processed) {
|
||||
element = processElement(element, options)
|
||||
}
|
||||
// tree management
|
||||
if (!stack.length && element !== root) {
|
||||
// allow root elements with v-if, v-else-if and v-else
|
||||
if (root.if && (element.elseif || element.else)) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
checkRootConstraints(element)
|
||||
}
|
||||
addIfCondition(root, {
|
||||
exp: element.elseif,
|
||||
block: element
|
||||
})
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
warnOnce(
|
||||
`Component template should contain exactly one root element. ` +
|
||||
`If you are using v-if on multiple elements, ` +
|
||||
`use v-else-if to chain them instead.`,
|
||||
{ start: element.start }
|
||||
)
|
||||
}
|
||||
}
|
||||
if (currentParent && !element.forbidden) {
|
||||
if (element.elseif || element.else) {
|
||||
processIfConditions(element, currentParent)
|
||||
} else {
|
||||
if (element.slotScope) {
|
||||
// scoped slot
|
||||
// keep it in the children list so that v-else(-if) conditions can
|
||||
// find it as the prev node.
|
||||
const name = element.slotTarget || '"default"'
|
||||
;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element
|
||||
}
|
||||
currentParent.children.push(element)
|
||||
element.parent = currentParent
|
||||
}
|
||||
}
|
||||
|
||||
// final children cleanup
|
||||
// filter out scoped slots
|
||||
element.children = element.children.filter(c => !(c: any).slotScope)
|
||||
// remove trailing whitespace node again
|
||||
trimEndingWhitespace(element)
|
||||
|
||||
// check pre state
|
||||
if (element.pre) {
|
||||
inVPre = false
|
||||
@@ -106,6 +170,37 @@ export function parse (
|
||||
}
|
||||
}
|
||||
|
||||
function trimEndingWhitespace (el) {
|
||||
// remove trailing whitespace node
|
||||
if (!inPre) {
|
||||
let lastNode
|
||||
while (
|
||||
(lastNode = el.children[el.children.length - 1]) &&
|
||||
lastNode.type === 3 &&
|
||||
lastNode.text === ' '
|
||||
) {
|
||||
el.children.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkRootConstraints (el) {
|
||||
if (el.tag === 'slot' || el.tag === 'template') {
|
||||
warnOnce(
|
||||
`Cannot use <${el.tag}> as component root element because it may ` +
|
||||
'contain multiple nodes.',
|
||||
{ start: el.start }
|
||||
)
|
||||
}
|
||||
if (el.attrsMap.hasOwnProperty('v-for')) {
|
||||
warnOnce(
|
||||
'Cannot use v-for on stateful component root element because ' +
|
||||
'it renders multiple elements.',
|
||||
el.rawAttrsMap['v-for']
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
parseHTML(template, {
|
||||
warn,
|
||||
expectHTML: options.expectHTML,
|
||||
@@ -114,7 +209,8 @@ export function parse (
|
||||
shouldDecodeNewlines: options.shouldDecodeNewlines,
|
||||
shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
|
||||
shouldKeepComment: options.comments,
|
||||
start (tag, attrs, unary) {
|
||||
outputSourceRange: options.outputSourceRange,
|
||||
start (tag, attrs, unary, start, end) {
|
||||
// check namespace.
|
||||
// inherit parent ns if there is one
|
||||
const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
|
||||
@@ -130,12 +226,36 @@ export function parse (
|
||||
element.ns = ns
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (options.outputSourceRange) {
|
||||
element.start = start
|
||||
element.end = end
|
||||
element.rawAttrsMap = element.attrsList.reduce((cumulated, attr) => {
|
||||
cumulated[attr.name] = attr
|
||||
return cumulated
|
||||
}, {})
|
||||
}
|
||||
attrs.forEach(attr => {
|
||||
if (invalidAttributeRE.test(attr.name)) {
|
||||
warn(
|
||||
`Invalid dynamic argument expression: attribute names cannot contain ` +
|
||||
`spaces, quotes, <, >, / or =.`,
|
||||
{
|
||||
start: attr.start + attr.name.indexOf(`[`),
|
||||
end: attr.start + attr.name.length
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (isForbiddenTag(element) && !isServerRendering()) {
|
||||
element.forbidden = true
|
||||
process.env.NODE_ENV !== 'production' && warn(
|
||||
'Templates should only be responsible for mapping the state to the ' +
|
||||
'UI. Avoid placing tags with side-effects in your templates, such as ' +
|
||||
`<${tag}>` + ', as they will not be parsed.'
|
||||
`<${tag}>` + ', as they will not be parsed.',
|
||||
{ start: element.start }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -160,59 +280,15 @@ export function parse (
|
||||
processFor(element)
|
||||
processIf(element)
|
||||
processOnce(element)
|
||||
// element-scope stuff
|
||||
processElement(element, options)
|
||||
}
|
||||
|
||||
function checkRootConstraints (el) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (el.tag === 'slot' || el.tag === 'template') {
|
||||
warnOnce(
|
||||
`Cannot use <${el.tag}> as component root element because it may ` +
|
||||
'contain multiple nodes.'
|
||||
)
|
||||
}
|
||||
if (el.attrsMap.hasOwnProperty('v-for')) {
|
||||
warnOnce(
|
||||
'Cannot use v-for on stateful component root element because ' +
|
||||
'it renders multiple elements.'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tree management
|
||||
if (!root) {
|
||||
root = element
|
||||
checkRootConstraints(root)
|
||||
} else if (!stack.length) {
|
||||
// allow root elements with v-if, v-else-if and v-else
|
||||
if (root.if && (element.elseif || element.else)) {
|
||||
checkRootConstraints(element)
|
||||
addIfCondition(root, {
|
||||
exp: element.elseif,
|
||||
block: element
|
||||
})
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
warnOnce(
|
||||
`Component template should contain exactly one root element. ` +
|
||||
`If you are using v-if on multiple elements, ` +
|
||||
`use v-else-if to chain them instead.`
|
||||
)
|
||||
}
|
||||
}
|
||||
if (currentParent && !element.forbidden) {
|
||||
if (element.elseif || element.else) {
|
||||
processIfConditions(element, currentParent)
|
||||
} else if (element.slotScope) { // scoped slot
|
||||
currentParent.plain = false
|
||||
const name = element.slotTarget || '"default"'
|
||||
;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element
|
||||
} else {
|
||||
currentParent.children.push(element)
|
||||
element.parent = currentParent
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
checkRootConstraints(root)
|
||||
}
|
||||
}
|
||||
|
||||
if (!unary) {
|
||||
currentParent = element
|
||||
stack.push(element)
|
||||
@@ -221,29 +297,29 @@ export function parse (
|
||||
}
|
||||
},
|
||||
|
||||
end () {
|
||||
// remove trailing whitespace
|
||||
end (tag, start, end) {
|
||||
const element = stack[stack.length - 1]
|
||||
const lastNode = element.children[element.children.length - 1]
|
||||
if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {
|
||||
element.children.pop()
|
||||
}
|
||||
// pop stack
|
||||
stack.length -= 1
|
||||
currentParent = stack[stack.length - 1]
|
||||
if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
|
||||
element.end = end
|
||||
}
|
||||
closeElement(element)
|
||||
},
|
||||
|
||||
chars (text: string) {
|
||||
chars (text: string, start: number, end: number) {
|
||||
if (!currentParent) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (text === template) {
|
||||
warnOnce(
|
||||
'Component template requires a root element, rather than just text.'
|
||||
'Component template requires a root element, rather than just text.',
|
||||
{ start }
|
||||
)
|
||||
} else if ((text = text.trim())) {
|
||||
warnOnce(
|
||||
`text "${text}" outside root element will be ignored.`
|
||||
`text "${text}" outside root element will be ignored.`,
|
||||
{ start }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -258,33 +334,66 @@ export function parse (
|
||||
return
|
||||
}
|
||||
const children = currentParent.children
|
||||
text = inPre || text.trim()
|
||||
? isTextTag(currentParent) ? text : decodeHTMLCached(text)
|
||||
// only preserve whitespace if its not right after a starting tag
|
||||
: preserveWhitespace && children.length ? ' ' : ''
|
||||
if (inPre || text.trim()) {
|
||||
text = isTextTag(currentParent) ? text : decodeHTMLCached(text)
|
||||
} else if (!children.length) {
|
||||
// remove the whitespace-only node right after an opening tag
|
||||
text = ''
|
||||
} else if (whitespaceOption) {
|
||||
if (whitespaceOption === 'condense') {
|
||||
// in condense mode, remove the whitespace node if it contains
|
||||
// line break, otherwise condense to a single space
|
||||
text = lineBreakRE.test(text) ? '' : ' '
|
||||
} else {
|
||||
text = ' '
|
||||
}
|
||||
} else {
|
||||
text = preserveWhitespace ? ' ' : ''
|
||||
}
|
||||
if (text) {
|
||||
if (whitespaceOption === 'condense') {
|
||||
// condense consecutive whitespaces into single space
|
||||
text = text.replace(whitespaceRE, ' ')
|
||||
}
|
||||
let res
|
||||
let child: ?ASTNode
|
||||
if (!inVPre && text !== ' ' && (res = parseText(text, delimiters))) {
|
||||
children.push({
|
||||
child = {
|
||||
type: 2,
|
||||
expression: res.expression,
|
||||
tokens: res.tokens,
|
||||
text
|
||||
})
|
||||
}
|
||||
} else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
|
||||
children.push({
|
||||
child = {
|
||||
type: 3,
|
||||
text
|
||||
})
|
||||
}
|
||||
}
|
||||
if (child) {
|
||||
if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
|
||||
child.start = start
|
||||
child.end = end
|
||||
}
|
||||
children.push(child)
|
||||
}
|
||||
}
|
||||
},
|
||||
comment (text: string) {
|
||||
currentParent.children.push({
|
||||
type: 3,
|
||||
text,
|
||||
isComment: true
|
||||
})
|
||||
comment (text: string, start, end) {
|
||||
// adding anyting as a sibling to the root node is forbidden
|
||||
// comments should still be allowed, but ignored
|
||||
if (currentParent) {
|
||||
const child: ASTText = {
|
||||
type: 3,
|
||||
text,
|
||||
isComment: true
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
|
||||
child.start = start
|
||||
child.end = end
|
||||
}
|
||||
currentParent.children.push(child)
|
||||
}
|
||||
}
|
||||
})
|
||||
return root
|
||||
@@ -297,13 +406,18 @@ function processPre (el) {
|
||||
}
|
||||
|
||||
function processRawAttrs (el) {
|
||||
const l = el.attrsList.length
|
||||
if (l) {
|
||||
const attrs = el.attrs = new Array(l)
|
||||
for (let i = 0; i < l; i++) {
|
||||
const list = el.attrsList
|
||||
const len = list.length
|
||||
if (len) {
|
||||
const attrs: Array<ASTAttr> = el.attrs = new Array(len)
|
||||
for (let i = 0; i < len; i++) {
|
||||
attrs[i] = {
|
||||
name: el.attrsList[i].name,
|
||||
value: JSON.stringify(el.attrsList[i].value)
|
||||
name: list[i].name,
|
||||
value: JSON.stringify(list[i].value)
|
||||
}
|
||||
if (list[i].start != null) {
|
||||
attrs[i].start = list[i].start
|
||||
attrs[i].end = list[i].end
|
||||
}
|
||||
}
|
||||
} else if (!el.pre) {
|
||||
@@ -312,27 +426,53 @@ function processRawAttrs (el) {
|
||||
}
|
||||
}
|
||||
|
||||
export function processElement (element: ASTElement, options: CompilerOptions) {
|
||||
export function processElement (
|
||||
element: ASTElement,
|
||||
options: CompilerOptions
|
||||
) {
|
||||
processKey(element)
|
||||
|
||||
// determine whether this is a plain element after
|
||||
// removing structural attributes
|
||||
element.plain = !element.key && !element.attrsList.length
|
||||
element.plain = (
|
||||
!element.key &&
|
||||
!element.scopedSlots &&
|
||||
!element.attrsList.length
|
||||
)
|
||||
|
||||
processRef(element)
|
||||
processSlot(element)
|
||||
processSlotContent(element)
|
||||
processSlotOutlet(element)
|
||||
processComponent(element)
|
||||
for (let i = 0; i < transforms.length; i++) {
|
||||
element = transforms[i](element, options) || element
|
||||
}
|
||||
processAttrs(element)
|
||||
return element
|
||||
}
|
||||
|
||||
function processKey (el) {
|
||||
const exp = getBindingAttr(el, 'key')
|
||||
if (exp) {
|
||||
if (process.env.NODE_ENV !== 'production' && el.tag === 'template') {
|
||||
warn(`<template> cannot be keyed. Place the key on real elements instead.`)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (el.tag === 'template') {
|
||||
warn(
|
||||
`<template> cannot be keyed. Place the key on real elements instead.`,
|
||||
getRawBindingAttr(el, 'key')
|
||||
)
|
||||
}
|
||||
if (el.for) {
|
||||
const iterator = el.iterator2 || el.iterator1
|
||||
const parent = el.parent
|
||||
if (iterator && iterator === exp && parent && parent.tag === 'transition-group') {
|
||||
warn(
|
||||
`Do not use v-for index as key on <transition-group> children, ` +
|
||||
`this is the same as not using keys.`,
|
||||
getRawBindingAttr(el, 'key'),
|
||||
true /* tip */
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
el.key = exp
|
||||
}
|
||||
@@ -354,7 +494,8 @@ export function processFor (el: ASTElement) {
|
||||
extend(el, res)
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
warn(
|
||||
`Invalid v-for expression: ${exp}`
|
||||
`Invalid v-for expression: ${exp}`,
|
||||
el.rawAttrsMap['v-for']
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -375,7 +516,7 @@ export function parseFor (exp: string): ?ForParseResult {
|
||||
const alias = inMatch[1].trim().replace(stripParensRE, '')
|
||||
const iteratorMatch = alias.match(forIteratorRE)
|
||||
if (iteratorMatch) {
|
||||
res.alias = alias.replace(forIteratorRE, '')
|
||||
res.alias = alias.replace(forIteratorRE, '').trim()
|
||||
res.iterator1 = iteratorMatch[1].trim()
|
||||
if (iteratorMatch[2]) {
|
||||
res.iterator2 = iteratorMatch[2].trim()
|
||||
@@ -415,7 +556,8 @@ function processIfConditions (el, parent) {
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
warn(
|
||||
`v-${el.elseif ? ('else-if="' + el.elseif + '"') : 'else'} ` +
|
||||
`used on element <${el.tag}> without corresponding v-if.`
|
||||
`used on element <${el.tag}> without corresponding v-if.`,
|
||||
el.rawAttrsMap[el.elseif ? 'v-else-if' : 'v-else']
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -429,7 +571,8 @@ function findPrevElement (children: Array<any>): ASTElement | void {
|
||||
if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
|
||||
warn(
|
||||
`text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
|
||||
`will be ignored.`
|
||||
`will be ignored.`,
|
||||
children[i]
|
||||
)
|
||||
}
|
||||
children.pop()
|
||||
@@ -451,52 +594,154 @@ function processOnce (el) {
|
||||
}
|
||||
}
|
||||
|
||||
function processSlot (el) {
|
||||
// handle content being passed to a component as slot,
|
||||
// e.g. <template slot="xxx">, <div slot-scope="xxx">
|
||||
function processSlotContent (el) {
|
||||
let slotScope
|
||||
if (el.tag === 'template') {
|
||||
slotScope = getAndRemoveAttr(el, 'scope')
|
||||
/* istanbul ignore if */
|
||||
if (process.env.NODE_ENV !== 'production' && slotScope) {
|
||||
warn(
|
||||
`the "scope" attribute for scoped slots have been deprecated and ` +
|
||||
`replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
|
||||
`can also be used on plain elements in addition to <template> to ` +
|
||||
`denote scoped slots.`,
|
||||
el.rawAttrsMap['scope'],
|
||||
true
|
||||
)
|
||||
}
|
||||
el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope')
|
||||
} else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
|
||||
/* istanbul ignore if */
|
||||
if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
|
||||
warn(
|
||||
`Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
|
||||
`(v-for takes higher priority). Use a wrapper <template> for the ` +
|
||||
`scoped slot to make it clearer.`,
|
||||
el.rawAttrsMap['slot-scope'],
|
||||
true
|
||||
)
|
||||
}
|
||||
el.slotScope = slotScope
|
||||
}
|
||||
|
||||
// slot="xxx"
|
||||
const slotTarget = getBindingAttr(el, 'slot')
|
||||
if (slotTarget) {
|
||||
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
|
||||
el.slotTargetDynamic = !!(el.attrsMap[':slot'] || el.attrsMap['v-bind:slot'])
|
||||
// preserve slot as an attribute for native shadow DOM compat
|
||||
// only for non-scoped slots.
|
||||
if (el.tag !== 'template' && !el.slotScope) {
|
||||
addAttr(el, 'slot', slotTarget, getRawBindingAttr(el, 'slot'))
|
||||
}
|
||||
}
|
||||
|
||||
// 2.6 v-slot syntax
|
||||
if (process.env.NEW_SLOT_SYNTAX) {
|
||||
if (el.tag === 'template') {
|
||||
// v-slot on <template>
|
||||
const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
|
||||
if (slotBinding) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (el.slotTarget || el.slotScope) {
|
||||
warn(
|
||||
`Unexpected mixed usage of different slot syntaxes.`,
|
||||
el
|
||||
)
|
||||
}
|
||||
if (el.parent && !maybeComponent(el.parent)) {
|
||||
warn(
|
||||
`<template v-slot> can only appear at the root level inside ` +
|
||||
`the receiving the component`,
|
||||
el
|
||||
)
|
||||
}
|
||||
}
|
||||
const { name, dynamic } = getSlotName(slotBinding)
|
||||
el.slotTarget = name
|
||||
el.slotTargetDynamic = dynamic
|
||||
el.slotScope = slotBinding.value || emptySlotScopeToken // force it into a scoped slot for perf
|
||||
}
|
||||
} else {
|
||||
// v-slot on component, denotes default slot
|
||||
const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
|
||||
if (slotBinding) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!maybeComponent(el)) {
|
||||
warn(
|
||||
`v-slot can only be used on components or <template>.`,
|
||||
slotBinding
|
||||
)
|
||||
}
|
||||
if (el.slotScope || el.slotTarget) {
|
||||
warn(
|
||||
`Unexpected mixed usage of different slot syntaxes.`,
|
||||
el
|
||||
)
|
||||
}
|
||||
if (el.scopedSlots) {
|
||||
warn(
|
||||
`To avoid scope ambiguity, the default slot should also use ` +
|
||||
`<template> syntax when there are other named slots.`,
|
||||
slotBinding
|
||||
)
|
||||
}
|
||||
}
|
||||
// add the component's children to its default slot
|
||||
const slots = el.scopedSlots || (el.scopedSlots = {})
|
||||
const { name, dynamic } = getSlotName(slotBinding)
|
||||
const slotContainer = slots[name] = createASTElement('template', [], el)
|
||||
slotContainer.slotTarget = name
|
||||
slotContainer.slotTargetDynamic = dynamic
|
||||
slotContainer.children = el.children.filter((c: any) => {
|
||||
if (!c.slotScope) {
|
||||
c.parent = slotContainer
|
||||
return true
|
||||
}
|
||||
})
|
||||
slotContainer.slotScope = slotBinding.value || emptySlotScopeToken
|
||||
// remove children as they are returned from scopedSlots now
|
||||
el.children = []
|
||||
// mark el non-plain so data gets generated
|
||||
el.plain = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSlotName (binding) {
|
||||
let name = binding.name.replace(slotRE, '')
|
||||
if (!name) {
|
||||
if (binding.name[0] !== '#') {
|
||||
name = 'default'
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
warn(
|
||||
`v-slot shorthand syntax requires a slot name.`,
|
||||
binding
|
||||
)
|
||||
}
|
||||
}
|
||||
return dynamicArgRE.test(name)
|
||||
// dynamic [name]
|
||||
? { name: name.slice(1, -1), dynamic: true }
|
||||
// static name
|
||||
: { name: `"${name}"`, dynamic: false }
|
||||
}
|
||||
|
||||
// handle <slot/> outlets
|
||||
function processSlotOutlet (el) {
|
||||
if (el.tag === 'slot') {
|
||||
el.slotName = getBindingAttr(el, 'name')
|
||||
if (process.env.NODE_ENV !== 'production' && el.key) {
|
||||
warn(
|
||||
`\`key\` does not work on <slot> because slots are abstract outlets ` +
|
||||
`and can possibly expand into multiple elements. ` +
|
||||
`Use the key on a wrapping element instead.`
|
||||
`Use the key on a wrapping element instead.`,
|
||||
getRawBindingAttr(el, 'key')
|
||||
)
|
||||
}
|
||||
} else {
|
||||
let slotScope
|
||||
if (el.tag === 'template') {
|
||||
slotScope = getAndRemoveAttr(el, 'scope')
|
||||
/* istanbul ignore if */
|
||||
if (process.env.NODE_ENV !== 'production' && slotScope) {
|
||||
warn(
|
||||
`the "scope" attribute for scoped slots have been deprecated and ` +
|
||||
`replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
|
||||
`can also be used on plain elements in addition to <template> to ` +
|
||||
`denote scoped slots.`,
|
||||
true
|
||||
)
|
||||
}
|
||||
el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope')
|
||||
} else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
|
||||
/* istanbul ignore if */
|
||||
if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
|
||||
warn(
|
||||
`Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
|
||||
`(v-for takes higher priority). Use a wrapper <template> for the ` +
|
||||
`scoped slot to make it clearer.`,
|
||||
true
|
||||
)
|
||||
}
|
||||
el.slotScope = slotScope
|
||||
}
|
||||
const slotTarget = getBindingAttr(el, 'slot')
|
||||
if (slotTarget) {
|
||||
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
|
||||
// preserve slot as an attribute for native shadow DOM compat
|
||||
// only for non-scoped slots.
|
||||
if (el.tag !== 'template' && !el.slotScope) {
|
||||
addAttr(el, 'slot', slotTarget)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +757,7 @@ function processComponent (el) {
|
||||
|
||||
function processAttrs (el) {
|
||||
const list = el.attrsList
|
||||
let i, l, name, rawName, value, modifiers, isProp
|
||||
let i, l, name, rawName, value, modifiers, syncGen, isDynamic
|
||||
for (i = 0, l = list.length; i < l; i++) {
|
||||
name = rawName = list[i].name
|
||||
value = list[i].value
|
||||
@@ -520,50 +765,103 @@ function processAttrs (el) {
|
||||
// mark element as dynamic
|
||||
el.hasBindings = true
|
||||
// modifiers
|
||||
modifiers = parseModifiers(name)
|
||||
if (modifiers) {
|
||||
modifiers = parseModifiers(name.replace(dirRE, ''))
|
||||
// support .foo shorthand syntax for the .prop modifier
|
||||
if (process.env.VBIND_PROP_SHORTHAND && propBindRE.test(name)) {
|
||||
(modifiers || (modifiers = {})).prop = true
|
||||
name = `.` + name.slice(1).replace(modifierRE, '')
|
||||
} else if (modifiers) {
|
||||
name = name.replace(modifierRE, '')
|
||||
}
|
||||
if (bindRE.test(name)) { // v-bind
|
||||
name = name.replace(bindRE, '')
|
||||
value = parseFilters(value)
|
||||
isProp = false
|
||||
isDynamic = dynamicArgRE.test(name)
|
||||
if (isDynamic) {
|
||||
name = name.slice(1, -1)
|
||||
}
|
||||
if (
|
||||
process.env.NODE_ENV !== 'production' &&
|
||||
value.trim().length === 0
|
||||
) {
|
||||
warn(
|
||||
`The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
|
||||
)
|
||||
}
|
||||
if (modifiers) {
|
||||
if (modifiers.prop) {
|
||||
isProp = true
|
||||
if (modifiers.prop && !isDynamic) {
|
||||
name = camelize(name)
|
||||
if (name === 'innerHtml') name = 'innerHTML'
|
||||
}
|
||||
if (modifiers.camel) {
|
||||
if (modifiers.camel && !isDynamic) {
|
||||
name = camelize(name)
|
||||
}
|
||||
if (modifiers.sync) {
|
||||
addHandler(
|
||||
el,
|
||||
`update:${camelize(name)}`,
|
||||
genAssignmentCode(value, `$event`)
|
||||
)
|
||||
syncGen = genAssignmentCode(value, `$event`)
|
||||
if (!isDynamic) {
|
||||
addHandler(
|
||||
el,
|
||||
`update:${camelize(name)}`,
|
||||
syncGen,
|
||||
null,
|
||||
false,
|
||||
warn,
|
||||
list[i]
|
||||
)
|
||||
if (hyphenate(name) !== camelize(name)) {
|
||||
addHandler(
|
||||
el,
|
||||
`update:${hyphenate(name)}`,
|
||||
syncGen,
|
||||
null,
|
||||
false,
|
||||
warn,
|
||||
list[i]
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// handler w/ dynamic event name
|
||||
addHandler(
|
||||
el,
|
||||
`"update:"+(${name})`,
|
||||
syncGen,
|
||||
null,
|
||||
false,
|
||||
warn,
|
||||
list[i],
|
||||
true // dynamic
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isProp || (
|
||||
if ((modifiers && modifiers.prop) || (
|
||||
!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name)
|
||||
)) {
|
||||
addProp(el, name, value)
|
||||
addProp(el, name, value, list[i], isDynamic)
|
||||
} else {
|
||||
addAttr(el, name, value)
|
||||
addAttr(el, name, value, list[i], isDynamic)
|
||||
}
|
||||
} else if (onRE.test(name)) { // v-on
|
||||
name = name.replace(onRE, '')
|
||||
addHandler(el, name, value, modifiers, false, warn)
|
||||
isDynamic = dynamicArgRE.test(name)
|
||||
if (isDynamic) {
|
||||
name = name.slice(1, -1)
|
||||
}
|
||||
addHandler(el, name, value, modifiers, false, warn, list[i], isDynamic)
|
||||
} else { // normal directives
|
||||
name = name.replace(dirRE, '')
|
||||
// parse arg
|
||||
const argMatch = name.match(argRE)
|
||||
const arg = argMatch && argMatch[1]
|
||||
let arg = argMatch && argMatch[1]
|
||||
isDynamic = false
|
||||
if (arg) {
|
||||
name = name.slice(0, -(arg.length + 1))
|
||||
if (dynamicArgRE.test(arg)) {
|
||||
arg = arg.slice(1, -1)
|
||||
isDynamic = true
|
||||
}
|
||||
}
|
||||
addDirective(el, name, rawName, value, arg, modifiers)
|
||||
addDirective(el, name, rawName, value, arg, isDynamic, modifiers, list[i])
|
||||
if (process.env.NODE_ENV !== 'production' && name === 'model') {
|
||||
checkForAliasModel(el, value)
|
||||
}
|
||||
@@ -577,17 +875,18 @@ function processAttrs (el) {
|
||||
`${name}="${value}": ` +
|
||||
'Interpolation inside attributes has been removed. ' +
|
||||
'Use v-bind or the colon shorthand instead. For example, ' +
|
||||
'instead of <div id="{{ val }}">, use <div :id="val">.'
|
||||
'instead of <div id="{{ val }}">, use <div :id="val">.',
|
||||
list[i]
|
||||
)
|
||||
}
|
||||
}
|
||||
addAttr(el, name, JSON.stringify(value))
|
||||
addAttr(el, name, JSON.stringify(value), list[i])
|
||||
// #6887 firefox doesn't update muted state if set via attribute
|
||||
// even immediately after element creation
|
||||
if (!el.component &&
|
||||
name === 'muted' &&
|
||||
platformMustUseProp(el.tag, el.attrsMap.type, name)) {
|
||||
addProp(el, name, 'true')
|
||||
addProp(el, name, 'true', list[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -620,7 +919,7 @@ function makeAttrsMap (attrs: Array<Object>): Object {
|
||||
process.env.NODE_ENV !== 'production' &&
|
||||
map[attrs[i].name] && !isIE && !isEdge
|
||||
) {
|
||||
warn('duplicate attribute: ' + attrs[i].name)
|
||||
warn('duplicate attribute: ' + attrs[i].name, attrs[i])
|
||||
}
|
||||
map[attrs[i].name] = attrs[i].value
|
||||
}
|
||||
@@ -667,7 +966,8 @@ function checkForAliasModel (el, value) {
|
||||
`You are binding v-model directly to a v-for iteration alias. ` +
|
||||
`This will not be able to modify the v-for source array because ` +
|
||||
`writing to the alias is like modifying a function local variable. ` +
|
||||
`Consider using an array of objects and use v-model on an object property instead.`
|
||||
`Consider using an array of objects and use v-model on an object property instead.`,
|
||||
el.rawAttrsMap['v-model']
|
||||
)
|
||||
}
|
||||
_el = _el.parent
|
||||
|
||||
2
node_modules/vue/src/compiler/parser/text-parser.js
generated
vendored
2
node_modules/vue/src/compiler/parser/text-parser.js
generated
vendored
@@ -3,7 +3,7 @@
|
||||
import { cached } from 'shared/util'
|
||||
import { parseFilters } from './filter-parser'
|
||||
|
||||
const defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g
|
||||
const defaultTagRE = /\{\{((?:.|\r?\n)+?)\}\}/g
|
||||
const regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g
|
||||
|
||||
const buildRegex = cached(delimiters => {
|
||||
|
||||
27
node_modules/vue/src/compiler/to-function.js
generated
vendored
27
node_modules/vue/src/compiler/to-function.js
generated
vendored
@@ -2,6 +2,7 @@
|
||||
|
||||
import { noop, extend } from 'shared/util'
|
||||
import { warn as baseWarn, tip } from 'core/util/debug'
|
||||
import { generateCodeFrame } from './codeframe'
|
||||
|
||||
type CompiledFunctionResult = {
|
||||
render: Function;
|
||||
@@ -61,14 +62,28 @@ export function createCompileToFunctionFn (compile: Function): Function {
|
||||
// check compilation errors/tips
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (compiled.errors && compiled.errors.length) {
|
||||
warn(
|
||||
`Error compiling template:\n\n${template}\n\n` +
|
||||
compiled.errors.map(e => `- ${e}`).join('\n') + '\n',
|
||||
vm
|
||||
)
|
||||
if (options.outputSourceRange) {
|
||||
compiled.errors.forEach(e => {
|
||||
warn(
|
||||
`Error compiling template:\n\n${e.msg}\n\n` +
|
||||
generateCodeFrame(template, e.start, e.end),
|
||||
vm
|
||||
)
|
||||
})
|
||||
} else {
|
||||
warn(
|
||||
`Error compiling template:\n\n${template}\n\n` +
|
||||
compiled.errors.map(e => `- ${e}`).join('\n') + '\n',
|
||||
vm
|
||||
)
|
||||
}
|
||||
}
|
||||
if (compiled.tips && compiled.tips.length) {
|
||||
compiled.tips.forEach(msg => tip(msg, vm))
|
||||
if (options.outputSourceRange) {
|
||||
compiled.tips.forEach(e => tip(e.msg, vm))
|
||||
} else {
|
||||
compiled.tips.forEach(msg => tip(msg, vm))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user