AssetSourceParser.js 821 B

12345678910111213141516171819202122232425262728293031
  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("../Parser").ParserState} ParserState */
  8. /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
  9. class AssetSourceParser extends Parser {
  10. /**
  11. * @param {string | Buffer | PreparsedAst} source the source to parse
  12. * @param {ParserState} state the parser state
  13. * @returns {ParserState} the parser state
  14. */
  15. parse(source, state) {
  16. if (typeof source === "object" && !Buffer.isBuffer(source)) {
  17. throw new Error("AssetSourceParser doesn't accept preparsed AST");
  18. }
  19. const { module } = state;
  20. module.buildInfo.strict = true;
  21. module.buildMeta.exportsType = "default";
  22. return state;
  23. }
  24. }
  25. module.exports = AssetSourceParser;