Skip to content

Commit db28ea9

Browse files
committed
refactor: add reversedChartMapper support
1 parent 6bd4494 commit db28ea9

File tree

5 files changed

+286
-205
lines changed

5 files changed

+286
-205
lines changed

src/utils.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ function normalizePath(file) {
259259
return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
260260
}
261261

262+
const reversedChartMapper = {};
263+
262264
// eslint-disable-next-line no-control-regex
263-
const filenameReservedRegex = /[<>:"/\\|?*\s]/g;
265+
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
264266
// eslint-disable-next-line no-control-regex
265267
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
266268

@@ -270,7 +272,18 @@ function escapeLocalIdent(localident) {
270272
localident
271273
// For `[hash]` placeholder
272274
.replace(/^((-?[0-9])|--)/, "_$1")
273-
.replace(filenameReservedRegex, "-")
275+
.replace(filenameReservedRegex, (_, $1) => {
276+
if (reversedChartMapper[$1]) {
277+
return reversedChartMapper[$1];
278+
}
279+
280+
const hex = $1.charCodeAt(0).toString(16).toUpperCase();
281+
const escaped = `\\C${hex}`;
282+
283+
reversedChartMapper[$1] = escaped;
284+
285+
return escaped;
286+
})
274287
.replace(reControlChars, "-")
275288
.replace(/\./g, "-"),
276289
);

0 commit comments

Comments
 (0)