deduplicate code
This commit is contained in:
parent
9f43b8b026
commit
1cc9f8799b
|
@ -28,6 +28,7 @@ class JsonGenerator {
|
|||
})
|
||||
);
|
||||
}
|
||||
let finalJson;
|
||||
if (
|
||||
Array.isArray(module.buildMeta.providedExports) &&
|
||||
!module.isUsed("default")
|
||||
|
@ -41,17 +42,14 @@ class JsonGenerator {
|
|||
reducedJson[used] = data[exportName];
|
||||
}
|
||||
}
|
||||
|
||||
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
||||
const jsonSource = JSON.stringify(stringifySafe(reducedJson));
|
||||
const jsonExpr = `JSON.parse(${jsonSource})`;
|
||||
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
||||
finalJson = reducedJson;
|
||||
} else {
|
||||
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
||||
const jsonSource = JSON.stringify(stringifySafe(data));
|
||||
const jsonExpr = `JSON.parse(${jsonSource})`;
|
||||
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
||||
finalJson = data;
|
||||
}
|
||||
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
||||
const jsonSource = JSON.stringify(stringifySafe(finalJson));
|
||||
const jsonExpr = `JSON.parse(${jsonSource})`;
|
||||
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue