chore: prefer nullish coalescing (#7125)

This commit is contained in:
neverland 2020-09-07 20:36:49 +08:00 committed by GitHub
parent c7303786ae
commit 4ffa6ead1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 37 deletions

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
import { raf, doubleRaf } from '../utils/dom/raf'; import { raf, doubleRaf } from '../utils/dom/raf';
// Mixins // Mixins
@ -35,7 +35,7 @@ export default createComponent({
computed: { computed: {
currentName() { currentName() {
return isDef(this.name) ? this.name : this.index; return this.name ?? this.index;
}, },
expanded() { expanded() {

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
import { route, routeProps } from '../utils/router'; import { route, routeProps } from '../utils/router';
import { ChildrenMixin } from '../mixins/relation'; import { ChildrenMixin } from '../mixins/relation';
import Info from '../info'; import Info from '../info';
@ -28,7 +28,7 @@ export default createComponent({
genIcon() { genIcon() {
const slot = this.slots('icon'); const slot = this.slots('icon');
const info = isDef(this.badge) ? this.badge : this.info; const info = this.badge ?? this.info;
if (slot) { if (slot) {
return ( return (

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, addUnit, isDef } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { BORDER } from '../utils/constant'; import { BORDER } from '../utils/constant';
import { route, routeProps } from '../utils/router'; import { route, routeProps } from '../utils/router';
@ -71,7 +71,7 @@ export default createComponent({
genIcon() { genIcon() {
const iconSlot = this.slots('icon'); const iconSlot = this.slots('icon');
const info = isDef(this.badge) ? this.badge : this.info; const info = this.badge ?? this.info;
if (iconSlot) { if (iconSlot) {
return ( return (

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, addUnit, isDef } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { inherit } from '../utils/functional'; import { inherit } from '../utils/functional';
// Components // Components
@ -64,10 +64,7 @@ function Icon(
> >
{slots.default && slots.default()} {slots.default && slots.default()}
{imageIcon && <img class={bem('image')} src={name} />} {imageIcon && <img class={bem('image')} src={name} />}
<Info <Info dot={props.dot} info={props.badge ?? props.info} />
dot={props.dot}
info={isDef(props.badge) ? props.badge : props.info}
/>
</props.tag> </props.tag>
); );
} }

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
import { preventDefault } from '../utils/dom/event'; import { preventDefault } from '../utils/dom/event';
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant'; import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared'; import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared';
@ -86,9 +86,7 @@ export default createComponent({
let cursor = { children: this.columns }; let cursor = { children: this.columns };
while (cursor && cursor.children) { while (cursor && cursor.children) {
const defaultIndex = isDef(cursor.defaultIndex) const defaultIndex = cursor.defaultIndex ?? +this.defaultIndex;
? cursor.defaultIndex
: +this.defaultIndex;
formatted.push({ formatted.push({
values: cursor.children, values: cursor.children,
@ -328,9 +326,7 @@ export default createComponent({
allowHtml={this.allowHtml} allowHtml={this.allowHtml}
className={item.className} className={item.className}
itemHeight={this.itemPxHeight} itemHeight={this.itemPxHeight}
defaultIndex={ defaultIndex={item.defaultIndex ?? +this.defaultIndex}
isDef(item.defaultIndex) ? item.defaultIndex : +this.defaultIndex
}
swipeDuration={this.swipeDuration} swipeDuration={this.swipeDuration}
visibleItemCount={this.visibleItemCount} visibleItemCount={this.visibleItemCount}
initialOptions={item.values} initialOptions={item.values}

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef, addUnit } from '../utils'; import { createNamespace, addUnit } from '../utils';
const [createComponent, bem] = createNamespace('progress'); const [createComponent, bem] = createNamespace('progress');
@ -49,7 +49,7 @@ export default createComponent({
render() { render() {
const { pivotText, percentage } = this; const { pivotText, percentage } = this;
const text = isDef(pivotText) ? pivotText : percentage + '%'; const text = pivotText ?? percentage + '%';
const showPivot = this.showPivot && text; const showPivot = this.showPivot && text;
const background = this.inactive ? '#cacaca' : this.color; const background = this.inactive ? '#cacaca' : this.color;

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
// Mixins // Mixins
import { popupMixinProps } from '../mixins/popup'; import { popupMixinProps } from '../mixins/popup';
@ -112,7 +112,7 @@ export default createComponent({
}, },
genCancelText() { genCancelText() {
const cancelText = isDef(this.cancelText) ? this.cancelText : t('cancel'); const cancelText = this.cancelText ?? t('cancel');
if (cancelText) { if (cancelText) {
return ( return (

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation'; import { ChildrenMixin } from '../mixins/relation';
import { route, routeProps } from '../utils/router'; import { route, routeProps } from '../utils/router';
import Info from '../info'; import Info from '../info';
@ -46,7 +46,7 @@ export default createComponent({
{this.title} {this.title}
<Info <Info
dot={this.dot} dot={this.dot}
info={isDef(this.badge) ? this.badge : this.info} info={this.badge ?? this.info}
class={bem('info')} class={bem('info')}
/> />
</div> </div>

View File

@ -10,7 +10,7 @@ import SkuRowPropItem from './components/SkuRowPropItem';
import SkuStepper from './components/SkuStepper'; import SkuStepper from './components/SkuStepper';
import SkuMessages from './components/SkuMessages'; import SkuMessages from './components/SkuMessages';
import SkuActions from './components/SkuActions'; import SkuActions from './components/SkuActions';
import { createNamespace, isDef } from '../utils'; import { createNamespace } from '../utils';
import { import {
isAllSelected, isAllSelected,
isSkuChoosable, isSkuChoosable,
@ -361,7 +361,7 @@ export default createComponent({
resetStepper() { resetStepper() {
const { skuStepper } = this.$refs; const { skuStepper } = this.$refs;
const { selectedNum } = this.initialSku; const { selectedNum } = this.initialSku;
const num = isDef(selectedNum) ? selectedNum : this.startSaleNum; const num = selectedNum ?? this.startSaleNum;
// 用来缓存不合法的情况 // 用来缓存不合法的情况
this.stepperError = null; this.stepperError = null;

View File

@ -72,7 +72,7 @@ export default createComponent({
}, },
data() { data() {
const defaultValue = isDef(this.value) ? this.value : this.defaultValue; const defaultValue = this.value ?? this.defaultValue;
const value = this.format(defaultValue); const value = this.format(defaultValue);
if (!equal(value, this.value)) { if (!equal(value, this.value)) {

View File

@ -1,4 +1,4 @@
import { isDef, createNamespace } from '../utils'; import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation'; import { ChildrenMixin } from '../mixins/relation';
import { routeProps } from '../utils/router'; import { routeProps } from '../utils/router';
@ -26,7 +26,7 @@ export default createComponent({
computed: { computed: {
computedName() { computedName() {
return isDef(this.name) ? this.name : this.index; return this.name ?? this.index;
}, },
isActive() { isActive() {

View File

@ -71,10 +71,7 @@ export default createComponent({
<div class={bem({ active })} style={{ color }} onClick={this.onClick}> <div class={bem({ active })} style={{ color }} onClick={this.onClick}>
<div class={bem('icon')}> <div class={bem('icon')}>
{this.genIcon(active)} {this.genIcon(active)}
<Info <Info dot={this.dot} info={this.badge ?? this.info} />
dot={this.dot}
info={isDef(this.badge) ? this.badge : this.info}
/>
</div> </div>
<div class={bem('text')}>{this.slots('default', { active })}</div> <div class={bem('text')}>{this.slots('default', { active })}</div>
</div> </div>

View File

@ -359,7 +359,7 @@ export default createComponent({
refInFor refInFor
type={type} type={type}
dot={item.dot} dot={item.dot}
info={isDef(item.badge) ? item.badge : item.info} info={item.badge ?? item.info}
title={item.title} title={item.title}
color={this.color} color={this.color}
style={item.titleStyle} style={item.titleStyle}

View File

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, addUnit, isDef } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { emit, inherit } from '../utils/functional'; import { emit, inherit } from '../utils/functional';
// Components // Components
@ -65,7 +65,7 @@ function TreeSelect(
const Navs = items.map((item) => ( const Navs = items.map((item) => (
<SidebarItem <SidebarItem
dot={item.dot} dot={item.dot}
info={isDef(item.badge) ? item.badge : item.info} info={item.badge ?? item.info}
title={item.text} title={item.text}
disabled={item.disabled} disabled={item.disabled}
class={[bem('nav-item'), item.className]} class={[bem('nav-item'), item.className]}

View File

@ -30,7 +30,7 @@ export function get(object: any, path: string): any {
let result = object; let result = object;
keys.forEach((key) => { keys.forEach((key) => {
result = isDef(result[key]) ? result[key] : ''; result = result[key] ?? '';
}); });
return result; return result;