| | |
| | | |
| | | "use strict"; |
| | | |
| | | const { CSS_TYPE } = require("../ModuleSourceTypeConstants"); |
| | | const makeSerializable = require("../util/makeSerializable"); |
| | | const CssIcssExportDependency = require("./CssIcssExportDependency"); |
| | | const NullDependency = require("./NullDependency"); |
| | |
| | | |
| | | class CssIcssSymbolDependency extends NullDependency { |
| | | /** |
| | | * @param {string} name name |
| | | * @param {string} symbol symbol |
| | | * Creates an instance of CssIcssSymbolDependency. |
| | | * @param {string} localName local name |
| | | * @param {Range} range range |
| | | * @param {boolean=} isReference true when is reference, otherwise false |
| | | * @param {string=} value value when it was defined in this module |
| | | * @param {string=} importName import name when it was imported from other module |
| | | */ |
| | | constructor(name, symbol, range, isReference) { |
| | | constructor(localName, range, value, importName) { |
| | | super(); |
| | | this.name = name; |
| | | this.symbol = symbol; |
| | | this.localName = localName; |
| | | this.range = range; |
| | | this.isReference = isReference; |
| | | this.value = value; |
| | | this.importName = importName; |
| | | /** @type {undefined | string} */ |
| | | this._hashUpdate = undefined; |
| | | } |
| | | |
| | |
| | | return "css symbol identifier"; |
| | | } |
| | | |
| | | get category() { |
| | | return "self"; |
| | | } |
| | | |
| | | /** |
| | | * Update the hash |
| | | * Updates the hash with the data contributed by this instance. |
| | | * @param {Hash} hash hash to be updated |
| | | * @param {UpdateHashContext} context context |
| | | * @returns {void} |
| | | */ |
| | | updateHash(hash, context) { |
| | | if (this._hashUpdate === undefined) { |
| | | this._hashUpdate = `${this.range}${this.name}${this.value}`; |
| | | this._hashUpdate = `${this.range}${this.localName}${this.value || this.importName}`; |
| | | } |
| | | hash.update(this._hashUpdate); |
| | | } |
| | | |
| | | /** |
| | | * Returns list of exports referenced by this dependency |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @param {RuntimeSpec} runtime the runtime for which the module is analysed |
| | | * @returns {ReferencedExports} referenced exports |
| | | */ |
| | | getReferencedExports(moduleGraph, runtime) { |
| | | return [[this.symbol]]; |
| | | } |
| | | |
| | | /** |
| | | * Serializes this instance into the provided serializer context. |
| | | * @param {ObjectSerializerContext} context context |
| | | */ |
| | | serialize(context) { |
| | | const { write } = context; |
| | | write(this.name); |
| | | write(this.symbol); |
| | | write(this.value); |
| | | write(this.localName); |
| | | write(this.range); |
| | | write(this.isReference); |
| | | write(this.value); |
| | | write(this.importName); |
| | | super.serialize(context); |
| | | } |
| | | |
| | | /** |
| | | * Restores this instance from the provided deserializer context. |
| | | * @param {ObjectDeserializerContext} context context |
| | | */ |
| | | deserialize(context) { |
| | | const { read } = context; |
| | | this.name = read(); |
| | | this.symbol = read(); |
| | | this.value = read(); |
| | | this.localName = read(); |
| | | this.range = read(); |
| | | this.isReference = read(); |
| | | this.value = read(); |
| | | this.importName = read(); |
| | | super.deserialize(context); |
| | | } |
| | | } |
| | |
| | | NullDependency.Template |
| | | ) { |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Dependency} dependency the dependency for which the template should be applied |
| | | * @param {ReplaceSource} source the current replace source which can be modified |
| | | * @param {DependencyTemplateContext} templateContext the context object |
| | | * @returns {void} |
| | | */ |
| | | apply(dependency, source, templateContext) { |
| | | if (templateContext.type === "css") { |
| | | if (templateContext.type === CSS_TYPE) { |
| | | const dep = /** @type {CssIcssSymbolDependency} */ (dependency); |
| | | /** @type {string | undefined} */ |
| | | const value = dep.isReference |
| | | ? CssIcssExportDependency.Template.findReference( |
| | | dep.symbol, |
| | | const value = dep.importName |
| | | ? CssIcssExportDependency.Template.resolve( |
| | | dep.localName, |
| | | dep.importName, |
| | | templateContext |
| | | ) |
| | | : dep.symbol; |
| | | : dep.value; |
| | | |
| | | if (!value) { |
| | | // TODO generate warning |
| | | return; |
| | | } |
| | | |