You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JsonParser.js 758B

123456789101112131415161718192021222324252627
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const parseJson = require("json-parse-better-errors");
  7. const JsonExportsDependency = require("./dependencies/JsonExportsDependency");
  8. class JsonParser {
  9. constructor(options) {
  10. this.options = options;
  11. }
  12. parse(source, state) {
  13. const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
  14. state.module.buildInfo.jsonData = data;
  15. state.module.buildMeta.exportsType = "named";
  16. if (typeof data === "object" && data) {
  17. state.module.addDependency(new JsonExportsDependency(Object.keys(data)));
  18. }
  19. state.module.addDependency(new JsonExportsDependency(["default"]));
  20. return state;
  21. }
  22. }
  23. module.exports = JsonParser;