diff --git a/src/compile/data/facet.ts b/src/compile/data/facet.ts index c5fb84b55a..0c678deeb1 100644 --- a/src/compile/data/facet.ts +++ b/src/compile/data/facet.ts @@ -213,7 +213,7 @@ export class FacetNode extends DataFlowNode { const hasSharedAxis: {row?: true; column?: true} = {}; for (const headerChannel of HEADER_CHANNELS) { for (const headerType of HEADER_TYPES) { - const headers = (layoutHeaders[headerChannel] && layoutHeaders[headerChannel][headerType]) ?? []; + const headers = layoutHeaders[headerChannel]?.[headerType] ?? []; for (const header of headers) { if (header.axes?.length > 0) { hasSharedAxis[headerChannel] = true; diff --git a/src/compile/selection/inputs.ts b/src/compile/selection/inputs.ts index d34d1fb13a..992581ad7b 100644 --- a/src/compile/selection/inputs.ts +++ b/src/compile/selection/inputs.ts @@ -25,7 +25,7 @@ const inputBindings: SelectionCompiler<'point'> = { const name = selCmpt.name; const proj = selCmpt.project; const bind = selCmpt.bind; - const init = selCmpt.init && selCmpt.init[0]; // Can only exist on single selections (one initial value). + const init = selCmpt.init?.[0]; // Can only exist on single selections (one initial value). const datum = nearest.defined(selCmpt) ? '(item().isVoronoi ? datum.datum : datum)' : 'datum'; proj.items.forEach((p, i) => { diff --git a/src/compile/selection/interval.ts b/src/compile/selection/interval.ts index 5ca5f400e0..aa71e151c2 100644 --- a/src/compile/selection/interval.ts +++ b/src/compile/selection/interval.ts @@ -61,7 +61,7 @@ const interval: SelectionCompiler<'interval'> = { const init = selCmpt.init ? selCmpt.init[0] : null; signals.push( - ...channels.reduce((arr, proj) => arr.concat(channelSignals(model, selCmpt, proj, init && init[proj.index])), []) + ...channels.reduce((arr, proj) => arr.concat(channelSignals(model, selCmpt, proj, init?.[proj.index])), []) ); if (!model.hasProjection) { @@ -119,10 +119,10 @@ const interval: SelectionCompiler<'interval'> = { const projection = stringValue(model.projectionName()); const centerSg = model.projectionName() + CENTER; const {x, y} = selCmpt.project.hasChannel; - const xvname = x && x.signals.visual; - const yvname = y && y.signals.visual; - const xinit = x ? init && init[x.index] : `${centerSg}[0]`; - const yinit = y ? init && init[y.index] : `${centerSg}[1]`; + const xvname = x?.signals.visual; + const yvname = y?.signals.visual; + const xinit = x ? init?.[x.index] : `${centerSg}[0]`; + const yinit = y ? init?.[y.index] : `${centerSg}[1]`; const sizeSg = (layout: keyof LayoutSizeIndex) => model.getSizeSignalRef(layout).signal; const bbox = `[` + diff --git a/src/compile/selection/translate.ts b/src/compile/selection/translate.ts index 8431ae10b0..faefc23be0 100644 --- a/src/compile/selection/translate.ts +++ b/src/compile/selection/translate.ts @@ -83,8 +83,8 @@ function onDelta( const signal = signals.find(s => s.name === proj.signals[boundScales ? 'data' : 'visual']); const sizeSg = model.getSizeSignalRef(size).signal; const scaleCmpt = model.getScaleComponent(channel); - const scaleType = scaleCmpt && scaleCmpt.get('type'); - const reversed = scaleCmpt && scaleCmpt.get('reverse'); // scale parsing sets this flag for fieldDef.sort + const scaleType = scaleCmpt?.get('type'); + const reversed = scaleCmpt?.get('reverse'); // scale parsing sets this flag for fieldDef.sort const sign = !boundScales ? '' : channel === X ? (reversed ? '' : '-') : reversed ? '-' : ''; const extent = `${anchor}.extent_${channel}`; const offset = `${sign}${delta}.${channel} / ${boundScales ? `${sizeSg}` : `span(${extent})`}`; diff --git a/src/compile/selection/zoom.ts b/src/compile/selection/zoom.ts index a326dd6969..680501324c 100644 --- a/src/compile/selection/zoom.ts +++ b/src/compile/selection/zoom.ts @@ -85,7 +85,7 @@ function onDelta( const signal = signals.find(s => s.name === proj.signals[boundScales ? 'data' : 'visual']); const sizeSg = model.getSizeSignalRef(size).signal; const scaleCmpt = model.getScaleComponent(channel); - const scaleType = scaleCmpt && scaleCmpt.get('type'); + const scaleType = scaleCmpt?.get('type'); const base = boundScales ? domain(model, channel) : signal.name; const delta = name + DELTA; const anchor = `${name}${ANCHOR}.${channel}`; diff --git a/src/encoding.ts b/src/encoding.ts index d37fbc74bb..e34ba7177a 100644 --- a/src/encoding.ts +++ b/src/encoding.ts @@ -337,7 +337,7 @@ export function channelHasField( encoding: EncodingWithFacet, channel: keyof EncodingWithFacet ): boolean { - const channelDef = encoding && encoding[channel]; + const channelDef = encoding?.[channel]; if (channelDef) { if (isArray(channelDef)) { return some(channelDef, fieldDef => !!fieldDef.field); @@ -352,7 +352,7 @@ export function channelHasFieldOrDatum( encoding: EncodingWithFacet, channel: keyof EncodingWithFacet ): boolean { - const channelDef = encoding && encoding[channel]; + const channelDef = encoding?.[channel]; if (channelDef) { if (isArray(channelDef)) { return some(channelDef, fieldDef => !!fieldDef.field); diff --git a/src/timeunit.ts b/src/timeunit.ts index 0ef009371f..9c25f134af 100644 --- a/src/timeunit.ts +++ b/src/timeunit.ts @@ -149,7 +149,7 @@ export function isBinnedTimeUnit( } export function isBinnedTimeUnitString(timeUnit: TimeUnit | BinnedTimeUnit | undefined): timeUnit is BinnedTimeUnit { - return timeUnit && timeUnit.startsWith('binned'); + return timeUnit?.startsWith('binned'); } export const UTC_MULTI_TIMEUNIT_INDEX = { diff --git a/src/util.ts b/src/util.ts index 8c8be120fd..f618ef923b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -484,7 +484,7 @@ export function stringify(data: any) { const seen: any[] = []; return (function _stringify(node: any) { - if (node && node.toJSON && typeof node.toJSON === 'function') { + if (node?.toJSON && typeof node.toJSON === 'function') { node = node.toJSON(); }