From 487e3c0776e41ea5333d77a85ec12fd24c8c038e Mon Sep 17 00:00:00 2001 From: Hannes Kunnen Date: Wed, 6 Dec 2023 19:19:09 +0100 Subject: [PATCH] fix(core): replace unicode with UTF-8 character Replace escaped unicode occurrences in text with their respective UTF-8 character. This enables the use of non-ASCII characters in the project path. Closes #1868 --- lib/plugin/utils/ast-utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/plugin/utils/ast-utils.ts b/lib/plugin/utils/ast-utils.ts index 162be3653..290401bc2 100644 --- a/lib/plugin/utils/ast-utils.ts +++ b/lib/plugin/utils/ast-utils.ts @@ -103,7 +103,17 @@ export function getText( typeFormatFlags = getDefaultTypeFormatFlags(enclosingNode); } const compilerNode = !enclosingNode ? undefined : enclosingNode; - return typeChecker.typeToString(type, compilerNode, typeFormatFlags); + + const text = typeChecker.typeToString(type, compilerNode, typeFormatFlags); + + // Regex to match escaped unicode + const unicodeRegex = /\\u([\dA-Fa-f]{4})/g + + // Replace all escaped unicode occurrences with respective UTF-8 character + return text.replace(unicodeRegex, (match, unicode) => { + const charCode = parseInt(unicode, 16); + return String.fromCharCode(charCode); + }); } export function getDefaultTypeFormatFlags(enclosingNode: Node) {