EXAMPLE 01 • order-pricing.ts

Variable Renaming, Constant Folding & Binding Expressions

Reconstruct mangled identifiers, folded module constants, complex multi-variable expressions, and eliminated dead variables.

OriginalScope (Module, Function, Block)Simple Identifier Bindings (c -> customer)Constant Literal Bindings (0.085 -> TAX_RATE)Complex JS Expression Bindings (d * 0.085 -> taxAmount)Null / Eliminated Variable Bindings (null -> rawAuditToken)
OPEN CHROME DEVTOOLS (F12) FIRST, THEN TRIGGER:
Ready. Click "Run & Pause in Debugger" with DevTools open.

How This Example Works

Production minifiers rename identifiers (customer → c), fold module constants directly into arithmetic (TAX_RATE = 0.085 disappears), eliminate unused variables (rawAuditToken), and inline single-use variables like fullName, isVip, lineTotal, and taxAmount.

With the Scopes proposal, each GeneratedRange provides a values array mapping every variable in its OriginalScope to an arbitrary JavaScript binding expression (or null when optimized out). Chrome DevTools uses this information to reconstruct the Scope sidebar, render inline variable hints, populate autocomplete suggestions with original variable names, and evaluate Conditional Breakpoints and Console expressions via debug evaluate.

What to Try & Verify in DevTools

Scope View

Try:Click "Run & Pause in Debugger" with DevTools open (Sources panel) to pause at debugger; in order-pricing.ts.

  • Local Scope (calculateInvoice): fullName ("Ada Lovelace"), isVip (true), subtotal (250), discountRate (0.15), discountedSubtotal (212.5), and taxAmount (18.0625) are all reconstructed from binding expressions.
  • Module Scope: Folded constants TAX_RATE (0.085), CURRENCY ("USD"), and FREE_SHIPPING_MIN (100) appear in the Module section.
  • Eliminated Variable: rawAuditToken (bound to null) displays cleanly as <unavailable>.
Inline Hints & Popover

Try:While paused in order-pricing.ts, inspect the editor lines 19–34 and hover over variables in the source code.

  • Inline Value Hints: Authored variables (subtotal, discountedSubtotal, grandTotal) show live inline values at the end of their lines.
  • Hover Popovers: Hovering over customer, taxAmount, or TAX_RATE opens an interactive preview evaluated from the source map binding.
Autocomplete

Try:Open the Console drawer (Esc) while paused and type prefixes like disc, tax, FREE_, or fullN.

  • Original Identifiers Suggested: Autocomplete offers discountRate, discountedSubtotal, taxAmount, FREE_SHIPPING_MIN, and fullName directly from the active OriginalScope chain.
Conditional Breakpoints

Try:Right-click line 26 (subtotal += lineTotal;), add a conditional breakpoint item.quantity > 1 && lineTotal < 100, resume (F8), and click "Run & Pause in Debugger" again.

  • Autocomplete in Condition Input: Typing item and lineTotal in the breakpoint dialog offers scope-aware suggestions.
  • Targeted Pause on Item #2: V8 skips item 1 (MECH-KB, qty: 1, lineTotal: 140), pauses inside the Block scope only on item 2 (USB-C-CABLE, qty: 2, lineTotal: 45), and skips item 3.
Debug Evaluate

Try:Copy and run the test expressions below in the DevTools Console while paused.

  • Transparent AST Rewriting: Expressions mixing fullName, taxAmount, shippingFee, and TAX_RATE are automatically rewritten to their underlying bundle.js bindings (c, d * 0.085, etc.) before evaluation.
Other things to try
  • Add a logpoint in the for loop that prints item.sku and lineTotal.
  • Add Watch expressions with folded constants (TAX_RATE, CURRENCY) and step through the loop.
  • Hover variables that were optimized away and check what the popover shows.
  • Toggle the source map scopes experiment and compare the Scope view.

Not sure if it's a DevTools bug? Tab 4. Decoded Scopes shows what the source map actually encodes.

Try in the Console While Paused

While paused, select a frame and evaluate these in the Console (Esc opens the drawer) using the authored names:

`${fullName} (${CURRENCY}): $${grandTotal.toFixed(2)}`
Expected Result: "Ada Lovelace (USD): $230.56"
Combines synthesized expression fullName (c.firstName + ' ' + c.lastName), folded constant CURRENCY ('USD'), and renamed local grandTotal (g).
discountedSubtotal + taxAmount + shippingFee
Expected Result: 230.5625
Evaluates arithmetic across renamed register d (discountedSubtotal) and two non-existent variables (taxAmount -> d * 0.085, shippingFee -> d >= 100 ? 0 : 12.99).
isVip && discountRate === 0.15 && TAX_RATE === 0.085
Expected Result: true
Verifies boolean and numeric expressions using synthesized isVip, discountRate, and module-scoped constant TAX_RATE.