77
88const Dependency = require ( "../../graph/Dependency" ) ;
99const makeSerializable = require ( "../../util/makeSerializable" ) ;
10+ const { ImportPhase, ImportPhaseUtils } = require ( "../core/ImportPhase" ) ;
1011const ModuleDependency = require ( "../core/ModuleDependency" ) ;
1112
1213/** @import ContextModule from "../../context/ContextModule" */
@@ -15,8 +16,9 @@ const ModuleDependency = require("../core/ModuleDependency");
1516/** @import ModuleGraph from "../../graph/ModuleGraph" */
1617/** @import { ImportAttributes } from "../../javascript/JavascriptParser" */
1718/** @import { RuntimeSpec } from "../../util/runtime" */
18- /** @typedef {import("../../serialization/ObjectMiddleware").ObjectDeserializerContext<[string | undefined, string, RawReferencedExports | null | undefined, ImportAttributes | undefined, string | undefined]> } ObjectDeserializerContext */
19- /** @typedef {import("../../serialization/ObjectMiddleware").ObjectSerializerContext<[string | undefined, string, RawReferencedExports | null | undefined, ImportAttributes | undefined, string | undefined]> } ObjectSerializerContext */
19+ /** @import { ImportPhaseType } from "../core/ImportPhase" */
20+ /** @typedef {import("../../serialization/ObjectMiddleware").ObjectDeserializerContext<[string | undefined, string, RawReferencedExports | null | undefined, ImportAttributes | undefined, string | undefined, ImportPhaseType]> } ObjectDeserializerContext */
21+ /** @typedef {import("../../serialization/ObjectMiddleware").ObjectSerializerContext<[string | undefined, string, RawReferencedExports | null | undefined, ImportAttributes | undefined, string | undefined, ImportPhaseType]> } ObjectSerializerContext */
2022
2123class ContextElementDependency extends ModuleDependency {
2224 /**
@@ -29,6 +31,7 @@ class ContextElementDependency extends ModuleDependency {
2931 * @param {string= } context context
3032 * @param {ImportAttributes= } attributes import assertions
3133 * @param {string= } contextRequest the request of the context as written by the user, without query and fragment
34+ * @param {ImportPhaseType= } phase import phase
3235 */
3336 constructor (
3437 request ,
@@ -38,7 +41,8 @@ class ContextElementDependency extends ModuleDependency {
3841 referencedExports ,
3942 context ,
4043 attributes ,
41- contextRequest
44+ contextRequest ,
45+ phase = ImportPhase . Evaluation
4246 ) {
4347 super ( request ) ;
4448
@@ -59,6 +63,8 @@ class ContextElementDependency extends ModuleDependency {
5963 this . attributes = attributes ;
6064 /** @type {string | undefined } */
6165 this . _contextRequest = contextRequest || undefined ;
66+ /** @type {ImportPhaseType } */
67+ this . phase = phase ;
6268 }
6369
6470 /**
@@ -92,6 +98,9 @@ class ContextElementDependency extends ModuleDependency {
9298 */
9399 getResourceIdentifier ( ) {
94100 let str = super . getResourceIdentifier ( ) ;
101+ if ( this . phase ) {
102+ str += `|phase${ ImportPhaseUtils . stringify ( this . phase ) } ` ;
103+ }
95104 if ( this . attributes ) {
96105 str += `|attributes${ JSON . stringify ( this . attributes ) } ` ;
97106 }
@@ -149,7 +158,8 @@ class ContextElementDependency extends ModuleDependency {
149158 . write ( this . _category )
150159 . write ( this . referencedExports )
151160 . write ( this . attributes )
152- . write ( this . _contextRequest ) ;
161+ . write ( this . _contextRequest )
162+ . write ( this . phase ) ;
153163 super . serialize ( context ) ;
154164 }
155165
@@ -167,7 +177,9 @@ class ContextElementDependency extends ModuleDependency {
167177 this . attributes = c3 . read ( ) ;
168178 const c4 = c3 . rest ;
169179 this . _contextRequest = c4 . read ( ) ;
170- super . deserialize ( c4 . rest ) ;
180+ const c5 = c4 . rest ;
181+ this . phase = c5 . read ( ) ;
182+ super . deserialize ( c5 . rest ) ;
171183 }
172184}
173185
0 commit comments