@tscircuit/core 0.0.498 → 0.0.499

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +41 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4646,16 +4646,49 @@ var Trace2 = class extends PrimitiveComponent2 {
4646
4646
  }));
4647
4647
  for (const { selector, port } of portsWithSelectors) {
4648
4648
  if (!port) {
4649
- const parentSelector = selector.replace(/(\> )?[^ ]+$/, "");
4650
- const targetComponent = this.getSubcircuit().selectOne(parentSelector);
4649
+ let parentSelector;
4650
+ let portToken;
4651
+ const dotIndex = selector.lastIndexOf(".");
4652
+ if (dotIndex !== -1 && dotIndex > selector.lastIndexOf(" ")) {
4653
+ parentSelector = selector.slice(0, dotIndex);
4654
+ portToken = selector.slice(dotIndex + 1);
4655
+ } else {
4656
+ const match = selector.match(/^(.*[ >])?([^ >]+)$/);
4657
+ parentSelector = match?.[1]?.trim() ?? "";
4658
+ portToken = match?.[2] ?? selector;
4659
+ }
4660
+ let targetComponent = parentSelector ? this.getSubcircuit().selectOne(parentSelector) : null;
4661
+ if (!targetComponent && parentSelector && !/[.#\[]/.test(parentSelector)) {
4662
+ targetComponent = this.getSubcircuit().selectOne(`.${parentSelector}`);
4663
+ }
4651
4664
  if (!targetComponent) {
4652
- this.renderError(`Could not find port for selector "${selector}"`);
4665
+ if (parentSelector) {
4666
+ this.renderError(
4667
+ `Could not find port for selector "${selector}". Component "${parentSelector}" not found`
4668
+ );
4669
+ } else {
4670
+ this.renderError(`Could not find port for selector "${selector}"`);
4671
+ }
4653
4672
  } else {
4673
+ const ports = targetComponent.children.filter(
4674
+ (c) => c.componentName === "Port"
4675
+ );
4676
+ const portLabel = portToken.includes(".") ? portToken.split(".").pop() ?? "" : portToken;
4677
+ const portNames = ports.map((c) => c.getNameAndAliases()).flat();
4678
+ const hasCustomLabels = portNames.some(
4679
+ (n) => !/^(pin\d+|\d+)$/.test(n)
4680
+ );
4681
+ const labelList = Array.from(new Set(portNames)).join(", ");
4682
+ let detail;
4683
+ if (ports.length === 0) {
4684
+ detail = "It has no ports";
4685
+ } else if (!hasCustomLabels) {
4686
+ detail = `It has ${ports.length} pins and no pinLabels (consider adding pinLabels)`;
4687
+ } else {
4688
+ detail = `It has [${labelList}]`;
4689
+ }
4654
4690
  this.renderError(
4655
- `Could not find port for selector "${selector}" (did you forget to include the pin name?)
4656
- searched component ${targetComponent.getString()}, which has ports: ${targetComponent.children.filter((c) => c.componentName === "Port").map(
4657
- (c) => `${c.getString()}(${c.getNameAndAliases().join(",")})`
4658
- ).join(" & ")}`
4691
+ `Could not find port for selector "${selector}". Component "${targetComponent.props.name ?? parentSelector}" found, but does not have pin "${portLabel}". ${detail}`
4659
4692
  );
4660
4693
  }
4661
4694
  }
@@ -10334,7 +10367,7 @@ import { identity as identity4 } from "transformation-matrix";
10334
10367
  var package_default = {
10335
10368
  name: "@tscircuit/core",
10336
10369
  type: "module",
10337
- version: "0.0.497",
10370
+ version: "0.0.498",
10338
10371
  types: "dist/index.d.ts",
10339
10372
  main: "dist/index.js",
10340
10373
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.498",
4
+ "version": "0.0.499",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",