Try using internal string-width in node:readline (#26306)

### What does this PR do?

Remove NFKDC normalization and stripVTControlCharacters since
Bun.stringWidth does this now

### How did you verify your code works?

ci

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2026-01-20 22:41:14 -08:00
committed by GitHub
parent 45af3335e6
commit bb4d150aed
4 changed files with 8 additions and 18 deletions

View File

@@ -172,10 +172,7 @@ export function createConsoleConstructor(console: typeof globalThis.console) {
* Returns the number of columns required to display the given string.
*/
var getStringWidth = function getStringWidth(str, removeControlChars = true) {
if (removeControlChars) str = stripVTControlCharacters(str);
str = StringPrototypeNormalize.$call(str, "NFC");
return internalGetStringWidth(str);
return internalGetStringWidth(str, removeControlChars);
};
const tableChars = {

View File

@@ -98,9 +98,7 @@ const ObjectCreate = Object.create;
* Returns the number of columns required to display the given string.
*/
var getStringWidth = function getStringWidth(str, removeControlChars = true) {
if (removeControlChars) str = stripVTControlCharacters(str);
str = StringPrototypeNormalize.$call(str, "NFC");
return internalGetStringWidth(str);
return internalGetStringWidth(str, removeControlChars);
};
const stripANSI = Bun.stripANSI;

View File

@@ -1093,20 +1093,15 @@ pub const String = extern struct {
extern fn JSC__createRangeError(*jsc.JSGlobalObject, str: *const String) jsc.JSValue;
pub fn jsGetStringWidth(globalObject: *jsc.JSGlobalObject, callFrame: *jsc.CallFrame) bun.JSError!jsc.JSValue {
const args = callFrame.arguments_old(1).slice();
const argument = callFrame.argument(0);
const str = try argument.toJSString(globalObject);
const view = str.view(globalObject);
if (args.len == 0 or !args.ptr[0].isString()) {
if (view.isEmpty()) {
return .jsNumber(@as(i32, 0));
}
const str = try args[0].toBunString(globalObject);
defer str.deref();
if (str.isEmpty()) {
return .jsNumber(@as(i32, 0));
}
const width = str.visibleWidth(false);
const width = bun.String.init(view).visibleWidth(false);
return .jsNumber(width);
}

View File

@@ -4,7 +4,7 @@
" catch bun.outOfMemory()": 0,
"!= alloc.ptr": 0,
"!= allocator.ptr": 0,
".arguments_old(": 264,
".arguments_old(": 263,
".jsBoolean(false)": 0,
".jsBoolean(true)": 0,
".stdDir()": 42,