AssetSourceParser.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Yuta Hiroto @hiroppy
  4. */
  5. "use strict";
  6. const Parser = require("../Parser");
  7. /** @typedef {import("../Module").BuildInfo} BuildInfo */
  8. /** @typedef {import("../Module").BuildMeta} BuildMeta */
  9. /** @typedef {import("../Parser").ParserState} ParserState */
  10. /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
  11. class AssetSourceParser extends Parser {
  12. /**
  13. * @param {string | Buffer | PreparsedAst} source the source to parse
  14. * @param {ParserState} state the parser state
  15. * @returns {ParserState} the parser state
  16. */
  17. parse(source, state) {
  18. if (typeof source === "object" && !Buffer.isBuffer(source)) {
  19. throw new Error("AssetSourceParser doesn't accept preparsed AST");
  20. }
  21. const { module } = state;
  22. /** @type {BuildInfo} */
  23. (module.buildInfo).strict = true;
  24. /** @type {BuildMeta} */
  25. (module.buildMeta).exportsType = "default";
  26. /** @type {BuildMeta} */
  27. (state.module.buildMeta).defaultObject = false;
  28. return state;
  29. }
  30. }
  31. module.exports = AssetSourceParser;