feat: add typed WRN declarations
This commit is contained in:
@@ -21,16 +21,19 @@ function block(source, keyword) {
|
||||
function propsOf(source) {
|
||||
const props = [];
|
||||
for (const line of block(source, "props").split(/\r?\n/)) {
|
||||
const match = line.trim().match(/^([A-Za-z][A-Za-z0-9_]*)\s*(?:=\s*(.+))?$/);
|
||||
const match = line
|
||||
.trim()
|
||||
.match(/^([A-Za-z][A-Za-z0-9_]*)(?:\s*:\s*([^=]+?))?\s*(?:=\s*(.+))?$/);
|
||||
if (!match) continue;
|
||||
const [, name, rawDefault] = match;
|
||||
const [, name, annotation, rawDefault] = match;
|
||||
const value = rawDefault?.trim();
|
||||
const type =
|
||||
value === "true" || value === "false"
|
||||
annotation?.trim() ||
|
||||
(value === "true" || value === "false"
|
||||
? "boolean"
|
||||
: /^-?\d+(?:\.\d+)?$/.test(value ?? "")
|
||||
? "number"
|
||||
: "string";
|
||||
: "string");
|
||||
props.push({ name, type, required: value === undefined, default: value ?? null });
|
||||
}
|
||||
return props;
|
||||
|
||||
Reference in New Issue
Block a user