[6a3a178] | 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 |
|
---|
| 15 | class HarmonyExportHeaderDependency extends NullDependency {
|
---|
| 16 | constructor(range, rangeStatement) {
|
---|
| 17 | super();
|
---|
| 18 | this.range = range;
|
---|
| 19 | this.rangeStatement = rangeStatement;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | get type() {
|
---|
| 23 | return "harmony export header";
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | serialize(context) {
|
---|
| 27 | const { write } = context;
|
---|
| 28 | write(this.range);
|
---|
| 29 | write(this.rangeStatement);
|
---|
| 30 | super.serialize(context);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | deserialize(context) {
|
---|
| 34 | const { read } = context;
|
---|
| 35 | this.range = read();
|
---|
| 36 | this.rangeStatement = read();
|
---|
| 37 | super.deserialize(context);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | makeSerializable(
|
---|
| 42 | HarmonyExportHeaderDependency,
|
---|
| 43 | "webpack/lib/dependencies/HarmonyExportHeaderDependency"
|
---|
| 44 | );
|
---|
| 45 |
|
---|
| 46 | HarmonyExportHeaderDependency.Template = class HarmonyExportDependencyTemplate extends (
|
---|
| 47 | NullDependency.Template
|
---|
| 48 | ) {
|
---|
| 49 | /**
|
---|
| 50 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 51 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 52 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 53 | * @returns {void}
|
---|
| 54 | */
|
---|
| 55 | apply(dependency, source, templateContext) {
|
---|
| 56 | const dep = /** @type {HarmonyExportHeaderDependency} */ (dependency);
|
---|
| 57 | const content = "";
|
---|
| 58 | const replaceUntil = dep.range
|
---|
| 59 | ? dep.range[0] - 1
|
---|
| 60 | : dep.rangeStatement[1] - 1;
|
---|
| 61 | source.replace(dep.rangeStatement[0], replaceUntil, content);
|
---|
| 62 | }
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | module.exports = HarmonyExportHeaderDependency;
|
---|