Skip to content

Commit 128f945

Browse files
authored
fix: unreachable code for directories
1 parent 50890cd commit 128f945

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/interpolateName.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ function interpolateName(loaderContext, name, options = {}) {
5151
directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
5252
}
5353

54-
if (directory.length === 1) {
54+
if (directory.length <= 1) {
5555
directory = "";
56-
} else if (directory.length > 1) {
56+
} else {
57+
// directory.length > 1
5758
folder = path.basename(directory);
5859
}
5960
}

test/interpolateName.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,21 @@ describe("interpolateName()", () => {
308308
"/path/to/",
309309
"should interpolate [path] token",
310310
],
311+
[
312+
[loaderContext, "[path]", { context: "/path/" }],
313+
"to/",
314+
"should interpolate [path] token with context",
315+
],
311316
[
312317
[loaderContext, "[folder]", {}],
313318
"to",
314319
"should interpolate [folder] token",
315320
],
321+
[
322+
[{ resourcePath: "." }, "[folder]", {}],
323+
"",
324+
"should interpolate [folder] token with short resourcePath",
325+
],
316326
]);
317327
});
318328

0 commit comments

Comments
 (0)