1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const makeSerializable = require("../util/makeSerializable");
|
---|
9 | const ContextDependency = require("./ContextDependency");
|
---|
10 | const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
---|
11 |
|
---|
12 | /** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
---|
13 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
14 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
15 |
|
---|
16 | class CommonJsRequireContextDependency extends ContextDependency {
|
---|
17 | /**
|
---|
18 | * @param {TODO} options options for the context module
|
---|
19 | * @param {Range} range location in source code
|
---|
20 | * @param {Range | undefined} valueRange location of the require call
|
---|
21 | * @param {boolean | string } inShorthand true or name
|
---|
22 | * @param {string} context context
|
---|
23 | */
|
---|
24 | constructor(options, range, valueRange, inShorthand, context) {
|
---|
25 | super(options, context);
|
---|
26 |
|
---|
27 | this.range = range;
|
---|
28 | this.valueRange = valueRange;
|
---|
29 | // inShorthand must be serialized by subclasses that use it
|
---|
30 | this.inShorthand = inShorthand;
|
---|
31 | }
|
---|
32 |
|
---|
33 | get type() {
|
---|
34 | return "cjs require context";
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * @param {ObjectSerializerContext} context context
|
---|
39 | */
|
---|
40 | serialize(context) {
|
---|
41 | const { write } = context;
|
---|
42 |
|
---|
43 | write(this.range);
|
---|
44 | write(this.valueRange);
|
---|
45 | write(this.inShorthand);
|
---|
46 |
|
---|
47 | super.serialize(context);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @param {ObjectDeserializerContext} context context
|
---|
52 | */
|
---|
53 | deserialize(context) {
|
---|
54 | const { read } = context;
|
---|
55 |
|
---|
56 | this.range = read();
|
---|
57 | this.valueRange = read();
|
---|
58 | this.inShorthand = read();
|
---|
59 |
|
---|
60 | super.deserialize(context);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | makeSerializable(
|
---|
65 | CommonJsRequireContextDependency,
|
---|
66 | "webpack/lib/dependencies/CommonJsRequireContextDependency"
|
---|
67 | );
|
---|
68 |
|
---|
69 | CommonJsRequireContextDependency.Template =
|
---|
70 | ContextDependencyTemplateAsRequireCall;
|
---|
71 |
|
---|
72 | module.exports = CommonJsRequireContextDependency;
|
---|