Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ export abstract class PrimitiveComponent<
doInitialOptimizeSelectorCache() {
if (!this.isSubcircuit) return
const ports = this.selectAll("port")
const isValidShorthandName = (name: string) =>
/^[A-Za-z_][A-Za-z0-9_-]*$/.test(name)

for (const port of ports) {
// For ports inside primitive containers (like Symbol), use getParentNormalComponent
Expand All @@ -910,6 +912,12 @@ export abstract class PrimitiveComponent<
`.${parentAlias} > .${portAlias}`,
`.${parentAlias} .${portAlias}`,
]
if (
isValidShorthandName(parentAlias) &&
isValidShorthandName(portAlias)
) {
selectors.push(`${parentAlias}.${portAlias}`)
}
for (const selector of selectors) {
const ar = this._cachedSelectAllQueries.get(selector)
if (ar) {
Expand Down
47 changes: 47 additions & 0 deletions tests/components/base-components/shorthand-selector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,50 @@ test("shorthand selector errors use original selector", () => {
'Could not find port for selector "R1.3". Component "R1" found, but does not have pin "3". It has [pin1, anode, pos, left, 1, pin2, cathode, neg, right, 2]',
)
})

test("shorthand selectors resolve ports nested in custom symbol", async () => {
const { circuit } = getTestFixture()

const GenericSymbol = () => (
<symbol name="GenericSymbol" width={4} height={4}>
<port
name="1"
pinNumber={1}
direction="right"
schStemLength={0.5}
schX={2}
schY={0}
/>
</symbol>
)

circuit.add(
<board width="10mm" height="10mm">
<chip
name="U1"
symbol={<GenericSymbol />}
footprint={
<footprint>
<platedhole
portHints={["1"]}
pcbX="0mm"
pcbY="0mm"
outerDiameter="1.3mm"
holeDiameter="0.78mm"
shape="circle"
/>
</footprint>
}
/>
<trace from="U1.pin1" to="net.GND" />
</board>,
)

await circuit.renderUntilSettled()

const circuitJson = circuit.getCircuitJson()
const traceErrors = circuitJson.filter(
(c) => c.type === "source_trace_not_connected_error",
)
expect(traceErrors.length).toBe(0)
})