1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Ivan Kopeykin @vankop
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const Dependency = require("../Dependency");
|
---|
9 | const makeSerializable = require("../util/makeSerializable");
|
---|
10 | const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
|
---|
11 |
|
---|
12 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
13 | /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
---|
14 | /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
---|
15 | /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
---|
16 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
17 | /** @typedef {import("../css/CssParser").Range} Range */
|
---|
18 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
19 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
20 | /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
---|
21 |
|
---|
22 | class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
---|
23 | /**
|
---|
24 | * @param {string} name name
|
---|
25 | * @param {Range} range range
|
---|
26 | * @param {string=} prefix prefix
|
---|
27 | * @param {Set<string>=} declaredSet set of declared names (will only be active when in declared set)
|
---|
28 | */
|
---|
29 | constructor(name, range, prefix = "", declaredSet = undefined) {
|
---|
30 | super(name, range, prefix);
|
---|
31 | this.declaredSet = declaredSet;
|
---|
32 | }
|
---|
33 |
|
---|
34 | get type() {
|
---|
35 | return "css self local identifier";
|
---|
36 | }
|
---|
37 |
|
---|
38 | get category() {
|
---|
39 | return "self";
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * @returns {string | null} an identifier to merge equal requests
|
---|
44 | */
|
---|
45 | getResourceIdentifier() {
|
---|
46 | return "self";
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Returns the exported names
|
---|
51 | * @param {ModuleGraph} moduleGraph module graph
|
---|
52 | * @returns {ExportsSpec | undefined} export names
|
---|
53 | */
|
---|
54 | getExports(moduleGraph) {
|
---|
55 | if (this.declaredSet && !this.declaredSet.has(this.name)) return;
|
---|
56 | return super.getExports(moduleGraph);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Returns list of exports referenced by this dependency
|
---|
61 | * @param {ModuleGraph} moduleGraph module graph
|
---|
62 | * @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
---|
63 | * @returns {(string[] | ReferencedExport)[]} referenced exports
|
---|
64 | */
|
---|
65 | getReferencedExports(moduleGraph, runtime) {
|
---|
66 | if (this.declaredSet && !this.declaredSet.has(this.name))
|
---|
67 | return Dependency.NO_EXPORTS_REFERENCED;
|
---|
68 | return [[this.name]];
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * @param {ObjectSerializerContext} context context
|
---|
73 | */
|
---|
74 | serialize(context) {
|
---|
75 | const { write } = context;
|
---|
76 | write(this.declaredSet);
|
---|
77 | super.serialize(context);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * @param {ObjectDeserializerContext} context context
|
---|
82 | */
|
---|
83 | deserialize(context) {
|
---|
84 | const { read } = context;
|
---|
85 | this.declaredSet = read();
|
---|
86 | super.deserialize(context);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
|
---|
91 | CssLocalIdentifierDependency.Template
|
---|
92 | ) {
|
---|
93 | /**
|
---|
94 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
95 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
96 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
97 | * @returns {void}
|
---|
98 | */
|
---|
99 | apply(dependency, source, templateContext) {
|
---|
100 | const dep = /** @type {CssSelfLocalIdentifierDependency} */ (dependency);
|
---|
101 | if (dep.declaredSet && !dep.declaredSet.has(dep.name)) return;
|
---|
102 | super.apply(dependency, source, templateContext);
|
---|
103 | }
|
---|
104 | };
|
---|
105 |
|
---|
106 | makeSerializable(
|
---|
107 | CssSelfLocalIdentifierDependency,
|
---|
108 | "webpack/lib/dependencies/CssSelfLocalIdentifierDependency"
|
---|
109 | );
|
---|
110 |
|
---|
111 | module.exports = CssSelfLocalIdentifierDependency;
|
---|