Skip to content

#85 dollar sign in replace #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/extractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {
const extractedContent = extractedDependencyContent.reduce((content, dependencyContent, idx) => {
const pattern = new RegExp(newDependencies[idx].rndPlaceholder, "g");

return content.replace(pattern, dependencyContent);
// should be callback because dep text could contain $'
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace
return content.replace(pattern, () => dependencyContent);
}, contentWithPlaceholders);

moduleCache.set(filename, extractedContent);
Expand Down
9 changes: 8 additions & 1 deletion test/extractLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ describe("extractLoader", () => {
const simpleJs = path.resolve(__dirname, "dist/simple-dist.js");

expect(simpleJs).to.be.a.file();
expect(simpleJs).to.have.content("hello");
expect(simpleJs).to.have.content("hello$'");
}));
it("should extract require with dollar sign correctly", () =>
compile({testModule: "require-dollar-sign.js"}).then(() => {
const simpleJs = path.resolve(__dirname, "dist/require-dollar-sign-dist.js");

expect(simpleJs).to.be.a.file();
expect(simpleJs).to.have.content("first hello$' last");
}));
it("should extract resource with query params into simple-css-with-query-param.js", () =>
compile({testModule: "simple-css-with-query-params.js"}).then(() => {
Expand Down
2 changes: 2 additions & 0 deletions test/modules/require-dollar-sign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable import/unambiguous */
module.exports = "first " + require("./simple.js") + " last";
2 changes: 1 addition & 1 deletion test/modules/simple.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-disable import/unambiguous */
module.exports = "hello";
module.exports = "hello$'";