RequireResolveDependency.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Dependency = require("../Dependency");
  7. const makeSerializable = require("../util/makeSerializable");
  8. const ModuleDependency = require("./ModuleDependency");
  9. const ModuleDependencyAsId = require("./ModuleDependencyTemplateAsId");
  10. /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
  11. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  12. /** @typedef {import("../javascript/JavascriptParser").Range} Range */
  13. /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
  14. class RequireResolveDependency extends ModuleDependency {
  15. /**
  16. * @param {string} request the request string
  17. * @param {Range} range location in source code
  18. * @param {string} [context] context
  19. */
  20. constructor(request, range, context) {
  21. super(request);
  22. this.range = range;
  23. this._context = context;
  24. }
  25. get type() {
  26. return "require.resolve";
  27. }
  28. get category() {
  29. return "commonjs";
  30. }
  31. /**
  32. * Returns list of exports referenced by this dependency
  33. * @param {ModuleGraph} moduleGraph module graph
  34. * @param {RuntimeSpec} runtime the runtime for which the module is analysed
  35. * @returns {(string[] | ReferencedExport)[]} referenced exports
  36. */
  37. getReferencedExports(moduleGraph, runtime) {
  38. // This doesn't use any export
  39. return Dependency.NO_EXPORTS_REFERENCED;
  40. }
  41. }
  42. makeSerializable(
  43. RequireResolveDependency,
  44. "webpack/lib/dependencies/RequireResolveDependency"
  45. );
  46. RequireResolveDependency.Template = ModuleDependencyAsId;
  47. module.exports = RequireResolveDependency;