You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const util = require("util");
  7. const compareLocations = require("./compareLocations");
  8. const DependencyReference = require("./dependencies/DependencyReference");
  9. /** @typedef {import("./Module")} Module */
  10. /** @typedef {import("webpack-sources").Source} Source */
  11. /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
  12. /**
  13. * @typedef {Object} DependencyTemplate
  14. * @property {function(Dependency, Source, RuntimeTemplate, Map<Function, DependencyTemplate>): void} apply
  15. */
  16. /** @typedef {Object} SourcePosition
  17. * @property {number} line
  18. * @property {number=} column
  19. */
  20. /** @typedef {Object} RealDependencyLocation
  21. * @property {SourcePosition} start
  22. * @property {SourcePosition=} end
  23. * @property {number=} index
  24. */
  25. /** @typedef {Object} SynteticDependencyLocation
  26. * @property {string} name
  27. * @property {number=} index
  28. */
  29. /** @typedef {SynteticDependencyLocation|RealDependencyLocation} DependencyLocation */
  30. class Dependency {
  31. constructor() {
  32. /** @type {Module|null} */
  33. this.module = null;
  34. // TODO remove in webpack 5
  35. /** @type {boolean} */
  36. this.weak = false;
  37. /** @type {boolean} */
  38. this.optional = false;
  39. /** @type {DependencyLocation} */
  40. this.loc = undefined;
  41. }
  42. getResourceIdentifier() {
  43. return null;
  44. }
  45. // Returns the referenced module and export
  46. getReference() {
  47. if (!this.module) return null;
  48. return new DependencyReference(this.module, true, this.weak);
  49. }
  50. // Returns the exported names
  51. getExports() {
  52. return null;
  53. }
  54. getWarnings() {
  55. return null;
  56. }
  57. getErrors() {
  58. return null;
  59. }
  60. updateHash(hash) {
  61. hash.update((this.module && this.module.id) + "");
  62. }
  63. disconnect() {
  64. this.module = null;
  65. }
  66. }
  67. // TODO remove in webpack 5
  68. Dependency.compare = util.deprecate(
  69. (a, b) => compareLocations(a.loc, b.loc),
  70. "Dependency.compare is deprecated and will be removed in the next major version"
  71. );
  72. module.exports = Dependency;