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-07 01:18:24 +08:00
|
|
|
"use strict";
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2018-10-11 18:39:14 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2017-01-07 01:18:24 +08:00
|
|
|
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
|
|
|
|
2017-01-07 01:18:24 +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
|
2023-05-22 06:58:24 +08:00
|
|
|
* @param {string} context context
|
|
|
|
*/
|
2022-03-28 23:51:48 +08:00
|
|
|
constructor(options, range, valueRange, inShorthand, context) {
|
|
|
|
super(options, context);
|
2018-10-11 18:39:14 +08:00
|
|
|
|
2017-01-07 01:18:24 +08:00
|
|
|
this.range = range;
|
|
|
|
this.valueRange = valueRange;
|
2021-11-02 18:40:26 +08:00
|
|
|
// inShorthand must be serialized by subclasses that use it
|
2021-10-21 14:52:07 +08:00
|
|
|
this.inShorthand = inShorthand;
|
2017-01-07 01:18:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "cjs require context";
|
|
|
|
}
|
2018-10-11 18:39:14 +08:00
|
|
|
|
2023-04-12 03:22:51 +08:00
|
|
|
/**
|
|
|
|
* @param {ObjectSerializerContext} context context
|
|
|
|
*/
|
2018-10-11 18:39:14 +08:00
|
|
|
serialize(context) {
|
|
|
|
const { write } = context;
|
|
|
|
|
|
|
|
write(this.range);
|
|
|
|
write(this.valueRange);
|
2021-10-21 14:52:07 +08:00
|
|
|
write(this.inShorthand);
|
2018-10-11 18:39:14 +08:00
|
|
|
|
|
|
|
super.serialize(context);
|
|
|
|
}
|
|
|
|
|
2023-04-12 03:22:51 +08:00
|
|
|
/**
|
|
|
|
* @param {ObjectDeserializerContext} context context
|
|
|
|
*/
|
2018-10-11 18:39:14 +08:00
|
|
|
deserialize(context) {
|
|
|
|
const { read } = context;
|
|
|
|
|
|
|
|
this.range = read();
|
|
|
|
this.valueRange = read();
|
2021-10-21 14:52:07 +08:00
|
|
|
this.inShorthand = read();
|
2018-10-11 18:39:14 +08:00
|
|
|
|
|
|
|
super.deserialize(context);
|
|
|
|
}
|
2017-01-07 01:18:24 +08:00
|
|
|
}
|
2016-06-24 07:51:52 +08:00
|
|
|
|
2018-10-11 18:39:14 +08:00
|
|
|
makeSerializable(
|
|
|
|
CommonJsRequireContextDependency,
|
|
|
|
"webpack/lib/dependencies/CommonJsRequireContextDependency"
|
|
|
|
);
|
|
|
|
|
2021-05-11 15:31:46 +08:00
|
|
|
CommonJsRequireContextDependency.Template =
|
|
|
|
ContextDependencyTemplateAsRequireCall;
|
2017-01-07 01:18:24 +08:00
|
|
|
|
|
|
|
module.exports = CommonJsRequireContextDependency;
|