Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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;