tweaks based on #2885

This commit is contained in:
Evan You 2016-05-16 21:29:50 -04:00
parent fd6944a597
commit 36a32e4466
7 changed files with 28 additions and 32 deletions

View File

@ -3,6 +3,7 @@ declare type CompilerOptions = {
expectHTML?: boolean,
preserveWhitespace?: boolean,
modules?: Array<ModuleOptions>,
staticKeys?: string,
directives?: { [key: string]: Function },
isUnaryTag?: (tag: string) => ?boolean,
isReservedTag?: (tag: string) => ?boolean,

View File

@ -120,9 +120,9 @@ function genData (el: ASTElement): string {
data += `slot:${el.slotTarget},`
}
// platform modules
platformModules.forEach(module => {
data += module.genData(el) || ''
})
for (let i = 0; i < platformModules.length; i++) {
data += platformModules[i].genData(el)
}
// v-show, used to avoid transition being applied
// since v-show takes it over
if (el.attrsMap['v-show']) {

View File

@ -108,9 +108,9 @@ export function parse (
processRender(element)
processSlot(element)
processComponent(element)
platformModules.forEach(module => {
module.parse(element, options)
})
for (let i = 0; i < platformModules.length; i++) {
platformModules[i].parse(element, options)
}
processAttrs(element)
}

View File

@ -56,14 +56,7 @@ export function compileToFunctions (
}
function genStaticKeys (modules: Array<ModuleOptions>): string {
let keys = []
if (modules) {
modules.forEach(module => {
const staticKeys = module.staticKeys
if (staticKeys && staticKeys.length) {
keys = keys.concat(staticKeys)
}
})
}
return keys.join(',')
return modules.reduce((keys, m) => {
return keys.concat(m.staticKeys || [])
}, []).join(',')
}

View File

@ -1,3 +1,5 @@
/* @flow */
import { parseText } from 'compiler/parser/text-parser'
import {
getAndRemoveAttr,
@ -5,7 +7,7 @@ import {
baseWarn
} from 'compiler/helpers'
function parse (el, options) {
function parse (el: ASTElement, options: CompilerOptions) {
const warn = options.warn || baseWarn
const staticClass = getAndRemoveAttr(el, 'class')
if (process.env.NODE_ENV !== 'production' && staticClass) {
@ -25,7 +27,7 @@ function parse (el, options) {
}
}
function genData (el) {
function genData (el: ASTElement): string {
let data = ''
if (el.staticClass) {
data += `staticClass:${el.staticClass},`

View File

@ -1,23 +1,23 @@
/* @flow */
import {
getBindingAttr
} from 'compiler/helpers'
function parse (el, options) {
function parse (el: ASTElement) {
const styleBinding = getBindingAttr(el, 'style', false /* getStatic */)
if (styleBinding) {
el.styleBinding = styleBinding
}
}
function genData (el) {
if (el.styleBinding) {
return `style:${el.styleBinding},`
}
return ''
function genData (el: ASTElement): string {
return el.styleBinding
? `style:${el.styleBinding},`
: ''
}
export default {
staticKeys: [],
parse,
genData
}

View File

@ -1,8 +1,10 @@
/* @flow */
import {
getBindingAttr
} from 'compiler/helpers'
function parse (el, options) {
function parse (el: ASTElement) {
let transition = getBindingAttr(el, 'transition')
if (transition === '""') {
transition = true
@ -13,15 +15,13 @@ function parse (el, options) {
}
}
function genData (el) {
if (el.transition) {
return `transition:{definition:(${el.transition}),appear:${el.transitionOnAppear}},`
}
return ''
function genData (el: ASTElement): string {
return el.transition
? `transition:{definition:(${el.transition}),appear:${el.transitionOnAppear}},`
: ''
}
export default {
staticKeys: [],
parse,
genData
}