From b5b1ac373a8f4d464454e7770a888fdd178891c4 Mon Sep 17 00:00:00 2001 From: chengchao Date: Tue, 9 May 2017 20:24:25 +0800 Subject: [PATCH] improve mutli-line `&&` coding style to keep consistence (#5625) --- src/compiler/codegen/events.js | 6 +++--- src/compiler/codegen/index.js | 7 ++++--- src/compiler/parser/html-parser.js | 5 +++-- src/compiler/parser/index.js | 5 +++-- src/core/instance/index.js | 3 ++- .../instance/render-helpers/resolve-slots.js | 3 ++- src/core/util/props.js | 3 ++- src/core/vdom/create-element.js | 3 ++- src/core/vdom/patch.js | 17 ++++++++++------- .../web/runtime/components/transition.js | 3 ++- src/platforms/web/runtime/index.js | 5 +++-- src/platforms/web/runtime/modules/style.js | 3 ++- src/platforms/web/runtime/modules/transition.js | 5 +++-- src/platforms/web/runtime/transition-util.js | 6 ++++-- src/platforms/web/server/modules/dom-props.js | 5 +++-- src/platforms/weex/runtime/modules/class.js | 6 ++++-- .../weex/runtime/modules/transition.js | 7 ++++--- src/server/render.js | 5 +++-- 18 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index 11cd4a5a370..6a64e1a1919 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -44,9 +44,9 @@ export function genHandlers ( const handler = events[name] // #5330: warn click.right, since right clicks do not actually fire click events. if (process.env.NODE_ENV !== 'production' && - name === 'click' && - handler && handler.modifiers && handler.modifiers.right - ) { + name === 'click' && + handler && handler.modifiers && handler.modifiers.right + ) { warn( `Use "contextmenu" instead of "click.right" since right clicks ` + `do not actually fire "click" events.` diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index 92cde3fca34..ee89356d6db 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -311,9 +311,10 @@ function genChildren (el: ASTElement, checkSkip?: boolean): string | void { const el: any = children[0] // optimize single v-for if (children.length === 1 && - el.for && - el.tag !== 'template' && - el.tag !== 'slot') { + el.for && + el.tag !== 'template' && + el.tag !== 'slot' + ) { return genElement(el) } const normalizationType = checkSkip ? getNormalizationType(children) : 0 diff --git a/src/compiler/parser/html-parser.js b/src/compiler/parser/html-parser.js index 522e373bb6d..4e4c0686758 100644 --- a/src/compiler/parser/html-parser.js +++ b/src/compiler/parser/html-parser.js @@ -279,8 +279,9 @@ export function parseHTML (html, options) { // Close all the open elements, up the stack for (let i = stack.length - 1; i >= pos; i--) { if (process.env.NODE_ENV !== 'production' && - (i > pos || !tagName) && - options.warn) { + (i > pos || !tagName) && + options.warn + ) { options.warn( `tag <${stack[i].tag}> has no matching end tag.` ) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index c49491b4c58..93db19610df 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -246,8 +246,9 @@ export function parse ( // IE textarea placeholder bug /* istanbul ignore if */ if (isIE && - currentParent.tag === 'textarea' && - currentParent.attrsMap.placeholder === text) { + currentParent.tag === 'textarea' && + currentParent.attrsMap.placeholder === text + ) { return } const children = currentParent.children diff --git a/src/core/instance/index.js b/src/core/instance/index.js index 6649eef3313..8a4402317f5 100644 --- a/src/core/instance/index.js +++ b/src/core/instance/index.js @@ -7,7 +7,8 @@ import { warn } from '../util/index' function Vue (options) { if (process.env.NODE_ENV !== 'production' && - !(this instanceof Vue)) { + !(this instanceof Vue) + ) { warn('Vue is a constructor and should be called with the `new` keyword') } this._init(options) diff --git a/src/core/instance/render-helpers/resolve-slots.js b/src/core/instance/render-helpers/resolve-slots.js index 9871858faad..ea79640f168 100644 --- a/src/core/instance/render-helpers/resolve-slots.js +++ b/src/core/instance/render-helpers/resolve-slots.js @@ -17,7 +17,8 @@ export function resolveSlots ( // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && child.data.slot != null) { + child.data && child.data.slot != null + ) { const name = child.data.slot const slot = (slots[name] || (slots[name] = [])) if (child.tag === 'template') { diff --git a/src/core/util/props.js b/src/core/util/props.js index 4444113a5a7..4461c76332f 100644 --- a/src/core/util/props.js +++ b/src/core/util/props.js @@ -66,7 +66,8 @@ function getPropDefaultValue (vm: ?Component, prop: PropOptions, key: string): a // return previous default value to avoid unnecessary watcher trigger if (vm && vm.$options.propsData && vm.$options.propsData[key] === undefined && - vm._props[key] !== undefined) { + vm._props[key] !== undefined + ) { return vm._props[key] } // call factory function for non-Function types diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index f0faacc4d2b..88a5addfc74 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -63,7 +63,8 @@ export function _createElement ( } // support single function children as default scoped slot if (Array.isArray(children) && - typeof children[0] === 'function') { + typeof children[0] === 'function' + ) { data = data || {} data.scopedSlots = { default: children[0] } children.length = 0 diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 69d1617fb93..25d418ce10c 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -285,8 +285,9 @@ export function createPatchFunction (backend) { } // for slot content they should also get the scopeId from the host instance. if (isDef(i = activeInstance) && - i !== vnode.context && - isDef(i = i.$options._scopeId)) { + i !== vnode.context && + isDef(i = i.$options._scopeId) + ) { nodeOps.setAttribute(vnode.elm, i, '') } } @@ -438,9 +439,10 @@ export function createPatchFunction (backend) { // if the new node is not cloned it means the render functions have been // reset by the hot-reload-api and we need to do a proper re-render. if (isTrue(vnode.isStatic) && - isTrue(oldVnode.isStatic) && - vnode.key === oldVnode.key && - (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))) { + isTrue(oldVnode.isStatic) && + vnode.key === oldVnode.key && + (isTrue(vnode.isCloned) || isTrue(vnode.isOnce)) + ) { vnode.elm = oldVnode.elm vnode.componentInstance = oldVnode.componentInstance return @@ -529,8 +531,9 @@ export function createPatchFunction (backend) { // longer than the virtual children list. if (!childrenMatch || childNode) { if (process.env.NODE_ENV !== 'production' && - typeof console !== 'undefined' && - !bailed) { + typeof console !== 'undefined' && + !bailed + ) { bailed = true console.warn('Parent: ', elm) console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children) diff --git a/src/platforms/web/runtime/components/transition.js b/src/platforms/web/runtime/components/transition.js index 9f8a512e49d..a6f44a32f81 100644 --- a/src/platforms/web/runtime/components/transition.js +++ b/src/platforms/web/runtime/components/transition.js @@ -103,7 +103,8 @@ export default { // warn invalid mode if (process.env.NODE_ENV !== 'production' && - mode && mode !== 'in-out' && mode !== 'out-in') { + mode && mode !== 'in-out' && mode !== 'out-in' + ) { warn( 'invalid mode: ' + mode, this.$parent diff --git a/src/platforms/web/runtime/index.js b/src/platforms/web/runtime/index.js index 26fcfc1637b..eb8cd76ccda 100644 --- a/src/platforms/web/runtime/index.js +++ b/src/platforms/web/runtime/index.js @@ -56,8 +56,9 @@ setTimeout(() => { } } if (process.env.NODE_ENV !== 'production' && - config.productionTip !== false && - inBrowser && typeof console !== 'undefined') { + config.productionTip !== false && + inBrowser && typeof console !== 'undefined' + ) { console[console.info ? 'info' : 'log']( `You are running Vue in development mode.\n` + `Make sure to turn on production mode when deploying for production.\n` + diff --git a/src/platforms/web/runtime/modules/style.js b/src/platforms/web/runtime/modules/style.js index 3456d2971c5..ee9b036ee79 100644 --- a/src/platforms/web/runtime/modules/style.js +++ b/src/platforms/web/runtime/modules/style.js @@ -49,7 +49,8 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) { const oldData = oldVnode.data if (isUndef(data.staticStyle) && isUndef(data.style) && - isUndef(oldData.staticStyle) && isUndef(oldData.style)) { + isUndef(oldData.staticStyle) && isUndef(oldData.style) + ) { return } diff --git a/src/platforms/web/runtime/modules/transition.js b/src/platforms/web/runtime/modules/transition.js index 3d22c9963f0..94acb90debc 100644 --- a/src/platforms/web/runtime/modules/transition.js +++ b/src/platforms/web/runtime/modules/transition.js @@ -134,8 +134,9 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) { const parent = el.parentNode const pendingNode = parent && parent._pending && parent._pending[vnode.key] if (pendingNode && - pendingNode.tag === vnode.tag && - pendingNode.elm._leaveCb) { + pendingNode.tag === vnode.tag && + pendingNode.elm._leaveCb + ) { pendingNode.elm._leaveCb() } enterHook && enterHook(el, cb) diff --git a/src/platforms/web/runtime/transition-util.js b/src/platforms/web/runtime/transition-util.js index 4bbc80923fd..d6c8fdf2b28 100644 --- a/src/platforms/web/runtime/transition-util.js +++ b/src/platforms/web/runtime/transition-util.js @@ -44,12 +44,14 @@ export let animationEndEvent = 'animationend' if (hasTransition) { /* istanbul ignore if */ if (window.ontransitionend === undefined && - window.onwebkittransitionend !== undefined) { + window.onwebkittransitionend !== undefined + ) { transitionProp = 'WebkitTransition' transitionEndEvent = 'webkitTransitionEnd' } if (window.onanimationend === undefined && - window.onwebkitanimationend !== undefined) { + window.onwebkitanimationend !== undefined + ) { animationProp = 'WebkitAnimation' animationEndEvent = 'webkitAnimationEnd' } diff --git a/src/platforms/web/server/modules/dom-props.js b/src/platforms/web/server/modules/dom-props.js index ceb1de8853a..8618b100d1b 100644 --- a/src/platforms/web/server/modules/dom-props.js +++ b/src/platforms/web/server/modules/dom-props.js @@ -30,8 +30,9 @@ export default function renderDOMProps (node: VNodeWithData): string { } else { const attr = propsToAttrMap[key] || key.toLowerCase() if (isRenderableAttr(attr) && - // avoid rendering double-bound props/attrs twice - !(isDef(attrs) && isDef(attrs[attr]))) { + // avoid rendering double-bound props/attrs twice + !(isDef(attrs) && isDef(attrs[attr])) + ) { res += renderAttr(attr, props[key]) } } diff --git a/src/platforms/weex/runtime/modules/class.js b/src/platforms/weex/runtime/modules/class.js index d3c3c792439..b1e3b188561 100755 --- a/src/platforms/weex/runtime/modules/class.js +++ b/src/platforms/weex/runtime/modules/class.js @@ -8,8 +8,10 @@ function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { const data: VNodeData = vnode.data const oldData: VNodeData = oldVnode.data - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if (!data.staticClass && + !data.class && + (!oldData || (!oldData.staticClass && !oldData.class)) + ) { return } diff --git a/src/platforms/weex/runtime/modules/transition.js b/src/platforms/weex/runtime/modules/transition.js index 8545e54ea72..86e3f6d9941 100644 --- a/src/platforms/weex/runtime/modules/transition.js +++ b/src/platforms/weex/runtime/modules/transition.js @@ -94,9 +94,10 @@ function enter (_, vnode) { const parent = el.parentNode const pendingNode = parent && parent._pending && parent._pending[vnode.key] if (pendingNode && - pendingNode.context === vnode.context && - pendingNode.tag === vnode.tag && - pendingNode.elm._leaveCb) { + pendingNode.context === vnode.context && + pendingNode.tag === vnode.tag && + pendingNode.elm._leaveCb + ) { pendingNode.elm._leaveCb() } enterHook && enterHook(el, cb) diff --git a/src/server/render.js b/src/server/render.js index 8b91fbc4cf6..3ebb3e6713e 100644 --- a/src/server/render.js +++ b/src/server/render.js @@ -255,8 +255,9 @@ function renderStartingTag (node: VNode, context) { let scopeId const activeInstance = context.activeInstance if (isDef(activeInstance) && - activeInstance !== node.context && - isDef(scopeId = activeInstance.$options._scopeId)) { + activeInstance !== node.context && + isDef(scopeId = activeInstance.$options._scopeId) + ) { markup += ` ${(scopeId: any)}` } while (isDef(node)) {