[79a0317] | 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 NullDependency = require("./NullDependency");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
| 12 | /** @typedef {import("../Dependency")} Dependency */
|
---|
| 13 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 14 | /** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
---|
| 15 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 16 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 17 |
|
---|
| 18 | class HarmonyExportHeaderDependency extends NullDependency {
|
---|
| 19 | /**
|
---|
| 20 | * @param {Range | false} range range
|
---|
| 21 | * @param {Range} rangeStatement range statement
|
---|
| 22 | */
|
---|
| 23 | constructor(range, rangeStatement) {
|
---|
| 24 | super();
|
---|
| 25 | this.range = range;
|
---|
| 26 | this.rangeStatement = rangeStatement;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | get type() {
|
---|
| 30 | return "harmony export header";
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @param {ObjectSerializerContext} context context
|
---|
| 35 | */
|
---|
| 36 | serialize(context) {
|
---|
| 37 | const { write } = context;
|
---|
| 38 | write(this.range);
|
---|
| 39 | write(this.rangeStatement);
|
---|
| 40 | super.serialize(context);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * @param {ObjectDeserializerContext} context context
|
---|
| 45 | */
|
---|
| 46 | deserialize(context) {
|
---|
| 47 | const { read } = context;
|
---|
| 48 | this.range = read();
|
---|
| 49 | this.rangeStatement = read();
|
---|
| 50 | super.deserialize(context);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | makeSerializable(
|
---|
| 55 | HarmonyExportHeaderDependency,
|
---|
| 56 | "webpack/lib/dependencies/HarmonyExportHeaderDependency"
|
---|
| 57 | );
|
---|
| 58 |
|
---|
| 59 | HarmonyExportHeaderDependency.Template = class HarmonyExportDependencyTemplate extends (
|
---|
| 60 | NullDependency.Template
|
---|
| 61 | ) {
|
---|
| 62 | /**
|
---|
| 63 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 64 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 65 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 66 | * @returns {void}
|
---|
| 67 | */
|
---|
| 68 | apply(dependency, source, templateContext) {
|
---|
| 69 | const dep = /** @type {HarmonyExportHeaderDependency} */ (dependency);
|
---|
| 70 | const content = "";
|
---|
| 71 | const replaceUntil = dep.range
|
---|
| 72 | ? dep.range[0] - 1
|
---|
| 73 | : dep.rangeStatement[1] - 1;
|
---|
| 74 | source.replace(dep.rangeStatement[0], replaceUntil, content);
|
---|
| 75 | }
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | module.exports = HarmonyExportHeaderDependency;
|
---|