PruneUnusedLabels.ts — react Source File
Architecture documentation for PruneUnusedLabels.ts, a typescript file in the react codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ac9d1354_1036_e3da_7e02_40ce71b820eb["PruneUnusedLabels.ts"] 18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> 18a78965_f593_105b_e5e8_07001321c2ec 4a73a9b9_07eb_502f_14c1_2f045ba2666c["BlockId"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> 4a73a9b9_07eb_502f_14c1_2f045ba2666c c0555545_1ea3_9d37_62ad_521eafe2daa8["ReactiveFunction"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> c0555545_1ea3_9d37_62ad_521eafe2daa8 d2571adf_c2aa_1e5e_5c56_f26810a3829e["ReactiveStatement"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> d2571adf_c2aa_1e5e_5c56_f26810a3829e 97848b70_4205_af8b_cc43_f635e9b08163["ReactiveTerminalStatement"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> 97848b70_4205_af8b_cc43_f635e9b08163 21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> 21609915_b03a_fd75_b58a_4cb86ef9315b af3ace55_db6d_865e_92b9_81486f6af1e7["ReactiveFunctionTransform"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> af3ace55_db6d_865e_92b9_81486f6af1e7 da7ad665_d709_433d_facd_dc3b2c4d34f5["Transformed"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> da7ad665_d709_433d_facd_dc3b2c4d34f5 2435b5f8_41a6_0458_ba88_4479b965455f["visitReactiveFunction"] ac9d1354_1036_e3da_7e02_40ce71b820eb --> 2435b5f8_41a6_0458_ba88_4479b965455f style ac9d1354_1036_e3da_7e02_40ce71b820eb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
BlockId,
ReactiveFunction,
ReactiveStatement,
ReactiveTerminalStatement,
} from '../HIR/HIR';
import {
ReactiveFunctionTransform,
Transformed,
visitReactiveFunction,
} from './visitors';
/*
* Flattens labeled terminals where the label is not reachable, and
* nulls out labels for other terminals where the label is unused.
*/
export function pruneUnusedLabels(fn: ReactiveFunction): void {
const labels: Labels = new Set();
visitReactiveFunction(fn, new Transform(), labels);
}
type Labels = Set<BlockId>;
class Transform extends ReactiveFunctionTransform<Labels> {
override transformTerminal(
stmt: ReactiveTerminalStatement,
state: Labels,
): Transformed<ReactiveStatement> {
this.traverseTerminal(stmt, state);
const {terminal} = stmt;
if (
(terminal.kind === 'break' || terminal.kind === 'continue') &&
terminal.targetKind === 'labeled'
) {
state.add(terminal.target);
}
// Is this terminal reachable via a break/continue to its label?
const isReachableLabel = stmt.label !== null && state.has(stmt.label.id);
if (stmt.terminal.kind === 'label' && !isReachableLabel) {
// Flatten labeled terminals where the label isn't necessary
const block = [...stmt.terminal.block];
const last = block.at(-1);
if (
last !== undefined &&
last.kind === 'terminal' &&
last.terminal.kind === 'break' &&
last.terminal.target === null
) {
block.pop();
}
return {kind: 'replace-many', value: block};
} else {
if (!isReachableLabel && stmt.label != null) {
stmt.label.implicit = true;
}
return {kind: 'keep'};
}
}
}
Domain
Subdomains
Functions
Classes
Types
Dependencies
Source
Frequently Asked Questions
What does PruneUnusedLabels.ts do?
PruneUnusedLabels.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in PruneUnusedLabels.ts?
PruneUnusedLabels.ts defines 1 function(s): pruneUnusedLabels.
What does PruneUnusedLabels.ts depend on?
PruneUnusedLabels.ts imports 9 module(s): BlockId, HIR.ts, ReactiveFunction, ReactiveFunctionTransform, ReactiveStatement, ReactiveTerminalStatement, Transformed, visitReactiveFunction, and 1 more.
Where is PruneUnusedLabels.ts in the architecture?
PruneUnusedLabels.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free