Skip to content

Commit 95bf0ce

Browse files
chore: add logical-assignment-operators (#7409)
* add logical-assignment-operators * apply some changes that my commit did not target * remove nested assignments
1 parent 298f6d1 commit 95bf0ce

53 files changed

Lines changed: 156 additions & 230 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/generate-struct-arrays.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,12 @@ function createStructArrayLayoutType({members, size, alignment}) {
113113
const key = `${members.map(m => `${m.components}${typeAbbreviations[m.type]}`).join('')}${size}`;
114114
const className = `StructArrayLayout${key}`;
115115

116-
if (!layoutCache[key]) {
117-
layoutCache[key] = {
118-
className,
119-
members,
120-
size,
121-
usedTypes
122-
};
123-
}
116+
layoutCache[key] ||= {
117+
className,
118+
members,
119+
size,
120+
usedTypes
121+
};
124122

125123
return className;
126124
}

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default [
7171
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
7272
'local/prefer-type-for-data-shapes': 'error',
7373

74+
'logical-assignment-operators': ['error', 'always', {enforceForIfStatements: true}],
7475
'prefer-object-spread': 'error',
7576
'prefer-object-has-own': 'error',
7677
'object-shorthand': 'error',

src/data/bucket/circle_bucket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
9797
sortFeaturesByKey = !circleSortKey.isConstant();
9898

9999
// Circles that are "printed" onto the map surface should be tessellated to follow the globe's curvature.
100-
subdivide = subdivide || circleStyle.paint.get('circle-pitch-alignment') === 'map';
100+
subdivide ||= circleStyle.paint.get('circle-pitch-alignment') === 'map';
101101
}
102102

103103
const granularity = subdivide ? options.subdivisionGranularity.circle : 1;

src/data/bucket/line_bucket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export class LineBucket implements Bucket {
347347

348348
// If we still don't have a previous normal, this is the beginning of a
349349
// non-closed line, so we're doing a straight "join".
350-
prevNormal = prevNormal || nextNormal;
350+
prevNormal ||= nextNormal;
351351

352352
// Determine the normal of the join extrusion. It is the angle bisector
353353
// of the segments between the previous line and the next line.

src/data/bucket/symbol_bucket.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@ export class SymbolBucket implements Bucket {
478478
const formattedText = Formatted.factory(resolvedTokens);
479479

480480
// on this instance: if hasRTLText is already true, all future calls to containsRTLText can be skipped.
481-
const bucketHasRTLText = this.hasRTLText = (this.hasRTLText || containsRTLText(formattedText));
481+
this.hasRTLText ||= containsRTLText(formattedText);
482482
if (
483-
!bucketHasRTLText || // non-rtl text so can proceed safely
483+
!this.hasRTLText || // non-rtl text so can proceed safely
484484
rtlWorkerPlugin.getRTLTextPluginStatus() === 'unavailable' || // We don't intend to lazy-load the rtl text plugin, so proceed with incorrect shaping
485-
bucketHasRTLText && rtlWorkerPlugin.isParsed() // Use the rtlText plugin to shape text
485+
this.hasRTLText && rtlWorkerPlugin.isParsed() // Use the rtlText plugin to shape text
486486
) {
487487
text = transformText(formattedText, layer, evaluationFeature);
488488
}
@@ -533,8 +533,8 @@ export class SymbolBucket implements Bucket {
533533
if (!section.image) {
534534
const doesAllowVerticalWritingMode = allowsVerticalWritingMode(text.toString());
535535
const sectionFont = section.fontStack || fontStack;
536-
const sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
537-
this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
536+
stacks[sectionFont] ||= {};
537+
this.calculateGlyphDependencies(section.text, stacks[sectionFont], textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
538538
} else {
539539
// Add section image to the list of dependencies.
540540
icons[section.image.name] = true;
@@ -544,7 +544,7 @@ export class SymbolBucket implements Bucket {
544544
}
545545

546546
if (layout.get('symbol-placement') === 'line') {
547-
// Merge adjacent lines with the same text to improve labelling.
547+
// Merge adjacent lines with the same text to improve labeling.
548548
// It's better to place labels on one long line than on many short segments.
549549
this.features = mergeLines(this.features);
550550
}

src/data/feature_index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ export class FeatureIndex {
174174
serializedLayers,
175175
sourceFeatureState,
176176
(feature: VectorTileFeatureLike, styleLayer: StyleLayer, featureState: FeatureState) => {
177-
if (!featureGeometry) {
178-
featureGeometry = loadGeometry(feature);
179-
}
177+
featureGeometry ||= loadGeometry(feature);
180178

181179
return styleLayer.queryIntersectsFeature({
182180
queryGeometry,

src/geo/projection/vertical_perspective_projection.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export class VerticalPerspectiveProjection implements Projection {
9696
}
9797

9898
public updateGPUdependent(renderContext: ProjectionGPUContext): void {
99-
if (!this._errorMeasurement) {
100-
this._errorMeasurement = new ProjectionErrorMeasurement(renderContext);
101-
}
99+
this._errorMeasurement ||= new ProjectionErrorMeasurement(renderContext);
102100
const mercatorY = mercatorYfromLat(this._errorQueryLatitudeDegrees);
103101
const expectedResult = 2.0 * Math.atan(Math.exp(Math.PI - (mercatorY * Math.PI * 2.0))) - Math.PI * 0.5;
104102
const newValue = this._errorMeasurement.updateErrorLoop(mercatorY, expectedResult);
@@ -155,9 +153,9 @@ export class VerticalPerspectiveProjection implements Projection {
155153
const currentTime = now();
156154
let dirty = false;
157155
// Error correction transition
158-
dirty = dirty || (currentTime - this._errorMeasurementLastChangeTime) / 1000.0 < (globeConstants.errorTransitionTimeSeconds + 0.2);
156+
dirty ||= (currentTime - this._errorMeasurementLastChangeTime) / 1000.0 < (globeConstants.errorTransitionTimeSeconds + 0.2);
159157
// Error correction query in flight
160-
dirty = dirty || (this._errorMeasurement?.awaitingQuery);
158+
dirty ||= (this._errorMeasurement?.awaitingQuery);
161159
return dirty;
162160
}
163161

src/render/glyph_manager.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export class GlyphManager {
7878
const result: GetGlyphsResponse = {};
7979

8080
for (const {stack, id, glyph} of updatedGlyphs) {
81-
if (!result[stack]) {
82-
result[stack] = {};
83-
}
81+
result[stack] ||= {};
8482
// Clone the glyph so that our own copy of its ArrayBuffer doesn't get transferred.
8583
result[stack][id] = glyph && {
8684
id: glyph.id,
@@ -94,14 +92,8 @@ export class GlyphManager {
9492

9593
async _getAndCacheGlyphsPromise(stack: string, id: number): Promise<{stack: string; id: number; glyph: StyleGlyph}> {
9694
// Create an entry for this fontstack if it doesn’t already exist.
97-
let entry = this.entries[stack];
98-
if (!entry) {
99-
entry = this.entries[stack] = {
100-
glyphs: {},
101-
requests: {},
102-
ranges: {}
103-
};
104-
}
95+
this.entries[stack] ??= {glyphs: {}, requests: {}, ranges: {}};
96+
const entry = this.entries[stack];
10597

10698
// Try to get the glyph from the cache of client-side glyphs by codepoint.
10799
let glyph = entry.glyphs[id];
@@ -127,9 +119,7 @@ export class GlyphManager {
127119
}
128120

129121
// Start downloading this range unless we’re currently downloading it.
130-
if (!entry.requests[range]) {
131-
entry.requests[range] = GlyphManager.loadGlyphRange(stack, range, this.url, this.requestManager);
132-
}
122+
entry.requests[range] ||= GlyphManager.loadGlyphRange(stack, range, this.url, this.requestManager);
133123

134124
try {
135125
// Get the response and cache the glyphs from it.
@@ -269,12 +259,8 @@ export class GlyphManager {
269259
destroy() {
270260
for (const stack in this.entries) {
271261
const entry = this.entries[stack];
272-
if (entry.tinySDF) {
273-
entry.tinySDF = null;
274-
}
275-
if (entry.ideographTinySDF) {
276-
entry.ideographTinySDF = null;
277-
}
262+
entry.tinySDF = null;
263+
entry.ideographTinySDF = null;
278264
entry.glyphs = {};
279265
entry.requests = {};
280266
entry.ranges = {};

src/render/line_atlas.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export class LineAtlas {
5050
getDash(dasharray: number[], round: boolean) {
5151
const key = dasharray.join(',') + String(round);
5252

53-
if (!this.dashEntry[key]) {
54-
this.dashEntry[key] = this.addDash(dasharray, round);
55-
}
53+
this.dashEntry[key] ||= this.addDash(dasharray, round);
5654
return this.dashEntry[key];
5755
}
5856

src/render/painter.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export class Painter {
727727
* @returns
728728
*/
729729
useProgram(name: string, programConfiguration?: ProgramConfiguration | null, forceSimpleProjection: boolean = false, defines: string[] = []): Program<any> {
730-
this.cache = this.cache || {};
730+
this.cache ||= {};
731731
const useTerrain = !!this.style.map.terrain;
732732

733733
const projection = this.style.projection;
@@ -743,19 +743,17 @@ export class Painter {
743743

744744
const key = name + configurationKey + projectionKey + overdrawKey + terrainKey + definesKey;
745745

746-
if (!this.cache[key]) {
747-
this.cache[key] = new Program(
748-
this.context,
749-
shaders[name],
750-
programConfiguration,
751-
programUniforms[name],
752-
this._showOverdrawInspector,
753-
useTerrain,
754-
projectionPrelude,
755-
projectionDefine,
756-
defines
757-
);
758-
}
746+
this.cache[key] ||= new Program(
747+
this.context,
748+
shaders[name],
749+
programConfiguration,
750+
programUniforms[name],
751+
this._showOverdrawInspector,
752+
useTerrain,
753+
projectionPrelude,
754+
projectionDefine,
755+
defines
756+
);
759757
return this.cache[key];
760758
}
761759

0 commit comments

Comments
 (0)