Skip to content

Commit a32eb3a

Browse files
authored
style(lib/commons): var -> let and const codemod (#4455)
Just like #4451 but for `lib/commons` Smaller part of the full vision: #4444
1 parent 00b9fba commit a32eb3a

18 files changed

+53
-53
lines changed

lib/commons/color/element-is-distinct.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ function _getFonts(style) {
2525
* @return {Boolean}
2626
*/
2727
function elementIsDistinct(node, ancestorNode) {
28-
var nodeStyle = window.getComputedStyle(node);
28+
const nodeStyle = window.getComputedStyle(node);
2929

3030
// Check if the link has a background
3131
if (nodeStyle.getPropertyValue('background-image') !== 'none') {
3232
return true;
3333
}
3434

3535
// Check if the link has a border or outline
36-
var hasBorder = ['border-bottom', 'border-top', 'outline'].reduce(
36+
const hasBorder = ['border-bottom', 'border-top', 'outline'].reduce(
3737
(result, edge) => {
38-
var borderClr = new Color();
38+
const borderClr = new Color();
3939
borderClr.parseString(nodeStyle.getPropertyValue(edge + '-color'));
4040

4141
// Check if a border/outline was specified
@@ -54,13 +54,13 @@ function elementIsDistinct(node, ancestorNode) {
5454
return true;
5555
}
5656

57-
var parentStyle = window.getComputedStyle(ancestorNode);
57+
const parentStyle = window.getComputedStyle(ancestorNode);
5858
// Compare fonts
5959
if (_getFonts(nodeStyle)[0] !== _getFonts(parentStyle)[0]) {
6060
return true;
6161
}
6262

63-
var hasStyle = [
63+
let hasStyle = [
6464
'text-decoration-line',
6565
'text-decoration-style',
6666
'font-weight',
@@ -74,7 +74,7 @@ function elementIsDistinct(node, ancestorNode) {
7474
);
7575
}, false);
7676

77-
var tDec = nodeStyle.getPropertyValue('text-decoration');
77+
const tDec = nodeStyle.getPropertyValue('text-decoration');
7878
if (tDec.split(' ').length < 3) {
7979
// old style CSS text decoration
8080
hasStyle =

lib/commons/color/flatten-shadow-colors.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import Color from './color';
1111
* @return {Color} Blended color
1212
*/
1313
export default function flattenShadowColors(fgColor, bgColor) {
14-
var alpha = fgColor.alpha;
15-
var r = (1 - alpha) * bgColor.red + alpha * fgColor.red;
16-
var g = (1 - alpha) * bgColor.green + alpha * fgColor.green;
17-
var b = (1 - alpha) * bgColor.blue + alpha * fgColor.blue;
18-
var a = fgColor.alpha + bgColor.alpha * (1 - fgColor.alpha);
14+
const alpha = fgColor.alpha;
15+
const r = (1 - alpha) * bgColor.red + alpha * fgColor.red;
16+
const g = (1 - alpha) * bgColor.green + alpha * fgColor.green;
17+
const b = (1 - alpha) * bgColor.blue + alpha * fgColor.blue;
18+
const a = fgColor.alpha + bgColor.alpha * (1 - fgColor.alpha);
1919

2020
return new Color(r, g, b, a);
2121
}

lib/commons/color/get-background-stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function shallowArraysEqual(a, b) {
9898
return false;
9999
}
100100

101-
for (var i = 0; i < a.length; ++i) {
101+
for (let i = 0; i < a.length; ++i) {
102102
if (a[i] !== b[i]) {
103103
return false;
104104
}

lib/commons/color/get-contrast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function getContrast(bgColor, fgColor) {
1818
fgColor = flattenColors(fgColor, bgColor);
1919
}
2020

21-
var bL = bgColor.getRelativeLuminance();
22-
var fL = fgColor.getRelativeLuminance();
21+
const bL = bgColor.getRelativeLuminance();
22+
const fL = fgColor.getRelativeLuminance();
2323

2424
return (Math.max(fL, bL) + 0.05) / (Math.min(fL, bL) + 0.05);
2525
}

lib/commons/color/has-valid-contrast-ratio.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import getContrast from './get-contrast';
1414
* @deprecated
1515
*/
1616
function hasValidContrastRatio(bg, fg, fontSize, isBold) {
17-
var contrast = getContrast(bg, fg);
18-
var isSmallFont =
17+
const contrast = getContrast(bg, fg);
18+
const isSmallFont =
1919
(isBold && Math.ceil(fontSize * 72) / 96 < 14) ||
2020
(!isBold && Math.ceil(fontSize * 72) / 96 < 18);
21-
var expectedContrastRatio = isSmallFont ? 4.5 : 3;
21+
const expectedContrastRatio = isSmallFont ? 4.5 : 3;
2222

2323
return {
2424
isValid: contrast > expectedContrastRatio,

lib/commons/dom/get-composed-parent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getComposedParent(element) {
1313
// we'll skip this part for now.
1414
return getComposedParent(element.assignedSlot); // parent of a shadow DOM slot
1515
} else if (element.parentNode) {
16-
var parentNode = element.parentNode;
16+
const parentNode = element.parentNode;
1717
if (parentNode.nodeType === 1) {
1818
return parentNode; // Regular node
1919
} else if (parentNode.host) {

lib/commons/dom/get-element-coordinates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import getScrollOffset from './get-scroll-offset';
2020
* @property {Number} height The height of the element
2121
*/
2222
function getElementCoordinates(element) {
23-
var scrollOffset = getScrollOffset(document),
23+
const scrollOffset = getScrollOffset(document),
2424
xOffset = scrollOffset.left,
2525
yOffset = scrollOffset.top,
2626
coords = element.getBoundingClientRect();

lib/commons/dom/get-scroll-offset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getScrollOffset(element) {
1313

1414
// 9 === Node.DOCUMENT_NODE
1515
if (element.nodeType === 9) {
16-
var docElement = element.documentElement,
16+
const docElement = element.documentElement,
1717
body = element.body;
1818

1919
return {

lib/commons/dom/has-content-virtual.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export function hasChildTextNodes(elm) {
4242
function hasContentVirtual(elm, noRecursion, ignoreAria) {
4343
return (
4444
// It has text
45+
// or one of it's descendants does
4546
hasChildTextNodes(elm) ||
4647
// It is a graphical element
4748
isVisualContent(elm.actualNode) ||
4849
// It has an ARIA label
4950
(!ignoreAria && !!labelVirtual(elm)) ||
50-
// or one of it's descendants does
5151
(!noRecursion &&
5252
elm.children.some(
5353
child => child.actualNode.nodeType === 1 && hasContentVirtual(child)

lib/commons/dom/is-focusable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function isFocusable(el) {
2323
return true;
2424
}
2525
// check if the tabindex is specified and a parseable number
26-
var tabindex = vNode.attr('tabindex');
26+
const tabindex = vNode.attr('tabindex');
2727
if (tabindex && !isNaN(parseInt(tabindex, 10))) {
2828
return true;
2929
}

0 commit comments

Comments
 (0)