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