( loopPath: NodePath<t.Loop>, captured: string[], updatedBindingsUsages: Map<string, NodePath<t.Identifier>[]>, )
| 306 | } |
| 307 | |
| 308 | export function wrapLoopBody( |
| 309 | loopPath: NodePath<t.Loop>, |
| 310 | captured: string[], |
| 311 | updatedBindingsUsages: Map<string, NodePath<t.Identifier>[]>, |
| 312 | ) { |
| 313 | const loopNode = loopPath.node; |
| 314 | const state: CompletionsAndVarsState = { |
| 315 | breaksContinues: [], |
| 316 | returns: [], |
| 317 | labelsStack: [], |
| 318 | labellessBreakTargets: 0, |
| 319 | labellessContinueTargets: 0, |
| 320 | vars: [], |
| 321 | loopNode, |
| 322 | }; |
| 323 | loopPath.traverse( |
| 324 | { |
| 325 | Function(path) { |
| 326 | path.skip(); |
| 327 | }, |
| 328 | LabeledStatement: { |
| 329 | enter({ node }, state) { |
| 330 | state.labelsStack.push(node.label.name); |
| 331 | }, |
| 332 | exit({ node }, state) { |
| 333 | const popped = state.labelsStack.pop(); |
| 334 | if (popped !== node.label.name) { |
| 335 | throw new Error( |
| 336 | "Assertion failure. Please report this bug to Babel.", |
| 337 | ); |
| 338 | } |
| 339 | }, |
| 340 | }, |
| 341 | Loop: { |
| 342 | enter(_, state) { |
| 343 | state.labellessContinueTargets++; |
| 344 | state.labellessBreakTargets++; |
| 345 | }, |
| 346 | exit(_, state) { |
| 347 | state.labellessContinueTargets--; |
| 348 | state.labellessBreakTargets--; |
| 349 | }, |
| 350 | }, |
| 351 | SwitchStatement: { |
| 352 | enter(_, state) { |
| 353 | state.labellessBreakTargets++; |
| 354 | }, |
| 355 | exit(_, state) { |
| 356 | state.labellessBreakTargets--; |
| 357 | }, |
| 358 | }, |
| 359 | "BreakStatement|ContinueStatement"( |
| 360 | path: NodePath<t.BreakStatement | t.ContinueStatement>, |
| 361 | state, |
| 362 | ) { |
| 363 | const { label } = path.node; |
| 364 | if (label) { |
| 365 | if (state.labelsStack.includes(label.name)) return; |
no test coverage detected