Fix - Exits abruptly when invalid JSON

This commit is contained in:
Kamran Ahmed 2018-04-25 00:35:58 +02:00
parent e5ee3be827
commit ab1d79bda2
1 changed files with 8 additions and 2 deletions

View File

@ -6,11 +6,17 @@
const { ConcatSource } = require("webpack-sources");
const stringifySafe = data =>
JSON.stringify(data).replace(
const stringifySafe = data => {
const stringified = JSON.stringify(data);
if (!stringified) {
return undefined; // Invalid JSON
}
return stringified.replace(
/\u2028|\u2029/g,
str => (str === "\u2029" ? "\\u2029" : "\\u2028")
); // invalid in JavaScript but valid JSON
};
class JsonGenerator {
generate(module, dependencyTemplates, runtimeTemplate) {