| [9af201e] | 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const Dependency = require("../Dependency");
|
|---|
| 9 | const DependencyTemplate = require("../DependencyTemplate");
|
|---|
| 10 |
|
|---|
| 11 | /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
|---|
| 12 | /** @typedef {import("../Module")} Module */
|
|---|
| 13 | /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|---|
| 14 | /** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|---|
| 15 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|---|
| 16 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|---|
| 17 |
|
|---|
| 18 | class ModuleDependency extends Dependency {
|
|---|
| 19 | /**
|
|---|
| 20 | * Creates an instance of ModuleDependency.
|
|---|
| 21 | * @param {string} request request path which needs resolving
|
|---|
| 22 | * @param {number=} sourceOrder source order
|
|---|
| 23 | */
|
|---|
| 24 | constructor(request, sourceOrder) {
|
|---|
| 25 | super();
|
|---|
| 26 | this.request = request;
|
|---|
| 27 | this.userRequest = request;
|
|---|
| 28 | this.sourceOrder = sourceOrder;
|
|---|
| 29 | /** @type {Range | undefined} */
|
|---|
| 30 | this.range = undefined;
|
|---|
| 31 | /** @type {undefined | string} */
|
|---|
| 32 | this._context = undefined;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | /**
|
|---|
| 36 | * Returns a request context.
|
|---|
| 37 | * @returns {string | undefined} a request context
|
|---|
| 38 | */
|
|---|
| 39 | getContext() {
|
|---|
| 40 | return this._context;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * Returns an identifier to merge equal requests.
|
|---|
| 45 | * @returns {string | null} an identifier to merge equal requests
|
|---|
| 46 | */
|
|---|
| 47 | getResourceIdentifier() {
|
|---|
| 48 | return `context${this._context || ""}|module${this.request}`;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | /**
|
|---|
| 52 | * Could affect referencing module.
|
|---|
| 53 | * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
|---|
| 54 | */
|
|---|
| 55 | couldAffectReferencingModule() {
|
|---|
| 56 | return true;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /**
|
|---|
| 60 | * Creates an ignored module.
|
|---|
| 61 | * @param {string} context context directory
|
|---|
| 62 | * @returns {Module} ignored module
|
|---|
| 63 | */
|
|---|
| 64 | createIgnoredModule(context) {
|
|---|
| 65 | const RawModule = require("../RawModule");
|
|---|
| 66 |
|
|---|
| 67 | const module = new RawModule(
|
|---|
| 68 | "/* (ignored) */",
|
|---|
| 69 | `ignored|${context}|${this.request}`,
|
|---|
| 70 | `${this.request} (ignored)`
|
|---|
| 71 | );
|
|---|
| 72 | module.factoryMeta = { sideEffectFree: true };
|
|---|
| 73 | return module;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * Serializes this instance into the provided serializer context.
|
|---|
| 78 | * @param {ObjectSerializerContext} context context
|
|---|
| 79 | */
|
|---|
| 80 | serialize(context) {
|
|---|
| 81 | const { write } = context;
|
|---|
| 82 | write(this.request);
|
|---|
| 83 | write(this.userRequest);
|
|---|
| 84 | write(this._context);
|
|---|
| 85 | write(this.range);
|
|---|
| 86 | write(this.sourceOrder);
|
|---|
| 87 | super.serialize(context);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | /**
|
|---|
| 91 | * Restores this instance from the provided deserializer context.
|
|---|
| 92 | * @param {ObjectDeserializerContext} context context
|
|---|
| 93 | */
|
|---|
| 94 | deserialize(context) {
|
|---|
| 95 | const { read } = context;
|
|---|
| 96 | this.request = read();
|
|---|
| 97 | this.userRequest = read();
|
|---|
| 98 | this._context = read();
|
|---|
| 99 | this.range = read();
|
|---|
| 100 | this.sourceOrder = read();
|
|---|
| 101 | super.deserialize(context);
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | ModuleDependency.Template = DependencyTemplate;
|
|---|
| 106 |
|
|---|
| 107 | module.exports = ModuleDependency;
|
|---|