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

Function wrapLoopBody

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

Source from the content-addressed store, hash-verified

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

Callers 1

LoopFunction · 0.90

Calls 14

traverseMethod · 0.80
generateUidMethod · 0.80
isFunctionParentMethod · 0.80
isFunctionMethod · 0.80
isForXStatementMethod · 0.80
removeMethod · 0.80
mapMethod · 0.80
isVariableDeclarationMethod · 0.80
getMethod · 0.65
addHelperMethod · 0.65
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected