mirror of https://github.com/webpack/webpack.git
Don't use JSON.parse when json is a string
This commit is contained in:
parent
d16abb3294
commit
567ff7f026
|
@ -122,7 +122,9 @@ class JsonGenerator extends Generator {
|
||||||
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
||||||
const jsonStr = stringifySafe(finalJson);
|
const jsonStr = stringifySafe(finalJson);
|
||||||
const jsonExpr =
|
const jsonExpr =
|
||||||
jsonStr.length > 20 ? `JSON.parse(${JSON.stringify(jsonStr)})` : jsonStr;
|
jsonStr.length > 20 && typeof finalJson === "object"
|
||||||
|
? `JSON.parse(${JSON.stringify(jsonStr)})`
|
||||||
|
: jsonStr;
|
||||||
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue