webpack/lib/dependencies/ContextElementDependency.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

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
"use strict";
2018-07-30 23:08:51 +08:00
2020-06-10 19:31:01 +08:00
const Dependency = require("../Dependency");
const makeSerializable = require("../util/makeSerializable");
const ModuleDependency = require("./ModuleDependency");
2013-01-31 01:49:25 +08:00
2020-06-10 19:31:01 +08:00
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
class ContextElementDependency extends ModuleDependency {
constructor(request, userRequest, category, referencedExports) {
super(request);
2020-06-10 19:31:01 +08:00
this.referencedExports = referencedExports;
this._category = category;
2018-02-25 09:00:20 +08:00
if (userRequest) {
this.userRequest = userRequest;
}
}
get type() {
return "context element";
}
2020-06-10 19:31:01 +08:00
get category() {
return this._category;
}
2020-06-10 19:31:01 +08:00
/**
* Returns list of exports referenced by this dependency
* @param {ModuleGraph} moduleGraph module graph
* @returns {(string[] | ReferencedExport)[]} referenced exports
*/
getReferencedExports(moduleGraph) {
return this.referencedExports
? this.referencedExports.map(e => ({
name: e,
canMangle: false
}))
: Dependency.EXPORTS_OBJECT_REFERENCED;
}
serialize(context) {
context.write(this.referencedExports);
super.serialize(context);
}
deserialize(context) {
this.referencedExports = context.read();
super.deserialize(context);
}
2013-01-31 01:49:25 +08:00
}
makeSerializable(
ContextElementDependency,
"webpack/lib/dependencies/ContextElementDependency"
);
module.exports = ContextElementDependency;