AssetSourceParser.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. * Parses the provided source and updates the parser state.
  14. * @param {string | Buffer | PreparsedAst} source the source to parse
  15. * @param {ParserState} state the parser state
  16. * @returns {ParserState} the parser state
  17. */
  18. parse(source, state) {
  19. if (typeof source === "object" && !Buffer.isBuffer(source)) {
  20. throw new Error("AssetSourceParser doesn't accept preparsed AST");
  21. }
  22. const { module } = state;
  23. /** @type {BuildInfo} */
  24. (module.buildInfo).strict = true;
  25. /** @type {BuildMeta} */
  26. (module.buildMeta).exportsType = "default";
  27. /** @type {BuildMeta} */
  28. (state.module.buildMeta).defaultObject = false;
  29. return state;
  30. }
  31. }
  32. module.exports = AssetSourceParser;