Skip to content

fix: escape manufacturerPartNumber safely in generated TSX (closes #552) - #553

Open
tcsenpai wants to merge 1 commit into
tscircuit:mainfrom
tcsenpai:fix/manufacturer-part-number-quote-escaping
Open

fix: escape manufacturerPartNumber safely in generated TSX (closes #552)#553
tcsenpai wants to merge 1 commit into
tscircuit:mainfrom
tcsenpai:fix/manufacturer-part-number-quote-escaping

Conversation

@tcsenpai

@tcsenpai tcsenpai commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #552.

generateTypescriptComponent interpolated manufacturerPartNumber directly into a plain double-quoted JSX attribute for every generated component type (chip, diode, led, pushbutton, switch, capacitor, resistor, inductor, crystal, connector). JSX quoted attributes do not interpret JavaScript escape sequences, so a manufacturer part number containing a double quote produced an unterminated string literal, making the generated TSX fail to parse.

Fix

Added a small renderJsxStringAttr helper in generate-typescript-component.ts:

  • If the value contains no ", \, {, or }, it keeps the existing plain attr="value" form, so output for ordinary part numbers is unchanged and all existing inline snapshots stay green.
  • Otherwise it falls back to a JSX expression container with JSON.stringify escaping, matching the convention already used elsewhere in this file for supplierPartNumbers and pin labels.

Testing

Added tests/convert-to-ts/manufacturer-part-number-quote.test.ts, which mutates an existing fixture's manufacturer part number to include a double quote, converts it to TSX, and asserts the result parses without syntax errors using the TypeScript compiler's source-file parser. Confirmed this test fails on main and passes with the fix.

Before pushing:

  • bun run format
  • bun run format:check
  • bunx tsc --noEmit
  • bun test (225 pass, 0 fail)

This report and fix were prepared with AI assistance.

…circuit#552)

manufacturerPartNumber was interpolated directly into a plain
double-quoted JSX attribute for every generated component type. JSX
quoted attributes do not interpret JavaScript escape sequences, so a
manufacturer part number containing a double quote produced an
unterminated string literal and invalid TSX.

Added a renderJsxStringAttr helper that keeps the existing plain
attr="value" form when the value is safe, and falls back to a JSX
expression container with JSON.stringify escaping otherwise. This
keeps existing snapshots stable for ordinary part numbers while fixing
the escaping for part numbers containing quotes, backslashes, or
braces.

Added a regression test that fails on main and passes with the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: manufacturerPartNumber with a double quote generates invalid TSX

1 participant