2013-01-31 01:49:25 +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-01-09 04:07:41 +08:00
|
|
|
"use strict";
|
2018-05-15 18:20:17 +08:00
|
|
|
|
2017-01-09 04:07:41 +08:00
|
|
|
const DependenciesBlock = require("./DependenciesBlock");
|
|
|
|
|
2018-05-15 18:20:17 +08:00
|
|
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
|
|
|
/** @typedef {import("./Module")} Module */
|
2018-07-17 22:42:05 +08:00
|
|
|
/** @typedef {import("./Compilation")} Compilation */
|
2018-06-25 16:43:59 +08:00
|
|
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
2018-06-25 22:01:57 +08:00
|
|
|
/** @typedef {import("./util/createHash").Hash} Hash */
|
2018-05-15 18:20:17 +08:00
|
|
|
/** @typedef {TODO} GroupOptions */
|
2018-05-04 00:57:02 +08:00
|
|
|
|
2018-07-20 22:24:35 +08:00
|
|
|
class AsyncDependenciesBlock extends DependenciesBlock {
|
2018-05-04 00:57:02 +08:00
|
|
|
/**
|
|
|
|
* @param {GroupOptions} groupOptions options for the group
|
|
|
|
* @param {Module} module the Module object
|
2018-05-07 13:29:26 +08:00
|
|
|
* @param {DependencyLocation=} loc the line of code
|
2018-05-04 00:57:02 +08:00
|
|
|
* @param {TODO=} request the request
|
|
|
|
*/
|
2018-04-16 16:27:22 +08:00
|
|
|
constructor(groupOptions, module, loc, request) {
|
2017-01-09 04:07:41 +08:00
|
|
|
super();
|
2018-04-16 16:27:22 +08:00
|
|
|
if (typeof groupOptions === "string") {
|
|
|
|
groupOptions = { name: groupOptions };
|
|
|
|
} else if (!groupOptions) {
|
|
|
|
groupOptions = { name: undefined };
|
|
|
|
}
|
|
|
|
this.groupOptions = groupOptions;
|
2017-01-09 04:07:41 +08:00
|
|
|
this.loc = loc;
|
2018-01-20 00:06:59 +08:00
|
|
|
this.request = request;
|
2018-05-04 00:57:02 +08:00
|
|
|
/** @type {DependenciesBlock} */
|
|
|
|
this.parent = undefined;
|
2018-07-20 22:24:35 +08:00
|
|
|
/** @type {[number, number]} */
|
|
|
|
this.range = undefined;
|
2017-01-09 22:09:29 +08:00
|
|
|
}
|
2018-01-20 00:06:59 +08:00
|
|
|
|
2018-05-04 00:57:02 +08:00
|
|
|
/**
|
|
|
|
* @returns {string} The name of the chunk
|
|
|
|
*/
|
2018-04-16 16:27:22 +08:00
|
|
|
get chunkName() {
|
|
|
|
return this.groupOptions.name;
|
|
|
|
}
|
|
|
|
|
2018-05-04 00:57:02 +08:00
|
|
|
/**
|
|
|
|
* @param {string} value The new chunk name
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-04-16 16:27:22 +08:00
|
|
|
set chunkName(value) {
|
|
|
|
this.groupOptions.name = value;
|
|
|
|
}
|
|
|
|
|
2018-05-04 00:57:02 +08:00
|
|
|
/**
|
2018-07-23 23:25:38 +08:00
|
|
|
* @param {Hash} hash the hash used to track dependencies
|
2018-07-17 22:42:05 +08:00
|
|
|
* @param {Compilation} compilation the compilation
|
2018-05-04 00:57:02 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-07-17 22:42:05 +08:00
|
|
|
updateHash(hash, compilation) {
|
2018-04-16 16:27:22 +08:00
|
|
|
hash.update(JSON.stringify(this.groupOptions));
|
2018-08-23 02:17:49 +08:00
|
|
|
const chunkGroup = compilation.chunkGraph.getBlockChunkGroup(this);
|
|
|
|
hash.update(chunkGroup ? chunkGroup.id : "");
|
2018-07-17 22:42:05 +08:00
|
|
|
super.updateHash(hash, compilation);
|
2017-01-09 04:07:41 +08:00
|
|
|
}
|
2018-07-20 22:24:35 +08:00
|
|
|
}
|
|
|
|
|
2018-07-24 21:30:37 +08:00
|
|
|
Object.defineProperty(AsyncDependenciesBlock.prototype, "module", {
|
|
|
|
get() {
|
|
|
|
throw new Error(
|
|
|
|
"module property was removed from AsyncDependenciesBlock (it's not needed)"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
set() {
|
|
|
|
throw new Error(
|
|
|
|
"module property was removed from AsyncDependenciesBlock (it's not needed)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-20 22:24:35 +08:00
|
|
|
module.exports = AsyncDependenciesBlock;
|