1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! `compmd-components`: the component reader of [CompMD](https://compmd.dev/) ([the language server], decision 11,
//! Q5): what a host-language component takes, read from its source with `oxc`, for component analysis (spec §7.1,
//! §13.1, W104).
//!
//! It reads what the source states, and nothing it would have to guess: a React component's props from its default
//! export's first parameter (JSX or TSX), a Svelte 5 component's from what its instance script gives `$props()`, each
//! with its type where TypeScript states one a signature's type can be checked against. A component whose props it
//! can't read is left unchecked.
//!
//! ```
//! use compmd::{Ambient, Language, ParseOptions, Processor};
//! use compmd::analysis::ComponentProps;
//! use compmd_components::ComponentReader;
//!
//! let props = ComponentReader.props(Language::Jsx, "export default function Badge({ label }) { return null; }");
//! assert_eq!(props.map(|props| props.props.len()), Some(1));
//!
//! let text = "```jsx component=badge\nexport default function Badge({ label }) { return null; }\n```\n\n```compmd component=badge signature\nparams:\n label: string\n size: number\n```\n";
//! let resolved = Processor::new("a.comp.md", text).parse(&ParseOptions::default()).analysing(ComponentReader).resolve((), (), &Ambient::default());
//! assert_eq!(resolved.diagnostics()[0].message, "the signature declares `size`, which a.comp.md has no prop for (`size`)");
//! ```
//!
//! [the language server]: https://github.com/comp-markdown/compmd/blob/main/docs/language-server.md
use Language;
use ;
/// The component reader: JSX, TSX and Svelte 5. Plain JavaScript and TypeScript components take no props from a
/// binding (spec §7.6), so it reads none.
;