Parser.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /**
  7. * @import {
  8. * WebpackOptionsNormalizedWithDefaults as WebpackOptions
  9. * } from "./config/defaults"
  10. */
  11. /** @import Compilation from "./Compilation" */
  12. /** @import NormalModule from "./NormalModule" */
  13. /** @typedef {Record<string, EXPECTED_ANY>} PreparsedAst */
  14. /**
  15. * Defines the parser state base type used by this module.
  16. * @typedef {object} ParserStateBase
  17. * @property {string | Buffer} source
  18. * @property {NormalModule} current
  19. * @property {NormalModule} module
  20. * @property {Compilation} compilation
  21. * @property {WebpackOptions} options
  22. */
  23. /** @typedef {ParserStateBase & Record<string, EXPECTED_ANY>} ParserState */
  24. class Parser {
  25. /* istanbul ignore next */
  26. /**
  27. * Parses the provided source and updates the parser state.
  28. * @abstract
  29. * @param {string | Buffer | PreparsedAst} source the source to parse
  30. * @param {ParserState} state the parser state
  31. * @returns {ParserState} the parser state
  32. */
  33. parse(source, state) {
  34. const AbstractMethodError = require("./errors/AbstractMethodError");
  35. throw new AbstractMethodError();
  36. }
  37. }
  38. module.exports = Parser;