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-10-18 17:57:14 +08:00
|
|
|
const makeSerializable = require("./util/makeSerializable");
|
2017-01-09 04:07:41 +08:00
|
|
|
|
2018-08-23 23:07:23 +08:00
|
|
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
2019-06-14 17:44:54 +08:00
|
|
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
|
|
|
/** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
2018-06-25 16:43:59 +08:00
|
|
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
2019-06-14 17:44:54 +08:00
|
|
|
/** @typedef {import("./Module")} Module */
|
2019-07-17 22:02:33 +08:00
|
|
|
/** @typedef {import("./util/Hash")} Hash */
|
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
|
|
|
/**
|
2019-06-14 17:44:54 +08:00
|
|
|
* @param {ChunkGroupOptions} groupOptions options for the group
|
2018-05-07 13:29:26 +08:00
|
|
|
* @param {DependencyLocation=} loc the line of code
|
2018-09-05 20:22:10 +08:00
|
|
|
* @param {string=} request the request
|
2018-05-04 00:57:02 +08:00
|
|
|
*/
|
2018-10-18 04:58:30 +08:00
|
|
|
constructor(groupOptions, 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;
|
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-08-23 23:07:23 +08:00
|
|
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
2018-05-04 00:57:02 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-08-23 23:07:23 +08:00
|
|
|
updateHash(hash, chunkGraph) {
|
2018-04-16 16:27:22 +08:00
|
|
|
hash.update(JSON.stringify(this.groupOptions));
|
2018-08-23 23:07:23 +08:00
|
|
|
const chunkGroup = chunkGraph.getBlockChunkGroup(this);
|
2018-08-23 02:17:49 +08:00
|
|
|
hash.update(chunkGroup ? chunkGroup.id : "");
|
2018-08-23 23:07:23 +08:00
|
|
|
super.updateHash(hash, chunkGraph);
|
2017-01-09 04:07:41 +08:00
|
|
|
}
|
2018-10-18 17:57:14 +08:00
|
|
|
|
2020-04-30 06:39:36 +08:00
|
|
|
/**
|
|
|
|
* @param {ChunkGroup} parentChunkGroup the parent chunk group
|
|
|
|
* @returns {boolean} true when this dependencies block should be loaded async
|
|
|
|
*/
|
|
|
|
isAsync(parentChunkGroup) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-18 17:57:14 +08:00
|
|
|
serialize(context) {
|
|
|
|
const { write } = context;
|
|
|
|
write(this.groupOptions);
|
|
|
|
write(this.loc);
|
|
|
|
write(this.request);
|
|
|
|
super.serialize(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
deserialize(context) {
|
|
|
|
const { read } = context;
|
|
|
|
this.groupOptions = read();
|
|
|
|
this.loc = read();
|
|
|
|
this.request = read();
|
|
|
|
super.deserialize(context);
|
|
|
|
}
|
2018-07-20 22:24:35 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 17:57:14 +08:00
|
|
|
makeSerializable(AsyncDependenciesBlock, "webpack/lib/AsyncDependenciesBlock");
|
|
|
|
|
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;
|