original parserOptions not getting passed to traversed files. Intentional?

Đang mở
#521 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react
Lĩnh vực
documentation, tooling

Hướng nghiên cứu

Bắt đầu tại src/importer/makeFsImporter.js, khoảng dòng 70, và theo dõi cách parserOptions được xử lý đối với các tệp được duyệt so với lệnh gọi parse ban đầu. Xác nhận hành vi bằng các kiểu Flow được import; hoàn tất khi các tùy chọn parser dự định được áp dụng nhất quán hoặc issue ghi lại lý do chúng phải được đặt lại.

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

Mô tả

I'm using react-docgen@next on a project that uses Flow, and I'm utilizing the new makeFsImporter importer to be able to parse imported types. Here's my setup:

value = docgen.parse(source, null, null, {
  importer: docgen.importers.makeFsImporter(),
  filename: path,
  parserOptions: {
    plugins: [
      'jsx',
      'flow',
      'nullishCoalescingOperator',
      'objectRestSpread',
      'optionalCatchBinding',
      'optionalChaining',
      'classProperties',
      'classPrivateProperties',
      'classPrivateMethods',
    ],
  },
});

I am passing parserOptions because the .babelrc that react-docgen finds is not the one I want it to use (it doesn't contain the flow plugin). I noticed that the parserOptions get applied correctly to the original file, but for other files that are traversed, parserOptions are ignored:

https://github.com/reactjs/react-docgen/blob/master/src/importer/makeFsImporter.js#L70

This causes a SyntaxError when traversed files with imported types are parsed because it reverts to the .babelrc that I was avoiding by specifying parserOptions.plugins.

Is the line in makeFsImporter that sets parserOptions: {} intentional? Or can it be removed so that parserOptions specified in the original parse call are applied to other files? I'm happy to open a PR if so.

EDIT: I found a similar question asked when this code was introduced: https://github.com/reactjs/react-docgen/pull/352/files/8c0a15fcae4053b1d2115bd7dbd24252cf70b228#r287538448.

Ngôn ngữ chính
TypeScript
Star
3.8k
Fork
316
Merge trung bình
3 giờ 28 phút
Pull request đã merge (30 ngày)
6

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 reactjs/react-docgen

Tất cả issue của reactjs/react-docgen

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.