webpack/lib/Dependency.js

122 lines
2.7 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const DependencyReference = require("./dependencies/DependencyReference");
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./ModuleGraph")} ModuleGraph */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("./WebpackError")} WebpackError */
/** @typedef {import("./util/createHash").Hash} Hash */
/** @typedef {Object} SourcePosition
* @property {number} line
* @property {number=} column
*/
/** @typedef {Object} RealDependencyLocation
* @property {SourcePosition} start
* @property {SourcePosition=} end
* @property {number=} index
*/
/** @typedef {Object} SynteticDependencyLocation
* @property {string} name
* @property {number=} index
*/
/** @typedef {SynteticDependencyLocation|RealDependencyLocation} DependencyLocation */
/**
* @typedef {Object} ExportsSpec
* @property {string[] | true | null} exports exported names, true for unknown exports or null for no exports
* @property {Module[]=} dependencies module on which the result depends on
*/
class Dependency {
constructor() {
/** @type {Module|null} */
this.module = null;
// TODO remove in webpack 5
/** @type {boolean} */
this.weak = false;
/** @type {boolean} */
this.optional = false;
/** @type {DependencyLocation} */
this.loc = undefined;
}
/**
* @returns {string} a display name for the type of dependency
*/
get type() {
return "unknown";
}
/**
* @returns {string | null} an identifier to merge equal requests
*/
getResourceIdentifier() {
return null;
}
/**
* Returns the referenced module and export
* @returns {DependencyReference} reference
*/
getReference() {
if (!this.module) return null;
return new DependencyReference(() => this.module, true, this.weak);
}
/**
* Returns the exported names
* @returns {ExportsSpec | undefined} export names
*/
getExports() {
return null;
}
/**
* Returns warnings
* @returns {WebpackError[]} warnings
*/
getWarnings() {
return null;
}
/**
* Returns errors
* @returns {WebpackError[]} errors
*/
getErrors() {
return null;
}
/**
* Update the hash
* @param {Hash} hash hash to be updated
* @param {ModuleGraph} moduleGraph module graph
* @returns {void}
*/
updateHash(hash, moduleGraph) {
hash.update((this.module && this.module.id) + "");
}
/**
* Disconnect the dependency from the graph
* @returns {void}
*/
disconnect() {
this.module = null;
}
}
module.exports = Dependency;