Skip to content
This repository was archived by the owner on Aug 20, 2018. It is now read-only.

refactor: use jsesc to escape special characters #62

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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const jsesc = require('jsesc');

module.exports = function (source) {
if (this.cacheable) this.cacheable();

var value = typeof source === "string" ? JSON.parse(source) : source;

value = JSON.stringify(value)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
value = JSON.stringify(value);
value = jsesc(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is jsesc(value, { json: true }) a thing/require/needed here? (I'm not familiar with this module)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given webpack handles json at this point, why are we updating this here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Native JSON Support' turned out to be mainly a push(jsonLoader) for .json if missing https://github.com/webpack/webpack/pull/3374/files#diff-6cff30a1f2b17edb1b17434da5a7d140

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, of course


return `module.exports = ${value}`;
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"repository": {
"type": "git",
"url": "https://github.com/webpack/json-loader.git"
},
"dependencies": {
"jsesc": "^2.5.1"
}
}