2017-11-12 01:48:29 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
2018-05-19 17:09:30 +08:00
|
|
|
const parseJson = require("json-parse-better-errors");
|
2017-12-07 03:37:58 +08:00
|
|
|
const JsonExportsDependency = require("./dependencies/JsonExportsDependency");
|
2017-11-12 01:48:29 +08:00
|
|
|
|
|
|
|
class JsonParser {
|
|
|
|
constructor(options) {
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse(source, state) {
|
2018-05-19 18:17:46 +08:00
|
|
|
const data = parseJson(source.replace(/^\ufeff/, ""));
|
2017-12-07 03:37:58 +08:00
|
|
|
state.module.buildInfo.jsonData = data;
|
|
|
|
state.module.buildMeta.exportsType = "named";
|
2018-02-25 09:00:20 +08:00
|
|
|
if (typeof data === "object" && data)
|
2017-12-07 03:37:58 +08:00
|
|
|
state.module.addDependency(new JsonExportsDependency(Object.keys(data)));
|
|
|
|
state.module.addDependency(new JsonExportsDependency(["default"]));
|
2017-11-12 01:48:29 +08:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = JsonParser;
|