Fix wcwidth TS errors

This commit is contained in:
Daniel Imms
2017-01-09 13:48:52 -08:00
parent 4a27b9a53f
commit 940bd2699e
+17 -15
View File
@@ -1033,10 +1033,10 @@ export class Parser {
} }
} }
var wcwidth = (function(opts) { const wcwidth = (function(opts) {
// extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
// combining characters // combining characters
var COMBINING = [ const COMBINING = [
[0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489], [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
[0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2], [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
[0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603], [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
@@ -1088,9 +1088,9 @@ var wcwidth = (function(opts) {
]; ];
// binary search // binary search
function bisearch(ucs) { function bisearch(ucs) {
var min = 0; let min = 0;
var max = COMBINING.length - 1; let max = COMBINING.length - 1;
var mid; let mid;
if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1]) if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1])
return false; return false;
while (max >= min) { while (max >= min) {
@@ -1114,14 +1114,18 @@ var wcwidth = (function(opts) {
if (bisearch(ucs)) if (bisearch(ucs))
return 0; return 0;
// if we arrive here, ucs is not a combining or C0/C1 control character // if we arrive here, ucs is not a combining or C0/C1 control character
return 1 + if (isWide(ucs)) {
( return 2;
ucs >= 0x1100 && }
( return 1;
}
function isWide(ucs) {
return (
ucs >= 0x1100 && (
ucs <= 0x115f || // Hangul Jamo init. consonants ucs <= 0x115f || // Hangul Jamo init. consonants
ucs == 0x2329 || ucs === 0x2329 ||
ucs == 0x232a || ucs === 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || // CJK..Yi (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) || // CJK..Yi
(ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables (ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables
(ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compat Ideographs (ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compat Ideographs
(ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms (ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms
@@ -1129,9 +1133,7 @@ var wcwidth = (function(opts) {
(ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms (ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms
(ucs >= 0xffe0 && ucs <= 0xffe6) || (ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd) (ucs >= 0x30000 && ucs <= 0x3fffd)));
)
);
} }
return wcwidth; return wcwidth;
})({nul: 0, control: 0}); // configurable options })({nul: 0, control: 0}); // configurable options