Merge pull request #13386 from timvandermeij/src-core-bidi-no-var
Enable the `no-var` linting rule in `src/core/bidi.js`
This commit is contained in:
commit
a5c74f53c1
@ -12,14 +12,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint-disable no-var */
|
|
||||||
|
|
||||||
import { warn } from "../shared/util.js";
|
import { warn } from "../shared/util.js";
|
||||||
|
|
||||||
// Character types for symbols from 0000 to 00FF.
|
// Character types for symbols from 0000 to 00FF.
|
||||||
// Source: ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
|
// Source: ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
var baseTypes = [
|
const baseTypes = [
|
||||||
"BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S",
|
"BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S",
|
||||||
"WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN",
|
"WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN",
|
||||||
"BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "ON", "ON", "ET",
|
"BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "ON", "ON", "ET",
|
||||||
@ -49,7 +48,7 @@ var baseTypes = [
|
|||||||
// empty string and issue a warning if we encounter this character. The
|
// empty string and issue a warning if we encounter this character. The
|
||||||
// empty string is required to properly index the items after it.
|
// empty string is required to properly index the items after it.
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
var arabicTypes = [
|
const arabicTypes = [
|
||||||
"AN", "AN", "AN", "AN", "AN", "AN", "ON", "ON", "AL", "ET", "ET", "AL",
|
"AN", "AN", "AN", "AN", "AN", "AN", "ON", "ON", "AL", "ET", "ET", "AL",
|
||||||
"CS", "AL", "ON", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM",
|
"CS", "AL", "ON", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM",
|
||||||
"NSM", "NSM", "NSM", "NSM", "AL", "AL", "", "AL", "AL", "AL", "AL", "AL",
|
"NSM", "NSM", "NSM", "NSM", "AL", "AL", "", "AL", "AL", "AL", "AL", "AL",
|
||||||
@ -83,7 +82,8 @@ function isEven(i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findUnequal(arr, start, value) {
|
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) {
|
if (arr[j] !== value) {
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
@ -92,14 +92,14 @@ function findUnequal(arr, start, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setValues(arr, start, end, value) {
|
function setValues(arr, start, end, value) {
|
||||||
for (var j = start; j < end; ++j) {
|
for (let j = start; j < end; ++j) {
|
||||||
arr[j] = value;
|
arr[j] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reverseValues(arr, start, end) {
|
function reverseValues(arr, start, end) {
|
||||||
for (var i = start, j = end - 1; i < j; ++i, --j) {
|
for (let i = start, j = end - 1; i < j; ++i, --j) {
|
||||||
var temp = arr[i];
|
const temp = arr[i];
|
||||||
arr[i] = arr[j];
|
arr[i] = arr[j];
|
||||||
arr[j] = temp;
|
arr[j] = temp;
|
||||||
}
|
}
|
||||||
@ -117,12 +117,12 @@ function createBidiText(str, isLTR, vertical = false) {
|
|||||||
|
|
||||||
// These are used in bidi(), which is called frequently. We re-use them on
|
// These are used in bidi(), which is called frequently. We re-use them on
|
||||||
// each call to avoid unnecessary allocations.
|
// each call to avoid unnecessary allocations.
|
||||||
var chars = [];
|
const chars = [];
|
||||||
var types = [];
|
const types = [];
|
||||||
|
|
||||||
function bidi(str, startLevel, vertical) {
|
function bidi(str, startLevel, vertical) {
|
||||||
var isLTR = true;
|
let isLTR = true;
|
||||||
var strLength = str.length;
|
const strLength = str.length;
|
||||||
if (strLength === 0 || vertical) {
|
if (strLength === 0 || vertical) {
|
||||||
return createBidiText(str, isLTR, vertical);
|
return createBidiText(str, isLTR, vertical);
|
||||||
}
|
}
|
||||||
@ -130,14 +130,14 @@ function bidi(str, startLevel, vertical) {
|
|||||||
// Get types and fill arrays
|
// Get types and fill arrays
|
||||||
chars.length = strLength;
|
chars.length = strLength;
|
||||||
types.length = strLength;
|
types.length = strLength;
|
||||||
var numBidi = 0;
|
let numBidi = 0;
|
||||||
|
|
||||||
var i, ii;
|
let i, ii;
|
||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
chars[i] = str.charAt(i);
|
chars[i] = str.charAt(i);
|
||||||
|
|
||||||
var charCode = str.charCodeAt(i);
|
const charCode = str.charCodeAt(i);
|
||||||
var charType = "L";
|
let charType = "L";
|
||||||
if (charCode <= 0x00ff) {
|
if (charCode <= 0x00ff) {
|
||||||
charType = baseTypes[charCode];
|
charType = baseTypes[charCode];
|
||||||
} else if (0x0590 <= charCode && charCode <= 0x05f4) {
|
} else if (0x0590 <= charCode && charCode <= 0x05f4) {
|
||||||
@ -175,7 +175,7 @@ function bidi(str, startLevel, vertical) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var levels = [];
|
const levels = [];
|
||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
levels[i] = startLevel;
|
levels[i] = startLevel;
|
||||||
}
|
}
|
||||||
@ -183,16 +183,16 @@ function bidi(str, startLevel, vertical) {
|
|||||||
/*
|
/*
|
||||||
X1-X10: skip most of this, since we are NOT doing the embeddings.
|
X1-X10: skip most of this, since we are NOT doing the embeddings.
|
||||||
*/
|
*/
|
||||||
var e = isOdd(startLevel) ? "R" : "L";
|
const e = isOdd(startLevel) ? "R" : "L";
|
||||||
var sor = e;
|
const sor = e;
|
||||||
var eor = sor;
|
const eor = sor;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
W1. Examine each non-spacing mark (NSM) in the level run, and change the
|
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
|
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.
|
start of the level run, it will get the type of sor.
|
||||||
*/
|
*/
|
||||||
var lastType = sor;
|
let lastType = sor;
|
||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
if (types[i] === "NSM") {
|
if (types[i] === "NSM") {
|
||||||
types[i] = lastType;
|
types[i] = lastType;
|
||||||
@ -207,7 +207,7 @@ function bidi(str, startLevel, vertical) {
|
|||||||
the type of the European number to Arabic number.
|
the type of the European number to Arabic number.
|
||||||
*/
|
*/
|
||||||
lastType = sor;
|
lastType = sor;
|
||||||
var t;
|
let t;
|
||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
t = types[i];
|
t = types[i];
|
||||||
if (t === "EN") {
|
if (t === "EN") {
|
||||||
@ -252,15 +252,14 @@ function bidi(str, startLevel, vertical) {
|
|||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
if (types[i] === "EN") {
|
if (types[i] === "EN") {
|
||||||
// do before
|
// do before
|
||||||
var j;
|
for (let j = i - 1; j >= 0; --j) {
|
||||||
for (j = i - 1; j >= 0; --j) {
|
|
||||||
if (types[j] !== "ET") {
|
if (types[j] !== "ET") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
types[j] = "EN";
|
types[j] = "EN";
|
||||||
}
|
}
|
||||||
// do after
|
// do after
|
||||||
for (j = i + 1; j < strLength; ++j) {
|
for (let j = i + 1; j < strLength; ++j) {
|
||||||
if (types[j] !== "ET") {
|
if (types[j] !== "ET") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -302,13 +301,13 @@ function bidi(str, startLevel, vertical) {
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < strLength; ++i) {
|
for (i = 0; i < strLength; ++i) {
|
||||||
if (types[i] === "ON") {
|
if (types[i] === "ON") {
|
||||||
var end = findUnequal(types, i + 1, "ON");
|
const end = findUnequal(types, i + 1, "ON");
|
||||||
var before = sor;
|
let before = sor;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
before = types[i - 1];
|
before = types[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var after = eor;
|
let after = eor;
|
||||||
if (end + 1 < strLength) {
|
if (end + 1 < strLength) {
|
||||||
after = types[end + 1];
|
after = types[end + 1];
|
||||||
}
|
}
|
||||||
@ -377,9 +376,9 @@ function bidi(str, startLevel, vertical) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// find highest level & lowest odd level
|
// find highest level & lowest odd level
|
||||||
var highestLevel = -1;
|
let highestLevel = -1;
|
||||||
var lowestOddLevel = 99;
|
let lowestOddLevel = 99;
|
||||||
var level;
|
let level;
|
||||||
for (i = 0, ii = levels.length; i < ii; ++i) {
|
for (i = 0, ii = levels.length; i < ii; ++i) {
|
||||||
level = levels[i];
|
level = levels[i];
|
||||||
if (highestLevel < level) {
|
if (highestLevel < level) {
|
||||||
@ -393,7 +392,7 @@ function bidi(str, startLevel, vertical) {
|
|||||||
// now reverse between those limits
|
// now reverse between those limits
|
||||||
for (level = highestLevel; level >= lowestOddLevel; --level) {
|
for (level = highestLevel; level >= lowestOddLevel; --level) {
|
||||||
// find segments to reverse
|
// find segments to reverse
|
||||||
var start = -1;
|
let start = -1;
|
||||||
for (i = 0, ii = levels.length; i < ii; ++i) {
|
for (i = 0, ii = levels.length; i < ii; ++i) {
|
||||||
if (levels[i] < level) {
|
if (levels[i] < level) {
|
||||||
if (start >= 0) {
|
if (start >= 0) {
|
||||||
@ -428,7 +427,7 @@ function bidi(str, startLevel, vertical) {
|
|||||||
|
|
||||||
// Finally, return string
|
// Finally, return string
|
||||||
for (i = 0, ii = chars.length; i < ii; ++i) {
|
for (i = 0, ii = chars.length; i < ii; ++i) {
|
||||||
var ch = chars[i];
|
const ch = chars[i];
|
||||||
if (ch === "<" || ch === ">") {
|
if (ch === "<" || ch === ">") {
|
||||||
chars[i] = "";
|
chars[i] = "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user