Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the no-var linting rule in src/core/bidi.js #13386

Merged
merged 1 commit into from
May 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 31 additions & 32 deletions src/core/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-var */

import { warn } from "../shared/util.js";

// Character types for symbols from 0000 to 00FF.
// Source: ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
// prettier-ignore
var baseTypes = [
const baseTypes = [
"BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S",
"WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN",
"BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "ON", "ON", "ET",
Expand Down Expand Up @@ -49,7 +48,7 @@ var baseTypes = [
// empty string and issue a warning if we encounter this character. The
// empty string is required to properly index the items after it.
// prettier-ignore
var arabicTypes = [
const arabicTypes = [
"AN", "AN", "AN", "AN", "AN", "AN", "ON", "ON", "AL", "ET", "ET", "AL",
"CS", "AL", "ON", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM",
"NSM", "NSM", "NSM", "NSM", "AL", "AL", "", "AL", "AL", "AL", "AL", "AL",
Expand Down Expand Up @@ -83,7 +82,8 @@ function isEven(i) {
}

function findUnequal(arr, start, value) {
for (var j = start, jj = arr.length; j < jj; ++j) {
let j, jj;
for (j = start, jj = arr.length; j < jj; ++j) {
if (arr[j] !== value) {
return j;
}
Expand All @@ -92,14 +92,14 @@ function findUnequal(arr, start, value) {
}

function setValues(arr, start, end, value) {
for (var j = start; j < end; ++j) {
for (let j = start; j < end; ++j) {
arr[j] = value;
}
}

function reverseValues(arr, start, end) {
for (var i = start, j = end - 1; i < j; ++i, --j) {
var temp = arr[i];
for (let i = start, j = end - 1; i < j; ++i, --j) {
const temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Expand All @@ -117,27 +117,27 @@ function createBidiText(str, isLTR, vertical = false) {

// These are used in bidi(), which is called frequently. We re-use them on
// each call to avoid unnecessary allocations.
var chars = [];
var types = [];
const chars = [];
const types = [];

function bidi(str, startLevel, vertical) {
var isLTR = true;
var strLength = str.length;
let isLTR = true;
const strLength = str.length;
if (strLength === 0 || vertical) {
return createBidiText(str, isLTR, vertical);
}

// Get types and fill arrays
chars.length = strLength;
types.length = strLength;
var numBidi = 0;
let numBidi = 0;

var i, ii;
let i, ii;
for (i = 0; i < strLength; ++i) {
chars[i] = str.charAt(i);

var charCode = str.charCodeAt(i);
var charType = "L";
const charCode = str.charCodeAt(i);
let charType = "L";
if (charCode <= 0x00ff) {
charType = baseTypes[charCode];
} else if (0x0590 <= charCode && charCode <= 0x05f4) {
Expand Down Expand Up @@ -175,24 +175,24 @@ function bidi(str, startLevel, vertical) {
}
}

var levels = [];
const levels = [];
for (i = 0; i < strLength; ++i) {
levels[i] = startLevel;
}

/*
X1-X10: skip most of this, since we are NOT doing the embeddings.
*/
var e = isOdd(startLevel) ? "R" : "L";
var sor = e;
var eor = sor;
const e = isOdd(startLevel) ? "R" : "L";
const sor = e;
const eor = sor;

/*
W1. Examine each non-spacing mark (NSM) in the level run, and change the
type of the NSM to the type of the previous character. If the NSM is at the
start of the level run, it will get the type of sor.
*/
var lastType = sor;
let lastType = sor;
for (i = 0; i < strLength; ++i) {
if (types[i] === "NSM") {
types[i] = lastType;
Expand All @@ -207,7 +207,7 @@ function bidi(str, startLevel, vertical) {
the type of the European number to Arabic number.
*/
lastType = sor;
var t;
let t;
for (i = 0; i < strLength; ++i) {
t = types[i];
if (t === "EN") {
Expand Down Expand Up @@ -252,15 +252,14 @@ function bidi(str, startLevel, vertical) {
for (i = 0; i < strLength; ++i) {
if (types[i] === "EN") {
// do before
var j;
for (j = i - 1; j >= 0; --j) {
for (let j = i - 1; j >= 0; --j) {
if (types[j] !== "ET") {
break;
}
types[j] = "EN";
}
// do after
for (j = i + 1; j < strLength; ++j) {
for (let j = i + 1; j < strLength; ++j) {
if (types[j] !== "ET") {
break;
}
Expand Down Expand Up @@ -302,13 +301,13 @@ function bidi(str, startLevel, vertical) {
*/
for (i = 0; i < strLength; ++i) {
if (types[i] === "ON") {
var end = findUnequal(types, i + 1, "ON");
var before = sor;
const end = findUnequal(types, i + 1, "ON");
let before = sor;
if (i > 0) {
before = types[i - 1];
}

var after = eor;
let after = eor;
if (end + 1 < strLength) {
after = types[end + 1];
}
Expand Down Expand Up @@ -377,9 +376,9 @@ function bidi(str, startLevel, vertical) {
*/

// find highest level & lowest odd level
var highestLevel = -1;
var lowestOddLevel = 99;
var level;
let highestLevel = -1;
let lowestOddLevel = 99;
let level;
for (i = 0, ii = levels.length; i < ii; ++i) {
level = levels[i];
if (highestLevel < level) {
Expand All @@ -393,7 +392,7 @@ function bidi(str, startLevel, vertical) {
// now reverse between those limits
for (level = highestLevel; level >= lowestOddLevel; --level) {
// find segments to reverse
var start = -1;
let start = -1;
for (i = 0, ii = levels.length; i < ii; ++i) {
if (levels[i] < level) {
if (start >= 0) {
Expand Down Expand Up @@ -428,7 +427,7 @@ function bidi(str, startLevel, vertical) {

// Finally, return string
for (i = 0, ii = chars.length; i < ii; ++i) {
var ch = chars[i];
const ch = chars[i];
if (ch === "<" || ch === ">") {
chars[i] = "";
}
Expand Down