normalizePropName strips `#` characters from Figma property names instead of only the `#id` suffix

Đang mở Phù hợp với người mới
#419 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
developer-experience

Hướng nghiên cứu

Bắt đầu từ normalizePropName trong cli/src/connect/create_template.ts và cli/src/connect/helpers.ts, nơi dùng /#[0-9:]*/g, rồi so sánh với normalizePropKey trong cli/src/connect/property_combinations.ts và getPropName trong cli/src/connect/validation.ts, các hàm này chỉ loại bỏ hậu tố ID #<digits>:<digits>. Tái hiện lỗi bằng các bước mock.json trong issue. Hoàn thành khi "Step #1#12:1" cho ra "Step #1", "C# Snippet#4:5" cho ra "C# Snippet" và xung đột Step không còn nữa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

figma connect create and client.getComponents() strip every # (and any following digits or colons) from Figma component property names instead of removing only the trailing #<digits>:<digits> property ID suffix.

Reproduction
mkdir repro && cd repro
npm init -y
npm install @figma/[email protected]

cat > mock.json << 'EOF'
{
  "document": {
    "id": "0:0",
    "name": "Document",
    "type": "DOCUMENT",
    "children": [{
      "id": "0:1",
      "name": "Page 1",
      "type": "CANVAS",
      "children": [{
        "id": "1:2",
        "name": "Stepper",
        "type": "COMPONENT_SET",
        "componentPropertyDefinitions": {
          "Step #1#12:1": { "type": "BOOLEAN", "defaultValue": true },
          "Step #2#12:2": { "type": "BOOLEAN", "defaultValue": false },
          "C# Snippet#4:5": { "type": "TEXT", "defaultValue": "x" },
          "Heading #1": { "type": "VARIANT", "defaultValue": "Small", "variantOptions": ["Small", "Large"] }
        },
        "children": []
      }]
    }]
  }
}
EOF

FIGMA_ACCESS_TOKEN=test CODE_CONNECT_MOCK_CREATE_API_RESPONSE=mock.json \
  npx figma connect create --skip-update-check "https://www.figma.com/design/abc/Test?node-id=1-2"
cat Stepper.figma.ts
Actual output (Stepper.figma.ts)
const step1 = figma.selectedInstance.getBoolean("Step ")
const step2 = figma.selectedInstance.getBoolean("Step ")
const cSnippet = figma.selectedInstance.getString("C Snippet")
const heading = figma.selectedInstance.getEnum("Heading ", {
  Small: "small",
  Large: "large",
})
Expected output
const step1 = figma.selectedInstance.getBoolean("Step #1")
const step2 = figma.selectedInstance.getBoolean("Step #2")
const cSnippet = figma.selectedInstance.getString("C# Snippet")
const heading1 = figma.selectedInstance.getEnum("Heading #1", {
  Small: "small",
  Large: "large",
})

normalizePropName in cli/src/connect/create_template.ts and cli/src/connect/helpers.ts (also used by client.getComponents() in cli/src/client/figma_client.ts, where "Step #1#12:1" and "Step #2#12:2" collide on "Step ") uses /#[0-9:]*/g (generateCodePropName also uses /#[0-9:]+$/g on variant keys that have no ID suffix), whereas normalizePropKey in cli/src/connect/property_combinations.ts and getPropName in cli/src/connect/validation.ts strip only the #<digits>:<digits> ID suffix.

Versions
  • @figma/code-connect: 2.1.0, main (d856baa)
  • Node.js: v26.13.0

Credit: https://ucsbplse.github.io/

Ngôn ngữ chính
TypeScript
Star
1.6k
Fork
126
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của figma/code-connect

Tất cả issue của figma/code-connect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.