AssetBytesParser.js 1019 B

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