release: WRNexusJS 0.6.0
This commit is contained in:
@@ -54,6 +54,14 @@ function stringLiteral(value) {
|
||||
return match ? (match[1] ?? match[2] ?? match[3]) : null;
|
||||
}
|
||||
|
||||
function declaredOptions(type) {
|
||||
const value = String(type || "").trim();
|
||||
if (!value) return [];
|
||||
const parts = value.split("|").map((part) => part.trim());
|
||||
if (!parts.every((part) => /^(?:"[^"]*"|'[^']*')$/.test(part))) return [];
|
||||
return parts.map((part) => part.slice(1, -1));
|
||||
}
|
||||
|
||||
function inferOptions(source, propName) {
|
||||
const escaped = propName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const options = new Set();
|
||||
@@ -77,22 +85,27 @@ function parseComponentMetadata(source, uri = null) {
|
||||
const bodyEnd = closingBrace === -1 ? source.length : closingBrace;
|
||||
const body = source.slice(openingBrace + 1, bodyEnd);
|
||||
const linePattern =
|
||||
/^(?:\s*\/\/\s*@required\s*\r?\n)?\s*([A-Za-z_$][\w$]*)(?:\s*:\s*([^=\r\n]+?))?(?:\s*=\s*(.*?))?\s*$/gm;
|
||||
/^(?:\s*\/\/\s*@required\s*\r?\n)?\s*([A-Za-z_$][\w$]*)(\?)?(?:\s*:\s*([^=\r\n]+?))?(?:\s*=\s*(.*?))?\s*$/gm;
|
||||
let propMatch;
|
||||
while ((propMatch = linePattern.exec(body)) !== null) {
|
||||
const annotation = propMatch[2] && propMatch[2].trim();
|
||||
const hasDefault = propMatch[3] !== undefined;
|
||||
const defaultValue = hasDefault ? propMatch[3] : "undefined";
|
||||
const optional = Boolean(propMatch[2]);
|
||||
const annotation = propMatch[3] && propMatch[3].trim();
|
||||
const hasDefault = propMatch[4] !== undefined;
|
||||
const defaultValue = hasDefault ? propMatch[4] : "undefined";
|
||||
const name = propMatch[1];
|
||||
props.push({
|
||||
name,
|
||||
defaultValue,
|
||||
required:
|
||||
!hasDefault ||
|
||||
defaultValue.trim() === "undefined" ||
|
||||
/^\s*\/\/\s*@required/m.test(propMatch[0]),
|
||||
!optional &&
|
||||
(!hasDefault ||
|
||||
defaultValue.trim() === "undefined" ||
|
||||
/^\s*\/\/\s*@required/m.test(propMatch[0])),
|
||||
type: annotation || inferType(defaultValue),
|
||||
options: inferOptions(source, name),
|
||||
options:
|
||||
declaredOptions(annotation).length > 0
|
||||
? declaredOptions(annotation)
|
||||
: inferOptions(source, name),
|
||||
});
|
||||
}
|
||||
const eventPattern = /^\s*@event\s+([A-Za-z_$][\w$]*)\s*=\s*function\s*$/gm;
|
||||
@@ -100,6 +113,22 @@ function parseComponentMetadata(source, uri = null) {
|
||||
while ((eventMatch = eventPattern.exec(body)) !== null) events.push(eventMatch[1]);
|
||||
}
|
||||
|
||||
const outputsKeyword = /\boutputs\s*\{/.exec(source.slice(declaration.index));
|
||||
if (outputsKeyword) {
|
||||
const start = declaration.index + outputsKeyword.index;
|
||||
const openingBrace = source.indexOf("{", start);
|
||||
const closingBrace = findMatchingBrace(source, openingBrace);
|
||||
const outputBody = source.slice(
|
||||
openingBrace + 1,
|
||||
closingBrace === -1 ? source.length : closingBrace,
|
||||
);
|
||||
const outputPattern = /(?:^|\s)([A-Za-z_$][\w$]*)\s*\(/g;
|
||||
let outputMatch;
|
||||
while ((outputMatch = outputPattern.exec(outputBody)) !== null) {
|
||||
if (!events.includes(outputMatch[1])) events.push(outputMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return { kind: declaration[1], name: declaration[2], props, events, uri };
|
||||
}
|
||||
|
||||
@@ -243,6 +272,7 @@ function validateComponentTags(source, components) {
|
||||
|
||||
module.exports = {
|
||||
attributeValueType,
|
||||
declaredOptions,
|
||||
inferType,
|
||||
runtimeType,
|
||||
isTypeCompatible,
|
||||
|
||||
Reference in New Issue
Block a user