webpack/lib/dependencies/CommonJsRequireContextDepen...

74 lines
2.1 KiB
JavaScript
Raw Permalink 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
const makeSerializable = require("../util/makeSerializable");
const ContextDependency = require("./ContextDependency");
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
2013-01-31 01:49:25 +08:00
2023-05-22 06:58:24 +08:00
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
2023-04-12 03:22:51 +08:00
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
2025-04-07 21:09:05 +08:00
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
2023-04-12 03:22:51 +08:00
class CommonJsRequireContextDependency extends ContextDependency {
2023-05-22 06:58:24 +08:00
/**
2025-04-07 21:09:05 +08:00
* @param {ContextDependencyOptions} options options for the context module
2023-05-22 06:58:24 +08:00
* @param {Range} range location in source code
2023-06-17 06:33:17 +08:00
* @param {Range | undefined} valueRange location of the require call
2023-06-17 01:13:03 +08:00
* @param {boolean | string } inShorthand true or name
2025-09-09 23:41:52 +08:00
* @param {string=} context context
2023-05-22 06:58:24 +08:00
*/
2022-03-28 23:51:48 +08:00
constructor(options, range, valueRange, inShorthand, context) {
super(options, context);
this.range = range;
this.valueRange = valueRange;
2021-11-02 18:40:26 +08:00
// inShorthand must be serialized by subclasses that use it
this.inShorthand = inShorthand;
}
get type() {
return "cjs require context";
}
2023-04-12 03:22:51 +08:00
/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.range);
write(this.valueRange);
write(this.inShorthand);
super.serialize(context);
}
2023-04-12 03:22:51 +08:00
/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.range = read();
this.valueRange = read();
this.inShorthand = read();
super.deserialize(context);
}
}
makeSerializable(
CommonJsRequireContextDependency,
"webpack/lib/dependencies/CommonJsRequireContextDependency"
);
2021-05-11 15:31:46 +08:00
CommonJsRequireContextDependency.Template =
ContextDependencyTemplateAsRequireCall;
module.exports = CommonJsRequireContextDependency;