123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- "use strict";
- const DependencyTemplate = require("../DependencyTemplate");
- const InitFragment = require("../InitFragment");
- const makeSerializable = require("../util/makeSerializable");
- const NullDependency = require("./NullDependency");
- class CachedConstDependency extends NullDependency {
-
- constructor(expression, range, identifier) {
- super();
- this.expression = expression;
- this.range = range;
- this.identifier = identifier;
- this._hashUpdate = undefined;
- }
-
- _createHashUpdate() {
- return `${this.identifier}${this.range}${this.expression}`;
- }
-
- updateHash(hash, context) {
- if (this._hashUpdate === undefined)
- this._hashUpdate = this._createHashUpdate();
- hash.update(this._hashUpdate);
- }
-
- serialize(context) {
- const { write } = context;
- write(this.expression);
- write(this.range);
- write(this.identifier);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.expression = read();
- this.range = read();
- this.identifier = read();
- super.deserialize(context);
- }
- }
- makeSerializable(
- CachedConstDependency,
- "webpack/lib/dependencies/CachedConstDependency"
- );
- CachedConstDependency.Template = class CachedConstDependencyTemplate extends (
- DependencyTemplate
- ) {
-
- apply(
- dependency,
- source,
- { runtimeTemplate, dependencyTemplates, initFragments }
- ) {
- const dep = (dependency);
- initFragments.push(
- new InitFragment(
- `var ${dep.identifier} = ${dep.expression};\n`,
- InitFragment.STAGE_CONSTANTS,
- 0,
- `const ${dep.identifier}`
- )
- );
- if (typeof dep.range === "number") {
- source.insert(dep.range, dep.identifier);
- return;
- }
- source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
- }
- };
- module.exports = CachedConstDependency;
|