webpack/lib/dependencies/StaticExportsDependency.js

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-12-07 03:37:58 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2018-07-30 23:08:51 +08:00
2017-12-07 03:37:58 +08:00
"use strict";
2018-07-30 23:08:51 +08:00
const makeSerializable = require("../util/makeSerializable");
2017-12-07 03:37:58 +08:00
const NullDependency = require("./NullDependency");
/** @typedef {import("../ChunkGraph")} ChunkGraph */
2019-06-12 20:00:34 +08:00
/** @typedef {import("../Dependency").ExportSpec} ExportSpec */
2018-07-25 15:33:48 +08:00
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
2018-07-17 22:34:36 +08:00
/** @typedef {import("../ModuleGraph")} ModuleGraph */
2019-07-17 22:02:33 +08:00
/** @typedef {import("../util/Hash")} Hash */
2018-07-25 15:33:48 +08:00
class StaticExportsDependency extends NullDependency {
2018-11-24 04:52:05 +08:00
/**
* @param {string[] | true} exports export names
* @param {boolean} canMangle true, if mangling exports names is allowed
2018-11-24 04:52:05 +08:00
*/
constructor(exports, canMangle) {
2017-12-07 03:37:58 +08:00
super();
this.exports = exports;
this.canMangle = canMangle;
2017-12-07 03:37:58 +08:00
}
get type() {
return "static exports";
2017-12-07 03:37:58 +08:00
}
2018-07-25 15:33:48 +08:00
/**
* Returns the exported names
2018-07-17 22:34:36 +08:00
* @param {ModuleGraph} moduleGraph module graph
2018-07-25 15:33:48 +08:00
* @returns {ExportsSpec | undefined} export names
*/
2018-07-17 22:34:36 +08:00
getExports(moduleGraph) {
return {
exports: this.exports,
canMangle: this.canMangle,
dependencies: undefined
};
2017-12-07 03:37:58 +08:00
}
/**
* Update the hash
* @param {Hash} hash hash to be updated
* @param {ChunkGraph} chunkGraph chunk graph
* @returns {void}
*/
updateHash(hash, chunkGraph) {
hash.update(JSON.stringify(this.exports));
2019-06-12 20:00:34 +08:00
if (this.canMangle) hash.update("canMangle");
super.updateHash(hash, chunkGraph);
}
serialize(context) {
const { write } = context;
write(this.exports);
write(this.canMangle);
super.serialize(context);
}
deserialize(context) {
const { read } = context;
this.exports = read();
this.canMangle = read();
super.deserialize(context);
}
2017-12-07 03:37:58 +08:00
}
makeSerializable(
StaticExportsDependency,
"webpack/lib/dependencies/StaticExportsDependency"
);
module.exports = StaticExportsDependency;