(rootMod, moduleGraph, ctx)
| 180 | * @returns {ConnectionState} the side-effects connection state |
| 181 | */ |
| 182 | const walkSideEffectsIterative = (rootMod, moduleGraph, ctx) => { |
| 183 | const SideEffectDep = getHarmonyImportSideEffectDependency(); |
| 184 | |
| 185 | /** @type {NormalModule[]} */ |
| 186 | const modStack = [rootMod]; |
| 187 | /** @type {Dependency[][]} */ |
| 188 | const depsStack = [rootMod.dependencies]; |
| 189 | const indexStack = [0]; |
| 190 | /** @type {ConnectionState[]} */ |
| 191 | const currentStack = [false]; |
| 192 | rootMod._isEvaluatingSideEffects = true; |
| 193 | |
| 194 | /** |
| 195 | * Result from a just-popped child frame, to be applied to the new |
| 196 | * top's current dep. `undefined` means "no pending; advance". |
| 197 | * @type {ConnectionState | undefined} |
| 198 | */ |
| 199 | let pending; |
| 200 | |
| 201 | while (modStack.length > 0) { |
| 202 | const top = modStack.length - 1; |
| 203 | const topMod = modStack[top]; |
| 204 | const deps = depsStack[top]; |
| 205 | let index = indexStack[top]; |
| 206 | let current = currentStack[top]; |
| 207 | |
| 208 | if (pending !== undefined) { |
| 209 | const state = pending; |
| 210 | pending = undefined; |
| 211 | const dep = deps[index]; |
| 212 | |
| 213 | if (state === true) { |
| 214 | recordSideEffectsBailout(topMod, moduleGraph, dep); |
| 215 | topMod._isEvaluatingSideEffects = false; |
| 216 | // `true` is monotonic — safe to memoize regardless of cycle |
| 217 | // status, matching the direct-bailout branch below. |
| 218 | topMod._sideEffectsStateGraph = moduleGraph; |
| 219 | topMod._sideEffectsStateValue = true; |
| 220 | modStack.pop(); |
| 221 | depsStack.pop(); |
| 222 | indexStack.pop(); |
| 223 | currentStack.pop(); |
| 224 | pending = true; |
| 225 | continue; |
| 226 | } |
| 227 | if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) { |
| 228 | current = ModuleGraphConnection.addConnectionStates(current, state); |
| 229 | } |
| 230 | index++; |
| 231 | } |
| 232 | |
| 233 | let descended = false; |
| 234 | const depCount = deps.length; |
| 235 | while (index < depCount) { |
| 236 | const dep = deps[index]; |
| 237 | /** @type {ConnectionState} */ |
| 238 | let state; |
| 239 |
no test coverage detected