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

Function wrapLoopBody

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

Source from the content-addressed store, hash-verified

295}
296
297export 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;

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