Skip to content

Commit

Permalink
fix(core): unescape unicode in filenames
Browse files Browse the repository at this point in the history
Unescape escaped unicode characters in file paths.
Filepaths returned from TypeScript have their non-ASCII characters
escaped.
See https://www.github.com/microsoft/TypeScript/issues/36174

This enables the use of non-ASCII characters in the project
path.

Closes nestjs#1868
  • Loading branch information
Hannes-Kunnen committed Dec 7, 2023
1 parent 123e7b7 commit ceffc5e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/plugin/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

// Unescape escaped unicode https://github.com/microsoft/TypeScript/issues/36174
return text.replace(unicodeRegex, (match, unicode) => {
const charCode = parseInt(unicode, 16);
return String.fromCharCode(charCode);
});
}

export function getDefaultTypeFormatFlags(enclosingNode: Node) {
Expand Down

0 comments on commit ceffc5e

Please sign in to comment.