MCPcopy Create free account
hub / github.com/babel/babel / wrapLoopBody

Function wrapLoopBody

packages/babel-plugin-transform-block-scoping/src/loop.ts:308–581  ·  view source on GitHub ↗
(
  loopPath: NodePath<t.Loop>,
  captured: string[],
  updatedBindingsUsages: Map<string, NodePath<t.Identifier>[]>,
)

Source from the content-addressed store, hash-verified

306}
307
308export 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;

Callers 1

LoopFunction · 0.90

Calls 10

traverseMethod · 0.80
generateUidMethod · 0.80
isFunctionParentMethod · 0.80
isForXStatementMethod · 0.80
removeMethod · 0.80
mapMethod · 0.80
isVariableDeclarationMethod · 0.80
pushMethod · 0.45
hasMethod · 0.45
addCommentMethod · 0.45

Tested by

no test coverage detected