Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 15, 2021
1 parent 62ef216 commit c44418f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
28 changes: 11 additions & 17 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,22 @@ function defaultGetLocalIdent(
localName,
options
) {
let matchResourceRequest;

// // eslint-disable-next-line no-underscore-dangle
// if (loaderContext._module.matchResource) {
// matchResourceRequest = normalizePath(
// // eslint-disable-next-line no-underscore-dangle
// path.relative(options.context, loaderContext._module.matchResource)
// );
// }
let relativeMatchResource = "";

// eslint-disable-next-line no-underscore-dangle
if (loaderContext._module.matchResource) {
relativeMatchResource = `${normalizePath(
// eslint-disable-next-line no-underscore-dangle
path.relative(options.context, loaderContext._module.matchResource)
)}\x00`;
}

const request = normalizePath(
const relativeResourcePath = normalizePath(
path.relative(options.context, loaderContext.resourcePath)
);

// eslint-disable-next-line no-param-reassign
options.content = `${
options.hashPrefix +
(typeof matchResourceRequest !== "undefined"
? `${matchResourceRequest}\x00`
: "") +
request
}\x00${localName}`;
options.content = `${options.hashPrefix}${relativeMatchResource}${relativeResourcePath}\x00${localName}`;

return interpolateName(loaderContext, localIdentName, options);
}
Expand Down
30 changes: 15 additions & 15 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -665,66 +665,66 @@ exports[`loader should work with inline module syntax: result 1`] = `
Array [
Array [
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
"._14oM7qkZ6dgC62uK5h4NI0 {
color: red;
}
.j3CQSVq_DdDvo0Ew74yQi {
._2NqyYysncZeLetATpl0xfW {
color: white;
}",
"",
],
Array [
"button.modules.css!=!./index-loader-syntax-sass.css",
".iuzmhXWrT3_Z-zKS-rMGM {
"._8aapa4kQQdSsOoRODcrwe {
width: 5px;
}",
"",
],
Array [
"other.modules.scss!=!../../src/index.js?[ident]!./index-loader-syntax-sass.modules.css",
"._1fGl5mRxLFCqIet0X3JYrB > ._2pVMnENaxk1YmKug-4EMYF {
"._2yVYVQfmDwKLZn9Qj6k_Q5 > ._3rHlnRnPEotX4nTkd82-aE {
color: red;
}",
"",
],
Array [
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
"._14oM7qkZ6dgC62uK5h4NI0 {
color: red;
}
.j3CQSVq_DdDvo0Ew74yQi {
._2NqyYysncZeLetATpl0xfW {
color: white;
}
.B7fdaUjwJ3YVou1v7dYEE {
._1-Aa1c8UQML46IWY0FjGXT {
from: custom;
}",
"",
],
Array [
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
"._14oM7qkZ6dgC62uK5h4NI0 {
color: red;
}
.j3CQSVq_DdDvo0Ew74yQi {
._2NqyYysncZeLetATpl0xfW {
color: white;
}
.B7fdaUjwJ3YVou1v7dYEE {
._1-Aa1c8UQML46IWY0FjGXT {
from: custom;
}",
"",
],
Array [
"other.modules.scss!=!../../src/index.js?[ident]!./index-loader-syntax-sass.modules.css",
"._1fGl5mRxLFCqIet0X3JYrB > ._2pVMnENaxk1YmKug-4EMYF {
"._2yVYVQfmDwKLZn9Qj6k_Q5 > ._3rHlnRnPEotX4nTkd82-aE {
color: red;
}
._1kK_VYa-N303wnLgpvL-7d {
._2kEhhupr-6tgHnCC_d4yO8 {
from: custom;
}",
"",
Expand All @@ -738,21 +738,21 @@ Array [
],
Array [
"button.modules.css!=!./index-loader-syntax-sass.css",
".iuzmhXWrT3_Z-zKS-rMGM {
"._8aapa4kQQdSsOoRODcrwe {
width: 5px;
}",
"",
],
Array [
"button.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=bar",
"._1DaPRMj4jImbX3XSIzjaR4 {
"._2hfVrRfux-FOrqimHr-fzt {
color: red;
}",
"",
],
Array [
"other.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=baz",
"._1DaPRMj4jImbX3XSIzjaR4 {
"._2jOyhMQwdpQ85V5dDLcfoG {
color: red;
}",
"",
Expand Down

0 comments on commit c44418f

Please sign in to comment.