Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f38ba36

Browse files
committedMay 2, 2025··
refactor: add reversedChartMapper support
1 parent 6bd4494 commit f38ba36

File tree

5 files changed

+289
-205
lines changed

5 files changed

+289
-205
lines changed
 

‎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 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,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 === "\\" && path.sep === "\\" ? "/" : $1;
278+
279+
if (reversedChartMapper[char]) {
280+
return reversedChartMapper[char];
281+
}
282+
283+
const hex = char.charCodeAt(0).toString(16).toUpperCase();
284+
const escaped = `\\C${hex}`;
285+
286+
reversedChartMapper[char] = escaped;
287+
288+
return escaped;
289+
})
274290
.replace(reControlChars, "-")
275291
.replace(/\./g, "-"),
276292
);

‎test/__snapshots__/modules-option.test.js.snap

Lines changed: 243 additions & 203 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a-b {
2+
color: red;
3+
}
4+
5+
a\C20b /* i.e. with spaces */ {
6+
color: red;
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as css from './source.css';
2+
3+
__export__ = css.default;
4+
5+
export default css;

‎test/modules-option.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,4 +2692,20 @@ describe('"modules" option', () => {
26922692
expect(getWarnings(stats)).toMatchSnapshot("warnings");
26932693
expect(getErrors(stats)).toMatchSnapshot("errors");
26942694
});
2695+
2696+
it("issue #1626", async () => {
2697+
const compiler = getCompiler("./modules/issue-1626/source.js", {
2698+
modules: true,
2699+
});
2700+
const stats = await compile(compiler);
2701+
2702+
expect(
2703+
getModuleSource("./modules/issue-1626/source.css", stats),
2704+
).toMatchSnapshot("module");
2705+
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
2706+
"result",
2707+
);
2708+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
2709+
expect(getErrors(stats)).toMatchSnapshot("errors");
2710+
});
26952711
});

0 commit comments

Comments
 (0)
Please sign in to comment.