Skip to content

Commit d3d775b

Browse files
committed
refactor: add reversedCharMapper support
1 parent 65f5d3e commit d3d775b

7 files changed

Lines changed: 291 additions & 207 deletions

File tree

src/utils.js

Lines changed: 18 additions & 2 deletions
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 reversedCharMapper = {};
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,21 @@ function escapeLocalIdent(localident) {
270272
localident
271273
// For `[hash]` placeholder
272274
.replace(/^((-?[0-9])|--)/, "_$1")
273-
.replace(filenameReservedRegex, "-")
275+
.replace(filenameReservedRegex, (_, $1) => {
276+
// normalize Windows path `\` as unix `/` for constancy
277+
const char = $1 === "\\" ? "/" : $1;
278+
279+
if (reversedCharMapper[char]) {
280+
return reversedCharMapper[char];
281+
}
282+
283+
const hex = char.charCodeAt(0).toString(16).toUpperCase();
284+
const escaped = `\\C${hex}`;
285+
286+
reversedCharMapper[char] = escaped;
287+
288+
return escaped;
289+
})
274290
.replace(reControlChars, "-")
275291
.replace(/\./g, "-"),
276292
);

test/__snapshots__/import-option.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`"import" option should jeep order of imports with 'webpackIgnore': errors 1`] = `[]`;
44

0 commit comments

Comments
 (0)