Skip to content

String parser fails for led and diode with imperial sizes (e.g., led0402, diode0603) #562

@claw-explorer

Description

@claw-explorer

Summary

The string parser does not correctly handle imperial/metric size codes for led and diode footprints. While res0402 and cap0603 work correctly, led0402 and diode0603 throw an error:

Error: Could not determine required pad dimensions (p, pw, ph)

Root Cause

In src/footprinter.ts, the proxy handler only recognizes res and cap as passive footprints that use imperial/metric sizing:

if (prop === "res" || prop === "cap") {
  target.imperial = v  // correctly sets imperial size
} else {
  target.num_pins = Number.parseFloat(v)  // incorrectly treats as pin count
}

So led0402 gets parsed as { fn: "led", num_pins: 402 } instead of { fn: "led", imperial: "0402" }.

Reproduction

import { fp } from "@tscircuit/footprinter"

// These work:
fp.string("res0402").circuitJson()  // ✓
fp.string("cap0603").circuitJson()  // ✓
fp().led().imperial("0402").circuitJson()  // ✓ (builder API works)

// These fail:
fp.string("led0402").circuitJson()    // ✗ Error
fp.string("led0603").circuitJson()    // ✗ Error
fp.string("diode0402").circuitJson()  // ✗ Error
fp.string("diode0805").circuitJson()  // ✗ Error

Expected Behavior

All four passive footprint types (res, cap, led, diode) should support the same <name><imperial_size> string syntax, since they all delegate to the same passive() function.

Impact

Users cannot use standard footprint strings for LED and diode passive packages. They must use the builder API instead, which is inconsistent with the res/cap behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions