AssetSourceParser.js 869 B

1234567891011121314151617181920212223242526272829303132
  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. state.module.buildMeta.defaultObject = false;
  23. return state;
  24. }
  25. }
  26. module.exports = AssetSourceParser;